jb-modal 1.6.1 → 1.7.0

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.
Files changed (38) hide show
  1. package/README.md +48 -2
  2. package/dist/JBModal.cjs.js +2 -0
  3. package/dist/JBModal.cjs.js.br +0 -0
  4. package/dist/JBModal.cjs.js.gz +0 -0
  5. package/dist/JBModal.cjs.js.map +1 -0
  6. package/dist/JBModal.js +1 -185
  7. package/dist/JBModal.js.br +0 -0
  8. package/dist/JBModal.js.gz +0 -0
  9. package/dist/JBModal.js.map +1 -1
  10. package/dist/JBModal.umd.js +1 -195
  11. package/dist/JBModal.umd.js.br +0 -0
  12. package/dist/JBModal.umd.js.gz +0 -0
  13. package/dist/JBModal.umd.js.map +1 -1
  14. package/dist/{JBModal.d.ts → web-component/jb-modal/lib/JBModal.d.ts} +7 -7
  15. package/index.js +1 -1
  16. package/lib/JBModal.scss +1 -1
  17. package/lib/JBModal.ts +148 -150
  18. package/package.json +5 -3
  19. package/react/LICENSE +21 -0
  20. package/react/README.md +82 -0
  21. package/react/dist/JBModal.cjs.js +67 -0
  22. package/react/dist/JBModal.cjs.js.map +1 -0
  23. package/react/dist/JBModal.js +65 -0
  24. package/react/dist/JBModal.js.map +1 -0
  25. package/react/dist/JBModal.umd.js +70 -0
  26. package/react/dist/JBModal.umd.js.map +1 -0
  27. package/react/dist/common/hooks/use-event.d.ts +3 -0
  28. package/react/dist/common/hooks/useLazyRef.d.ts +4 -0
  29. package/react/dist/common/hooks/useMobx.d.ts +4 -0
  30. package/react/dist/common/scripts/device-detection.d.ts +1 -0
  31. package/react/dist/common/scripts/persian-helper.d.ts +3 -0
  32. package/react/dist/web-component/jb-modal/react/lib/JBModal.d.ts +30 -0
  33. package/react/index.js +1 -0
  34. package/react/lib/JBModal.tsx +80 -0
  35. package/react/package.json +38 -0
  36. package/react/tsconfig.json +18 -0
  37. package/lib/global.d.ts +0 -11
  38. /package/dist/{Types.d.ts → web-component/jb-modal/lib/Types.d.ts} +0 -0
@@ -0,0 +1,65 @@
1
+ import React, { useEffect, useRef, useState, useImperativeHandle } from 'react';
2
+ import 'jb-modal';
3
+
4
+ function useBindEvent(ref, event, handler, passive = false) {
5
+ useEffect(() => {
6
+ const dom = ref.current;
7
+ if (dom) {
8
+ // initiate the event handler
9
+ dom.addEventListener(event, handler, passive);
10
+ }
11
+ // this will clean up the event every time the component is re-rendered
12
+ return function cleanup() {
13
+ if (dom) {
14
+ dom.removeEventListener(event, handler, passive);
15
+ }
16
+ };
17
+ }, [ref, event, handler, passive]);
18
+ }
19
+
20
+ const JBModal = React.forwardRef((props, ref) => {
21
+ const element = useRef(null);
22
+ const [refChangeCount, refChangeCountSetter] = useState(0);
23
+ useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
24
+ useEffect(() => {
25
+ refChangeCountSetter(refChangeCount + 1);
26
+ }, [element.current]);
27
+ useEffect(() => {
28
+ if (element.current) {
29
+ if (props.isOpen == true) {
30
+ element.current.open();
31
+ }
32
+ else {
33
+ element.current.close();
34
+ }
35
+ }
36
+ }, [props.isOpen]);
37
+ useEffect(() => {
38
+ if (props.id !== undefined && element.current) {
39
+ element.current.addEventListener('urlOpen', onUrlOpen);
40
+ element.current.id = props.id;
41
+ }
42
+ return () => {
43
+ if (props.id !== undefined && element.current) {
44
+ element.current.removeEventListener('urlOpen', onUrlOpen);
45
+ }
46
+ };
47
+ }, [props.id]);
48
+ function onClose() {
49
+ if (props.onClose) {
50
+ props.onClose();
51
+ }
52
+ }
53
+ function onUrlOpen() {
54
+ if (props.onUrlOpen) {
55
+ props.onUrlOpen();
56
+ }
57
+ }
58
+ useBindEvent(element, 'close', onClose);
59
+ return (React.createElement("jb-modal", { ref: element, class: props.className ? props.className : '' },
60
+ React.createElement("div", { slot: "content" }, props.children)));
61
+ });
62
+ JBModal.displayName = "JBModal";
63
+
64
+ export { JBModal };
65
+ //# sourceMappingURL=JBModal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JBModal.js","sources":["../../../../common/hooks/use-event.ts","../lib/JBModal.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom:HTMLElement, event:any, handler:any, passive = false) {\r\n useEffect(() => {\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n });\r\n}\r\nexport function useBindEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler:(e:TEvent)=>void, passive = false) {\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","import PropTypes from 'prop-types';\r\nimport 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 { useBindEvent } from '../../../../common/hooks/use-event.js';\r\nexport type JBModalProps = React.PropsWithChildren<{\r\n onClose?: () => void,\r\n onUrlOpen?: () => void,\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\nconst JBModal = React.forwardRef((props:JBModalProps, 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 (props.id !== undefined && element.current) {\r\n element.current.addEventListener('urlOpen', onUrlOpen);\r\n element.current.id = props.id;\r\n }\r\n return () => {\r\n if (props.id !== undefined && element.current) {\r\n element.current.removeEventListener('urlOpen', onUrlOpen);\r\n }\r\n };\r\n }, [props.id]);\r\n function onClose() {\r\n if (props.onClose) {\r\n props.onClose();\r\n }\r\n }\r\n function onUrlOpen() {\r\n if (props.onUrlOpen) {\r\n props.onUrlOpen();\r\n }\r\n }\r\n useBindEvent(element, 'close', onClose);\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\nexport {JBModal};\r\n"],"names":[],"mappings":";;;AAgBM,SAAU,YAAY,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAwB,EAAE,OAAO,GAAG,KAAK,EAAA;IAClJ,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;AACxB,QAAA,IAAI,GAAG,EAAE;;YAEP,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,SAAA;;AAED,QAAA,OAAO,SAAS,OAAO,GAAA;AACrB,YAAA,IAAG,GAAG,EAAC;gBACL,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAClD,aAAA;AACH,SAAC,CAAC;KACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CAAC,CA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AE,SAAS,CAAC,CAAC;AAC3D,aAAA;AACH,SAAC,CAAC;AACJ,KAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACf,IAAA,SAAS,OAAO,GAAA;QACd,IAAI,KAAK,CAAC,OAAO,EAAE;YACjB,KAAK,CAAC,OAAO,EAAE,CAAC;AACjB,SAAA;KACF;AACD,IAAA,SAAS,SAAS,GAAA;QAChB,IAAI,KAAK,CAAC,SAAS,EAAE;YACnB,KAAK,CAAC,SAAS,EAAE,CAAC;AACnB,SAAA;KACF;AACD,IAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACxC,QACE,kCAAU,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,GAAG,EAAE,EAAA;QACnE,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,IAAI,EAAC,SAAS,EAChB,EAAA,KAAK,CAAC,QAAQ,CACX,CACG,EACX;AACJ,CAAC,EAAE;AAEH,OAAO,CAAC,WAAW,GAAG,SAAS;;;;"}
@@ -0,0 +1,70 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('jb-modal')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'jb-modal'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JBModal = {}, global.React));
5
+ })(this, (function (exports, React) { 'use strict';
6
+
7
+ function useBindEvent(ref, event, handler, passive = false) {
8
+ React.useEffect(() => {
9
+ const dom = ref.current;
10
+ if (dom) {
11
+ // initiate the event handler
12
+ dom.addEventListener(event, handler, passive);
13
+ }
14
+ // this will clean up the event every time the component is re-rendered
15
+ return function cleanup() {
16
+ if (dom) {
17
+ dom.removeEventListener(event, handler, passive);
18
+ }
19
+ };
20
+ }, [ref, event, handler, passive]);
21
+ }
22
+
23
+ const JBModal = React.forwardRef((props, ref) => {
24
+ const element = React.useRef(null);
25
+ const [refChangeCount, refChangeCountSetter] = React.useState(0);
26
+ React.useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
27
+ React.useEffect(() => {
28
+ refChangeCountSetter(refChangeCount + 1);
29
+ }, [element.current]);
30
+ React.useEffect(() => {
31
+ if (element.current) {
32
+ if (props.isOpen == true) {
33
+ element.current.open();
34
+ }
35
+ else {
36
+ element.current.close();
37
+ }
38
+ }
39
+ }, [props.isOpen]);
40
+ React.useEffect(() => {
41
+ if (props.id !== undefined && element.current) {
42
+ element.current.addEventListener('urlOpen', onUrlOpen);
43
+ element.current.id = props.id;
44
+ }
45
+ return () => {
46
+ if (props.id !== undefined && element.current) {
47
+ element.current.removeEventListener('urlOpen', onUrlOpen);
48
+ }
49
+ };
50
+ }, [props.id]);
51
+ function onClose() {
52
+ if (props.onClose) {
53
+ props.onClose();
54
+ }
55
+ }
56
+ function onUrlOpen() {
57
+ if (props.onUrlOpen) {
58
+ props.onUrlOpen();
59
+ }
60
+ }
61
+ useBindEvent(element, 'close', onClose);
62
+ return (React.createElement("jb-modal", { ref: element, class: props.className ? props.className : '' },
63
+ React.createElement("div", { slot: "content" }, props.children)));
64
+ });
65
+ JBModal.displayName = "JBModal";
66
+
67
+ exports.JBModal = JBModal;
68
+
69
+ }));
70
+ //# sourceMappingURL=JBModal.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JBModal.umd.js","sources":["../../../../common/hooks/use-event.ts","../lib/JBModal.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom:HTMLElement, event:any, handler:any, passive = false) {\r\n useEffect(() => {\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n });\r\n}\r\nexport function useBindEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler:(e:TEvent)=>void, passive = false) {\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","import PropTypes from 'prop-types';\r\nimport 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 { useBindEvent } from '../../../../common/hooks/use-event.js';\r\nexport type JBModalProps = React.PropsWithChildren<{\r\n onClose?: () => void,\r\n onUrlOpen?: () => void,\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\nconst JBModal = React.forwardRef((props:JBModalProps, 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 (props.id !== undefined && element.current) {\r\n element.current.addEventListener('urlOpen', onUrlOpen);\r\n element.current.id = props.id;\r\n }\r\n return () => {\r\n if (props.id !== undefined && element.current) {\r\n element.current.removeEventListener('urlOpen', onUrlOpen);\r\n }\r\n };\r\n }, [props.id]);\r\n function onClose() {\r\n if (props.onClose) {\r\n props.onClose();\r\n }\r\n }\r\n function onUrlOpen() {\r\n if (props.onUrlOpen) {\r\n props.onUrlOpen();\r\n }\r\n }\r\n useBindEvent(element, 'close', onClose);\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\nexport {JBModal};\r\n"],"names":["useEffect","useRef","useState","useImperativeHandle"],"mappings":";;;;;;EAgBM,SAAU,YAAY,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAwB,EAAE,OAAO,GAAG,KAAK,EAAA;MAClJA,eAAS,CAAC,MAAK;EACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;EACxB,QAAA,IAAI,GAAG,EAAE;;cAEP,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EAC/C,SAAA;;EAED,QAAA,OAAO,SAAS,OAAO,GAAA;EACrB,YAAA,IAAG,GAAG,EAAC;kBACL,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EAClD,aAAA;EACH,SAAC,CAAC;OACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CAAC,CAAC,CAAC;EACjC;;ACJM,QAAA,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAkB,EAAE,GAAG,KAAI;EAC3D,IAAA,MAAM,OAAO,GAAGC,YAAM,CAAsB,IAAI,CAAC,CAAC;MAClD,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC,GAAGC,cAAQ,CAAC,CAAC,CAAC,CAAC;MAC3DC,yBAAmB,CACjB,GAAG,EACH,OAAO,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,EAA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S,EAAE,CAAC;EACnB,SAAA;OACF;EACD,IAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;MACxC,QACE,kCAAU,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,GAAG,EAAE,EAAA;UACnE,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,IAAI,EAAC,SAAS,EAChB,EAAA,KAAK,CAAC,QAAQ,CACX,CACG,EACX;EACJ,CAAC,EAAE;EAEH,OAAO,CAAC,WAAW,GAAG,SAAS;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function useEvent(dom: HTMLElement, event: any, handler: any, passive?: boolean): void;
3
+ export declare function useBindEvent<TRef extends React.MutableRefObject<any | null>, TEvent>(ref: TRef, event: string, handler: (e: TEvent) => void, passive?: boolean): void;
@@ -0,0 +1,4 @@
1
+ import { MutableRefObject } from "react";
2
+ type InitFunc<T> = () => T;
3
+ export declare const useLazyRef: <T>(initValFunc: InitFunc<T>) => MutableRefObject<any>;
4
+ export {};
@@ -0,0 +1,4 @@
1
+ type Initializers = any[];
2
+ type Constructor<T extends object = object> = new (...args: any[]) => T;
3
+ export declare const useMobx: <T extends object>(Store: Constructor<T>, initializers: Initializers) => T;
4
+ export {};
@@ -0,0 +1 @@
1
+ export declare const isMobile: () => boolean;
@@ -0,0 +1,3 @@
1
+ declare function faToEnDigits(input: string | number): string;
2
+ declare function enToFaDigits(input: string | number): string;
3
+ export { enToFaDigits, faToEnDigits };
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import 'jb-modal';
3
+ import { JBModalWebComponent } from 'jb-modal';
4
+ export type JBModalProps = React.PropsWithChildren<{
5
+ onClose?: () => void;
6
+ onUrlOpen?: () => void;
7
+ className?: string;
8
+ isOpen?: boolean;
9
+ id?: string;
10
+ }>;
11
+ declare global {
12
+ namespace JSX {
13
+ interface IntrinsicElements {
14
+ 'jb-modal': JBModalType;
15
+ }
16
+ interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {
17
+ class?: string;
18
+ }
19
+ }
20
+ }
21
+ declare const JBModal: React.ForwardRefExoticComponent<{
22
+ onClose?: () => void;
23
+ onUrlOpen?: () => void;
24
+ className?: string;
25
+ isOpen?: boolean;
26
+ id?: string;
27
+ } & {
28
+ children?: React.ReactNode;
29
+ } & React.RefAttributes<unknown>>;
30
+ export { JBModal };
package/react/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/JBModal.js';
@@ -0,0 +1,80 @@
1
+ import PropTypes from 'prop-types';
2
+ import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
3
+ import 'jb-modal';
4
+ // eslint-disable-next-line no-duplicate-imports
5
+ import { JBModalWebComponent } from 'jb-modal';
6
+ import { useBindEvent } from '../../../../common/hooks/use-event.js';
7
+ export type JBModalProps = React.PropsWithChildren<{
8
+ onClose?: () => void,
9
+ onUrlOpen?: () => void,
10
+ className?:string,
11
+ isOpen?: boolean,
12
+ id?: string,
13
+ }>
14
+
15
+ declare global {
16
+ // eslint-disable-next-line @typescript-eslint/no-namespace
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'jb-modal': JBModalType;
20
+ }
21
+ interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {
22
+ class?:string,
23
+ }
24
+ }
25
+ }
26
+
27
+ const JBModal = React.forwardRef((props:JBModalProps, ref) => {
28
+ const element = useRef<JBModalWebComponent>(null);
29
+ const [refChangeCount, refChangeCountSetter] = useState(0);
30
+ useImperativeHandle(
31
+ ref,
32
+ () => (element ? element.current : {}),
33
+ [element],
34
+ );
35
+ useEffect(() => {
36
+ refChangeCountSetter(refChangeCount + 1);
37
+ }, [element.current]);
38
+ useEffect(() => {
39
+ if (element.current) {
40
+ if (props.isOpen == true) {
41
+ element.current.open();
42
+ } else {
43
+ element.current.close();
44
+ }
45
+ }
46
+
47
+ }, [props.isOpen]);
48
+ useEffect(() => {
49
+ if (props.id !== undefined && element.current) {
50
+ element.current.addEventListener('urlOpen', onUrlOpen);
51
+ element.current.id = props.id;
52
+ }
53
+ return () => {
54
+ if (props.id !== undefined && element.current) {
55
+ element.current.removeEventListener('urlOpen', onUrlOpen);
56
+ }
57
+ };
58
+ }, [props.id]);
59
+ function onClose() {
60
+ if (props.onClose) {
61
+ props.onClose();
62
+ }
63
+ }
64
+ function onUrlOpen() {
65
+ if (props.onUrlOpen) {
66
+ props.onUrlOpen();
67
+ }
68
+ }
69
+ useBindEvent(element, 'close', onClose);
70
+ return (
71
+ <jb-modal ref={element} class={props.className ? props.className : ''}>
72
+ <div slot="content">
73
+ {props.children}
74
+ </div>
75
+ </jb-modal>
76
+ );
77
+ });
78
+
79
+ JBModal.displayName = "JBModal";
80
+ export {JBModal};
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "jb-modal-react",
3
+ "description": "modal react component",
4
+ "type": "module",
5
+ "author": {
6
+ "name": "mohammad javad bathaei",
7
+ "email": "javadbat@gmail.com"
8
+ },
9
+ "keywords": [
10
+ "jb",
11
+ "jb-modal",
12
+ "react component",
13
+ "dialog",
14
+ "modal",
15
+ "react",
16
+ "react modal",
17
+ "modal window",
18
+ "pop up"
19
+ ],
20
+ "version": "1.1.0",
21
+ "bugs": "https://github.com/javadbat/jb-modal/issues",
22
+ "license": "MIT",
23
+ "files": [
24
+ "LICENSE",
25
+ "README.md",
26
+ "lib/",
27
+ "dist/"
28
+ ],
29
+ "main": "index.js",
30
+ "types": "./dist/web-component/jb-modal/react/lib/JBModal.d.ts",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git@github.com:javadbat/jb-modal.git"
34
+ },
35
+ "dependencies": {
36
+ "jb-modal": ">=1.5.3"
37
+ }
38
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "."
4
+ },
5
+ "include": [
6
+ "../../../common/scripts/**/*.ts",
7
+ "../../../common/hooks/**/*.ts",
8
+ "../../../common/hooks/**/*.js",
9
+ "lib/**/*.ts",
10
+ "lib/**/*.tsx"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "**/*.spec.ts",
15
+ "dist",
16
+ ],
17
+ "extends":"../../tsconfig-react.json"
18
+ }
package/lib/global.d.ts DELETED
@@ -1,11 +0,0 @@
1
- type FileStringModule = {
2
- readonly default: string;
3
- }
4
- declare module '*.scss' {
5
- const value: FileStringModule;
6
- export default value;
7
- }
8
- declare module '*.html' {
9
- const value: FileStringModule;
10
- export default value.default
11
- }