1.7.1 • Published 3 months ago

jb-modal v1.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

jb-modal

Published on webcomponents.org GitHub license NPM Downloads

modal web component with features:

  • framework free so you can use it anywhere
  • customizable content & style
  • support typescript
  • auto close on background click
  • you can add custom route history in browser
  • back button handler to just close the modal instead of real back
  • keep modal open in case of page refresh (by just provide an id)

Demo & Sample
in github: https://javadbat.github.io/jb-modal/

using with JS frameworks

to use this component in react see jb-modal/react;

install

npm i jb-modal

usage

<jb-modal is-open="true">
    <div slot="content">modal content</div>
</jb-modal>

auto close on background click

document.querySelector('jb-modal').config.autoCloseOnBackgroundClick = true;

keep modal state

if you want your modal to keep open when user refresh the page or you want capture back button in mobile when modal is open you just need to provide an id attribute.

<jb-modal is-open="true" id="Something">
</jb-modal>

events

//when web-component load and you can access modal logic
document.querySelector('jb-modal').addEventListener("load",(e)=>{/*your function*/});
// when modal load and initiated completely 
document.querySelector('jb-modal').addEventListener("init",(e)=>{/*your function*/});
// when page refresh and modal open by default because of url 
document.querySelector('jb-modal').addEventListener("urlOpen",(e)=>{/*your function*/});
// when modal closed
document.querySelector('jb-modal').addEventListener("close",(e)=>{
    // could be "BACKGROUND_CLICK"  "HISTORY_BACK_EVENT" "CLOSE_BUTTON_CLICK"
    const closeType = e.detail.eventType 
    /*your function*/
});

customize modal look

you can customize modal look by following css properties | css variable name | description | | ------------- | ------------- | | --jb-modal-bg-color | modal content background color default is black #fff | | --jb-modal-back-bg-color | modal back background color | | --jb-modal-border-radius | modal border-radius default 24px | | --jb-modal-border-radius-mobile | modal border-radius on mobile default is 24px 24px 0 0 |

Other Related Docs:

1.7.1

3 months ago

1.7.0

5 months ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago