@simplybusiness/mobius 4.4.0 → 4.4.2

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.
@@ -26,20 +26,26 @@ const Drawer = /*#__PURE__*/ forwardRef((props, ref)=>{
26
26
  event.preventDefault();
27
27
  event.stopPropagation();
28
28
  }
29
+ // Name the callback function, so we can add and remove event listener
30
+ const transitionCallback = (e)=>{
31
+ // Close drawer only if the transition is on the dialog element
32
+ // As it can be on a child element (ie `<Button>` inside the drawer)
33
+ if (e.target === modalRef.current) {
34
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
35
+ doClose();
36
+ }
37
+ };
29
38
  const doClose = ()=>{
30
- var _modalRef_current;
39
+ var _modalRef_current, _modalRef_current1;
31
40
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.close();
32
41
  onClose === null || onClose === void 0 ? void 0 : onClose();
42
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.removeEventListener("transitionend", transitionCallback);
33
43
  };
34
44
  // Delay close to allow backdrop exit transition
35
45
  if (hasDialogSupport) {
36
46
  var _modalRef_current, _modalRef_current1;
37
47
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.classList.remove(TRANSITION_CLASS_NAME);
38
- (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", ()=>{
39
- doClose();
40
- }, {
41
- once: true
42
- });
48
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", transitionCallback);
43
49
  } else {
44
50
  doClose();
45
51
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { VisuallyHidden } from \"../VisuallyHidden\";\nimport { DrawerProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type DialogElementType = HTMLDialogElement;\nexport type DialogRef = Ref<DialogElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Drawer = forwardRef((props: DrawerProps, ref: DialogRef) => {\n const {\n isOpen,\n className,\n closeLabel,\n direction,\n announce = \"Drawer opened on screen\",\n onOpen,\n onClose,\n children,\n } = props;\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing transitions\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\n \"transitionend\",\n () => {\n doClose();\n },\n { once: true },\n );\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Drawer\",\n `--${direction}`,\n className,\n {\n \"--should-transition\": hasDialogSupport,\n },\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n aria-describedby=\"screen-reader-announce\"\n >\n <VisuallyHidden>\n <div id=\"screen-reader-announce\">{announce}</div>\n </VisuallyHidden>\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer };\n"],"names":["classNames","Children","cloneElement","forwardRef","isValidElement","useCallback","useEffect","useRef","useBodyScrollLock","supportsDialog","VisuallyHidden","mergeRefs","TRANSITION_CLASS_NAME","Drawer","props","ref","isOpen","className","closeLabel","direction","announce","onOpen","onClose","children","hasOpened","modalRef","hasDialogSupport","current","enabled","handleClose","event","preventDefault","stopPropagation","doClose","close","classList","remove","addEventListener","once","modalClasses","toggleModal","window","default","dialogPolyfill","registerDialog","error","console","open","showModal","add","dialog","onCancel","aria-describedby","div","id","map","child","displayName"],"mappings":"AAAA;;AAEA,OAAOA,gBAAgB,oBAAoB;AAC3C,SACEC,QAAQ,EAGRC,YAAY,EACZC,UAAU,EACVC,cAAc,EACdC,WAAW,EACXC,SAAS,EACTC,MAAM,QACD,QAAQ;AACf,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,cAAc,QAAQ,6BAA6B;AAC5D,SAASC,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BACA,6DAA6D;gBAC7D,MAAM,EAAEe,SAASC,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC;gBACjD,IAAI;oBACFA,eAAeC,cAAc,CAACnB,SAASE,OAAO;gBAChD,EAAE,OAAOkB,OAAO;oBACd,mDAAmD;oBACnD,oEAAoE;oBACpE,qGAAqG;oBACrGC,QAAQD,KAAK,CAAC,kCAAkCA;gBAClD;YACF;YAEA,IAAI7B,UAAU,GAACS,oBAAAA,SAASE,OAAO,cAAhBF,wCAAAA,kBAAkBsB,IAAI,GAAE;oBACrCtB,oBACAA;iBADAA,qBAAAA,SAASE,OAAO,cAAhBF,yCAAAA,mBAAkBuB,SAAS;iBAC3BvB,qBAAAA,SAASE,OAAO,cAAhBF,yCAAAA,mBAAkBU,SAAS,CAACc,GAAG,CAACrC;gBAChCS,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACL,YAAUS,qBAAAA,SAASE,OAAO,cAAhBF,yCAAAA,mBAAkBsB,IAAI,GAAE;gBAC5ClB;YACF;QACF;QAEAW;IACF,GAAG;QAACxB;QAAQK;QAAQQ;QAAaH;KAAiB;IAElD,qBACE,MAACwB;QACCnC,KAAKJ,UAAU;YAACc;YAAUV;SAAI;QAC9BoC,UAAUtB;QACVZ,WAAWsB;QACXa,oBAAiB;;0BAEjB,KAAC1C;0BACC,cAAA,KAAC2C;oBAAIC,IAAG;8BAA0BlC;;;YAEnCnB,SAASsD,GAAG,CAAChC,UAAUiC,CAAAA;gBACtB,kBAAIpD,eAAeoD,QAAQ;oBACzB,qBAAOtD,aAAasD,OAAO;wBACzBlC,SAASO;wBACTX;oBACF;gBACF;gBAEA,OAAOsC;YACT;;;AAGN;AAEA3C,OAAO4C,WAAW,GAAG;AACrB,SAAS5C,MAAM,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { VisuallyHidden } from \"../VisuallyHidden\";\nimport { DrawerProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type DialogElementType = HTMLDialogElement;\nexport type DialogRef = Ref<DialogElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Drawer = forwardRef((props: DrawerProps, ref: DialogRef) => {\n const {\n isOpen,\n className,\n closeLabel,\n direction,\n announce = \"Drawer opened on screen\",\n onOpen,\n onClose,\n children,\n } = props;\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing transitions\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n // Name the callback function, so we can add and remove event listener\n const transitionCallback = (e: Event) => {\n // Close drawer only if the transition is on the dialog element\n // As it can be on a child element (ie `<Button>` inside the drawer)\n if (e.target === modalRef.current) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n doClose();\n }\n };\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n modalRef.current?.removeEventListener(\n \"transitionend\",\n transitionCallback,\n );\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\"transitionend\", transitionCallback);\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Drawer\",\n `--${direction}`,\n className,\n {\n \"--should-transition\": hasDialogSupport,\n },\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n aria-describedby=\"screen-reader-announce\"\n >\n <VisuallyHidden>\n <div id=\"screen-reader-announce\">{announce}</div>\n </VisuallyHidden>\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer };\n"],"names":["classNames","Children","cloneElement","forwardRef","isValidElement","useCallback","useEffect","useRef","useBodyScrollLock","supportsDialog","VisuallyHidden","mergeRefs","TRANSITION_CLASS_NAME","Drawer","props","ref","isOpen","className","closeLabel","direction","announce","onOpen","onClose","children","hasOpened","modalRef","hasDialogSupport","current","enabled","handleClose","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","toggleModal","window","default","dialogPolyfill","registerDialog","error","console","open","showModal","add","dialog","onCancel","aria-describedby","div","id","map","child","displayName"],"mappings":"AAAA;;AA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0BAEjB,KAAC7C;0BACC,cAAA,KAAC8C;oBAAIC,IAAG;8BAA0BrC;;;YAEnCnB,SAASyD,GAAG,CAACnC,UAAUoC,CAAAA;gBACtB,kBAAIvD,eAAeuD,QAAQ;oBACzB,qBAAOzD,aAAayD,OAAO;wBACzBrC,SAASO;wBACTX;oBACF;gBACF;gBAEA,OAAOyC;YACT;;;AAGN;AAEA9C,OAAO+C,WAAW,GAAG;AACrB,SAAS/C,MAAM,GAAG"}
@@ -34,20 +34,26 @@ const Modal = /*#__PURE__*/ forwardRef((props, ref)=>{
34
34
  event.preventDefault();
35
35
  event.stopPropagation();
36
36
  }
37
+ // Name the callback function, so we can add and remove event listener
38
+ const transitionCallback = (e)=>{
39
+ // Close modal only if the transition is on the dialog element
40
+ // As it can be on a child element (ie `<Button>` inside the drawer)
41
+ if (e.target === modalRef.current) {
42
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
43
+ doClose();
44
+ }
45
+ };
37
46
  const doClose = ()=>{
38
- var _modalRef_current;
47
+ var _modalRef_current, _modalRef_current1;
39
48
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.close();
40
49
  onClose === null || onClose === void 0 ? void 0 : onClose();
50
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.removeEventListener("transitionend", transitionCallback);
41
51
  };
42
52
  // Delay close to allow backdrop exit transition
43
53
  if (hasDialogSupport && animation) {
44
54
  var _modalRef_current, _modalRef_current1;
45
55
  (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.classList.remove(TRANSITION_CLASS_NAME);
46
- (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", ()=>{
47
- doClose();
48
- }, {
49
- once: true
50
- });
56
+ (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", transitionCallback);
51
57
  } else {
52
58
  doClose();
53
59
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type ModalElementType = HTMLDialogElement;\nexport type ModalRef = Ref<ModalElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Modal = forwardRef((props: ModalProps, ref: ModalRef) => {\n const {\n isOpen,\n onClose,\n onOpen,\n children,\n className,\n closeLabel,\n isFullScreen,\n animation,\n // Deprecated props below\n size,\n appElement,\n preventCloseOnEsc,\n shouldFocusAfterRender,\n parentSelector,\n } = props;\n const hasWarnedAboutMissingLabels = useRef<boolean>(false);\n // Handle deprecated props\n if (!hasWarnedAboutMissingLabels.current) {\n if (\n size ||\n appElement ||\n preventCloseOnEsc ||\n shouldFocusAfterRender ||\n parentSelector\n ) {\n console.warn(\n `Deprecation warning: Mobius Modal no longer supports the following props: size, appElement, preventCloseOnEsc, shouldFocusAfterRender and parentSelector.`,\n );\n hasWarnedAboutMissingLabels.current = true;\n }\n }\n\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing animations\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport && animation) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\n \"transitionend\",\n () => {\n doClose();\n },\n { once: true },\n );\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport, animation],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Modal\",\n {\n \"--no-dialog-support\": !hasDialogSupport, // This class is used to correctly position modal in x/y middle on iOS <= 15.2\n \"--should-transition\": hasDialogSupport && animation,\n \"--slide-up\": animation === \"slideUp\",\n \"--fade\": animation === \"fade\",\n \"--is-fullscreen\": isFullScreen,\n },\n className,\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n >\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nModal.displayName = \"Modal\";\nexport { Modal };\n"],"names":["classNames","Children","cloneElement","forwardRef","isValidElement","useCallback","useEffect","useRef","useBodyScrollLock","supportsDialog","mergeRefs","TRANSITION_CLASS_NAME","Modal","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","current","console","warn","hasOpened","modalRef","hasDialogSupport","enabled","handleClose","event","preventDefault","stopPropagation","doClose","close","classList","remove","addEventListener","once","modalClasses","toggleModal","window","default","dialogPolyfill","registerDialog","error","open","showModal","add","dialog","onCancel","map","child","displayName"],"mappings":"AAAA;;AAEA,OAAOA,gBAAgB,oBAAoB;AAC3C,SACEC,QAAQ,EAGRC,YAAY,EACZC,UAAU,EACVC,cAAc,EACdC,WAAW,EACXC,SAAS,EACTC,MAAM,QACD,QAAQ;AACf,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,cAAc,QAAQ,6BAA6B;AAE5D,SAASC,SAAS,QAAQ,cAAc;AAKxC,MAAMC,wBAAwB;AAE9B,MAAMC,sBAAQT,WAAW,CAACU,OAAmBC;IAC3C,MAAM,EACJC,MAAM,EACNC,OAAO,EACPC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,YAAY,EACZC,SAAS,EACT,yBAAyB;IACzBC,IAAI,EACJC,UAAU,EACVC,iBAAiB,EACjBC,sBAAsB,EACtBC,cAAc,EACf,GAAGd;IACJ,MAAMe,8BAA8BrB,OAAgB;IACpD,0BAA0B;IAC1B,IAAI,CAACqB,4BAA4BC,OAAO,EAAE;QACxC,IACEN,QACAC,cACAC,qBACAC,0BACAC,gBACA;YACAG,QAAQC,IAAI,CACV,CAAC,yJAAyJ,CAAC;YAE7JH,4BAA4BC,OAAO,GAAG;QACxC;IACF;IAEA,MAAMG,YAAYzB,OAAgB;IAClC,MAAM0B,WAAW1B,OAAiC;IAClD,MAAM2B,mBAAmBzB;IAEzB,mBAAmB;IACnB,IAAIQ,UAAU,CAACe,UAAUH,OAAO,EAAE;QAChCZ;QACAe,UAA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kBoB,IAAI,GAAE;oBACrCpB,oBACAA;iBADAA,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBqB,SAAS;iBAC3BrB,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBS,SAAS,CAACa,GAAG,CAAC5C;gBAChCM,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACF,YAAUkB,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBoB,IAAI,GAAE;gBAC5CjB;YACF;QACF;QAEAW;IACF,GAAG;QAAChC;QAAQE;QAAQmB;QAAaF;KAAiB;IAElD,qBACE,KAACsB;QACC1C,KAAKJ,UAAU;YAACuB;YAAUnB;SAAI;QAC9B2C,UAAUrB;QACVjB,WAAW2B;kBAEV7C,SAASyD,GAAG,CAACxC,UAAUyC,CAAAA;YACtB,kBAAIvD,eAAeuD,QAAQ;gBACzB,qBAAOzD,aAAayD,OAAO;oBACzB3C,SAASoB;oBACThB;gBACF;YACF;YAEA,OAAOuC;QACT;;AAGN;AAEA/C,MAAMgD,WAAW,GAAG;AACpB,SAAShD,KAAK,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Children,\n Ref,\n SyntheticEvent,\n cloneElement,\n forwardRef,\n isValidElement,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\n\nexport type ModalElementType = HTMLDialogElement;\nexport type ModalRef = Ref<ModalElementType>;\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\n\nconst Modal = forwardRef((props: ModalProps, ref: ModalRef) => {\n const {\n isOpen,\n onClose,\n onOpen,\n children,\n className,\n closeLabel,\n isFullScreen,\n animation,\n // Deprecated props below\n size,\n appElement,\n preventCloseOnEsc,\n shouldFocusAfterRender,\n parentSelector,\n } = props;\n const hasWarnedAboutMissingLabels = useRef<boolean>(false);\n // Handle deprecated props\n if (!hasWarnedAboutMissingLabels.current) {\n if (\n size ||\n appElement ||\n preventCloseOnEsc ||\n shouldFocusAfterRender ||\n parentSelector\n ) {\n console.warn(\n `Deprecation warning: Mobius Modal no longer supports the following props: size, appElement, preventCloseOnEsc, shouldFocusAfterRender and parentSelector.`,\n );\n hasWarnedAboutMissingLabels.current = true;\n }\n }\n\n const hasOpened = useRef<boolean>(false);\n const modalRef = useRef<HTMLDialogElement | null>(null);\n const hasDialogSupport = supportsDialog();\n\n // Fire onOpen once\n if (onOpen && !hasOpened.current) {\n onOpen();\n hasOpened.current = true;\n }\n\n useBodyScrollLock({ enabled: isOpen });\n\n // Add close handler, to enable closing animations\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n // Name the callback function, so we can add and remove event listener\n const transitionCallback = (e: Event) => {\n // Close modal only if the transition is on the dialog element\n // As it can be on a child element (ie `<Button>` inside the drawer)\n if (e.target === modalRef.current) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n doClose();\n }\n };\n\n const doClose = () => {\n modalRef.current?.close();\n onClose?.();\n modalRef.current?.removeEventListener(\n \"transitionend\",\n transitionCallback,\n );\n };\n\n // Delay close to allow backdrop exit transition\n if (hasDialogSupport && animation) {\n modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);\n modalRef.current?.addEventListener(\"transitionend\", transitionCallback);\n } else {\n doClose();\n }\n },\n [onClose, hasDialogSupport, animation],\n );\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Modal\",\n {\n \"--no-dialog-support\": !hasDialogSupport, // This class is used to correctly position modal in x/y middle on iOS <= 15.2\n \"--should-transition\": hasDialogSupport && animation,\n \"--slide-up\": animation === \"slideUp\",\n \"--fade\": animation === \"fade\",\n \"--is-fullscreen\": isFullScreen,\n },\n className,\n );\n\n // Add polyfill for HTML Dialog in old browsers\n useEffect(() => {\n async function toggleModal() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n modalRef.current !== null\n ) {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n\n try {\n dialogPolyfill.registerDialog(modalRef.current);\n } catch (error) {\n // In iOS 15 <= 15.2 this intermittently fails with\n // TypeError: null is not an object (evaluating 'element.showModal')\n // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️\n console.error(\"Failed to load dialog-polyfill\", error);\n }\n }\n\n if (isOpen && !modalRef.current?.open) {\n modalRef.current?.showModal();\n modalRef.current?.classList.add(TRANSITION_CLASS_NAME);\n onOpen?.();\n } else if (!isOpen && modalRef.current?.open) {\n handleClose();\n }\n }\n\n toggleModal();\n }, [isOpen, onOpen, handleClose, hasDialogSupport]);\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n >\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose: handleClose,\n closeLabel,\n } as any);\n }\n\n return child;\n })}\n </dialog>\n );\n});\n\nModal.displayName = \"Modal\";\nexport { Modal };\n"],"names":["classNames","Children","cloneElement","forwardRef","isValidElement","useCallback","useEffect","useRef","useBodyScrollLock","supportsDialog","mergeRefs","TRANSITION_CLASS_NAME","Modal","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","current","console","warn","hasOpened","modalRef","hasDialogSupport","enabled","handleClose","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","toggleModal","window","default","dialogPolyfill","registerDialog","error","open","showModal","add","dialog","onCancel","map","child","displayName"],"mappings":"AAAA;;AAEA,OAAOA,gBAAgB,oB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Ba,SAAS,CAACY,GAAG,CAAC/C;gBAChCM,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACF,YAAUkB,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBuB,IAAI,GAAE;gBAC5CpB;YACF;QACF;QAEAc;IACF,GAAG;QAACnC;QAAQE;QAAQmB;QAAaF;KAAiB;IAElD,qBACE,KAACyB;QACC7C,KAAKJ,UAAU;YAACuB;YAAUnB;SAAI;QAC9B8C,UAAUxB;QACVjB,WAAW8B;kBAEVhD,SAAS4D,GAAG,CAAC3C,UAAU4C,CAAAA;YACtB,kBAAI1D,eAAe0D,QAAQ;gBACzB,qBAAO5D,aAAa4D,OAAO;oBACzB9C,SAASoB;oBACThB;gBACF;YACF;YAEA,OAAO0C;QACT;;AAGN;AAEAlD,MAAMmD,WAAW,GAAG;AACpB,SAASnD,KAAK,GAAG"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simplybusiness/mobius",
3
3
  "license": "UNLICENSED",
4
- "version": "4.4.0",
4
+ "version": "4.4.2",
5
5
  "description": "Core library of Mobius react components",
6
6
  "repository": {
7
7
  "type": "git",
@@ -25,8 +25,8 @@
25
25
  "scripts": {
26
26
  "clean": "rm -rf dist",
27
27
  "build": "yarn run -T turbo run turbo:build",
28
- "build:cjs": "swc --config-file ../.swcrc ./src -d ./dist/cjs -C module.type=commonjs",
29
- "build:esm": "swc --config-file ../.swcrc ./src -d ./dist/esm -C module.type=es6",
28
+ "build:cjs": "cd src && swc --config-file ../../.swcrc . -d ../dist/cjs -C module.type=commonjs",
29
+ "build:esm": "cd src && swc --config-file ../../.swcrc . -d ../dist/esm -C module.type=es6",
30
30
  "build:types": "tsc --emitDeclarationOnly",
31
31
  "lint": "eslint --ext .tsx,.ts,.js,.jsx,.mjs .",
32
32
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
@@ -40,20 +40,21 @@
40
40
  "@react-types/button": "^3.9.1",
41
41
  "@react-types/dialog": "^3.5.7",
42
42
  "@react-types/progress": "^3.5.1",
43
- "@storybook/addon-links": "^7.6.7",
44
- "@swc/core": "^1.3.102",
45
- "@swc/jest": "^0.2.29",
46
- "@testing-library/dom": "^9.3.3",
47
- "@testing-library/jest-dom": "^6.1.6",
48
- "@testing-library/react": "^14.1.2",
43
+ "@storybook/addon-links": "^7.6.12",
44
+ "@swc/cli": "^0.3.9",
45
+ "@swc/core": "^1.4.0",
46
+ "@swc/jest": "^0.2.36",
47
+ "@testing-library/dom": "^9.3.4",
48
+ "@testing-library/jest-dom": "6.2.0",
49
+ "@testing-library/react": "^14.2.1",
49
50
  "@testing-library/user-event": "^14.5.2",
50
- "@types/jest": "^29.5.11",
51
+ "@types/jest": "^29.5.12",
51
52
  "@types/lodash.debounce": "^4.0.9",
52
- "@types/node": "^20.10.6",
53
- "@types/react": "18.2.46",
53
+ "@types/node": "^20.11.16",
54
+ "@types/react": "18.2.51",
54
55
  "@types/react-dom": "18.2.18",
55
- "@typescript-eslint/eslint-plugin": "^6.17.0",
56
- "@typescript-eslint/parser": "^6.17.0",
56
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
57
+ "@typescript-eslint/parser": "^6.20.0",
57
58
  "csstype": "^3.1.3",
58
59
  "eslint": "^8.56.0",
59
60
  "eslint-config-airbnb": "^19.0.4",
@@ -61,15 +62,15 @@
61
62
  "eslint-import-resolver-typescript": "^3.6.1",
62
63
  "eslint-plugin-import": "^2.29.1",
63
64
  "eslint-plugin-jsx-a11y": "^6.8.0",
64
- "eslint-plugin-prettier": "^5.1.2",
65
+ "eslint-plugin-prettier": "^5.1.3",
65
66
  "eslint-plugin-react": "^7.33.2",
66
67
  "eslint-plugin-react-hooks": "^4.6.0",
67
68
  "eslint-plugin-storybook": "^0.6.15",
68
69
  "identity-obj-proxy": "^3.0.0",
69
70
  "jest": "^29.7.0",
70
71
  "jest-environment-jsdom": "^29.7.0",
71
- "prettier": "^3.1.1",
72
- "ts-jest": "^29.1.1",
72
+ "prettier": "^3.2.4",
73
+ "ts-jest": "^29.1.2",
73
74
  "tslib": "^2.6.2",
74
75
  "typescript": "^5.3.3"
75
76
  },
@@ -78,9 +79,8 @@
78
79
  "react-dom": "^16.13.1 || ^17.0.1 || ^18.0.0"
79
80
  },
80
81
  "dependencies": {
81
- "@floating-ui/react": "^0.26.4",
82
+ "@floating-ui/react": "^0.26.8",
82
83
  "@simplybusiness/icons": "^4.2.9",
83
- "@swc/cli": "^0.1.63",
84
84
  "classnames": "^2.5.1",
85
85
  "dialog-polyfill": "^0.5.6",
86
86
  "lodash.debounce": "^4.0.8",
@@ -54,21 +54,29 @@ const Drawer = forwardRef((props: DrawerProps, ref: DialogRef) => {
54
54
  event.stopPropagation();
55
55
  }
56
56
 
57
+ // Name the callback function, so we can add and remove event listener
58
+ const transitionCallback = (e: Event) => {
59
+ // Close drawer only if the transition is on the dialog element
60
+ // As it can be on a child element (ie `<Button>` inside the drawer)
61
+ if (e.target === modalRef.current) {
62
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
63
+ doClose();
64
+ }
65
+ };
66
+
57
67
  const doClose = () => {
58
68
  modalRef.current?.close();
59
69
  onClose?.();
70
+ modalRef.current?.removeEventListener(
71
+ "transitionend",
72
+ transitionCallback,
73
+ );
60
74
  };
61
75
 
62
76
  // Delay close to allow backdrop exit transition
63
77
  if (hasDialogSupport) {
64
78
  modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);
65
- modalRef.current?.addEventListener(
66
- "transitionend",
67
- () => {
68
- doClose();
69
- },
70
- { once: true },
71
- );
79
+ modalRef.current?.addEventListener("transitionend", transitionCallback);
72
80
  } else {
73
81
  doClose();
74
82
  }
@@ -76,21 +76,29 @@ const Modal = forwardRef((props: ModalProps, ref: ModalRef) => {
76
76
  event.stopPropagation();
77
77
  }
78
78
 
79
+ // Name the callback function, so we can add and remove event listener
80
+ const transitionCallback = (e: Event) => {
81
+ // Close modal only if the transition is on the dialog element
82
+ // As it can be on a child element (ie `<Button>` inside the drawer)
83
+ if (e.target === modalRef.current) {
84
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
85
+ doClose();
86
+ }
87
+ };
88
+
79
89
  const doClose = () => {
80
90
  modalRef.current?.close();
81
91
  onClose?.();
92
+ modalRef.current?.removeEventListener(
93
+ "transitionend",
94
+ transitionCallback,
95
+ );
82
96
  };
83
97
 
84
98
  // Delay close to allow backdrop exit transition
85
99
  if (hasDialogSupport && animation) {
86
100
  modalRef.current?.classList.remove(TRANSITION_CLASS_NAME);
87
- modalRef.current?.addEventListener(
88
- "transitionend",
89
- () => {
90
- doClose();
91
- },
92
- { once: true },
93
- );
101
+ modalRef.current?.addEventListener("transitionend", transitionCallback);
94
102
  } else {
95
103
  doClose();
96
104
  }