jb-modal 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -2
- package/dist/jb-modal.cjs.js +2 -0
- package/dist/jb-modal.cjs.js.br +0 -0
- package/dist/jb-modal.cjs.js.gz +0 -0
- package/dist/jb-modal.cjs.js.map +1 -0
- package/dist/{JBModal.d.ts → jb-modal.d.ts} +8 -7
- package/dist/jb-modal.js +2 -0
- package/dist/jb-modal.js.br +0 -0
- package/dist/jb-modal.js.gz +0 -0
- package/dist/jb-modal.js.map +1 -0
- package/dist/jb-modal.umd.js +2 -0
- package/dist/jb-modal.umd.js.br +0 -0
- package/dist/jb-modal.umd.js.gz +0 -0
- package/dist/jb-modal.umd.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/index.js +1 -1
- package/lib/{JBModal.scss → jb-modal.scss} +1 -1
- package/lib/jb-modal.ts +158 -0
- package/lib/types.ts +9 -0
- package/package.json +9 -3
- package/react/LICENSE +21 -0
- package/react/README.md +82 -0
- package/react/dist/JBModal.cjs.js +2 -0
- package/react/dist/JBModal.cjs.js.map +1 -0
- package/react/dist/JBModal.d.ts +26 -0
- package/react/dist/JBModal.js +2 -0
- package/react/dist/JBModal.js.map +1 -0
- package/react/dist/JBModal.umd.js +2 -0
- package/react/dist/JBModal.umd.js.map +1 -0
- package/react/dist/common/hooks/use-event.d.ts +3 -0
- package/react/dist/common/hooks/useLazyRef.d.ts +4 -0
- package/react/dist/common/hooks/useMobx.d.ts +4 -0
- package/react/dist/common/scripts/device-detection.d.ts +1 -0
- package/react/dist/common/scripts/persian-helper.d.ts +3 -0
- package/react/dist/events-hook.d.ts +18 -0
- package/react/dist/lib/JBModal.d.ts +26 -0
- package/react/dist/lib/events-hook.d.ts +18 -0
- package/react/dist/web-component/jb-modal/react/lib/JBModal.d.ts +26 -0
- package/react/dist/web-component/jb-modal/react/lib/events-hook.d.ts +18 -0
- package/react/index.js +1 -0
- package/react/lib/JBModal.tsx +62 -0
- package/react/lib/events-hook.ts +25 -0
- package/react/package.json +38 -0
- package/react/tsconfig.json +16 -0
- package/dist/JBModal.js +0 -186
- package/dist/JBModal.js.map +0 -1
- package/dist/JBModal.umd.js +0 -196
- package/dist/JBModal.umd.js.map +0 -1
- package/dist/Types.d.ts +0 -4
- package/lib/JBModal.ts +0 -158
- package/lib/Types.ts +0 -4
- package/lib/global.d.ts +0 -11
- /package/lib/{JBModal.html → jb-modal.html} +0 -0
package/README.md
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
# jb-modal
|
|
2
|
+
[](https://www.webcomponents.org/element/jb-modal)
|
|
3
|
+
[](https://raw.githubusercontent.com/javadbat/jb-modal/main/LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/jb-modal)
|
|
5
|
+
|
|
2
6
|
modal web component with features:
|
|
3
7
|
|
|
4
|
-
-
|
|
8
|
+
- framework free so you can use it anywhere
|
|
9
|
+
- customizable content & style
|
|
5
10
|
- support typescript
|
|
6
11
|
- auto close on background click
|
|
7
|
-
- you can add custom route history in browser
|
|
12
|
+
- you can add custom route history in browser
|
|
13
|
+
- back button handler to just close the modal instead of real back
|
|
14
|
+
- keep modal open in case of page refresh (by just provide an id)
|
|
8
15
|
|
|
9
16
|
Demo & Sample
|
|
10
17
|
in github: <https://javadbat.github.io/jb-modal/>
|
|
11
18
|
|
|
19
|
+
## using with JS frameworks
|
|
20
|
+
|
|
21
|
+
to use this component in **react** see [`jb-modal/react`](https://github.com/javadbat/jb-modal/tree/main/react);
|
|
22
|
+
|
|
12
23
|
## install
|
|
13
24
|
|
|
14
25
|
```cmd
|
|
@@ -25,6 +36,33 @@ npm i jb-modal
|
|
|
25
36
|
```js
|
|
26
37
|
document.querySelector('jb-modal').config.autoCloseOnBackgroundClick = true;
|
|
27
38
|
```
|
|
39
|
+
|
|
40
|
+
## keep modal state
|
|
41
|
+
|
|
42
|
+
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.
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<jb-modal is-open="true" id="Something">
|
|
46
|
+
</jb-modal>
|
|
47
|
+
```
|
|
48
|
+
## events
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
//when web-component load and you can access modal logic
|
|
52
|
+
document.querySelector('jb-modal').addEventListener("load",(e)=>{/*your function*/});
|
|
53
|
+
// when modal load and initiated completely
|
|
54
|
+
document.querySelector('jb-modal').addEventListener("init",(e)=>{/*your function*/});
|
|
55
|
+
// when page refresh and modal open by default because of url
|
|
56
|
+
document.querySelector('jb-modal').addEventListener("urlOpen",(e)=>{/*your function*/});
|
|
57
|
+
// when modal closed
|
|
58
|
+
document.querySelector('jb-modal').addEventListener("close",(e)=>{
|
|
59
|
+
// could be "BACKGROUND_CLICK" "HISTORY_BACK_EVENT" "CLOSE_BUTTON_CLICK"
|
|
60
|
+
const closeType = e.detail.eventType
|
|
61
|
+
/*your function*/
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
|
|
28
66
|
## customize modal look
|
|
29
67
|
|
|
30
68
|
you can customize modal look by following css properties
|
|
@@ -34,3 +72,11 @@ you can customize modal look by following css properties
|
|
|
34
72
|
| --jb-modal-back-bg-color | modal back background color |
|
|
35
73
|
| --jb-modal-border-radius | modal border-radius default `24px` |
|
|
36
74
|
| --jb-modal-border-radius-mobile | modal border-radius on mobile default is `24px 24px 0 0` |
|
|
75
|
+
|
|
76
|
+
## Other Related Docs:
|
|
77
|
+
|
|
78
|
+
- see [`jb-modal/react`](https://github.com/javadbat/jb-modal/tree/main/react); if you want to use this component in react
|
|
79
|
+
|
|
80
|
+
- see [All JB Design system Component List](https://github.com/javadbat/design-system/blob/main/docs/component-list.md) for more components
|
|
81
|
+
|
|
82
|
+
- use [Contribution Guide](https://github.com/javadbat/design-system/blob/main/docs/contribution-guide.md) if you want to contribute in this component.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function e(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function t(e,t,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}var n,o,i,a,s=class extends HTMLElement{get id(){const t=this.getAttribute("id")||"";return e(this,i,"f")||t}set id(e){t(this,i,e,"f"),this.checkInitialOpenness()}get isOpen(){return e(this,o,"f")}constructor(){super(),n.add(this),o.set(this,!1),i.set(this,""),this.config={autoCloseOnBackgroundClick:!1},this.initWebComponent()}connectedCallback(){this.callOnLoadEvent(),this.initProp(),this.callOnInitEvent()}callOnLoadEvent(){const e=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(e)}callOnInitEvent(){const e=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(e)}initWebComponent(){const e=this.attachShadow({mode:"open"}),t=document.createElement("template");t.innerHTML='<style>.jb-modal-web-component{position:fixed;top:0;left:0;z-index:var(--jb-modal-z-index, 1);width:100%;height:100%}.jb-modal-web-component.--closed{display:none}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component.--closed .modal-content-wrapper{transform:translateY(100%)}}.jb-modal-web-component.--opened{display:block}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component.--opened .modal-content-wrapper{animation-name:swipe-up;animation-duration:.3s;animation-delay:0s;animation-iteration-count:1;animation-timing-function:ease}}@keyframes swipe-up{0%{transform:translateY(100%)}100%{transform:translateY(0%)}}.jb-modal-web-component .modal-background{position:absolute;top:0;left:0;background-color:var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1));backdrop-filter:blur(10px);z-index:2;width:100%;height:100%}.jb-modal-web-component .modal-content-wrapper{position:absolute;top:0;left:0;z-index:3;width:100%;height:100%;display:flex;align-items:center;justify-content:center;pointer-events:none}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component .modal-content-wrapper{bottom:0;top:initial;align-items:flex-end}}.jb-modal-web-component .modal-content-wrapper .modal-content{pointer-events:all;width:auto;height:auto;background-color:var(--jb-modal-bg-color, #fff);border-radius:var(--jb-modal-border-radius, 24px)}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component .modal-content-wrapper .modal-content{width:100%;height:auto;max-height:calc(100% - 80px);min-height:32px;border-radius:var(--jb-modal-border-radius-mobile, 24px 24px 0 0);overflow-y:auto}}</style>\n<div class="jb-modal-web-component --closed">\r\n <div class="modal-background"></div>\r\n <div class="modal-content-wrapper">\r\n <div class="modal-content">\r\n <slot name="content"></slot>\r\n </div>\r\n </div>\r\n</div>',e.appendChild(t.content.cloneNode(!0)),this.elements={componentWrapper:e.querySelector(".jb-modal-web-component"),background:e.querySelector(".modal-background")}}registerEventListener(){this.elements.background.addEventListener("click",this.onBackgroundClick.bind(this)),window.addEventListener("popstate",e(this,n,"m",a).bind(this))}initProp(){this.registerEventListener()}checkInitialOpenness(){window.location.hash==`#${this.id}`&&(this.triggerUrlOpenEvent(),this.open())}triggerUrlOpenEvent(){const e=new CustomEvent("urlOpen",{bubbles:!0,composed:!0});this.dispatchEvent(e)}static get observedAttributes(){return["is-open","id"]}attributeChangedCallback(e,t,n){this.onAttributeChange(e,n)}onAttributeChange(t,n){switch(t){case"is-open":"true"==n?e(this,o,"f")||this.open():e(this,o,"f")&&this.close();break;case"id":this.id=n}}onBackgroundClick(){this.dispatchCloseEvent("BACKGROUND_CLICK"),this.config.autoCloseOnBackgroundClick&&this.close()}dispatchCloseEvent(e){const t=new CustomEvent("close",{detail:{eventType:e}});this.dispatchEvent(t)}close(){t(this,o,!1,"f"),this.elements.componentWrapper.classList.remove("--opened"),this.elements.componentWrapper.classList.add("--closed");const e=window.history;window.location.hash==`#${this.id}`&&e.go(-1)}open(){if(t(this,o,!0,"f"),this.elements.componentWrapper.classList.remove("--closed"),this.elements.componentWrapper.classList.add("--opened"),this.id){const e=window.history;window.location.hash!=`#${this.id}`&&e.pushState({JBModal:{}},"",`#${this.id}`)}}};o=new WeakMap,i=new WeakMap,n=new WeakSet,a=function(){this.isOpen&&(this.dispatchCloseEvent("HISTORY_BACK_EVENT"),this.config.autoCloseOnBackgroundClick&&this.close())};!customElements.get("jb-modal")&&window.customElements.define("jb-modal",s),exports.JBModalWebComponent=s;
|
|
2
|
+
//# sourceMappingURL=jb-modal.cjs.js.map
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jb-modal.cjs.js","names":[],"sources":["../lib/jb-modal.html","../../../../../../../../../../../Home/NeveshtAfzar/work/Azad/Azad/design-system/design-system/web-component/jb-modal/lib/jb-modal.scss","../../../../../../../../../../../Home/NeveshtAfzar/work/Azad/Azad/design-system/design-system/node_modules/jb-core/styles/medias.scss","../lib/jb-modal.ts"],"sourcesContent":["<div class=\"jb-modal-web-component --closed\">\r\n <div class=\"modal-background\"></div>\r\n <div class=\"modal-content-wrapper\">\r\n <div class=\"modal-content\">\r\n <slot name=\"content\"></slot>\r\n </div>\r\n </div>\r\n</div>","@use '~jb-core/styles/medias.scss' as *;\r\n.jb-modal-web-component {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n z-index: var(--jb-modal-z-index, 1);\r\n width: 100%;\r\n height: 100%;\r\n &.--closed{\r\n display: none;\r\n .modal-content-wrapper{\r\n @include mobile-tablet{\r\n transform: translateY(100%);\r\n \r\n }\r\n }\r\n }\r\n &.--opened{\r\n display: block;\r\n .modal-content-wrapper{\r\n @include mobile-tablet{\r\n // transform: translateY(0%);\r\n animation-name: swipe-up;\r\n animation-duration: 0.3s;\r\n animation-delay: 0s;\r\n animation-iteration-count: 1;\r\n animation-timing-function: ease;\r\n }\r\n }\r\n \r\n }\r\n @keyframes swipe-up{\r\n 0%{\r\n transform: translateY(100%);\r\n }\r\n 100%{\r\n transform: translateY(0%);\r\n }\r\n }\r\n .modal-background {\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n background-color:var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1)) ;\r\n backdrop-filter: blur(10px);\r\n z-index: 2;\r\n width: 100%;\r\n height: 100%;\r\n }\r\n .modal-content-wrapper{\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n z-index: 3;\r\n width: 100%;\r\n height: 100%;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n pointer-events: none;\r\n @include mobile-tablet{\r\n bottom: 0;\r\n top:initial;\r\n align-items: flex-end;\r\n }\r\n .modal-content{\r\n pointer-events: all;\r\n width: auto;\r\n height: auto;\r\n background-color: var(--jb-modal-bg-color, #fff);\r\n border-radius: var(--jb-modal-border-radius, 24px);\r\n @include mobile-tablet{\r\n width: 100%;\r\n height: auto;\r\n max-height: calc(100% - 80px);\r\n min-height: 32px;\r\n border-radius: var(--jb-modal-border-radius-mobile, 24px 24px 0 0);\r\n overflow-y: auto;\r\n }\r\n }\r\n }\r\n \r\n}\r\n","import HTML from \"./jb-modal.html\";\r\nimport CSS from \"./jb-modal.scss\";\r\nimport { ElementsObject } from \"./types.js\";\r\n\r\nexport * from \"./types.js\";\r\n\r\nexport class JBModalWebComponent extends HTMLElement {\r\n #isOpen = false;\r\n #id = \"\";\r\n elements!: ElementsObject;\r\n config = {\r\n autoCloseOnBackgroundClick: false,\r\n };\r\n get id() {\r\n const id: string = this.getAttribute(\"id\") || \"\";\r\n return this.#id || id;\r\n }\r\n set id(value: string) {\r\n this.#id = value;\r\n this.checkInitialOpenness();\r\n }\r\n get isOpen() {\r\n return this.#isOpen;\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n }\r\n connectedCallback() {\r\n // standard web component event that called when all of dom is binded\r\n this.callOnLoadEvent();\r\n this.initProp();\r\n this.callOnInitEvent();\r\n }\r\n callOnLoadEvent() {\r\n const event = new CustomEvent(\"load\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n callOnInitEvent() {\r\n const event = new CustomEvent(\"init\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: \"open\",\r\n });\r\n const html = `<style>${CSS}</style>` + \"\\n\" + HTML;\r\n const element = document.createElement(\"template\");\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.elements = {\r\n componentWrapper: shadowRoot.querySelector(\".jb-modal-web-component\")!,\r\n background: shadowRoot.querySelector(\".modal-background\")!,\r\n };\r\n }\r\n registerEventListener() {\r\n this.elements.background.addEventListener(\r\n \"click\",\r\n this.onBackgroundClick.bind(this)\r\n );\r\n //TODO: remove listener on component unmount\r\n window.addEventListener(\"popstate\", this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n this.registerEventListener();\r\n }\r\n checkInitialOpenness() {\r\n //if page has modal url we open it automatically\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n this.triggerUrlOpenEvent();\r\n this.open();\r\n }\r\n }\r\n triggerUrlOpenEvent() {\r\n //when modal open itself becuase url contain modal id\r\n const event = new CustomEvent(\"urlOpen\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n static get observedAttributes() {\r\n return [\"is-open\", \"id\"];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case \"is-open\":\r\n if (value == \"true\") {\r\n if (!this.#isOpen) {\r\n this.open();\r\n }\r\n } else {\r\n if (this.#isOpen) {\r\n this.close();\r\n }\r\n }\r\n break;\r\n case \"id\":\r\n this.id = value;\r\n break;\r\n }\r\n }\r\n onBackgroundClick() {\r\n this.dispatchCloseEvent(\"BACKGROUND_CLICK\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n dispatchCloseEvent(type:\"BACKGROUND_CLICK\"| \"HISTORY_BACK_EVENT\" | \"CLOSE_BUTTON_CLICK\") {\r\n //we have many ways to dispatch close event like back button on close clicked\r\n const event = new CustomEvent(\"close\", { detail: { eventType: type } });\r\n this.dispatchEvent(event);\r\n }\r\n /**\r\n * @public\r\n * will close modal\r\n */\r\n close() {\r\n this.#isOpen = false;\r\n this.elements.componentWrapper.classList.remove(\"--opened\");\r\n this.elements.componentWrapper.classList.add(\"--closed\");\r\n const history = window.history;\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n history.go(-1);\r\n }\r\n }\r\n /**\r\n * @public\r\n * will open modal\r\n */\r\n open() {\r\n this.#isOpen = true;\r\n this.elements.componentWrapper.classList.remove(\"--closed\");\r\n this.elements.componentWrapper.classList.add(\"--opened\");\r\n if (this.id) {\r\n const history = window.history;\r\n const location = window.location;\r\n if (!(location.hash == `#${this.id}`)) {\r\n history.pushState({ JBModal: {} }, \"\", `#${this.id}`);\r\n }\r\n }\r\n }\r\n #onBrowserBack() {\r\n if (this.isOpen) {\r\n this.dispatchCloseEvent(\"HISTORY_BACK_EVENT\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n }\r\n}\r\nconst myElementNotExists = !customElements.get(\"jb-modal\");\r\nif (myElementNotExists) {\r\n window.customElements.define(\"jb-modal\", JBModalWebComponent);\r\n}\r\n"],"x_google_ignoreList":[2],"mappings":"2qBGMa,EAAP,cAAmC,YAOvC,MAAI,GACF,MAAM,EAAa,KAAK,aAAa,OAAS,GAC9C,OAAO,EAAA,KAAI,EAAA,MAAQ,CACpB,CACD,MAAI,CAAG,GACL,EAAA,KAAI,EAAO,EAAK,KAChB,KAAK,sBACN,CACD,UAAI,GACF,OAAO,EAAA,KAAI,EAAA,IACZ,CACD,WAAA,GACE,oBAlBF,EAAA,IAAA,MAAU,GACV,EAAA,IAAA,KAAM,IAEN,KAAA,OAAS,CACP,4BAA4B,GAe5B,KAAK,kBACN,CACD,iBAAA,GAEE,KAAK,kBACL,KAAK,WACL,KAAK,iBACN,CACD,eAAA,GACE,MAAM,EAAQ,IAAI,YAAY,OAAQ,CAAE,SAAS,EAAM,UAAU,IACjE,KAAK,cAAc,EACpB,CACD,eAAA,GACE,MAAM,EAAQ,IAAI,YAAY,OAAQ,CAAE,SAAS,EAAM,UAAU,IACjE,KAAK,cAAc,EACpB,CACD,gBAAA,GACE,MAAM,EAAa,KAAK,aAAa,CACnC,KAAM,SAGF,EAAU,SAAS,cAAc,YACvC,EAAQ,UAFF,w3DAGN,EAAW,YAAY,EAAQ,QAAQ,WAAU,IACjD,KAAK,SAAW,CACd,iBAAkB,EAAW,cAAc,2BAC3C,WAAY,EAAW,cAAc,qBAExC,CACD,qBAAA,GACE,KAAK,SAAS,WAAW,iBACvB,QACA,KAAK,kBAAkB,KAAK,OAG9B,OAAO,iBAAiB,WAAY,EAAA,KAAI,EAAA,IAAA,GAAgB,KAAK,MAC9D,CACD,QAAA,GACE,KAAK,uBACN,CACD,oBAAA,GAEmB,OAAO,SACX,MAAA,IAAY,KAAK,OAC5B,KAAK,sBACL,KAAK,OAER,CACD,mBAAA,GAEE,MAAM,EAAQ,IAAI,YAAY,UAAW,CAAE,SAAS,EAAM,UAAU,IACpE,KAAK,cAAc,EACpB,CACD,6BAAW,GACT,MAAO,CAAC,UAAW,KACpB,CACD,wBAAA,CAAyB,EAAa,EAAiB,GAErD,KAAK,kBAAkB,EAAM,EAC9B,CACD,iBAAA,CAAkB,EAAa,GAC7B,OAAQ,GACN,IAAK,UACU,QAAT,EACG,EAAA,KAAI,EAAA,MACP,KAAK,OAGH,EAAA,KAAI,EAAA,MACN,KAAK,QAGT,MACF,IAAK,KACH,KAAK,GAAK,EAGf,CACD,iBAAA,GACE,KAAK,mBAAmB,oBACpB,KAAK,OAAO,4BACd,KAAK,OAER,CACD,kBAAA,CAAmB,GAEjB,MAAM,EAAQ,IAAI,YAAY,QAAS,CAAE,OAAQ,CAAE,UAAW,KAC9D,KAAK,cAAc,EACpB,CAKD,KAAA,GACE,EAAA,KAAI,GAAW,EAAK,KACpB,KAAK,SAAS,iBAAiB,UAAU,OAAO,YAChD,KAAK,SAAS,iBAAiB,UAAU,IAAI,YAC7C,MAAM,EAAU,OAAO,QACN,OAAO,SACX,MAAA,IAAY,KAAK,MAC5B,EAAQ,IAAG,EAEd,CAKD,IAAA,GAIE,GAHA,EAAA,KAAI,GAAW,EAAI,KACnB,KAAK,SAAS,iBAAiB,UAAU,OAAO,YAChD,KAAK,SAAS,iBAAiB,UAAU,IAAI,YACzC,KAAK,GAAI,CACX,MAAM,EAAU,OAAO,QACN,OAAO,SACT,MAAA,IAAY,KAAK,MAC9B,EAAQ,UAAU,CAAE,QAAS,CAAE,GAAI,GAAA,IAAQ,KAAK,KAEnD,CACF,0DAEK,KAAK,SACP,KAAK,mBAAmB,sBACpB,KAAK,OAAO,4BACd,KAAK,QAGV,GAEyB,eAAe,IAAI,aAE7C,OAAO,eAAe,OAAO,WAAY"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ElementsObject } from
|
|
1
|
+
import { ElementsObject } from "./types.js";
|
|
2
|
+
export * from "./types.js";
|
|
2
3
|
export declare class JBModalWebComponent extends HTMLElement {
|
|
3
4
|
#private;
|
|
4
5
|
elements: ElementsObject;
|
|
@@ -18,14 +19,14 @@ export declare class JBModalWebComponent extends HTMLElement {
|
|
|
18
19
|
checkInitialOpenness(): void;
|
|
19
20
|
triggerUrlOpenEvent(): void;
|
|
20
21
|
static get observedAttributes(): string[];
|
|
21
|
-
attributeChangedCallback(name:
|
|
22
|
-
onAttributeChange(name:
|
|
22
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
23
|
+
onAttributeChange(name: string, value: string): void;
|
|
23
24
|
onBackgroundClick(): void;
|
|
24
|
-
dispatchCloseEvent(type:
|
|
25
|
+
dispatchCloseEvent(type: "BACKGROUND_CLICK" | "HISTORY_BACK_EVENT" | "CLOSE_BUTTON_CLICK"): void;
|
|
25
26
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
* @public
|
|
28
|
+
* will close modal
|
|
29
|
+
*/
|
|
29
30
|
close(): void;
|
|
30
31
|
/**
|
|
31
32
|
* @public
|
package/dist/jb-modal.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function t(e,t,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}var n,o,i,a,s=class extends HTMLElement{get id(){const t=this.getAttribute("id")||"";return e(this,i,"f")||t}set id(e){t(this,i,e,"f"),this.checkInitialOpenness()}get isOpen(){return e(this,o,"f")}constructor(){super(),n.add(this),o.set(this,!1),i.set(this,""),this.config={autoCloseOnBackgroundClick:!1},this.initWebComponent()}connectedCallback(){this.callOnLoadEvent(),this.initProp(),this.callOnInitEvent()}callOnLoadEvent(){const e=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(e)}callOnInitEvent(){const e=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(e)}initWebComponent(){const e=this.attachShadow({mode:"open"}),t=document.createElement("template");t.innerHTML='<style>.jb-modal-web-component{position:fixed;top:0;left:0;z-index:var(--jb-modal-z-index, 1);width:100%;height:100%}.jb-modal-web-component.--closed{display:none}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component.--closed .modal-content-wrapper{transform:translateY(100%)}}.jb-modal-web-component.--opened{display:block}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component.--opened .modal-content-wrapper{animation-name:swipe-up;animation-duration:.3s;animation-delay:0s;animation-iteration-count:1;animation-timing-function:ease}}@keyframes swipe-up{0%{transform:translateY(100%)}100%{transform:translateY(0%)}}.jb-modal-web-component .modal-background{position:absolute;top:0;left:0;background-color:var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1));backdrop-filter:blur(10px);z-index:2;width:100%;height:100%}.jb-modal-web-component .modal-content-wrapper{position:absolute;top:0;left:0;z-index:3;width:100%;height:100%;display:flex;align-items:center;justify-content:center;pointer-events:none}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component .modal-content-wrapper{bottom:0;top:initial;align-items:flex-end}}.jb-modal-web-component .modal-content-wrapper .modal-content{pointer-events:all;width:auto;height:auto;background-color:var(--jb-modal-bg-color, #fff);border-radius:var(--jb-modal-border-radius, 24px)}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component .modal-content-wrapper .modal-content{width:100%;height:auto;max-height:calc(100% - 80px);min-height:32px;border-radius:var(--jb-modal-border-radius-mobile, 24px 24px 0 0);overflow-y:auto}}</style>\n<div class="jb-modal-web-component --closed">\r\n <div class="modal-background"></div>\r\n <div class="modal-content-wrapper">\r\n <div class="modal-content">\r\n <slot name="content"></slot>\r\n </div>\r\n </div>\r\n</div>',e.appendChild(t.content.cloneNode(!0)),this.elements={componentWrapper:e.querySelector(".jb-modal-web-component"),background:e.querySelector(".modal-background")}}registerEventListener(){this.elements.background.addEventListener("click",this.onBackgroundClick.bind(this)),window.addEventListener("popstate",e(this,n,"m",a).bind(this))}initProp(){this.registerEventListener()}checkInitialOpenness(){window.location.hash==`#${this.id}`&&(this.triggerUrlOpenEvent(),this.open())}triggerUrlOpenEvent(){const e=new CustomEvent("urlOpen",{bubbles:!0,composed:!0});this.dispatchEvent(e)}static get observedAttributes(){return["is-open","id"]}attributeChangedCallback(e,t,n){this.onAttributeChange(e,n)}onAttributeChange(t,n){switch(t){case"is-open":"true"==n?e(this,o,"f")||this.open():e(this,o,"f")&&this.close();break;case"id":this.id=n}}onBackgroundClick(){this.dispatchCloseEvent("BACKGROUND_CLICK"),this.config.autoCloseOnBackgroundClick&&this.close()}dispatchCloseEvent(e){const t=new CustomEvent("close",{detail:{eventType:e}});this.dispatchEvent(t)}close(){t(this,o,!1,"f"),this.elements.componentWrapper.classList.remove("--opened"),this.elements.componentWrapper.classList.add("--closed");const e=window.history;window.location.hash==`#${this.id}`&&e.go(-1)}open(){if(t(this,o,!0,"f"),this.elements.componentWrapper.classList.remove("--closed"),this.elements.componentWrapper.classList.add("--opened"),this.id){const e=window.history;window.location.hash!=`#${this.id}`&&e.pushState({JBModal:{}},"",`#${this.id}`)}}};o=new WeakMap,i=new WeakMap,n=new WeakSet,a=function(){this.isOpen&&(this.dispatchCloseEvent("HISTORY_BACK_EVENT"),this.config.autoCloseOnBackgroundClick&&this.close())};!customElements.get("jb-modal")&&window.customElements.define("jb-modal",s);export{s as JBModalWebComponent};
|
|
2
|
+
//# sourceMappingURL=jb-modal.js.map
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jb-modal.js","names":[],"sources":["../lib/jb-modal.html","../../../../../../../../../../../Home/NeveshtAfzar/work/Azad/Azad/design-system/design-system/web-component/jb-modal/lib/jb-modal.scss","../../../../../../../../../../../Home/NeveshtAfzar/work/Azad/Azad/design-system/design-system/node_modules/jb-core/styles/medias.scss","../lib/jb-modal.ts"],"sourcesContent":["<div class=\"jb-modal-web-component --closed\">\r\n <div class=\"modal-background\"></div>\r\n <div class=\"modal-content-wrapper\">\r\n <div class=\"modal-content\">\r\n <slot name=\"content\"></slot>\r\n </div>\r\n </div>\r\n</div>","@use '~jb-core/styles/medias.scss' as *;\r\n.jb-modal-web-component {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n z-index: var(--jb-modal-z-index, 1);\r\n width: 100%;\r\n height: 100%;\r\n &.--closed{\r\n display: none;\r\n .modal-content-wrapper{\r\n @include mobile-tablet{\r\n transform: translateY(100%);\r\n \r\n }\r\n }\r\n }\r\n &.--opened{\r\n display: block;\r\n .modal-content-wrapper{\r\n @include mobile-tablet{\r\n // transform: translateY(0%);\r\n animation-name: swipe-up;\r\n animation-duration: 0.3s;\r\n animation-delay: 0s;\r\n animation-iteration-count: 1;\r\n animation-timing-function: ease;\r\n }\r\n }\r\n \r\n }\r\n @keyframes swipe-up{\r\n 0%{\r\n transform: translateY(100%);\r\n }\r\n 100%{\r\n transform: translateY(0%);\r\n }\r\n }\r\n .modal-background {\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n background-color:var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1)) ;\r\n backdrop-filter: blur(10px);\r\n z-index: 2;\r\n width: 100%;\r\n height: 100%;\r\n }\r\n .modal-content-wrapper{\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n z-index: 3;\r\n width: 100%;\r\n height: 100%;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n pointer-events: none;\r\n @include mobile-tablet{\r\n bottom: 0;\r\n top:initial;\r\n align-items: flex-end;\r\n }\r\n .modal-content{\r\n pointer-events: all;\r\n width: auto;\r\n height: auto;\r\n background-color: var(--jb-modal-bg-color, #fff);\r\n border-radius: var(--jb-modal-border-radius, 24px);\r\n @include mobile-tablet{\r\n width: 100%;\r\n height: auto;\r\n max-height: calc(100% - 80px);\r\n min-height: 32px;\r\n border-radius: var(--jb-modal-border-radius-mobile, 24px 24px 0 0);\r\n overflow-y: auto;\r\n }\r\n }\r\n }\r\n \r\n}\r\n","import HTML from \"./jb-modal.html\";\r\nimport CSS from \"./jb-modal.scss\";\r\nimport { ElementsObject } from \"./types.js\";\r\n\r\nexport * from \"./types.js\";\r\n\r\nexport class JBModalWebComponent extends HTMLElement {\r\n #isOpen = false;\r\n #id = \"\";\r\n elements!: ElementsObject;\r\n config = {\r\n autoCloseOnBackgroundClick: false,\r\n };\r\n get id() {\r\n const id: string = this.getAttribute(\"id\") || \"\";\r\n return this.#id || id;\r\n }\r\n set id(value: string) {\r\n this.#id = value;\r\n this.checkInitialOpenness();\r\n }\r\n get isOpen() {\r\n return this.#isOpen;\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n }\r\n connectedCallback() {\r\n // standard web component event that called when all of dom is binded\r\n this.callOnLoadEvent();\r\n this.initProp();\r\n this.callOnInitEvent();\r\n }\r\n callOnLoadEvent() {\r\n const event = new CustomEvent(\"load\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n callOnInitEvent() {\r\n const event = new CustomEvent(\"init\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: \"open\",\r\n });\r\n const html = `<style>${CSS}</style>` + \"\\n\" + HTML;\r\n const element = document.createElement(\"template\");\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.elements = {\r\n componentWrapper: shadowRoot.querySelector(\".jb-modal-web-component\")!,\r\n background: shadowRoot.querySelector(\".modal-background\")!,\r\n };\r\n }\r\n registerEventListener() {\r\n this.elements.background.addEventListener(\r\n \"click\",\r\n this.onBackgroundClick.bind(this)\r\n );\r\n //TODO: remove listener on component unmount\r\n window.addEventListener(\"popstate\", this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n this.registerEventListener();\r\n }\r\n checkInitialOpenness() {\r\n //if page has modal url we open it automatically\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n this.triggerUrlOpenEvent();\r\n this.open();\r\n }\r\n }\r\n triggerUrlOpenEvent() {\r\n //when modal open itself becuase url contain modal id\r\n const event = new CustomEvent(\"urlOpen\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n static get observedAttributes() {\r\n return [\"is-open\", \"id\"];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case \"is-open\":\r\n if (value == \"true\") {\r\n if (!this.#isOpen) {\r\n this.open();\r\n }\r\n } else {\r\n if (this.#isOpen) {\r\n this.close();\r\n }\r\n }\r\n break;\r\n case \"id\":\r\n this.id = value;\r\n break;\r\n }\r\n }\r\n onBackgroundClick() {\r\n this.dispatchCloseEvent(\"BACKGROUND_CLICK\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n dispatchCloseEvent(type:\"BACKGROUND_CLICK\"| \"HISTORY_BACK_EVENT\" | \"CLOSE_BUTTON_CLICK\") {\r\n //we have many ways to dispatch close event like back button on close clicked\r\n const event = new CustomEvent(\"close\", { detail: { eventType: type } });\r\n this.dispatchEvent(event);\r\n }\r\n /**\r\n * @public\r\n * will close modal\r\n */\r\n close() {\r\n this.#isOpen = false;\r\n this.elements.componentWrapper.classList.remove(\"--opened\");\r\n this.elements.componentWrapper.classList.add(\"--closed\");\r\n const history = window.history;\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n history.go(-1);\r\n }\r\n }\r\n /**\r\n * @public\r\n * will open modal\r\n */\r\n open() {\r\n this.#isOpen = true;\r\n this.elements.componentWrapper.classList.remove(\"--closed\");\r\n this.elements.componentWrapper.classList.add(\"--opened\");\r\n if (this.id) {\r\n const history = window.history;\r\n const location = window.location;\r\n if (!(location.hash == `#${this.id}`)) {\r\n history.pushState({ JBModal: {} }, \"\", `#${this.id}`);\r\n }\r\n }\r\n }\r\n #onBrowserBack() {\r\n if (this.isOpen) {\r\n this.dispatchCloseEvent(\"HISTORY_BACK_EVENT\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n }\r\n}\r\nconst myElementNotExists = !customElements.get(\"jb-modal\");\r\nif (myElementNotExists) {\r\n window.customElements.define(\"jb-modal\", JBModalWebComponent);\r\n}\r\n"],"x_google_ignoreList":[2],"mappings":"8pBGMa,EAAP,cAAmC,YAOvC,MAAI,GACF,MAAM,EAAa,KAAK,aAAa,OAAS,GAC9C,OAAO,EAAA,KAAI,EAAA,MAAQ,CACpB,CACD,MAAI,CAAG,GACL,EAAA,KAAI,EAAO,EAAK,KAChB,KAAK,sBACN,CACD,UAAI,GACF,OAAO,EAAA,KAAI,EAAA,IACZ,CACD,WAAA,GACE,oBAlBF,EAAA,IAAA,MAAU,GACV,EAAA,IAAA,KAAM,IAEN,KAAA,OAAS,CACP,4BAA4B,GAe5B,KAAK,kBACN,CACD,iBAAA,GAEE,KAAK,kBACL,KAAK,WACL,KAAK,iBACN,CACD,eAAA,GACE,MAAM,EAAQ,IAAI,YAAY,OAAQ,CAAE,SAAS,EAAM,UAAU,IACjE,KAAK,cAAc,EACpB,CACD,eAAA,GACE,MAAM,EAAQ,IAAI,YAAY,OAAQ,CAAE,SAAS,EAAM,UAAU,IACjE,KAAK,cAAc,EACpB,CACD,gBAAA,GACE,MAAM,EAAa,KAAK,aAAa,CACnC,KAAM,SAGF,EAAU,SAAS,cAAc,YACvC,EAAQ,UAFF,w3DAGN,EAAW,YAAY,EAAQ,QAAQ,WAAU,IACjD,KAAK,SAAW,CACd,iBAAkB,EAAW,cAAc,2BAC3C,WAAY,EAAW,cAAc,qBAExC,CACD,qBAAA,GACE,KAAK,SAAS,WAAW,iBACvB,QACA,KAAK,kBAAkB,KAAK,OAG9B,OAAO,iBAAiB,WAAY,EAAA,KAAI,EAAA,IAAA,GAAgB,KAAK,MAC9D,CACD,QAAA,GACE,KAAK,uBACN,CACD,oBAAA,GAEmB,OAAO,SACX,MAAA,IAAY,KAAK,OAC5B,KAAK,sBACL,KAAK,OAER,CACD,mBAAA,GAEE,MAAM,EAAQ,IAAI,YAAY,UAAW,CAAE,SAAS,EAAM,UAAU,IACpE,KAAK,cAAc,EACpB,CACD,6BAAW,GACT,MAAO,CAAC,UAAW,KACpB,CACD,wBAAA,CAAyB,EAAa,EAAiB,GAErD,KAAK,kBAAkB,EAAM,EAC9B,CACD,iBAAA,CAAkB,EAAa,GAC7B,OAAQ,GACN,IAAK,UACU,QAAT,EACG,EAAA,KAAI,EAAA,MACP,KAAK,OAGH,EAAA,KAAI,EAAA,MACN,KAAK,QAGT,MACF,IAAK,KACH,KAAK,GAAK,EAGf,CACD,iBAAA,GACE,KAAK,mBAAmB,oBACpB,KAAK,OAAO,4BACd,KAAK,OAER,CACD,kBAAA,CAAmB,GAEjB,MAAM,EAAQ,IAAI,YAAY,QAAS,CAAE,OAAQ,CAAE,UAAW,KAC9D,KAAK,cAAc,EACpB,CAKD,KAAA,GACE,EAAA,KAAI,GAAW,EAAK,KACpB,KAAK,SAAS,iBAAiB,UAAU,OAAO,YAChD,KAAK,SAAS,iBAAiB,UAAU,IAAI,YAC7C,MAAM,EAAU,OAAO,QACN,OAAO,SACX,MAAA,IAAY,KAAK,MAC5B,EAAQ,IAAG,EAEd,CAKD,IAAA,GAIE,GAHA,EAAA,KAAI,GAAW,EAAI,KACnB,KAAK,SAAS,iBAAiB,UAAU,OAAO,YAChD,KAAK,SAAS,iBAAiB,UAAU,IAAI,YACzC,KAAK,GAAI,CACX,MAAM,EAAU,OAAO,QACN,OAAO,SACT,MAAA,IAAY,KAAK,MAC9B,EAAQ,UAAU,CAAE,QAAS,CAAE,GAAI,GAAA,IAAQ,KAAK,KAEnD,CACF,0DAEK,KAAK,SACP,KAAK,mBAAmB,sBACpB,KAAK,OAAO,4BACd,KAAK,QAGV,GAEyB,eAAe,IAAI,aAE7C,OAAO,eAAe,OAAO,WAAY"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JBModal={})}(this,(function(e){"use strict";function t(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function n(e,t,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}var o,i,a,s,d=class extends HTMLElement{get id(){const e=this.getAttribute("id")||"";return t(this,a,"f")||e}set id(e){n(this,a,e,"f"),this.checkInitialOpenness()}get isOpen(){return t(this,i,"f")}constructor(){super(),o.add(this),i.set(this,!1),a.set(this,""),this.config={autoCloseOnBackgroundClick:!1},this.initWebComponent()}connectedCallback(){this.callOnLoadEvent(),this.initProp(),this.callOnInitEvent()}callOnLoadEvent(){const e=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(e)}callOnInitEvent(){const e=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(e)}initWebComponent(){const e=this.attachShadow({mode:"open"}),t=document.createElement("template");t.innerHTML='<style>.jb-modal-web-component{position:fixed;top:0;left:0;z-index:var(--jb-modal-z-index, 1);width:100%;height:100%}.jb-modal-web-component.--closed{display:none}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component.--closed .modal-content-wrapper{transform:translateY(100%)}}.jb-modal-web-component.--opened{display:block}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component.--opened .modal-content-wrapper{animation-name:swipe-up;animation-duration:.3s;animation-delay:0s;animation-iteration-count:1;animation-timing-function:ease}}@keyframes swipe-up{0%{transform:translateY(100%)}100%{transform:translateY(0%)}}.jb-modal-web-component .modal-background{position:absolute;top:0;left:0;background-color:var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1));backdrop-filter:blur(10px);z-index:2;width:100%;height:100%}.jb-modal-web-component .modal-content-wrapper{position:absolute;top:0;left:0;z-index:3;width:100%;height:100%;display:flex;align-items:center;justify-content:center;pointer-events:none}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component .modal-content-wrapper{bottom:0;top:initial;align-items:flex-end}}.jb-modal-web-component .modal-content-wrapper .modal-content{pointer-events:all;width:auto;height:auto;background-color:var(--jb-modal-bg-color, #fff);border-radius:var(--jb-modal-border-radius, 24px)}@media(min-width: 320px)and (max-width: 767px){.jb-modal-web-component .modal-content-wrapper .modal-content{width:100%;height:auto;max-height:calc(100% - 80px);min-height:32px;border-radius:var(--jb-modal-border-radius-mobile, 24px 24px 0 0);overflow-y:auto}}</style>\n<div class="jb-modal-web-component --closed">\r\n <div class="modal-background"></div>\r\n <div class="modal-content-wrapper">\r\n <div class="modal-content">\r\n <slot name="content"></slot>\r\n </div>\r\n </div>\r\n</div>',e.appendChild(t.content.cloneNode(!0)),this.elements={componentWrapper:e.querySelector(".jb-modal-web-component"),background:e.querySelector(".modal-background")}}registerEventListener(){this.elements.background.addEventListener("click",this.onBackgroundClick.bind(this)),window.addEventListener("popstate",t(this,o,"m",s).bind(this))}initProp(){this.registerEventListener()}checkInitialOpenness(){window.location.hash==`#${this.id}`&&(this.triggerUrlOpenEvent(),this.open())}triggerUrlOpenEvent(){const e=new CustomEvent("urlOpen",{bubbles:!0,composed:!0});this.dispatchEvent(e)}static get observedAttributes(){return["is-open","id"]}attributeChangedCallback(e,t,n){this.onAttributeChange(e,n)}onAttributeChange(e,n){switch(e){case"is-open":"true"==n?t(this,i,"f")||this.open():t(this,i,"f")&&this.close();break;case"id":this.id=n}}onBackgroundClick(){this.dispatchCloseEvent("BACKGROUND_CLICK"),this.config.autoCloseOnBackgroundClick&&this.close()}dispatchCloseEvent(e){const t=new CustomEvent("close",{detail:{eventType:e}});this.dispatchEvent(t)}close(){n(this,i,!1,"f"),this.elements.componentWrapper.classList.remove("--opened"),this.elements.componentWrapper.classList.add("--closed");const e=window.history;window.location.hash==`#${this.id}`&&e.go(-1)}open(){if(n(this,i,!0,"f"),this.elements.componentWrapper.classList.remove("--closed"),this.elements.componentWrapper.classList.add("--opened"),this.id){const e=window.history;window.location.hash!=`#${this.id}`&&e.pushState({JBModal:{}},"",`#${this.id}`)}}};i=new WeakMap,a=new WeakMap,o=new WeakSet,s=function(){this.isOpen&&(this.dispatchCloseEvent("HISTORY_BACK_EVENT"),this.config.autoCloseOnBackgroundClick&&this.close())};!customElements.get("jb-modal")&&window.customElements.define("jb-modal",d),e.JBModalWebComponent=d}));
|
|
2
|
+
//# sourceMappingURL=jb-modal.umd.js.map
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jb-modal.umd.js","names":[],"sources":["../lib/jb-modal.html","../../../../../../../../../../../Home/NeveshtAfzar/work/Azad/Azad/design-system/design-system/web-component/jb-modal/lib/jb-modal.scss","../../../../../../../../../../../Home/NeveshtAfzar/work/Azad/Azad/design-system/design-system/node_modules/jb-core/styles/medias.scss","../lib/jb-modal.ts"],"sourcesContent":["<div class=\"jb-modal-web-component --closed\">\r\n <div class=\"modal-background\"></div>\r\n <div class=\"modal-content-wrapper\">\r\n <div class=\"modal-content\">\r\n <slot name=\"content\"></slot>\r\n </div>\r\n </div>\r\n</div>","@use '~jb-core/styles/medias.scss' as *;\r\n.jb-modal-web-component {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n z-index: var(--jb-modal-z-index, 1);\r\n width: 100%;\r\n height: 100%;\r\n &.--closed{\r\n display: none;\r\n .modal-content-wrapper{\r\n @include mobile-tablet{\r\n transform: translateY(100%);\r\n \r\n }\r\n }\r\n }\r\n &.--opened{\r\n display: block;\r\n .modal-content-wrapper{\r\n @include mobile-tablet{\r\n // transform: translateY(0%);\r\n animation-name: swipe-up;\r\n animation-duration: 0.3s;\r\n animation-delay: 0s;\r\n animation-iteration-count: 1;\r\n animation-timing-function: ease;\r\n }\r\n }\r\n \r\n }\r\n @keyframes swipe-up{\r\n 0%{\r\n transform: translateY(100%);\r\n }\r\n 100%{\r\n transform: translateY(0%);\r\n }\r\n }\r\n .modal-background {\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n background-color:var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1)) ;\r\n backdrop-filter: blur(10px);\r\n z-index: 2;\r\n width: 100%;\r\n height: 100%;\r\n }\r\n .modal-content-wrapper{\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n z-index: 3;\r\n width: 100%;\r\n height: 100%;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n pointer-events: none;\r\n @include mobile-tablet{\r\n bottom: 0;\r\n top:initial;\r\n align-items: flex-end;\r\n }\r\n .modal-content{\r\n pointer-events: all;\r\n width: auto;\r\n height: auto;\r\n background-color: var(--jb-modal-bg-color, #fff);\r\n border-radius: var(--jb-modal-border-radius, 24px);\r\n @include mobile-tablet{\r\n width: 100%;\r\n height: auto;\r\n max-height: calc(100% - 80px);\r\n min-height: 32px;\r\n border-radius: var(--jb-modal-border-radius-mobile, 24px 24px 0 0);\r\n overflow-y: auto;\r\n }\r\n }\r\n }\r\n \r\n}\r\n","import HTML from \"./jb-modal.html\";\r\nimport CSS from \"./jb-modal.scss\";\r\nimport { ElementsObject } from \"./types.js\";\r\n\r\nexport * from \"./types.js\";\r\n\r\nexport class JBModalWebComponent extends HTMLElement {\r\n #isOpen = false;\r\n #id = \"\";\r\n elements!: ElementsObject;\r\n config = {\r\n autoCloseOnBackgroundClick: false,\r\n };\r\n get id() {\r\n const id: string = this.getAttribute(\"id\") || \"\";\r\n return this.#id || id;\r\n }\r\n set id(value: string) {\r\n this.#id = value;\r\n this.checkInitialOpenness();\r\n }\r\n get isOpen() {\r\n return this.#isOpen;\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n }\r\n connectedCallback() {\r\n // standard web component event that called when all of dom is binded\r\n this.callOnLoadEvent();\r\n this.initProp();\r\n this.callOnInitEvent();\r\n }\r\n callOnLoadEvent() {\r\n const event = new CustomEvent(\"load\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n callOnInitEvent() {\r\n const event = new CustomEvent(\"init\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: \"open\",\r\n });\r\n const html = `<style>${CSS}</style>` + \"\\n\" + HTML;\r\n const element = document.createElement(\"template\");\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.elements = {\r\n componentWrapper: shadowRoot.querySelector(\".jb-modal-web-component\")!,\r\n background: shadowRoot.querySelector(\".modal-background\")!,\r\n };\r\n }\r\n registerEventListener() {\r\n this.elements.background.addEventListener(\r\n \"click\",\r\n this.onBackgroundClick.bind(this)\r\n );\r\n //TODO: remove listener on component unmount\r\n window.addEventListener(\"popstate\", this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n this.registerEventListener();\r\n }\r\n checkInitialOpenness() {\r\n //if page has modal url we open it automatically\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n this.triggerUrlOpenEvent();\r\n this.open();\r\n }\r\n }\r\n triggerUrlOpenEvent() {\r\n //when modal open itself becuase url contain modal id\r\n const event = new CustomEvent(\"urlOpen\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n static get observedAttributes() {\r\n return [\"is-open\", \"id\"];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case \"is-open\":\r\n if (value == \"true\") {\r\n if (!this.#isOpen) {\r\n this.open();\r\n }\r\n } else {\r\n if (this.#isOpen) {\r\n this.close();\r\n }\r\n }\r\n break;\r\n case \"id\":\r\n this.id = value;\r\n break;\r\n }\r\n }\r\n onBackgroundClick() {\r\n this.dispatchCloseEvent(\"BACKGROUND_CLICK\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n dispatchCloseEvent(type:\"BACKGROUND_CLICK\"| \"HISTORY_BACK_EVENT\" | \"CLOSE_BUTTON_CLICK\") {\r\n //we have many ways to dispatch close event like back button on close clicked\r\n const event = new CustomEvent(\"close\", { detail: { eventType: type } });\r\n this.dispatchEvent(event);\r\n }\r\n /**\r\n * @public\r\n * will close modal\r\n */\r\n close() {\r\n this.#isOpen = false;\r\n this.elements.componentWrapper.classList.remove(\"--opened\");\r\n this.elements.componentWrapper.classList.add(\"--closed\");\r\n const history = window.history;\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n history.go(-1);\r\n }\r\n }\r\n /**\r\n * @public\r\n * will open modal\r\n */\r\n open() {\r\n this.#isOpen = true;\r\n this.elements.componentWrapper.classList.remove(\"--closed\");\r\n this.elements.componentWrapper.classList.add(\"--opened\");\r\n if (this.id) {\r\n const history = window.history;\r\n const location = window.location;\r\n if (!(location.hash == `#${this.id}`)) {\r\n history.pushState({ JBModal: {} }, \"\", `#${this.id}`);\r\n }\r\n }\r\n }\r\n #onBrowserBack() {\r\n if (this.isOpen) {\r\n this.dispatchCloseEvent(\"HISTORY_BACK_EVENT\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n }\r\n}\r\nconst myElementNotExists = !customElements.get(\"jb-modal\");\r\nif (myElementNotExists) {\r\n window.customElements.define(\"jb-modal\", JBModalWebComponent);\r\n}\r\n"],"x_google_ignoreList":[2],"mappings":"64BGMa,EAAP,cAAmC,YAOvC,MAAI,GACF,MAAM,EAAa,KAAK,aAAa,OAAS,GAC9C,OAAO,EAAA,KAAI,EAAA,MAAQ,CACpB,CACD,MAAI,CAAG,GACL,EAAA,KAAI,EAAO,EAAK,KAChB,KAAK,sBACN,CACD,UAAI,GACF,OAAO,EAAA,KAAI,EAAA,IACZ,CACD,WAAA,GACE,oBAlBF,EAAA,IAAA,MAAU,GACV,EAAA,IAAA,KAAM,IAEN,KAAA,OAAS,CACP,4BAA4B,GAe5B,KAAK,kBACN,CACD,iBAAA,GAEE,KAAK,kBACL,KAAK,WACL,KAAK,iBACN,CACD,eAAA,GACE,MAAM,EAAQ,IAAI,YAAY,OAAQ,CAAE,SAAS,EAAM,UAAU,IACjE,KAAK,cAAc,EACpB,CACD,eAAA,GACE,MAAM,EAAQ,IAAI,YAAY,OAAQ,CAAE,SAAS,EAAM,UAAU,IACjE,KAAK,cAAc,EACpB,CACD,gBAAA,GACE,MAAM,EAAa,KAAK,aAAa,CACnC,KAAM,SAGF,EAAU,SAAS,cAAc,YACvC,EAAQ,UAFF,w3DAGN,EAAW,YAAY,EAAQ,QAAQ,WAAU,IACjD,KAAK,SAAW,CACd,iBAAkB,EAAW,cAAc,2BAC3C,WAAY,EAAW,cAAc,qBAExC,CACD,qBAAA,GACE,KAAK,SAAS,WAAW,iBACvB,QACA,KAAK,kBAAkB,KAAK,OAG9B,OAAO,iBAAiB,WAAY,EAAA,KAAI,EAAA,IAAA,GAAgB,KAAK,MAC9D,CACD,QAAA,GACE,KAAK,uBACN,CACD,oBAAA,GAEmB,OAAO,SACX,MAAA,IAAY,KAAK,OAC5B,KAAK,sBACL,KAAK,OAER,CACD,mBAAA,GAEE,MAAM,EAAQ,IAAI,YAAY,UAAW,CAAE,SAAS,EAAM,UAAU,IACpE,KAAK,cAAc,EACpB,CACD,6BAAW,GACT,MAAO,CAAC,UAAW,KACpB,CACD,wBAAA,CAAyB,EAAa,EAAiB,GAErD,KAAK,kBAAkB,EAAM,EAC9B,CACD,iBAAA,CAAkB,EAAa,GAC7B,OAAQ,GACN,IAAK,UACU,QAAT,EACG,EAAA,KAAI,EAAA,MACP,KAAK,OAGH,EAAA,KAAI,EAAA,MACN,KAAK,QAGT,MACF,IAAK,KACH,KAAK,GAAK,EAGf,CACD,iBAAA,GACE,KAAK,mBAAmB,oBACpB,KAAK,OAAO,4BACd,KAAK,OAER,CACD,kBAAA,CAAmB,GAEjB,MAAM,EAAQ,IAAI,YAAY,QAAS,CAAE,OAAQ,CAAE,UAAW,KAC9D,KAAK,cAAc,EACpB,CAKD,KAAA,GACE,EAAA,KAAI,GAAW,EAAK,KACpB,KAAK,SAAS,iBAAiB,UAAU,OAAO,YAChD,KAAK,SAAS,iBAAiB,UAAU,IAAI,YAC7C,MAAM,EAAU,OAAO,QACN,OAAO,SACX,MAAA,IAAY,KAAK,MAC5B,EAAQ,IAAG,EAEd,CAKD,IAAA,GAIE,GAHA,EAAA,KAAI,GAAW,EAAI,KACnB,KAAK,SAAS,iBAAiB,UAAU,OAAO,YAChD,KAAK,SAAS,iBAAiB,UAAU,IAAI,YACzC,KAAK,GAAI,CACX,MAAM,EAAU,OAAO,QACN,OAAO,SACT,MAAA,IAAY,KAAK,MAC9B,EAAQ,UAAU,CAAE,QAAS,CAAE,GAAI,GAAA,IAAQ,KAAK,KAEnD,CACF,0DAEK,KAAK,SACP,KAAK,mBAAmB,sBACpB,KAAK,OAAO,4BACd,KAAK,QAGV,GAEyB,eAAe,IAAI,aAE7C,OAAO,eAAe,OAAO,WAAY"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JBModalWebComponent } from "./jb-modal";
|
|
2
|
+
import type { EventTypeWithTarget } from 'jb-core';
|
|
3
|
+
export type ElementsObject = {
|
|
4
|
+
componentWrapper: HTMLDivElement;
|
|
5
|
+
background: HTMLDivElement;
|
|
6
|
+
};
|
|
7
|
+
export type JBModalEventType<TEvent> = EventTypeWithTarget<TEvent, JBModalWebComponent>;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './dist/jb-modal.js';
|
package/lib/jb-modal.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import HTML from "./jb-modal.html";
|
|
2
|
+
import CSS from "./jb-modal.scss";
|
|
3
|
+
import { ElementsObject } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
|
|
7
|
+
export class JBModalWebComponent extends HTMLElement {
|
|
8
|
+
#isOpen = false;
|
|
9
|
+
#id = "";
|
|
10
|
+
elements!: ElementsObject;
|
|
11
|
+
config = {
|
|
12
|
+
autoCloseOnBackgroundClick: false,
|
|
13
|
+
};
|
|
14
|
+
get id() {
|
|
15
|
+
const id: string = this.getAttribute("id") || "";
|
|
16
|
+
return this.#id || id;
|
|
17
|
+
}
|
|
18
|
+
set id(value: string) {
|
|
19
|
+
this.#id = value;
|
|
20
|
+
this.checkInitialOpenness();
|
|
21
|
+
}
|
|
22
|
+
get isOpen() {
|
|
23
|
+
return this.#isOpen;
|
|
24
|
+
}
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this.initWebComponent();
|
|
28
|
+
}
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
// standard web component event that called when all of dom is binded
|
|
31
|
+
this.callOnLoadEvent();
|
|
32
|
+
this.initProp();
|
|
33
|
+
this.callOnInitEvent();
|
|
34
|
+
}
|
|
35
|
+
callOnLoadEvent() {
|
|
36
|
+
const event = new CustomEvent("load", { bubbles: true, composed: true });
|
|
37
|
+
this.dispatchEvent(event);
|
|
38
|
+
}
|
|
39
|
+
callOnInitEvent() {
|
|
40
|
+
const event = new CustomEvent("init", { bubbles: true, composed: true });
|
|
41
|
+
this.dispatchEvent(event);
|
|
42
|
+
}
|
|
43
|
+
initWebComponent() {
|
|
44
|
+
const shadowRoot = this.attachShadow({
|
|
45
|
+
mode: "open",
|
|
46
|
+
});
|
|
47
|
+
const html = `<style>${CSS}</style>` + "\n" + HTML;
|
|
48
|
+
const element = document.createElement("template");
|
|
49
|
+
element.innerHTML = html;
|
|
50
|
+
shadowRoot.appendChild(element.content.cloneNode(true));
|
|
51
|
+
this.elements = {
|
|
52
|
+
componentWrapper: shadowRoot.querySelector(".jb-modal-web-component")!,
|
|
53
|
+
background: shadowRoot.querySelector(".modal-background")!,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
registerEventListener() {
|
|
57
|
+
this.elements.background.addEventListener(
|
|
58
|
+
"click",
|
|
59
|
+
this.onBackgroundClick.bind(this)
|
|
60
|
+
);
|
|
61
|
+
//TODO: remove listener on component unmount
|
|
62
|
+
window.addEventListener("popstate", this.#onBrowserBack.bind(this));
|
|
63
|
+
}
|
|
64
|
+
initProp() {
|
|
65
|
+
this.registerEventListener();
|
|
66
|
+
}
|
|
67
|
+
checkInitialOpenness() {
|
|
68
|
+
//if page has modal url we open it automatically
|
|
69
|
+
const location = window.location;
|
|
70
|
+
if (location.hash == `#${this.id}`) {
|
|
71
|
+
this.triggerUrlOpenEvent();
|
|
72
|
+
this.open();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
triggerUrlOpenEvent() {
|
|
76
|
+
//when modal open itself becuase url contain modal id
|
|
77
|
+
const event = new CustomEvent("urlOpen", { bubbles: true, composed: true });
|
|
78
|
+
this.dispatchEvent(event);
|
|
79
|
+
}
|
|
80
|
+
static get observedAttributes() {
|
|
81
|
+
return ["is-open", "id"];
|
|
82
|
+
}
|
|
83
|
+
attributeChangedCallback(name:string, oldValue:string, newValue:string) {
|
|
84
|
+
// do something when an attribute has changed
|
|
85
|
+
this.onAttributeChange(name, newValue);
|
|
86
|
+
}
|
|
87
|
+
onAttributeChange(name:string, value:string) {
|
|
88
|
+
switch (name) {
|
|
89
|
+
case "is-open":
|
|
90
|
+
if (value == "true") {
|
|
91
|
+
if (!this.#isOpen) {
|
|
92
|
+
this.open();
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
if (this.#isOpen) {
|
|
96
|
+
this.close();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "id":
|
|
101
|
+
this.id = value;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
onBackgroundClick() {
|
|
106
|
+
this.dispatchCloseEvent("BACKGROUND_CLICK");
|
|
107
|
+
if (this.config.autoCloseOnBackgroundClick) {
|
|
108
|
+
this.close();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
dispatchCloseEvent(type:"BACKGROUND_CLICK"| "HISTORY_BACK_EVENT" | "CLOSE_BUTTON_CLICK") {
|
|
112
|
+
//we have many ways to dispatch close event like back button on close clicked
|
|
113
|
+
const event = new CustomEvent("close", { detail: { eventType: type } });
|
|
114
|
+
this.dispatchEvent(event);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @public
|
|
118
|
+
* will close modal
|
|
119
|
+
*/
|
|
120
|
+
close() {
|
|
121
|
+
this.#isOpen = false;
|
|
122
|
+
this.elements.componentWrapper.classList.remove("--opened");
|
|
123
|
+
this.elements.componentWrapper.classList.add("--closed");
|
|
124
|
+
const history = window.history;
|
|
125
|
+
const location = window.location;
|
|
126
|
+
if (location.hash == `#${this.id}`) {
|
|
127
|
+
history.go(-1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @public
|
|
132
|
+
* will open modal
|
|
133
|
+
*/
|
|
134
|
+
open() {
|
|
135
|
+
this.#isOpen = true;
|
|
136
|
+
this.elements.componentWrapper.classList.remove("--closed");
|
|
137
|
+
this.elements.componentWrapper.classList.add("--opened");
|
|
138
|
+
if (this.id) {
|
|
139
|
+
const history = window.history;
|
|
140
|
+
const location = window.location;
|
|
141
|
+
if (!(location.hash == `#${this.id}`)) {
|
|
142
|
+
history.pushState({ JBModal: {} }, "", `#${this.id}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
#onBrowserBack() {
|
|
147
|
+
if (this.isOpen) {
|
|
148
|
+
this.dispatchCloseEvent("HISTORY_BACK_EVENT");
|
|
149
|
+
if (this.config.autoCloseOnBackgroundClick) {
|
|
150
|
+
this.close();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const myElementNotExists = !customElements.get("jb-modal");
|
|
156
|
+
if (myElementNotExists) {
|
|
157
|
+
window.customElements.define("jb-modal", JBModalWebComponent);
|
|
158
|
+
}
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JBModalWebComponent } from "./jb-modal";
|
|
2
|
+
import type {EventTypeWithTarget} from 'jb-core';
|
|
3
|
+
|
|
4
|
+
export type ElementsObject = {
|
|
5
|
+
componentWrapper: HTMLDivElement;
|
|
6
|
+
background: HTMLDivElement;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type JBModalEventType<TEvent> = EventTypeWithTarget<TEvent,JBModalWebComponent>
|
package/package.json
CHANGED
|
@@ -14,19 +14,25 @@
|
|
|
14
14
|
"pop up",
|
|
15
15
|
"web component"
|
|
16
16
|
],
|
|
17
|
-
"version": "1.
|
|
17
|
+
"version": "1.7.1",
|
|
18
18
|
"bugs": "https://github.com/javadbat/jb-modal/issues",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"files": [
|
|
21
21
|
"LICENSE",
|
|
22
22
|
"README.md",
|
|
23
23
|
"lib/",
|
|
24
|
-
"dist/"
|
|
24
|
+
"dist/",
|
|
25
|
+
"react/",
|
|
26
|
+
"react/dist/"
|
|
25
27
|
],
|
|
26
28
|
"main": "index.js",
|
|
27
|
-
"types": "./dist/
|
|
29
|
+
"types": "./dist/jb-modal.d.ts",
|
|
28
30
|
"repository": {
|
|
29
31
|
"type": "git",
|
|
30
32
|
"url": "git@github.com:javadbat/jb-modal.git"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"jb-core":">=0.4.0"
|
|
31
36
|
}
|
|
37
|
+
|
|
32
38
|
}
|
package/react/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 javad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/react/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# JBModal
|
|
2
|
+
|
|
3
|
+
a react component modal that open different in mobile and desktop
|
|
4
|
+
this component is React.js wrapper for [jb-modal](https://www.npmjs.com/package/jb-modal) web component.
|
|
5
|
+
|
|
6
|
+
- open like bottomsheet in mobile and open in center position in desktop
|
|
7
|
+
|
|
8
|
+
- customizable layout with css variable
|
|
9
|
+
|
|
10
|
+
- support typescript
|
|
11
|
+
|
|
12
|
+
- support custom url to adapt "back to close" on android and "auto open modal on refresh"
|
|
13
|
+
|
|
14
|
+
## installation
|
|
15
|
+
|
|
16
|
+
```command
|
|
17
|
+
npm i jb-modal
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
in your jsx file
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import {JBModal} from 'jb-modal/react'
|
|
24
|
+
```
|
|
25
|
+
``` jsx
|
|
26
|
+
<JBModal></JBModal>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## use
|
|
30
|
+
|
|
31
|
+
you can place your modal content in ` <JBModal></JBModal>` like:
|
|
32
|
+
```jsx
|
|
33
|
+
<JBModal>
|
|
34
|
+
<div>
|
|
35
|
+
<p>this is the modal content<p>
|
|
36
|
+
</div>
|
|
37
|
+
</JBModal>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### props
|
|
41
|
+
- onClose
|
|
42
|
+
you can pass a function to onClose props so that when a user click outside of the modal, the modal closes.
|
|
43
|
+
|
|
44
|
+
``` jsx
|
|
45
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
46
|
+
<JBModal onClose={() => setIsOpen(false)}></JBModal>
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- isOpen
|
|
51
|
+
you can pass true or false to this props,this way the modal will be open based on the isOpen props.
|
|
52
|
+
|
|
53
|
+
``` jsx
|
|
54
|
+
<JBModal isOpen={isOpen}></JBModal>
|
|
55
|
+
// the modal is open
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- id
|
|
59
|
+
you can set a specific id for each one of your modals,this way when the modal is open the id of the modal will be in your url.
|
|
60
|
+
when you set id modal will add `#your-id` to the url when open so when you refresh the page, modal will open automatically.
|
|
61
|
+
|
|
62
|
+
``` jsx
|
|
63
|
+
<JBModal id={MYMODAL}></JBModal>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- onUrlOpen
|
|
67
|
+
when the react copmonent first renders the default state of isModalOpen is false.
|
|
68
|
+
when the url contains the id of the modal the function passed to onUrlOpen will update the react state and set the isModalOpen state to true.
|
|
69
|
+
example:
|
|
70
|
+
|
|
71
|
+
```jsx
|
|
72
|
+
[isModalOpen, setOpen] = useState(false);
|
|
73
|
+
<JBModal onUrlOpen={() => setOpen(true)}></JBModal>
|
|
74
|
+
```
|
|
75
|
+
## customize modal look
|
|
76
|
+
|
|
77
|
+
you can customize modal look by following css properties
|
|
78
|
+
| css variable name | description |
|
|
79
|
+
| ------------- | ------------- |
|
|
80
|
+
| --jb-modal-bg-color | modal background color default is black `#fff` |
|
|
81
|
+
| --jb-modal-border-radius | modal border-radius default `24px` |
|
|
82
|
+
| --jb-modal-border-radius-mobile | modal border-radius on mobile default is `24px 24px 0 0` |
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=Object.create,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty,c=(e,l,c,o)=>{if(l&&"object"==typeof l||"function"==typeof l)for(var a,s=n(l),d=0,f=s.length;d<f;d++)a=s[d],u.call(e,a)||a===c||t(e,a,{get:(e=>l[e]).bind(null,a),enumerable:!(o=r(l,a))||o.enumerable});return e},o=(r,n,u)=>(u=null!=r?e(l(r)):{},c(!n&&r&&r.__esModule?u:t(u,"default",{value:r,enumerable:!0}),r));const a=o(require("react"));require("jb-modal");const s=o(require("jb-core/react")),d=a.default.forwardRef((e,t)=>{let r=(0,a.useRef)(null),[n,l]=(0,a.useState)(0);return(0,a.useImperativeHandle)(t,()=>r?r.current:{},[r]),(0,a.useEffect)(()=>{l(n+1)},[r.current]),(0,a.useEffect)(()=>{r.current&&(!0==e.isOpen?r.current.open():r.current.close())},[e.isOpen]),(0,a.useEffect)(()=>{r.current&&(r.current.id=e.id)},[e.id]),(0,s.useEvent)(r,"load",e.onLoad,!0),(0,s.useEvent)(r,"init",e.onInit,!0),(0,s.useEvent)(r,"close",e.onClose),(0,s.useEvent)(r,"urlOpen",e.onUrlOpen),a.default.createElement("jb-modal",{ref:r,class:e.className?e.className:""},a.default.createElement("div",{slot:"content"},e.children))});d.displayName="JBModal",exports.JBModal=d;
|
|
2
|
+
//# sourceMappingURL=JBModal.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JBModal.cjs.js","names":[],"sources":["../lib/events-hook.ts","../lib/JBModal.tsx"],"sourcesContent":["import { useEvent } from \"jb-core/react\";\r\nimport { RefObject } from \"react\";\r\nimport type {JBModalWebComponent, JBModalEventType} from 'jb-modal';\r\n\r\nexport type EventProps = {\r\n /**\r\n * when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount\r\n */\r\n onLoad?: (e: JBModalEventType<CustomEvent>) => void,\r\n /**\r\n * when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount\r\n */\r\n onInit?: (e: JBModalEventType<CustomEvent>) => void,\r\n onClose?: (e: JBModalEventType<CustomEvent>) => void,\r\n /**\r\n * when modal opened automatically by url hash (when element have id and url has #id) use this to update open state in parent component\r\n */\r\n onUrlOpen?: (e: JBModalEventType<CustomEvent>) => void,\r\n}\r\nexport function useEvents(element:RefObject<JBModalWebComponent>,props:EventProps){\r\n useEvent(element, 'load', props.onLoad, true);\r\n useEvent(element, 'init', props.onInit, true);\r\n useEvent(element, 'close', props.onClose);\r\n useEvent(element, 'urlOpen', props.onUrlOpen);\r\n}","import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';\r\nimport 'jb-modal';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport { JBModalWebComponent } from 'jb-modal';\r\nimport { useEvents, EventProps } from './events-hook.js';\r\n\r\nexport type Props = EventProps & React.PropsWithChildren<{\r\n className?:string,\r\n isOpen?: boolean,\r\n id?: string,\r\n}>\r\n\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace JSX {\r\n interface IntrinsicElements {\r\n 'jb-modal': JBModalType;\r\n }\r\n interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {\r\n class?:string,\r\n }\r\n }\r\n}\r\n\r\nexport const JBModal = React.forwardRef((props:Props, ref) => {\r\n const element = useRef<JBModalWebComponent>(null);\r\n const [refChangeCount, refChangeCountSetter] = useState(0);\r\n useImperativeHandle(\r\n ref,\r\n () => (element ? element.current : {}),\r\n [element],\r\n );\r\n useEffect(() => {\r\n refChangeCountSetter(refChangeCount + 1);\r\n }, [element.current]);\r\n useEffect(() => {\r\n if (element.current) {\r\n if (props.isOpen == true) {\r\n element.current.open();\r\n } else {\r\n element.current.close();\r\n }\r\n }\r\n\r\n }, [props.isOpen]);\r\n useEffect(() => {\r\n if (element.current) {\r\n element.current.id = props.id;\r\n }\r\n }, [props.id]);\r\n\r\n useEvents(element, props);\r\n return (\r\n <jb-modal ref={element} class={props.className ? props.className : ''}>\r\n <div slot=\"content\">\r\n {props.children}\r\n </div>\r\n </jb-modal>\r\n );\r\n});\r\n\r\nJBModal.displayName = \"JBModal\";\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBM,SAAU,UAAU,SAAuC,OAAgB;AAC/E,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,6BAAS,SAAS,WAAW,MAAM,UAAU;AAC9C;;;;MCAY,wBAAgB,cAAY,WAAkB,CAAE,OAAA,QAAA;CAC3D,MAAM,UAAU,kBAA4B,KAAK;CACjD,MAAM,CAAC,gBAAgB,qBAAqB,GAAG,oBAAS,EAAE;AAC1D,gCACE,KACA,MAAG,UAAW,QAAG,UAAe,CAAE,GAAC,CAGrC;AAEA,sBAAI,MAAQ;AACZ,uBAAe,iBAAA,EAAA;aAEP;sBAEH,MAAA;cAAM,aACL,MAAA,UAAgB,KACjB,SAAA,QAAA,MAAA;MAGK,SAAS,QAAA,OAAA;WAIhB,MACF,EAAA;AAED,sBAAU,MAAA;AACV,MACE,QAAA,QACE,SAAA,QAAA,KAAA,MAAK;CAOX,GAAO"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import 'jb-modal';
|
|
3
|
+
import { JBModalWebComponent } from 'jb-modal';
|
|
4
|
+
import { EventProps } from './events-hook.js';
|
|
5
|
+
export type Props = EventProps & React.PropsWithChildren<{
|
|
6
|
+
className?: string;
|
|
7
|
+
isOpen?: boolean;
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare global {
|
|
11
|
+
namespace JSX {
|
|
12
|
+
interface IntrinsicElements {
|
|
13
|
+
'jb-modal': JBModalType;
|
|
14
|
+
}
|
|
15
|
+
interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export declare const JBModal: React.ForwardRefExoticComponent<EventProps & {
|
|
21
|
+
className?: string;
|
|
22
|
+
isOpen?: boolean;
|
|
23
|
+
id?: string;
|
|
24
|
+
} & {
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
} & React.RefAttributes<unknown>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e,{useEffect as r,useImperativeHandle as n,useRef as t,useState as o}from"react";import"jb-modal";import{useEvent as l}from"jb-core/react";let c=e.forwardRef((c,a)=>{let i=t(null),[d,s]=o(0);return n(a,()=>i?i.current:{},[i]),r(()=>{s(d+1)},[i.current]),r(()=>{i.current&&(!0==c.isOpen?i.current.open():i.current.close())},[c.isOpen]),r(()=>{i.current&&(i.current.id=c.id)},[c.id]),l(i,"load",c.onLoad,!0),l(i,"init",c.onInit,!0),l(i,"close",c.onClose),l(i,"urlOpen",c.onUrlOpen),e.createElement("jb-modal",{ref:i,class:c.className?c.className:""},e.createElement("div",{slot:"content"},c.children))});c.displayName="JBModal";export{c as JBModal};
|
|
2
|
+
//# sourceMappingURL=JBModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JBModal.js","names":[],"sources":["../lib/events-hook.ts","../lib/JBModal.tsx"],"sourcesContent":["import { useEvent } from \"jb-core/react\";\r\nimport { RefObject } from \"react\";\r\nimport type {JBModalWebComponent, JBModalEventType} from 'jb-modal';\r\n\r\nexport type EventProps = {\r\n /**\r\n * when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount\r\n */\r\n onLoad?: (e: JBModalEventType<CustomEvent>) => void,\r\n /**\r\n * when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount\r\n */\r\n onInit?: (e: JBModalEventType<CustomEvent>) => void,\r\n onClose?: (e: JBModalEventType<CustomEvent>) => void,\r\n /**\r\n * when modal opened automatically by url hash (when element have id and url has #id) use this to update open state in parent component\r\n */\r\n onUrlOpen?: (e: JBModalEventType<CustomEvent>) => void,\r\n}\r\nexport function useEvents(element:RefObject<JBModalWebComponent>,props:EventProps){\r\n useEvent(element, 'load', props.onLoad, true);\r\n useEvent(element, 'init', props.onInit, true);\r\n useEvent(element, 'close', props.onClose);\r\n useEvent(element, 'urlOpen', props.onUrlOpen);\r\n}","import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';\r\nimport 'jb-modal';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport { JBModalWebComponent } from 'jb-modal';\r\nimport { useEvents, EventProps } from './events-hook.js';\r\n\r\nexport type Props = EventProps & React.PropsWithChildren<{\r\n className?:string,\r\n isOpen?: boolean,\r\n id?: string,\r\n}>\r\n\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace JSX {\r\n interface IntrinsicElements {\r\n 'jb-modal': JBModalType;\r\n }\r\n interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {\r\n class?:string,\r\n }\r\n }\r\n}\r\n\r\nexport const JBModal = React.forwardRef((props:Props, ref) => {\r\n const element = useRef<JBModalWebComponent>(null);\r\n const [refChangeCount, refChangeCountSetter] = useState(0);\r\n useImperativeHandle(\r\n ref,\r\n () => (element ? element.current : {}),\r\n [element],\r\n );\r\n useEffect(() => {\r\n refChangeCountSetter(refChangeCount + 1);\r\n }, [element.current]);\r\n useEffect(() => {\r\n if (element.current) {\r\n if (props.isOpen == true) {\r\n element.current.open();\r\n } else {\r\n element.current.close();\r\n }\r\n }\r\n\r\n }, [props.isOpen]);\r\n useEffect(() => {\r\n if (element.current) {\r\n element.current.id = props.id;\r\n }\r\n }, [props.id]);\r\n\r\n useEvents(element, props);\r\n return (\r\n <jb-modal ref={element} class={props.className ? props.className : ''}>\r\n <div slot=\"content\">\r\n {props.children}\r\n </div>\r\n </jb-modal>\r\n );\r\n});\r\n\r\nJBModal.displayName = \"JBModal\";\r\n"],"mappings":";;;;;AAmBM,SAAU,UAAU,SAAuC,OAAgB;AAC/E,UAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,UAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,UAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,UAAS,SAAS,WAAW,MAAM,UAAU;AAC9C;;;;MCAY,wBAAgB,MAAY,WAAkB,CAAE,OAAA,QAAA;CAC3D,MAAM,UAAU,OAA4B,KAAK;CACjD,MAAM,CAAC,gBAAgB,qBAAqB,GAAG,SAAS,EAAE;AAC1D,qBACE,KACA,MAAG,UAAW,QAAG,UAAe,CAAE,GAAC,CAGrC;AAEA,WAAI,MAAQ;AACZ,uBAAe,iBAAA,EAAA;aAEP;WAEH,MAAA;cAAM,aACL,MAAA,UAAgB,KACjB,SAAA,QAAA,MAAA;MAGK,SAAS,QAAA,OAAA;WAIhB,MACF,EAAA;AAED,WAAU,MAAA;AACV,MACE,QAAA,QACE,SAAA,QAAA,KAAA,MAAK;CAOX,GAAO"}
|