@simplybusiness/mobius 4.4.5 → 4.5.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 (83) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/components/Drawer/Content.js +2 -9
  3. package/dist/cjs/components/Drawer/Content.js.map +1 -1
  4. package/dist/cjs/components/Drawer/Drawer.js +11 -8
  5. package/dist/cjs/components/Drawer/Drawer.js.map +1 -1
  6. package/dist/cjs/components/Drawer/DrawerContext.js +17 -0
  7. package/dist/cjs/components/Drawer/DrawerContext.js.map +1 -0
  8. package/dist/cjs/components/Drawer/Header.js +6 -2
  9. package/dist/cjs/components/Drawer/Header.js.map +1 -1
  10. package/dist/cjs/components/Drawer/index.js +12 -3
  11. package/dist/cjs/components/Drawer/index.js.map +1 -1
  12. package/dist/cjs/components/Drawer/useDrawer.js +21 -0
  13. package/dist/cjs/components/Drawer/useDrawer.js.map +1 -0
  14. package/dist/cjs/components/Modal/Content.js +2 -9
  15. package/dist/cjs/components/Modal/Content.js.map +1 -1
  16. package/dist/cjs/components/Modal/Header.js +6 -2
  17. package/dist/cjs/components/Modal/Header.js.map +1 -1
  18. package/dist/cjs/components/Modal/Modal.js +11 -8
  19. package/dist/cjs/components/Modal/Modal.js.map +1 -1
  20. package/dist/cjs/components/Modal/ModalContext.js +17 -0
  21. package/dist/cjs/components/Modal/ModalContext.js.map +1 -0
  22. package/dist/cjs/components/Modal/index.js +12 -3
  23. package/dist/cjs/components/Modal/index.js.map +1 -1
  24. package/dist/cjs/components/Modal/useModal.js +21 -0
  25. package/dist/cjs/components/Modal/useModal.js.map +1 -0
  26. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  27. package/dist/esm/components/Drawer/Content.js +3 -10
  28. package/dist/esm/components/Drawer/Content.js.map +1 -1
  29. package/dist/esm/components/Drawer/Drawer.js +12 -9
  30. package/dist/esm/components/Drawer/Drawer.js.map +1 -1
  31. package/dist/esm/components/Drawer/DrawerContext.js +7 -0
  32. package/dist/esm/components/Drawer/DrawerContext.js.map +1 -0
  33. package/dist/esm/components/Drawer/Header.js +6 -2
  34. package/dist/esm/components/Drawer/Header.js.map +1 -1
  35. package/dist/esm/components/Drawer/index.js +2 -1
  36. package/dist/esm/components/Drawer/index.js.map +1 -1
  37. package/dist/esm/components/Drawer/types.js.map +1 -1
  38. package/dist/esm/components/Drawer/useDrawer.js +11 -0
  39. package/dist/esm/components/Drawer/useDrawer.js.map +1 -0
  40. package/dist/esm/components/Modal/Content.js +3 -10
  41. package/dist/esm/components/Modal/Content.js.map +1 -1
  42. package/dist/esm/components/Modal/Header.js +6 -2
  43. package/dist/esm/components/Modal/Header.js.map +1 -1
  44. package/dist/esm/components/Modal/Modal.js +12 -9
  45. package/dist/esm/components/Modal/Modal.js.map +1 -1
  46. package/dist/esm/components/Modal/ModalContext.js +7 -0
  47. package/dist/esm/components/Modal/ModalContext.js.map +1 -0
  48. package/dist/esm/components/Modal/index.js +2 -1
  49. package/dist/esm/components/Modal/index.js.map +1 -1
  50. package/dist/esm/components/Modal/types.js.map +1 -1
  51. package/dist/esm/components/Modal/useModal.js +11 -0
  52. package/dist/esm/components/Modal/useModal.js.map +1 -0
  53. package/dist/types/components/Drawer/Content.d.ts +0 -2
  54. package/dist/types/components/Drawer/DrawerContext.d.ts +2 -0
  55. package/dist/types/components/Drawer/Header.d.ts +0 -2
  56. package/dist/types/components/Drawer/index.d.ts +4 -3
  57. package/dist/types/components/Drawer/types.d.ts +5 -1
  58. package/dist/types/components/Drawer/useDrawer.d.ts +4 -0
  59. package/dist/types/components/Modal/Content.d.ts +0 -2
  60. package/dist/types/components/Modal/Header.d.ts +0 -2
  61. package/dist/types/components/Modal/ModalContext.d.ts +2 -0
  62. package/dist/types/components/Modal/index.d.ts +4 -3
  63. package/dist/types/components/Modal/types.d.ts +5 -1
  64. package/dist/types/components/Modal/useModal.d.ts +4 -0
  65. package/package.json +1 -1
  66. package/src/components/Drawer/Content.tsx +4 -26
  67. package/src/components/Drawer/Drawer.mdx +62 -0
  68. package/src/components/Drawer/Drawer.stories.tsx +25 -6
  69. package/src/components/Drawer/Drawer.tsx +13 -13
  70. package/src/components/Drawer/DrawerContext.tsx +7 -0
  71. package/src/components/Drawer/Header.tsx +19 -20
  72. package/src/components/Drawer/index.tsx +4 -2
  73. package/src/components/Drawer/types.ts +6 -1
  74. package/src/components/Drawer/useDrawer.ts +8 -0
  75. package/src/components/Modal/Content.tsx +4 -26
  76. package/src/components/Modal/Header.tsx +19 -20
  77. package/src/components/Modal/Modal.mdx +57 -0
  78. package/src/components/Modal/Modal.stories.tsx +25 -6
  79. package/src/components/Modal/Modal.tsx +13 -13
  80. package/src/components/Modal/ModalContext.tsx +7 -0
  81. package/src/components/Modal/index.tsx +4 -2
  82. package/src/components/Modal/types.ts +6 -1
  83. package/src/components/Modal/useModal.ts +8 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d1ba747: Refactor `onClose`, `closeLabel` child props in `<Drawer>` / `<Modal>`
8
+
9
+ ## 4.4.6
10
+
11
+ ### Patch Changes
12
+
13
+ - b9544c2: Fix an issue where `<Drawer>`, `<Modal>` may close unexpectedly
14
+
3
15
  ## 4.4.5
4
16
 
5
17
  ### Patch Changes
@@ -10,18 +10,11 @@ Object.defineProperty(exports, "Content", {
10
10
  });
11
11
  const _jsxruntime = require("react/jsx-runtime");
12
12
  const _react = require("react");
13
- const Content = /*#__PURE__*/ (0, _react.forwardRef)(({ children, onClose, closeLabel: _, ...otherProps }, ref)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
13
+ const Content = /*#__PURE__*/ (0, _react.forwardRef)(({ children, ...otherProps }, ref)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
14
14
  ref: ref,
15
15
  ...otherProps,
16
16
  className: "mobius/DrawerContent",
17
- children: _react.Children.map(children, (child)=>{
18
- if (/*#__PURE__*/ (0, _react.isValidElement)(child)) {
19
- return /*#__PURE__*/ (0, _react.cloneElement)(child, {
20
- onClose
21
- });
22
- }
23
- return child;
24
- })
17
+ children: children
25
18
  }));
26
19
  Content.displayName = "Content";
27
20
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Drawer/Content.tsx"],"sourcesContent":["import {\n Children,\n PropsWithChildren,\n Ref,\n RefAttributes,\n cloneElement,\n forwardRef,\n isValidElement,\n} from \"react\";\nimport { DOMProps } from \"../../types/dom\";\n\nexport type DivRef = Ref<HTMLDivElement>;\nexport type DivElementType = HTMLDivElement;\nexport interface ContentProps\n extends DOMProps,\n RefAttributes<DivElementType>,\n PropsWithChildren {\n onClose?: () => void;\n closeLabel?: string;\n}\n\nconst Content = forwardRef(\n (\n { children, onClose, closeLabel: _, ...otherProps }: ContentProps,\n ref: DivRef,\n ) => (\n <div ref={ref} {...otherProps} className=\"mobius/DrawerContent\">\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose,\n } as any);\n }\n\n return child;\n })}\n </div>\n ),\n);\n\nContent.displayName = \"Content\";\nexport { Content };\n"],"names":["Content","forwardRef","children","onClose","closeLabel","_","otherProps","ref","div","className","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":";;;;+BAyCSA;;;eAAAA;;;;uBAjCF;AAaP,MAAMA,wBAAUC,IAAAA,iBAAU,EACxB,CACE,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,YAAYC,CAAC,EAAE,GAAGC,YAA0B,EACjEC,oBAEA,qBAACC;QAAID,KAAKA;QAAM,GAAGD,UAAU;QAAEG,WAAU;kBACtCC,eAAQ,CAACC,GAAG,CAACT,UAAUU,CAAAA;YACtB,kBAAIC,IAAAA,qBAAc,EAACD,QAAQ;gBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;oBACzBT;gBACF;YACF;YAEA,OAAOS;QACT;;AAKNZ,QAAQe,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Drawer/Content.tsx"],"sourcesContent":["import { PropsWithChildren, Ref, RefAttributes, forwardRef } from \"react\";\nimport { DOMProps } from \"../../types/dom\";\n\nexport type DivRef = Ref<HTMLDivElement>;\nexport type DivElementType = HTMLDivElement;\nexport interface ContentProps\n extends DOMProps,\n RefAttributes<DivElementType>,\n PropsWithChildren {}\n\nconst Content = forwardRef(\n ({ children, ...otherProps }: ContentProps, ref: DivRef) => (\n <div ref={ref} {...otherProps} className=\"mobius/DrawerContent\">\n {children}\n </div>\n ),\n);\n\nContent.displayName = \"Content\";\nexport { Content };\n"],"names":["Content","forwardRef","children","otherProps","ref","div","className","displayName"],"mappings":";;;;+BAmBSA;;;eAAAA;;;;uBAnByD;AAUlE,MAAMA,wBAAUC,IAAAA,iBAAU,EACxB,CAAC,EAAEC,QAAQ,EAAE,GAAGC,YAA0B,EAAEC,oBAC1C,qBAACC;QAAID,KAAKA;QAAM,GAAGD,UAAU;QAAEG,WAAU;kBACtCJ;;AAKPF,QAAQO,WAAW,GAAG"}
@@ -16,6 +16,7 @@ const _useBodyScrollLock = require("../../hooks/useBodyScrollLock");
16
16
  const _polyfilltests = require("../../utils/polyfill-tests");
17
17
  const _VisuallyHidden = require("../VisuallyHidden");
18
18
  const _utils = require("../../utils");
19
+ const _DrawerContext = require("./DrawerContext");
19
20
  function _interop_require_default(obj) {
20
21
  return obj && obj.__esModule ? obj : {
21
22
  default: obj
@@ -144,6 +145,13 @@ const Drawer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
144
145
  handleClose,
145
146
  hasDialogSupport
146
147
  ]);
148
+ const contextValue = (0, _react.useMemo)(()=>({
149
+ onClose: handleClose,
150
+ closeLabel
151
+ }), [
152
+ handleClose,
153
+ closeLabel
154
+ ]);
147
155
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)("dialog", {
148
156
  ref: (0, _utils.mergeRefs)([
149
157
  modalRef,
@@ -159,14 +167,9 @@ const Drawer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
159
167
  children: announce
160
168
  })
161
169
  }),
162
- _react.Children.map(children, (child)=>{
163
- if (/*#__PURE__*/ (0, _react.isValidElement)(child)) {
164
- return /*#__PURE__*/ (0, _react.cloneElement)(child, {
165
- onClose: handleClose,
166
- closeLabel
167
- });
168
- }
169
- return child;
170
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_DrawerContext.DrawerContext.Provider, {
171
+ value: contextValue,
172
+ children: children
170
173
  })
171
174
  ]
172
175
  });
@@ -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 // 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":["Drawer","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","className","closeLabel","direction","announce","onOpen","onClose","children","hasOpened","useRef","modalRef","hasDialogSupport","supportsDialog","current","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","console","open","showModal","add","dialog","mergeRefs","onCancel","aria-describedby","VisuallyHidden","div","id","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":"AAAA;;;;;+BAyJSA;;;eAAAA;;;;+DAvJc;uBAWhB;mCAC2B;+BACH;gCACA;uBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK1B,MAAMC,wBAAwB;AAE9B,MAAMD,uBAASE,IAAAA,iBAAU,EAAC,CAACC,OAAoBC;IAC7C,MAAM,EACJC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,WAAW,yBAAyB,EACpCC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACT,GAAGT;IACJ,MAAMU,YAAYC,IAAAA,aAAM,EAAU;IAClC,MAAMC,WAAWD,IAAAA,aAAM,EAA2B;IAClD,MAAME,mBAAmBC,IAAAA,6BAAc;IAEvC,mBAAmB;IACnB,IAAIP,UAAU,CAACG,UAAUK,OAAO,EAAE;QAChCR;QACAG,UAAUK,OAAO,GAAG;IACtB;IAEAC,IAAAA,oCAAiB,EAAC;QAAEC,SAASf;IAAO;IAEpC,mDAAmD;IACnD,MAAMgB,cAAcC,IAAAA,kBAAW,EAC7B,CAACC;QACC,IAAIA,OAAO;YACTA,MAAMC,cAAc;YACpBD,MAAME,eAAe;QACvB;QAEA,sEAAsE;QACtE,MAAMC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qBAAAA,SAASG,OAAO,cAAhBH,yCAAAA,mBAAkB+B,SAAS;iBAC3B/B,qBAAAA,SAASG,OAAO,cAAhBH,yCAAAA,mBAAkBiB,SAAS,CAACe,GAAG,CAAC9C;gBAChCS,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACL,YAAUU,qBAAAA,SAASG,OAAO,cAAhBH,yCAAAA,mBAAkB8B,IAAI,GAAE;gBAC5CxB;YACF;QACF;QAEAiB;IACF,GAAG;QAACjC;QAAQK;QAAQW;QAAaL;KAAiB;IAElD,qBACE,sBAACgC;QACC5C,KAAK6C,IAAAA,gBAAS,EAAC;YAAClC;YAAUX;SAAI;QAC9B8C,UAAU7B;QACVf,WAAW6B;QACXgB,oBAAiB;;0BAEjB,qBAACC,8BAAc;0BACb,cAAA,qBAACC;oBAAIC,IAAG;8BAA0B7C;;;YAEnC8C,eAAQ,CAACC,GAAG,CAAC5C,UAAU6C,CAAAA;gBACtB,kBAAIC,IAAAA,qBAAc,EAACD,QAAQ;oBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;wBACzB9C,SAASU;wBACTd;oBACF;gBACF;gBAEA,OAAOkD;YACT;;;AAGN;AAEAzD,OAAO4D,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Drawer/Drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Ref,\n SyntheticEvent,\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\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\";\nimport { DrawerContext } from \"./DrawerContext\";\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 const contextValue = useMemo(\n () => ({\n onClose: handleClose,\n closeLabel,\n }),\n [handleClose, closeLabel],\n );\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 <DrawerContext.Provider value={contextValue}>\n {children}\n </DrawerContext.Provider>\n </dialog>\n );\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer };\n"],"names":["Drawer","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","className","closeLabel","direction","announce","onOpen","onClose","children","hasOpened","useRef","modalRef","hasDialogSupport","supportsDialog","current","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","console","open","showModal","add","contextValue","useMemo","dialog","mergeRefs","onCancel","aria-describedby","VisuallyHidden","div","id","DrawerContext","Provider","value","displayName"],"mappings":"AAAA;;;;;+BAyJSA;;;eAAAA;;;;+DAvJc;uBAShB;mCAC2B;+BACH;gCACA;uBAEL;+BACI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK9B,MAAMC,wBAAwB;AAE9B,MAAMD,uBAASE,IAAAA,iBAAU,EAAC,CAACC,OAAoBC;IAC7C,MAAM,EACJC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,WAAW,yBAAyB,E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use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "DrawerContext", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return DrawerContext;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const DrawerContext = /*#__PURE__*/ (0, _react.createContext)({
13
+ onClose: ()=>{},
14
+ closeLabel: undefined
15
+ });
16
+
17
+ //# sourceMappingURL=DrawerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/components/Drawer/DrawerContext.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { DrawerContextProps } from \"./types\";\n\nexport const DrawerContext = createContext<DrawerContextProps>({\n onClose: () => {},\n closeLabel: undefined,\n});\n"],"names":["DrawerContext","createContext","onClose","closeLabel","undefined"],"mappings":";;;;+BAGaA;;;eAAAA;;;uBAHiB;AAGvB,MAAMA,8BAAgBC,IAAAA,oBAAa,EAAqB;IAC7DC,SAAS,KAAO;IAChBC,YAAYC;AACd"}
@@ -13,7 +13,10 @@ const _react = require("react");
13
13
  const _icons = require("@simplybusiness/icons");
14
14
  const _Button = require("../Button");
15
15
  const _Icon = require("../Icon");
16
- const Header = /*#__PURE__*/ (0, _react.forwardRef)(({ children, onClose, closeLabel, ...otherProps }, ref)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("header", {
16
+ const _useDrawer = require("./useDrawer");
17
+ const Header = /*#__PURE__*/ (0, _react.forwardRef)(({ children, ...otherProps }, ref)=>{
18
+ const { onClose, closeLabel } = (0, _useDrawer.useDrawer)();
19
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)("header", {
17
20
  ref: ref,
18
21
  ...otherProps,
19
22
  className: "mobius/DrawerHeader",
@@ -33,7 +36,8 @@ const Header = /*#__PURE__*/ (0, _react.forwardRef)(({ children, onClose, closeL
33
36
  ]
34
37
  })
35
38
  ]
36
- }));
39
+ });
40
+ });
37
41
  Header.displayName = "Header";
38
42
 
39
43
  //# sourceMappingURL=Header.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Drawer/Header.tsx"],"sourcesContent":["import { PropsWithChildren, Ref, RefAttributes, forwardRef } from \"react\";\n\nimport { cross } from \"@simplybusiness/icons\";\nimport { DOMProps } from \"../../types/dom\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\n\nexport type HeaderElementType = HTMLDivElement;\nexport type HeaderRef = Ref<HTMLElement>;\n\nexport interface HeaderProps\n extends DOMProps,\n RefAttributes<HeaderElementType>,\n PropsWithChildren {\n onClose?: () => void;\n closeLabel?: string;\n}\n\nconst Header = forwardRef(\n (\n { children, onClose, closeLabel, ...otherProps }: HeaderProps,\n ref: HeaderRef,\n ) => (\n <header ref={ref} {...otherProps} className=\"mobius/DrawerHeader\">\n {children}\n <Button\n aria-label=\"Close\"\n variant=\"basic\"\n onPress={onClose}\n className=\"mobius/DrawerClose\"\n >\n <Icon icon={cross} /> {closeLabel}\n </Button>\n </header>\n ),\n);\n\nHeader.displayName = \"Header\";\nexport { Header };\n"],"names":["Header","forwardRef","children","onClose","closeLabel","otherProps","ref","header","className","Button","aria-label","variant","onPress","Icon","icon","cross","displayName"],"mappings":";;;;+BAsCSA;;;eAAAA;;;;uBAtCyD;uBAE5C;wBAEC;sBACF;AAarB,MAAMA,uBAASC,IAAAA,iBAAU,EACvB,CACE,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,YAAyB,EAC7DC,oBAEA,sBAACC;QAAOD,KAAKA;QAAM,GAAGD,UAAU;QAAEG,WAAU;;YACzCN;0BACD,sBAACO,cAAM;gBACLC,cAAW;gBACXC,SAAQ;gBACRC,SAAST;gBACTK,WAAU;;kCAEV,qBAACK,UAAI;wBAACC,MAAMC,YAAK;;oBAAI;oBAAEX;;;;;AAM/BJ,OAAOgB,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Drawer/Header.tsx"],"sourcesContent":["import { PropsWithChildren, Ref, RefAttributes, forwardRef } from \"react\";\n\nimport { cross } from \"@simplybusiness/icons\";\nimport { DOMProps } from \"../../types/dom\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { useDrawer } from \"./useDrawer\";\n\nexport type HeaderElementType = HTMLDivElement;\nexport type HeaderRef = Ref<HTMLElement>;\n\nexport interface HeaderProps\n extends DOMProps,\n RefAttributes<HeaderElementType>,\n PropsWithChildren {}\n\nconst Header = forwardRef(\n ({ children, ...otherProps }: HeaderProps, ref: HeaderRef) => {\n const { onClose, closeLabel } = useDrawer();\n\n return (\n <header ref={ref} {...otherProps} className=\"mobius/DrawerHeader\">\n {children}\n <Button\n aria-label=\"Close\"\n variant=\"basic\"\n onPress={onClose}\n className=\"mobius/DrawerClose\"\n >\n <Icon icon={cross} /> {closeLabel}\n </Button>\n </header>\n );\n },\n);\n\nHeader.displayName = \"Header\";\nexport { Header };\n"],"names":["Header","forwardRef","children","otherProps","ref","onClose","closeLabel","useDrawer","header","className","Button","aria-label","variant","onPress","Icon","icon","cross","displayName"],"mappings":";;;;+BAqCSA;;;eAAAA;;;;uBArCyD;uBAE5C;wBAEC;sBACF;2BACK;AAU1B,MAAMA,uBAASC,IAAAA,iBAAU,EACvB,CAAC,EAAEC,QAAQ,EAAE,GAAGC,YAAyB,EAAEC;IACzC,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,IAAAA,oBAAS;IAEzC,qBACE,sBAACC;QAAOJ,KAAKA;QAAM,GAAGD,UAAU;QAAEM,WAAU;;YACzCP;0BACD,sBAACQ,cAAM;gBACLC,cAAW;gBACXC,SAAQ;gBACRC,SAASR;gBACTI,WAAU;;kCAEV,qBAACK,UAAI;wBAACC,MAAMC,YAAK;;oBAAI;oBAAEV;;;;;AAI/B;AAGFN,OAAOiB,WAAW,GAAG"}
@@ -2,14 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "Drawer", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ Drawer: function() {
8
13
  return Drawer;
14
+ },
15
+ useDrawer: function() {
16
+ return _useDrawer.useDrawer;
9
17
  }
10
18
  });
11
19
  const _Content = require("./Content");
12
20
  const _Drawer = require("./Drawer");
21
+ const _useDrawer = require("./useDrawer");
13
22
  const _Header = require("./Header");
14
23
  const Drawer = Object.assign(_Drawer.Drawer, {
15
24
  Header: _Header.Header,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Drawer/index.tsx"],"sourcesContent":["import {\n Content,\n DivElementType as DrawerContentDivElementType,\n ContentProps as DrawerContentProps,\n} from \"./Content\";\nimport { Drawer as DrawerComponent } from \"./Drawer\";\nimport { DrawerProps } from \"./types\";\nimport {\n HeaderElementType as DrawerHeaderElementType,\n HeaderProps as DrawerHeaderProps,\n Header,\n} from \"./Header\";\n\nconst Drawer = Object.assign(DrawerComponent, {\n Header,\n Content,\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer };\n\nexport type {\n DrawerContentDivElementType,\n DrawerContentProps,\n DrawerHeaderElementType,\n DrawerHeaderProps,\n DrawerProps,\n};\n"],"names":["Drawer","Object","assign","DrawerComponent","Header","Content","displayName"],"mappings":";;;;+BAmBSA;;;eAAAA;;;yBAfF;wBACmC;wBAMnC;AAEP,MAAMA,SAASC,OAAOC,MAAM,CAACC,cAAe,EAAE;IAC5CC,QAAAA,cAAM;IACNC,SAAAA,gBAAO;AACT;AAEAL,OAAOM,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Drawer/index.tsx"],"sourcesContent":["import {\n Content,\n DivElementType as DrawerContentDivElementType,\n ContentProps as DrawerContentProps,\n} from \"./Content\";\nimport { Drawer as DrawerComponent } from \"./Drawer\";\nimport { DrawerProps, DrawerContextProps } from \"./types\";\nimport { useDrawer } from \"./useDrawer\";\nimport {\n HeaderElementType as DrawerHeaderElementType,\n HeaderProps as DrawerHeaderProps,\n Header,\n} from \"./Header\";\n\nconst Drawer = Object.assign(DrawerComponent, {\n Header,\n Content,\n});\n\nDrawer.displayName = \"Drawer\";\nexport { Drawer, useDrawer };\n\nexport type {\n DrawerContextProps,\n DrawerContentDivElementType,\n DrawerContentProps,\n DrawerHeaderElementType,\n DrawerHeaderProps,\n DrawerProps,\n};\n"],"names":["Drawer","useDrawer","Object","assign","DrawerComponent","Header","Content","displayName"],"mappings":";;;;;;;;;;;IAoBSA,MAAM;eAANA;;IAAQC,SAAS;eAATA,oBAAS;;;yBAhBnB;wBACmC;2BAEhB;wBAKnB;AAEP,MAAMD,SAASE,OAAOC,MAAM,CAACC,cAAe,EAAE;IAC5CC,QAAAA,cAAM;IACNC,SAAAA,gBAAO;AACT;AAEAN,OAAOO,WAAW,GAAG"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useDrawer", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useDrawer;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _DrawerContext = require("./DrawerContext");
13
+ const useDrawer = ()=>{
14
+ const { onClose, closeLabel } = (0, _react.useContext)(_DrawerContext.DrawerContext);
15
+ return {
16
+ onClose,
17
+ closeLabel
18
+ };
19
+ };
20
+
21
+ //# sourceMappingURL=useDrawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/components/Drawer/useDrawer.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { DrawerContext } from \"./DrawerContext\";\n\nexport const useDrawer = () => {\n const { onClose, closeLabel } = useContext(DrawerContext);\n\n return { onClose, closeLabel };\n};\n"],"names":["useDrawer","onClose","closeLabel","useContext","DrawerContext"],"mappings":";;;;+BAGaA;;;eAAAA;;;uBAHc;+BACG;AAEvB,MAAMA,YAAY;IACvB,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,IAAAA,iBAAU,EAACC,4BAAa;IAExD,OAAO;QAAEH;QAASC;IAAW;AAC/B"}
@@ -10,18 +10,11 @@ Object.defineProperty(exports, "Content", {
10
10
  });
11
11
  const _jsxruntime = require("react/jsx-runtime");
12
12
  const _react = require("react");
13
- const Content = /*#__PURE__*/ (0, _react.forwardRef)(({ children, onClose, closeLabel: _, ...otherProps }, ref)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
13
+ const Content = /*#__PURE__*/ (0, _react.forwardRef)(({ children, ...otherProps }, ref)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
14
14
  ref: ref,
15
15
  ...otherProps,
16
16
  className: "mobius/ModalContent",
17
- children: _react.Children.map(children, (child)=>{
18
- if (/*#__PURE__*/ (0, _react.isValidElement)(child)) {
19
- return /*#__PURE__*/ (0, _react.cloneElement)(child, {
20
- onClose
21
- });
22
- }
23
- return child;
24
- })
17
+ children: children
25
18
  }));
26
19
  Content.displayName = "Content";
27
20
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Modal/Content.tsx"],"sourcesContent":["import {\n Children,\n PropsWithChildren,\n Ref,\n RefAttributes,\n cloneElement,\n forwardRef,\n isValidElement,\n} from \"react\";\nimport { DOMProps } from \"../../types/dom\";\n\nexport type DivRef = Ref<HTMLDivElement>;\nexport type DivElementType = HTMLDivElement;\nexport interface ContentProps\n extends DOMProps,\n RefAttributes<DivElementType>,\n PropsWithChildren {\n onClose?: () => void;\n closeLabel?: string;\n}\n\nconst Content = forwardRef(\n (\n { children, onClose, closeLabel: _, ...otherProps }: ContentProps,\n ref: DivRef,\n ) => (\n <div ref={ref} {...otherProps} className=\"mobius/ModalContent\">\n {Children.map(children, child => {\n if (isValidElement(child)) {\n return cloneElement(child, {\n onClose,\n } as any);\n }\n\n return child;\n })}\n </div>\n ),\n);\n\nContent.displayName = \"Content\";\nexport { Content };\n"],"names":["Content","forwardRef","children","onClose","closeLabel","_","otherProps","ref","div","className","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":";;;;+BAyCSA;;;eAAAA;;;;uBAjCF;AAaP,MAAMA,wBAAUC,IAAAA,iBAAU,EACxB,CACE,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,YAAYC,CAAC,EAAE,GAAGC,YAA0B,EACjEC,oBAEA,qBAACC;QAAID,KAAKA;QAAM,GAAGD,UAAU;QAAEG,WAAU;kBACtCC,eAAQ,CAACC,GAAG,CAACT,UAAUU,CAAAA;YACtB,kBAAIC,IAAAA,qBAAc,EAACD,QAAQ;gBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;oBACzBT;gBACF;YACF;YAEA,OAAOS;QACT;;AAKNZ,QAAQe,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/Content.tsx"],"sourcesContent":["import { PropsWithChildren, Ref, RefAttributes, forwardRef } from \"react\";\nimport { DOMProps } from \"../../types/dom\";\n\nexport type DivRef = Ref<HTMLDivElement>;\nexport type DivElementType = HTMLDivElement;\nexport interface ContentProps\n extends DOMProps,\n RefAttributes<DivElementType>,\n PropsWithChildren {}\n\nconst Content = forwardRef(\n ({ children, ...otherProps }: ContentProps, ref: DivRef) => (\n <div ref={ref} {...otherProps} className=\"mobius/ModalContent\">\n {children}\n </div>\n ),\n);\n\nContent.displayName = \"Content\";\nexport { Content };\n"],"names":["Content","forwardRef","children","otherProps","ref","div","className","displayName"],"mappings":";;;;+BAmBSA;;;eAAAA;;;;uBAnByD;AAUlE,MAAMA,wBAAUC,IAAAA,iBAAU,EACxB,CAAC,EAAEC,QAAQ,EAAE,GAAGC,YAA0B,EAAEC,oBAC1C,qBAACC;QAAID,KAAKA;QAAM,GAAGD,UAAU;QAAEG,WAAU;kBACtCJ;;AAKPF,QAAQO,WAAW,GAAG"}
@@ -13,7 +13,10 @@ const _react = require("react");
13
13
  const _icons = require("@simplybusiness/icons");
14
14
  const _Button = require("../Button");
15
15
  const _Icon = require("../Icon");
16
- const Header = /*#__PURE__*/ (0, _react.forwardRef)(({ children, onClose, closeLabel, ...otherProps }, ref)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("header", {
16
+ const _useModal = require("./useModal");
17
+ const Header = /*#__PURE__*/ (0, _react.forwardRef)(({ children, ...otherProps }, ref)=>{
18
+ const { onClose, closeLabel } = (0, _useModal.useModal)();
19
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)("header", {
17
20
  ref: ref,
18
21
  ...otherProps,
19
22
  className: "mobius/ModalHeader",
@@ -33,7 +36,8 @@ const Header = /*#__PURE__*/ (0, _react.forwardRef)(({ children, onClose, closeL
33
36
  ]
34
37
  })
35
38
  ]
36
- }));
39
+ });
40
+ });
37
41
  Header.displayName = "Header";
38
42
 
39
43
  //# sourceMappingURL=Header.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Modal/Header.tsx"],"sourcesContent":["import { PropsWithChildren, Ref, RefAttributes, forwardRef } from \"react\";\n\nimport { cross } from \"@simplybusiness/icons\";\nimport { DOMProps } from \"../../types/dom\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\n\nexport type HeaderElementType = HTMLDivElement;\nexport type HeaderRef = Ref<HTMLElement>;\n\nexport interface HeaderProps\n extends DOMProps,\n RefAttributes<HeaderElementType>,\n PropsWithChildren {\n onClose?: () => void;\n closeLabel?: string;\n}\n\nconst Header = forwardRef(\n (\n { children, onClose, closeLabel, ...otherProps }: HeaderProps,\n ref: HeaderRef,\n ) => (\n <header ref={ref} {...otherProps} className=\"mobius/ModalHeader\">\n {children}\n <Button\n aria-label=\"Close\"\n variant=\"basic\"\n onPress={onClose}\n className=\"mobius/ModalClose\"\n >\n <Icon icon={cross} /> {closeLabel}\n </Button>\n </header>\n ),\n);\n\nHeader.displayName = \"Header\";\nexport { Header };\n"],"names":["Header","forwardRef","children","onClose","closeLabel","otherProps","ref","header","className","Button","aria-label","variant","onPress","Icon","icon","cross","displayName"],"mappings":";;;;+BAsCSA;;;eAAAA;;;;uBAtCyD;uBAE5C;wBAEC;sBACF;AAarB,MAAMA,uBAASC,IAAAA,iBAAU,EACvB,CACE,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,YAAyB,EAC7DC,oBAEA,sBAACC;QAAOD,KAAKA;QAAM,GAAGD,UAAU;QAAEG,WAAU;;YACzCN;0BACD,sBAACO,cAAM;gBACLC,cAAW;gBACXC,SAAQ;gBACRC,SAAST;gBACTK,WAAU;;kCAEV,qBAACK,UAAI;wBAACC,MAAMC,YAAK;;oBAAI;oBAAEX;;;;;AAM/BJ,OAAOgB,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/Header.tsx"],"sourcesContent":["import { PropsWithChildren, Ref, RefAttributes, forwardRef } from \"react\";\n\nimport { cross } from \"@simplybusiness/icons\";\nimport { DOMProps } from \"../../types/dom\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { useModal } from \"./useModal\";\n\nexport type HeaderElementType = HTMLDivElement;\nexport type HeaderRef = Ref<HTMLElement>;\n\nexport interface HeaderProps\n extends DOMProps,\n RefAttributes<HeaderElementType>,\n PropsWithChildren {}\n\nconst Header = forwardRef(\n ({ children, ...otherProps }: HeaderProps, ref: HeaderRef) => {\n const { onClose, closeLabel } = useModal();\n\n return (\n <header ref={ref} {...otherProps} className=\"mobius/ModalHeader\">\n {children}\n <Button\n aria-label=\"Close\"\n variant=\"basic\"\n onPress={onClose}\n className=\"mobius/ModalClose\"\n >\n <Icon icon={cross} /> {closeLabel}\n </Button>\n </header>\n );\n },\n);\n\nHeader.displayName = \"Header\";\nexport { Header };\n"],"names":["Header","forwardRef","children","otherProps","ref","onClose","closeLabel","useModal","header","className","Button","aria-label","variant","onPress","Icon","icon","cross","displayName"],"mappings":";;;;+BAqCSA;;;eAAAA;;;;uBArCyD;uBAE5C;wBAEC;sBACF;0BACI;AAUzB,MAAMA,uBAASC,IAAAA,iBAAU,EACvB,CAAC,EAAEC,QAAQ,EAAE,GAAGC,YAAyB,EAAEC;IACzC,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,IAAAA,kBAAQ;IAExC,qBACE,sBAACC;QAAOJ,KAAKA;QAAM,GAAGD,UAAU;QAAEM,WAAU;;YACzCP;0BACD,sBAACQ,cAAM;gBACLC,cAAW;gBACXC,SAAQ;gBACRC,SAASR;gBACTI,WAAU;;kCAEV,qBAACK,UAAI;wBAACC,MAAMC,YAAK;;oBAAI;oBAAEV;;;;;AAI/B;AAGFN,OAAOiB,WAAW,GAAG"}
@@ -15,6 +15,7 @@ const _react = require("react");
15
15
  const _useBodyScrollLock = require("../../hooks/useBodyScrollLock");
16
16
  const _polyfilltests = require("../../utils/polyfill-tests");
17
17
  const _utils = require("../../utils");
18
+ const _ModalContext = require("./ModalContext");
18
19
  function _interop_require_default(obj) {
19
20
  return obj && obj.__esModule ? obj : {
20
21
  default: obj
@@ -157,6 +158,13 @@ const Modal = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
157
158
  handleClose,
158
159
  hasDialogSupport
159
160
  ]);
161
+ const contextValue = (0, _react.useMemo)(()=>({
162
+ onClose: handleClose,
163
+ closeLabel
164
+ }), [
165
+ handleClose,
166
+ closeLabel
167
+ ]);
160
168
  return /*#__PURE__*/ (0, _jsxruntime.jsx)("dialog", {
161
169
  ref: (0, _utils.mergeRefs)([
162
170
  modalRef,
@@ -164,14 +172,9 @@ const Modal = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
164
172
  ]),
165
173
  onCancel: handleClose,
166
174
  className: modalClasses,
167
- children: _react.Children.map(children, (child)=>{
168
- if (/*#__PURE__*/ (0, _react.isValidElement)(child)) {
169
- return /*#__PURE__*/ (0, _react.cloneElement)(child, {
170
- onClose: handleClose,
171
- closeLabel
172
- });
173
- }
174
- return child;
175
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_ModalContext.ModalContext.Provider, {
176
+ value: contextValue,
177
+ children: children
175
178
  })
176
179
  });
177
180
  });
@@ -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 // 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":["Modal","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","useRef","current","console","warn","hasOpened","modalRef","hasDialogSupport","supportsDialog","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","open","showModal","add","dialog","mergeRefs","onCancel","Children","map","child","isValidElement","cloneElement","displayName"],"mappings":"AAAA;;;;;+BA+KSA;;;eAAAA;;;;+DA7Kc;uBAWhB;mCAC2B;+BACH;uBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK1B,MAAMC,wBAAwB;AAE9B,MAAMD,sBAAQE,IAAAA,iBAAU,EAAC,CAACC,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,8BAA8BC,IAAAA,aAAM,EAAU;IACpD,0BAA0B;IAC1B,IAAI,CAACD,4BAA4BE,OAAO,EAAE;QACxC,IACEP,QACAC,cACAC,qBACAC,0BACAC,gBACA;YACAI,QAAQC,IAAI,CACV,CAAC,yJAAyJ,CAAC;YAE7JJ,4BAA4BE,OAAO,GAAG;QACxC;IACF;IAEA,MAAMG,YAAYJ,IAAAA,aAAM,EAAU;IAClC,MAAMK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mBAIOA;YAtBtB,IACE,CAACC,oBACD,OAAOsB,WAAW,eAClBvB,SAASJ,OAAO,KAAK,MACrB;gBACA,6DAA6D;gBAC7D,MAAM,EAAE4B,SAASC,cAAc,EAAE,GAAG,MAAM,mEAAA,QAAO;gBAEjD,IAAI;oBACFA,eAAeC,cAAc,CAAC1B,SAASJ,OAAO;gBAChD,EAAE,OAAO+B,OAAO;oBACd,mDAAmD;oBACnD,oEAAoE;oBACpE,qGAAqG;oBACrG9B,QAAQ8B,KAAK,CAAC,kCAAkCA;gBAClD;YACF;YAEA,IAAI9C,UAAU,GAACmB,oBAAAA,SAASJ,OAAO,cAAhBI,wCAAAA,kBAAkB4B,IAAI,GAAE;oBACrC5B,oBACAA;iBADAA,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkB6B,SAAS;iBAC3B7B,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBgB,SAAS,CAACc,GAAG,CAACrD;gBAChCM,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACF,YAAUmB,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkB4B,IAAI,GAAE;gBAC5CvB;YACF;QACF;QAEAiB;IACF,GAAG;QAACzC;QAAQE;QAAQsB;QAAaJ;KAAiB;IAElD,qBACE,qBAAC8B;QACCnD,KAAKoD,IAAAA,gBAAS,EAAC;YAAChC;YAAUpB;SAAI;QAC9BqD,UAAU5B;QACVpB,WAAWkC;kBAEVe,eAAQ,CAACC,GAAG,CAACnD,UAAUoD,CAAAA;YACtB,kBAAIC,IAAAA,qBAAc,EAACD,QAAQ;gBACzB,qBAAOE,IAAAA,mBAAY,EAACF,OAAO;oBACzBtD,SAASuB;oBACTnB;gBACF;YACF;YAEA,OAAOkD;QACT;;AAGN;AAEA5D,MAAM+D,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport {\n Ref,\n SyntheticEvent,\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { useBodyScrollLock } from \"../../hooks/useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\nimport { ModalContext } from \"./ModalContext\";\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 const contextValue = useMemo(\n () => ({\n onClose: handleClose,\n closeLabel,\n }),\n [handleClose, closeLabel],\n );\n\n return (\n <dialog\n ref={mergeRefs([modalRef, ref])}\n onCancel={handleClose}\n className={modalClasses}\n >\n <ModalContext.Provider value={contextValue}>\n {children}\n </ModalContext.Provider>\n </dialog>\n );\n});\n\nModal.displayName = \"Modal\";\nexport { Modal };\n"],"names":["Modal","TRANSITION_CLASS_NAME","forwardRef","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","useRef","current","console","warn","hasOpened","modalRef","hasDialogSupport","supportsDialog","useBodyScrollLock","enabled","handleClose","useCallback","event","preventDefault","stopPropagation","transitionCallback","e","target","doClose","close","removeEventListener","classList","remove","addEventListener","modalClasses","classNames","useEffect","toggleModal","window","default","dialogPolyfill","registerDialog","error","open","showModal","add","contextValue","useMemo","dialog","mergeRefs","onCancel","ModalContext","Provider","value","displayName"],"mappings":"AAAA;;;;;+BA+KSA;;;eAAAA;;;;+DA7Kc;uBAShB;mCAC2B;+BACH;uBAEL;8BACG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK7B,MAAMC,wBAAwB;AAE9B,MAAMD,sBAAQE,IAAAA,iBAAU,EAAC,CAACC,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,8BAA8BC,IAAAA,aAAM,EAAU;IACpD,0BAA0B;IAC1B,IAAI,CAACD,4BAA4BE,OAAO,EAAE;QACxC,IACEP,QACAC,cACAC,qBACAC,0BACAC,gBACA;YACAI,QAAQC,IAAI,CACV,CAAC,yJAAyJ,CAAC;YAE7JJ,4BAA4BE,OAAO,GAAG;QACxC;IACF;IAEA,MAAMG,YAAYJ,IAAAA,aAAM,EAAU;IAClC,MAAMK,WAAWL,IAAAA,aAAM,EAA2B;IAClD,MAAMM,mBAAmBC,IAAAA,6BAAc;IAEvC,mBAAmB;IAC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ACA,6DAA6D;gBAC7D,MAAM,EAAE4B,SAASC,cAAc,EAAE,GAAG,MAAM,mEAAA,QAAO;gBAEjD,IAAI;oBACFA,eAAeC,cAAc,CAAC1B,SAASJ,OAAO;gBAChD,EAAE,OAAO+B,OAAO;oBACd,mDAAmD;oBACnD,oEAAoE;oBACpE,qGAAqG;oBACrG9B,QAAQ8B,KAAK,CAAC,kCAAkCA;gBAClD;YACF;YAEA,IAAI9C,UAAU,GAACmB,oBAAAA,SAASJ,OAAO,cAAhBI,wCAAAA,kBAAkB4B,IAAI,GAAE;oBACrC5B,oBACAA;iBADAA,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkB6B,SAAS;iBAC3B7B,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkBgB,SAAS,CAACc,GAAG,CAACrD;gBAChCM,mBAAAA,6BAAAA;YACF,OAAO,IAAI,CAACF,YAAUmB,qBAAAA,SAASJ,OAAO,cAAhBI,yCAAAA,mBAAkB4B,IAAI,GAAE;gBAC5CvB;YACF;QACF;QAEAiB;IACF,GAAG;QAACzC;QAAQE;QAAQsB;QAAaJ;KAAiB;IAElD,MAAM8B,eAAeC,IAAAA,cAAO,EAC1B,IAAO,CAAA;YACLlD,SAASuB;YACTnB;QACF,CAAA,GACA;QAACmB;QAAanB;KAAW;IAG3B,qBACE,qBAAC+C;QACCrD,KAAKsD,IAAAA,gBAAS,EAAC;YAAClC;YAAUpB;SAAI;QAC9BuD,UAAU9B;QACVpB,WAAWkC;kBAEX,cAAA,qBAACiB,0BAAY,CAACC,QAAQ;YAACC,OAAOP;sBAC3B/C;;;AAIT;AAEAR,MAAM+D,WAAW,GAAG"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ModalContext", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ModalContext;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const ModalContext = /*#__PURE__*/ (0, _react.createContext)({
13
+ onClose: ()=>{},
14
+ closeLabel: undefined
15
+ });
16
+
17
+ //# sourceMappingURL=ModalContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/components/Modal/ModalContext.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { ModalContextProps } from \"./types\";\n\nexport const ModalContext = createContext<ModalContextProps>({\n onClose: () => {},\n closeLabel: undefined,\n});\n"],"names":["ModalContext","createContext","onClose","closeLabel","undefined"],"mappings":";;;;+BAGaA;;;eAAAA;;;uBAHiB;AAGvB,MAAMA,6BAAeC,IAAAA,oBAAa,EAAoB;IAC3DC,SAAS,KAAO;IAChBC,YAAYC;AACd"}
@@ -2,15 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "Modal", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ Modal: function() {
8
13
  return Modal;
14
+ },
15
+ useModal: function() {
16
+ return _useModal.useModal;
9
17
  }
10
18
  });
11
19
  const _Content = require("./Content");
12
20
  const _Header = require("./Header");
13
21
  const _Modal = require("./Modal");
22
+ const _useModal = require("./useModal");
14
23
  const Modal = Object.assign(_Modal.Modal, {
15
24
  Header: _Header.Header,
16
25
  Content: _Content.Content
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Modal/index.tsx"],"sourcesContent":["import {\n Content,\n DivElementType as ModalContentDivElementType,\n ContentProps as ModalContentProps,\n} from \"./Content\";\nimport {\n Header,\n HeaderElementType as ModalHeaderElementType,\n HeaderProps as ModalHeaderProps,\n} from \"./Header\";\nimport { Modal as ModalComponent } from \"./Modal\";\nimport { ModalProps } from \"./types\";\n\nconst Modal = Object.assign(ModalComponent, {\n Header,\n Content,\n});\n\nModal.displayName = \"Modal\";\nexport { Modal };\n\nexport type {\n ModalContentDivElementType,\n ModalContentProps,\n ModalHeaderElementType,\n ModalHeaderProps,\n ModalProps,\n};\n"],"names":["Modal","Object","assign","ModalComponent","Header","Content","displayName"],"mappings":";;;;+BAmBSA;;;eAAAA;;;yBAfF;wBAKA;uBACiC;AAGxC,MAAMA,QAAQC,OAAOC,MAAM,CAACC,YAAc,EAAE;IAC1CC,QAAAA,cAAM;IACNC,SAAAA,gBAAO;AACT;AAEAL,MAAMM,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/index.tsx"],"sourcesContent":["import {\n Content,\n DivElementType as ModalContentDivElementType,\n ContentProps as ModalContentProps,\n} from \"./Content\";\nimport {\n Header,\n HeaderElementType as ModalHeaderElementType,\n HeaderProps as ModalHeaderProps,\n} from \"./Header\";\nimport { Modal as ModalComponent } from \"./Modal\";\nimport { ModalProps, ModalContextProps } from \"./types\";\nimport { useModal } from \"./useModal\";\n\nconst Modal = Object.assign(ModalComponent, {\n Header,\n Content,\n});\n\nModal.displayName = \"Modal\";\nexport { Modal, useModal };\n\nexport type {\n ModalContextProps,\n ModalContentDivElementType,\n ModalContentProps,\n ModalHeaderElementType,\n ModalHeaderProps,\n ModalProps,\n};\n"],"names":["Modal","useModal","Object","assign","ModalComponent","Header","Content","displayName"],"mappings":";;;;;;;;;;;IAoBSA,KAAK;eAALA;;IAAOC,QAAQ;eAARA,kBAAQ;;;yBAhBjB;wBAKA;uBACiC;0BAEf;AAEzB,MAAMD,QAAQE,OAAOC,MAAM,CAACC,YAAc,EAAE;IAC1CC,QAAAA,cAAM;IACNC,SAAAA,gBAAO;AACT;AAEAN,MAAMO,WAAW,GAAG"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useModal", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useModal;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _ModalContext = require("./ModalContext");
13
+ const useModal = ()=>{
14
+ const { onClose, closeLabel } = (0, _react.useContext)(_ModalContext.ModalContext);
15
+ return {
16
+ onClose,
17
+ closeLabel
18
+ };
19
+ };
20
+
21
+ //# sourceMappingURL=useModal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/components/Modal/useModal.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { ModalContext } from \"./ModalContext\";\n\nexport const useModal = () => {\n const { onClose, closeLabel } = useContext(ModalContext);\n\n return { onClose, closeLabel };\n};\n"],"names":["useModal","onClose","closeLabel","useContext","ModalContext"],"mappings":";;;;+BAGaA;;;eAAAA;;;uBAHc;8BACE;AAEtB,MAAMA,WAAW;IACtB,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,IAAAA,iBAAU,EAACC,0BAAY;IAEvD,OAAO;QAAEH;QAASC;IAAW;AAC/B"}