@simplybusiness/mobius 4.4.6 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) 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 +28 -134
  5. package/dist/cjs/components/Drawer/Drawer.js.map +1 -1
  6. package/dist/cjs/components/Drawer/DrawerContext.js +2 -2
  7. package/dist/cjs/components/Drawer/DrawerContext.js.map +1 -1
  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 +2 -2
  13. package/dist/cjs/components/Drawer/useDrawer.js.map +1 -1
  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 +27 -133
  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/hooks/index.js +1 -0
  27. package/dist/cjs/hooks/index.js.map +1 -1
  28. package/dist/cjs/hooks/useDialog/index.js +20 -0
  29. package/dist/cjs/hooks/useDialog/index.js.map +1 -0
  30. package/dist/cjs/hooks/useDialog/useDialog.js +94 -0
  31. package/dist/cjs/hooks/useDialog/useDialog.js.map +1 -0
  32. package/dist/cjs/hooks/useDialogPolyfill/index.js +20 -0
  33. package/dist/cjs/hooks/useDialogPolyfill/index.js.map +1 -0
  34. package/dist/cjs/hooks/useDialogPolyfill/useDialogPolyfill.js +77 -0
  35. package/dist/cjs/hooks/useDialogPolyfill/useDialogPolyfill.js.map +1 -0
  36. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  37. package/dist/esm/components/Drawer/Content.js +3 -10
  38. package/dist/esm/components/Drawer/Content.js.map +1 -1
  39. package/dist/esm/components/Drawer/Drawer.js +30 -95
  40. package/dist/esm/components/Drawer/Drawer.js.map +1 -1
  41. package/dist/esm/components/Drawer/DrawerContext.js +2 -2
  42. package/dist/esm/components/Drawer/DrawerContext.js.map +1 -1
  43. package/dist/esm/components/Drawer/Header.js +6 -2
  44. package/dist/esm/components/Drawer/Header.js.map +1 -1
  45. package/dist/esm/components/Drawer/index.js +2 -1
  46. package/dist/esm/components/Drawer/index.js.map +1 -1
  47. package/dist/esm/components/Drawer/types.js.map +1 -1
  48. package/dist/esm/components/Drawer/useDrawer.js +2 -2
  49. package/dist/esm/components/Drawer/useDrawer.js.map +1 -1
  50. package/dist/esm/components/Modal/Content.js +3 -10
  51. package/dist/esm/components/Modal/Content.js.map +1 -1
  52. package/dist/esm/components/Modal/Header.js +6 -2
  53. package/dist/esm/components/Modal/Header.js.map +1 -1
  54. package/dist/esm/components/Modal/Modal.js +28 -93
  55. package/dist/esm/components/Modal/Modal.js.map +1 -1
  56. package/dist/esm/components/Modal/ModalContext.js +7 -0
  57. package/dist/esm/components/Modal/ModalContext.js.map +1 -0
  58. package/dist/esm/components/Modal/index.js +2 -1
  59. package/dist/esm/components/Modal/index.js.map +1 -1
  60. package/dist/esm/components/Modal/types.js.map +1 -1
  61. package/dist/esm/components/Modal/useModal.js +11 -0
  62. package/dist/esm/components/Modal/useModal.js.map +1 -0
  63. package/dist/esm/hooks/index.js +1 -0
  64. package/dist/esm/hooks/index.js.map +1 -1
  65. package/dist/esm/hooks/useDialog/index.js +3 -0
  66. package/dist/esm/hooks/useDialog/index.js.map +1 -0
  67. package/dist/esm/hooks/useDialog/useDialog.js +84 -0
  68. package/dist/esm/hooks/useDialog/useDialog.js.map +1 -0
  69. package/dist/esm/hooks/useDialogPolyfill/index.js +3 -0
  70. package/dist/esm/hooks/useDialogPolyfill/index.js.map +1 -0
  71. package/dist/esm/hooks/useDialogPolyfill/useDialogPolyfill.js +27 -0
  72. package/dist/esm/hooks/useDialogPolyfill/useDialogPolyfill.js.map +1 -0
  73. package/dist/types/components/Drawer/Content.d.ts +0 -2
  74. package/dist/types/components/Drawer/DrawerContext.d.ts +2 -0
  75. package/dist/types/components/Drawer/Header.d.ts +0 -2
  76. package/dist/types/components/Drawer/index.d.ts +4 -3
  77. package/dist/types/components/Drawer/types.d.ts +5 -1
  78. package/dist/types/components/Drawer/useDrawer.d.ts +4 -0
  79. package/dist/types/components/Modal/Content.d.ts +0 -2
  80. package/dist/types/components/Modal/Header.d.ts +0 -2
  81. package/dist/types/components/Modal/ModalContext.d.ts +2 -0
  82. package/dist/types/components/Modal/index.d.ts +4 -3
  83. package/dist/types/components/Modal/types.d.ts +5 -1
  84. package/dist/types/components/Modal/useModal.d.ts +4 -0
  85. package/dist/types/hooks/index.d.ts +1 -0
  86. package/dist/types/hooks/useDialog/index.d.ts +1 -0
  87. package/dist/types/hooks/useDialog/useDialog.d.ts +16 -0
  88. package/dist/types/hooks/useDialogPolyfill/index.d.ts +1 -0
  89. package/dist/types/hooks/useDialogPolyfill/useDialogPolyfill.d.ts +2 -0
  90. package/package.json +2 -1
  91. package/src/components/Drawer/Content.tsx +4 -26
  92. package/src/components/Drawer/Drawer.mdx +62 -0
  93. package/src/components/Drawer/Drawer.stories.tsx +1 -1
  94. package/src/components/Drawer/Drawer.tsx +31 -113
  95. package/src/components/Drawer/DrawerContext.tsx +7 -0
  96. package/src/components/Drawer/Header.tsx +19 -20
  97. package/src/components/Drawer/index.tsx +4 -2
  98. package/src/components/Drawer/types.ts +6 -1
  99. package/src/components/Drawer/useDrawer.ts +8 -0
  100. package/src/components/Modal/Content.tsx +4 -26
  101. package/src/components/Modal/Header.tsx +19 -20
  102. package/src/components/Modal/Modal.mdx +57 -0
  103. package/src/components/Modal/Modal.tsx +29 -111
  104. package/src/components/Modal/ModalContext.tsx +7 -0
  105. package/src/components/Modal/index.tsx +4 -2
  106. package/src/components/Modal/types.ts +6 -1
  107. package/src/components/Modal/useModal.ts +8 -0
  108. package/src/hooks/index.tsx +1 -0
  109. package/src/hooks/useDialog/index.ts +1 -0
  110. package/src/hooks/useDialog/useDialog.ts +98 -0
  111. package/src/hooks/useDialogPolyfill/index.ts +1 -0
  112. package/src/hooks/useDialogPolyfill/useDialogPolyfill.ts +32 -0
@@ -12,56 +12,16 @@ Object.defineProperty(exports, "Modal", {
12
12
  const _jsxruntime = require("react/jsx-runtime");
13
13
  const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
14
14
  const _react = require("react");
15
- const _useBodyScrollLock = require("../../hooks/useBodyScrollLock");
16
15
  const _polyfilltests = require("../../utils/polyfill-tests");
17
16
  const _utils = require("../../utils");
17
+ const _ModalContext = require("./ModalContext");
18
+ const _hooks = require("../../hooks");
18
19
  function _interop_require_default(obj) {
19
20
  return obj && obj.__esModule ? obj : {
20
21
  default: obj
21
22
  };
22
23
  }
23
- function _getRequireWildcardCache(nodeInterop) {
24
- if (typeof WeakMap !== "function") return null;
25
- var cacheBabelInterop = new WeakMap();
26
- var cacheNodeInterop = new WeakMap();
27
- return (_getRequireWildcardCache = function(nodeInterop) {
28
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
29
- })(nodeInterop);
30
- }
31
- function _interop_require_wildcard(obj, nodeInterop) {
32
- if (!nodeInterop && obj && obj.__esModule) {
33
- return obj;
34
- }
35
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
36
- return {
37
- default: obj
38
- };
39
- }
40
- var cache = _getRequireWildcardCache(nodeInterop);
41
- if (cache && cache.has(obj)) {
42
- return cache.get(obj);
43
- }
44
- var newObj = {
45
- __proto__: null
46
- };
47
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
48
- for(var key in obj){
49
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
50
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
51
- if (desc && (desc.get || desc.set)) {
52
- Object.defineProperty(newObj, key, desc);
53
- } else {
54
- newObj[key] = obj[key];
55
- }
56
- }
57
- }
58
- newObj.default = obj;
59
- if (cache) {
60
- cache.set(obj, newObj);
61
- }
62
- return newObj;
63
- }
64
- const TRANSITION_CLASS_NAME = "--transition";
24
+ const TRANSITION_CSS_VARIABLE = "--modal-transition-duration";
65
25
  const Modal = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
66
26
  const { isOpen, onClose, onOpen, children, className, closeLabel, isFullScreen, animation, // Deprecated props below
67
27
  size, appElement, preventCloseOnEsc, shouldFocusAfterRender, parentSelector } = props;
@@ -73,108 +33,42 @@ const Modal = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
73
33
  hasWarnedAboutMissingLabels.current = true;
74
34
  }
75
35
  }
76
- const hasOpened = (0, _react.useRef)(false);
77
- const modalRef = (0, _react.useRef)(null);
78
- const hasDialogSupport = (0, _polyfilltests.supportsDialog)();
79
- // Fire onOpen once
80
- if (onOpen && !hasOpened.current) {
81
- onOpen();
82
- hasOpened.current = true;
83
- }
84
- (0, _useBodyScrollLock.useBodyScrollLock)({
85
- enabled: isOpen
86
- });
87
- // Add close handler, to enable closing animations
88
- const handleClose = (0, _react.useCallback)((event)=>{
89
- // `transitionend` may be called from another component but `event` may be undefined.
90
- // This fixes an issue where closing `<Accordion>` inside `<Modal>` will close both
91
- if (!event) return;
92
- if (event) {
93
- event.preventDefault();
94
- event.stopPropagation();
95
- }
96
- // Name the callback function, so we can add and remove event listener
97
- const transitionCallback = (e)=>{
98
- // Close modal only if the transition is on the dialog element
99
- // As it can be on a child element (ie `<Button>` inside the drawer)
100
- if (e.target === modalRef.current) {
101
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
102
- doClose();
103
- }
104
- };
105
- const doClose = ()=>{
106
- var _modalRef_current, _modalRef_current1;
107
- (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.close();
108
- onClose === null || onClose === void 0 ? void 0 : onClose();
109
- (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.removeEventListener("transitionend", transitionCallback);
110
- };
111
- // Delay close to allow backdrop exit transition
112
- if (hasDialogSupport && animation) {
113
- var _modalRef_current, _modalRef_current1;
114
- (_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.classList.remove(TRANSITION_CLASS_NAME);
115
- (_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.addEventListener("transitionend", transitionCallback);
116
- } else {
117
- doClose();
118
- }
119
- }, [
36
+ const shouldTransition = (0, _polyfilltests.supportsDialog)();
37
+ const dialogRef = (0, _react.useRef)(null);
38
+ const { close } = (0, _hooks.useDialog)({
39
+ ref: dialogRef,
40
+ isOpen,
41
+ onOpen,
120
42
  onClose,
121
- hasDialogSupport,
122
- animation
123
- ]);
43
+ transition: {
44
+ isEnabled: !!animation,
45
+ CSSVariable: TRANSITION_CSS_VARIABLE
46
+ }
47
+ });
124
48
  const modalClasses = (0, _dedupe.default)("mobius", "mobius/Modal", {
125
- "--no-dialog-support": !hasDialogSupport,
126
- "--should-transition": hasDialogSupport && animation,
49
+ "--no-dialog-support": !shouldTransition,
50
+ "--should-transition": shouldTransition && animation,
127
51
  "--slide-up": animation === "slideUp",
128
52
  "--fade": animation === "fade",
129
53
  "--is-fullscreen": isFullScreen
130
54
  }, className);
131
- // Add polyfill for HTML Dialog in old browsers
132
- (0, _react.useEffect)(()=>{
133
- async function toggleModal() {
134
- var _modalRef_current, _modalRef_current1;
135
- if (!hasDialogSupport && typeof window !== "undefined" && modalRef.current !== null) {
136
- // eslint-disable-next-line import/no-extraneous-dependencies
137
- const { default: dialogPolyfill } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("dialog-polyfill")));
138
- try {
139
- dialogPolyfill.registerDialog(modalRef.current);
140
- } catch (error) {
141
- // In iOS 15 <= 15.2 this intermittently fails with
142
- // TypeError: null is not an object (evaluating 'element.showModal')
143
- // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️
144
- console.error("Failed to load dialog-polyfill", error);
145
- }
146
- }
147
- if (isOpen && !((_modalRef_current = modalRef.current) === null || _modalRef_current === void 0 ? void 0 : _modalRef_current.open)) {
148
- var _modalRef_current2, _modalRef_current3;
149
- (_modalRef_current2 = modalRef.current) === null || _modalRef_current2 === void 0 ? void 0 : _modalRef_current2.showModal();
150
- (_modalRef_current3 = modalRef.current) === null || _modalRef_current3 === void 0 ? void 0 : _modalRef_current3.classList.add(TRANSITION_CLASS_NAME);
151
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
152
- } else if (!isOpen && ((_modalRef_current1 = modalRef.current) === null || _modalRef_current1 === void 0 ? void 0 : _modalRef_current1.open)) {
153
- handleClose();
154
- }
155
- }
156
- toggleModal();
157
- }, [
158
- isOpen,
159
- onOpen,
160
- handleClose,
161
- hasDialogSupport
55
+ const contextValue = (0, _react.useMemo)(()=>({
56
+ onClose: close,
57
+ closeLabel
58
+ }), [
59
+ close,
60
+ closeLabel
162
61
  ]);
163
62
  return /*#__PURE__*/ (0, _jsxruntime.jsx)("dialog", {
164
63
  ref: (0, _utils.mergeRefs)([
165
- modalRef,
64
+ dialogRef,
166
65
  ref
167
66
  ]),
168
- onCancel: handleClose,
67
+ onCancel: close,
169
68
  className: modalClasses,
170
- children: _react.Children.map(children, (child)=>{
171
- if (/*#__PURE__*/ (0, _react.isValidElement)(child)) {
172
- return /*#__PURE__*/ (0, _react.cloneElement)(child, {
173
- onClose: handleClose,
174
- closeLabel
175
- });
176
- }
177
- return child;
69
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_ModalContext.ModalContext.Provider, {
70
+ value: contextValue,
71
+ children: children
178
72
  })
179
73
  });
180
74
  });
@@ -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 // `transitionend` may be called from another component but `event` may be undefined.\n // This fixes an issue where closing `<Accordion>` inside `<Modal>` will close both\n if (!event) return;\n\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":"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"}
1
+ {"version":3,"sources":["../../../../src/components/Modal/Modal.tsx"],"sourcesContent":["\"use client\";\n\nimport classNames from \"classnames/dedupe\";\nimport { Ref, forwardRef, useMemo, useRef } from \"react\";\nimport { supportsDialog } from \"../../utils/polyfill-tests\";\nimport { ModalProps } from \"./types\";\nimport { mergeRefs } from \"../../utils\";\nimport { ModalContext } from \"./ModalContext\";\nimport { useDialog } from \"../../hooks\";\n\nexport type ModalElementType = HTMLDialogElement;\nexport type ModalRef = Ref<ModalElementType>;\n\nconst TRANSITION_CSS_VARIABLE = \"--modal-transition-duration\";\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 shouldTransition = supportsDialog();\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const { close } = useDialog({\n ref: dialogRef,\n isOpen,\n onOpen,\n onClose,\n transition: {\n isEnabled: !!animation,\n CSSVariable: TRANSITION_CSS_VARIABLE,\n },\n });\n\n const modalClasses = classNames(\n \"mobius\",\n \"mobius/Modal\",\n {\n \"--no-dialog-support\": !shouldTransition, // This class is used to correctly position modal in x/y middle on iOS <= 15.2\n \"--should-transition\": shouldTransition && animation,\n \"--slide-up\": animation === \"slideUp\",\n \"--fade\": animation === \"fade\",\n \"--is-fullscreen\": isFullScreen,\n },\n className,\n );\n\n const contextValue = useMemo(\n () => ({\n onClose: close,\n closeLabel,\n }),\n [close, closeLabel],\n );\n\n return (\n <dialog\n ref={mergeRefs([dialogRef, ref])}\n onCancel={close}\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_CSS_VARIABLE","forwardRef","props","ref","isOpen","onClose","onOpen","children","className","closeLabel","isFullScreen","animation","size","appElement","preventCloseOnEsc","shouldFocusAfterRender","parentSelector","hasWarnedAboutMissingLabels","useRef","current","console","warn","shouldTransition","supportsDialog","dialogRef","close","useDialog","transition","isEnabled","CSSVariable","modalClasses","classNames","contextValue","useMemo","dialog","mergeRefs","onCancel","ModalContext","Provider","value","displayName"],"mappings":"AAAA;;;;;+BAiGSA;;;eAAAA;;;;+DA/Fc;uBAC0B;+BAClB;uBAEL;8BACG;uBACH;;;;;;AAK1B,MAAMC,0BAA0B;AAEhC,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,mBAAmBC,IAAAA,6BAAc;IACvC,MAAMC,YAAYN,IAAAA,aAAM,EAA2B;IACnD,MAAM,EAAEO,KAAK,EAAE,GAAGC,IAAAA,gBAAS,EAAC;QAC1BvB,KAAKqB;QACLpB;QACAE;QACAD;QACAsB,YAAY;YACVC,WAAW,CAAC,CAACjB;YACbkB,aAAa7B;QACf;IACF;IAEA,MAAM8B,eAAeC,IAAAA,eAAU,EAC7B,UACA,gBACA;QACE,uBAAuB,CAACT;QACxB,uBAAuBA,oBAAoBX;QAC3C,cAAcA,cAAc;QAC5B,UAAUA,cAAc;QACxB,mBAAmBD;IACrB,GACAF;IAGF,MAAMwB,eAAeC,IAAAA,cAAO,EAC1B,IAAO,CAAA;YACL5B,SAASoB;YACThB;QACF,CAAA,GACA;QAACgB;QAAOhB;KAAW;IAGrB,qBACE,qBAACyB;QACC/B,KAAKgC,IAAAA,gBAAS,EAAC;YAACX;YAAWrB;SAAI;QAC/BiC,UAAUX;QACVjB,WAAWsB;kBAEX,cAAA,qBAACO,0BAAY,CAACC,QAAQ;YAACC,OAAOP;sBAC3BzB;;;AAIT;AAEAR,MAAMyC,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"}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  _export_star(require("./useBodyScrollLock"), exports);
6
6
  _export_star(require("./useBreakpoint"), exports);
7
7
  _export_star(require("./useButton"), exports);
8
+ _export_star(require("./useDialog"), exports);
8
9
  _export_star(require("./useLabel"), exports);
9
10
  _export_star(require("./useOnClickOutside"), exports);
10
11
  _export_star(require("./useTextField"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/index.tsx"],"sourcesContent":["export * from \"./useBodyScrollLock\";\nexport * from \"./useBreakpoint\";\nexport * from \"./useButton\";\nexport * from \"./useLabel\";\nexport * from \"./useOnClickOutside\";\nexport * from \"./useTextField\";\nexport * from \"./useWindowEvent\";\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
1
+ {"version":3,"sources":["../../../src/hooks/index.tsx"],"sourcesContent":["export * from \"./useBodyScrollLock\";\nexport * from \"./useBreakpoint\";\nexport * from \"./useButton\";\nexport * from \"./useDialog\";\nexport * from \"./useLabel\";\nexport * from \"./useOnClickOutside\";\nexport * from \"./useTextField\";\nexport * from \"./useWindowEvent\";\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./useDialog"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
19
+
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/hooks/useDialog/index.ts"],"sourcesContent":["export * from \"./useDialog\";\n"],"names":[],"mappings":";;;;qBAAc"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useDialog", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useDialog;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _useDialogPolyfill = require("../useDialogPolyfill");
13
+ const _useBodyScrollLock = require("../useBodyScrollLock");
14
+ const _utils = require("../../utils");
15
+ const TRANSITION_CLASS_NAME = "--transition";
16
+ const FALLBACK_TRANSITION_DURATION = 0;
17
+ const useDialog = (props)=>{
18
+ const { ref, isOpen, transition, onOpen, onClose } = props;
19
+ const shouldTransition = (0, _utils.supportsDialog)() && transition.isEnabled;
20
+ // Read CSS variable value as number
21
+ const TRANSITION_DURATION_IN_MS = ref.current && Number(getComputedStyle(ref.current).getPropertyValue(transition.CSSVariable).replace("ms", "")) || FALLBACK_TRANSITION_DURATION;
22
+ (0, _useDialogPolyfill.useDialogPolyfill)(ref);
23
+ (0, _useBodyScrollLock.useBodyScrollLock)({
24
+ enabled: isOpen
25
+ });
26
+ const open = (0, _react.useCallback)(()=>{
27
+ var _ref_current;
28
+ (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.showModal();
29
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
30
+ }, [
31
+ onOpen,
32
+ ref
33
+ ]);
34
+ const close = (0, _react.useCallback)(()=>{
35
+ var _ref_current;
36
+ (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.close();
37
+ onClose === null || onClose === void 0 ? void 0 : onClose();
38
+ }, [
39
+ onClose,
40
+ ref
41
+ ]);
42
+ // Add close handler, to enable closing transitions
43
+ const handleClose = (0, _react.useCallback)((event)=>{
44
+ if (event) {
45
+ // Prevent default event coming from onCancel,
46
+ // which is triggered by pressing ESC key
47
+ event.preventDefault();
48
+ // Ensure that nested `<dialog>` elements
49
+ // don't close the parent
50
+ event.stopPropagation();
51
+ }
52
+ if (shouldTransition) {
53
+ var _ref_current;
54
+ (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.classList.remove(TRANSITION_CLASS_NAME);
55
+ // Delay close to allow exit transition
56
+ setTimeout(()=>close(), TRANSITION_DURATION_IN_MS);
57
+ } else {
58
+ close();
59
+ }
60
+ }, [
61
+ TRANSITION_DURATION_IN_MS,
62
+ close,
63
+ ref,
64
+ shouldTransition
65
+ ]);
66
+ (0, _react.useEffect)(()=>{
67
+ async function toggleDialog() {
68
+ var _ref_current, _ref_current1;
69
+ if (isOpen && !((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.open)) {
70
+ open();
71
+ // Fix opening transition in Safari being skipped
72
+ // by wrapping with setTimeout
73
+ setTimeout(()=>{
74
+ var _ref_current;
75
+ (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.classList.add(TRANSITION_CLASS_NAME);
76
+ }, 0);
77
+ } else if (!isOpen && ((_ref_current1 = ref.current) === null || _ref_current1 === void 0 ? void 0 : _ref_current1.open)) {
78
+ handleClose();
79
+ }
80
+ }
81
+ toggleDialog();
82
+ }, [
83
+ handleClose,
84
+ isOpen,
85
+ open,
86
+ ref
87
+ ]);
88
+ return {
89
+ open,
90
+ close: handleClose
91
+ };
92
+ };
93
+
94
+ //# sourceMappingURL=useDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/hooks/useDialog/useDialog.ts"],"sourcesContent":["import {\n MutableRefObject,\n SyntheticEvent,\n useCallback,\n useEffect,\n} from \"react\";\nimport { useDialogPolyfill } from \"../useDialogPolyfill\";\nimport { useBodyScrollLock } from \"../useBodyScrollLock\";\nimport { supportsDialog } from \"../../utils\";\n\nexport type TransitionProps = {\n isEnabled: boolean;\n CSSVariable: string;\n};\n\nexport type useDialogProps = {\n ref: MutableRefObject<HTMLDialogElement | null>;\n transition: TransitionProps;\n isOpen: boolean;\n onOpen?: () => void;\n onClose?: () => void;\n};\n\nconst TRANSITION_CLASS_NAME = \"--transition\";\nconst FALLBACK_TRANSITION_DURATION = 0;\n\nexport const useDialog = (props: useDialogProps) => {\n const { ref, isOpen, transition, onOpen, onClose } = props;\n const shouldTransition = supportsDialog() && transition.isEnabled;\n\n // Read CSS variable value as number\n const TRANSITION_DURATION_IN_MS =\n (ref.current &&\n Number(\n getComputedStyle(ref.current)\n .getPropertyValue(transition.CSSVariable)\n .replace(\"ms\", \"\"),\n )) ||\n FALLBACK_TRANSITION_DURATION;\n\n useDialogPolyfill(ref);\n useBodyScrollLock({ enabled: isOpen });\n\n const open = useCallback(() => {\n ref.current?.showModal();\n onOpen?.();\n }, [onOpen, ref]);\n\n const close = useCallback(() => {\n ref.current?.close();\n onClose?.();\n }, [onClose, ref]);\n\n // Add close handler, to enable closing transitions\n const handleClose = useCallback(\n (event?: SyntheticEvent<HTMLElement, Event>) => {\n if (event) {\n // Prevent default event coming from onCancel,\n // which is triggered by pressing ESC key\n event.preventDefault();\n // Ensure that nested `<dialog>` elements\n // don't close the parent\n event.stopPropagation();\n }\n\n if (shouldTransition) {\n ref.current?.classList.remove(TRANSITION_CLASS_NAME);\n // Delay close to allow exit transition\n setTimeout(() => close(), TRANSITION_DURATION_IN_MS);\n } else {\n close();\n }\n },\n [TRANSITION_DURATION_IN_MS, close, ref, shouldTransition],\n );\n\n useEffect(() => {\n async function toggleDialog() {\n if (isOpen && !ref.current?.open) {\n open();\n // Fix opening transition in Safari being skipped\n // by wrapping with setTimeout\n setTimeout(() => {\n ref.current?.classList.add(TRANSITION_CLASS_NAME);\n }, 0);\n } else if (!isOpen && ref.current?.open) {\n handleClose();\n }\n }\n\n toggleDialog();\n }, [handleClose, isOpen, open, ref]);\n\n return {\n open,\n close: handleClose,\n };\n};\n"],"names":["useDialog","TRANSITION_CLASS_NAME","FALLBACK_TRANSITION_DURATION","props","ref","isOpen","transition","onOpen","onClose","shouldTransition","supportsDialog","isEnabled","TRANSITION_DURATION_IN_MS","current","Number","getComputedStyle","getPropertyValue","CSSVariable","replace","useDialogPolyfill","useBodyScrollLock","enabled","open","useCallback","showModal","close","handleClose","event","preventDefault","stopPropagation","classList","remove","setTimeout","useEffect","toggleDialog","add"],"mappings":";;;;+BA0BaA;;;eAAAA;;;uBArBN;mCAC2B;mCACA;uBACH;AAe/B,MAAMC,wBAAwB;AAC9B,MAAMC,+BAA+B;AAE9B,MAAMF,YAAY,CAACG;IACxB,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGL;IACrD,MAAMM,mBAAmBC,IAAAA,qBAAc,OAAMJ,WAAWK,SAAS;IAEjE,oCAAoC;IACpC,MAAMC,4BACJ,AAACR,IAAIS,OAAO,IACVC,OACEC,iBAAiBX,IAAIS,OAAO,EACzBG,gBAAgB,CAACV,WAAWW,WAAW,EACvCC,OAAO,CAAC,MAAM,QAErBhB;IAEFiB,IAAAA,oCAAiB,EAACf;IAClBgB,IAAAA,oCAAiB,EAAC;QAAEC,SAAShB;IAAO;IAEpC,MAAMiB,OAAOC,IAAAA,kBAAW,EAAC;YACvBnB;SAAAA,eAAAA,IAAIS,OAAO,cAAXT,mCAAAA,aAAaoB,SAAS;QACtBjB,mBAAAA,6BAAAA;IACF,GAAG;QAACA;QAAQH;KAAI;IAEhB,MAAMqB,QAAQF,IAAAA,kBAAW,EAAC;YACxBnB;SAAAA,eAAAA,IAAIS,OAAO,cAAXT,mCAAAA,aAAaqB,KAAK;QAClBjB,oBAAAA,8BAAAA;IACF,GAAG;QAACA;QAASJ;KAAI;IAEjB,mDAAmD;IACnD,MAAMsB,cAAcH,IAAAA,kBAAW,EAC7B,CAACI;QACC,IAAIA,OAAO;YACT,8CAA8C;YAC9C,yCAAyC;YACzCA,MAAMC,cAAc;YACpB,yCAAyC;YACzC,yBAAyB;YACzBD,MAAME,eAAe;QACvB;QAEA,IAAIpB,kBAAkB;gBACpBL;aAAAA,eAAAA,IAAIS,OAAO,cAAXT,mCAAAA,aAAa0B,SAAS,CAACC,MAAM,CAAC9B;YAC9B,uCAAuC;YACvC+B,WAAW,IAAMP,SAASb;QAC5B,OAAO;YACLa;QACF;IACF,GACA;QAACb;QAA2Ba;QAAOrB;QAAKK;KAAiB;IAG3DwB,IAAAA,gBAAS,EAAC;QACR,eAAeC;gBACE9B,cAOOA;YAPtB,IAAIC,UAAU,GAACD,eAAAA,IAAIS,OAAO,cAAXT,mCAAAA,aAAakB,IAAI,GAAE;gBAChCA;gBACA,iDAAiD;gBACjD,8BAA8B;gBAC9BU,WAAW;wBACT5B;qBAAAA,eAAAA,IAAIS,OAAO,cAAXT,mCAAAA,aAAa0B,SAAS,CAACK,GAAG,CAAClC;gBAC7B,GAAG;YACL,OAAO,IAAI,CAACI,YAAUD,gBAAAA,IAAIS,OAAO,cAAXT,oCAAAA,cAAakB,IAAI,GAAE;gBACvCI;YACF;QACF;QAEAQ;IACF,GAAG;QAACR;QAAarB;QAAQiB;QAAMlB;KAAI;IAEnC,OAAO;QACLkB;QACAG,OAAOC;IACT;AACF"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./useDialogPolyfill"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
19
+
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/hooks/useDialogPolyfill/index.ts"],"sourcesContent":["export * from \"./useDialogPolyfill\";\n"],"names":[],"mappings":";;;;qBAAc"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useDialogPolyfill", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useDialogPolyfill;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _utils = require("../../utils");
13
+ function _getRequireWildcardCache(nodeInterop) {
14
+ if (typeof WeakMap !== "function") return null;
15
+ var cacheBabelInterop = new WeakMap();
16
+ var cacheNodeInterop = new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop) {
18
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {
35
+ __proto__: null
36
+ };
37
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
38
+ for(var key in obj){
39
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
40
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
41
+ if (desc && (desc.get || desc.set)) {
42
+ Object.defineProperty(newObj, key, desc);
43
+ } else {
44
+ newObj[key] = obj[key];
45
+ }
46
+ }
47
+ }
48
+ newObj.default = obj;
49
+ if (cache) {
50
+ cache.set(obj, newObj);
51
+ }
52
+ return newObj;
53
+ }
54
+ const useDialogPolyfill = (ref)=>{
55
+ const hasDialogSupport = (0, _utils.supportsDialog)();
56
+ (0, _react.useEffect)(()=>{
57
+ async function polyfillDialog() {
58
+ if (!hasDialogSupport && typeof window !== "undefined" && ref.current !== null) {
59
+ const { default: dialogPolyfill } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("dialog-polyfill")));
60
+ try {
61
+ dialogPolyfill.registerDialog(ref.current);
62
+ } catch (error) {
63
+ // In iOS 15 <= 15.2 this intermittently fails with
64
+ // TypeError: null is not an object (evaluating 'element.showModal')
65
+ // Checking showModal presence through hasOwnProperty is falsy natively, truthy with polyfill 🤷🏼‍♂️
66
+ console.error("Failed to load dialog-polyfill", error);
67
+ }
68
+ }
69
+ }
70
+ polyfillDialog();
71
+ }, [
72
+ ref,
73
+ hasDialogSupport
74
+ ]);
75
+ };
76
+
77
+ //# sourceMappingURL=useDialogPolyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/hooks/useDialogPolyfill/useDialogPolyfill.ts"],"sourcesContent":["import { MutableRefObject, useEffect } from \"react\";\nimport { supportsDialog } from \"../../utils\";\n\n// Add polyfill for HTML Dialog in old browsers\nexport const useDialogPolyfill = (\n ref: MutableRefObject<HTMLDialogElement | null>,\n) => {\n const hasDialogSupport = supportsDialog();\n\n useEffect(() => {\n async function polyfillDialog() {\n if (\n !hasDialogSupport &&\n typeof window !== \"undefined\" &&\n ref.current !== null\n ) {\n const { default: dialogPolyfill } = await import(\"dialog-polyfill\");\n\n try {\n dialogPolyfill.registerDialog(ref.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\n polyfillDialog();\n }, [ref, hasDialogSupport]);\n};\n"],"names":["useDialogPolyfill","ref","hasDialogSupport","supportsDialog","useEffect","polyfillDialog","window","current","default","dialogPolyfill","registerDialog","error","console"],"mappings":";;;;+BAIaA;;;eAAAA;;;uBAJ+B;uBACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGxB,MAAMA,oBAAoB,CAC/BC;IAEA,MAAMC,mBAAmBC,IAAAA,qBAAc;IAEvCC,IAAAA,gBAAS,EAAC;QACR,eAAeC;YACb,IACE,CAACH,oBACD,OAAOI,WAAW,eAClBL,IAAIM,OAAO,KAAK,MAChB;gBACA,MAAM,EAAEC,SAASC,cAAc,EAAE,GAAG,MAAM,mEAAA,QAAO;gBAEjD,IAAI;oBACFA,eAAeC,cAAc,CAACT,IAAIM,OAAO;gBAC3C,EAAE,OAAOI,OAAO;oBACd,mDAAmD;oBACnD,oEAAoE;oBACpE,qGAAqG;oBACrGC,QAAQD,KAAK,CAAC,kCAAkCA;gBAClD;YACF;QACF;QAEAN;IACF,GAAG;QAACJ;QAAKC;KAAiB;AAC5B"}