react-responsive-modal 4.0.1 → 5.0.3

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.
@@ -0,0 +1,439 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var React = require('react');
8
+ var React__default = _interopDefault(React);
9
+ var ReactDom = _interopDefault(require('react-dom'));
10
+ var cx = _interopDefault(require('classnames'));
11
+ var noScroll = _interopDefault(require('no-scroll'));
12
+
13
+ function _extends() {
14
+ _extends = Object.assign || function (target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = arguments[i];
17
+
18
+ for (var key in source) {
19
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
20
+ target[key] = source[key];
21
+ }
22
+ }
23
+ }
24
+
25
+ return target;
26
+ };
27
+
28
+ return _extends.apply(this, arguments);
29
+ }
30
+
31
+ var CloseIcon = function CloseIcon(_ref) {
32
+ var classes = _ref.classes,
33
+ classNames = _ref.classNames,
34
+ styles = _ref.styles,
35
+ id = _ref.id,
36
+ closeIcon = _ref.closeIcon,
37
+ onClickCloseIcon = _ref.onClickCloseIcon;
38
+ return React__default.createElement("button", {
39
+ id: id,
40
+ className: cx(classes.closeButton, classNames === null || classNames === void 0 ? void 0 : classNames.closeButton),
41
+ style: styles === null || styles === void 0 ? void 0 : styles.closeButton,
42
+ onClick: onClickCloseIcon,
43
+ "data-testid": "close-button"
44
+ }, closeIcon ? closeIcon : React__default.createElement("svg", {
45
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.closeIcon,
46
+ style: styles === null || styles === void 0 ? void 0 : styles.closeIcon,
47
+ xmlns: "http://www.w3.org/2000/svg",
48
+ width: 28,
49
+ height: 28,
50
+ viewBox: "0 0 36 36",
51
+ "data-testid": "close-icon"
52
+ }, React__default.createElement("path", {
53
+ d: "M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z"
54
+ })));
55
+ };
56
+
57
+ var _modals = [];
58
+ /**
59
+ * Handle the order of the modals.
60
+ * Inspired by the material-ui implementation.
61
+ */
62
+
63
+ var modalManager = {
64
+ /**
65
+ * Return the modals array
66
+ */
67
+ modals: function modals() {
68
+ return _modals;
69
+ },
70
+
71
+ /**
72
+ * Register a new modal
73
+ */
74
+ add: function add(newModal, blockScroll) {
75
+ if (_modals.findIndex(function (modal) {
76
+ return modal.element === newModal;
77
+ }) === -1) {
78
+ _modals.push({
79
+ element: newModal,
80
+ blockScroll: blockScroll
81
+ });
82
+ }
83
+ },
84
+
85
+ /**
86
+ * Remove a modal
87
+ */
88
+ remove: function remove(oldModal) {
89
+ var index = _modals.findIndex(function (modal) {
90
+ return modal.element === oldModal;
91
+ });
92
+
93
+ if (index !== -1) {
94
+ _modals.splice(index, 1);
95
+ }
96
+ },
97
+
98
+ /**
99
+ * Check if the modal is the first one on the screen
100
+ */
101
+ isTopModal: function isTopModal(modal) {
102
+ var _modals2;
103
+
104
+ return !!_modals.length && ((_modals2 = _modals[_modals.length - 1]) === null || _modals2 === void 0 ? void 0 : _modals2.element) === modal;
105
+ }
106
+ };
107
+
108
+ var isBrowser = typeof window !== 'undefined';
109
+ var blockNoScroll = function blockNoScroll() {
110
+ noScroll.on();
111
+ };
112
+ var unblockNoScroll = function unblockNoScroll() {
113
+ // Restore the scroll only if there is no modal on the screen
114
+ // We filter the modals that are not affecting the scroll
115
+ var modals = modalManager.modals().filter(function (modal) {
116
+ return modal.blockScroll;
117
+ });
118
+
119
+ if (modals.length === 0) {
120
+ noScroll.off();
121
+ }
122
+ };
123
+
124
+ // https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9
125
+ var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'];
126
+
127
+ function isHidden(node) {
128
+ // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,
129
+ // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.
130
+ return node.offsetParent === null || getComputedStyle(node).visibility === 'hidden';
131
+ }
132
+
133
+ function getAllTabbingElements(parentElem) {
134
+ var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));
135
+ var onlyTabbable = [];
136
+
137
+ for (var i = 0; i < tabbableNodes.length; i++) {
138
+ var node = tabbableNodes[i];
139
+
140
+ if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {
141
+ onlyTabbable.push(node);
142
+ }
143
+ }
144
+
145
+ return onlyTabbable;
146
+ }
147
+ function tabTrappingKey(event, parentElem) {
148
+ // check if current event keyCode is tab
149
+ if (!event || event.key !== 'Tab') return;
150
+
151
+ if (!parentElem || !parentElem.contains) {
152
+ if (process && "development" === 'development') {
153
+ console.warn('focus-trap-js: parent element is not defined');
154
+ }
155
+
156
+ return false;
157
+ }
158
+
159
+ if (!parentElem.contains(event.target)) {
160
+ return false;
161
+ }
162
+
163
+ var allTabbingElements = getAllTabbingElements(parentElem);
164
+ var firstFocusableElement = allTabbingElements[0];
165
+ var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];
166
+
167
+ if (event.shiftKey && event.target === firstFocusableElement) {
168
+ lastFocusableElement.focus();
169
+ event.preventDefault();
170
+ return true;
171
+ } else if (!event.shiftKey && event.target === lastFocusableElement) {
172
+ firstFocusableElement.focus();
173
+ event.preventDefault();
174
+ return true;
175
+ }
176
+
177
+ return false;
178
+ }
179
+
180
+ function getTabindex(node) {
181
+ var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);
182
+ if (!isNaN(tabindexAttr)) return tabindexAttr; // Browsers do not return tabIndex correctly for contentEditable nodes;
183
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
184
+
185
+ if (isContentEditable(node)) return 0;
186
+ return node.tabIndex;
187
+ }
188
+
189
+ function isContentEditable(node) {
190
+ return node.getAttribute('contentEditable');
191
+ }
192
+
193
+ var FocusTrap = function FocusTrap(_ref) {
194
+ var container = _ref.container;
195
+ var refLastFocus = React.useRef();
196
+ /**
197
+ * Handle focus lock on the modal
198
+ */
199
+
200
+ React.useEffect(function () {
201
+ var handleKeyEvent = function handleKeyEvent(event) {
202
+ if (container === null || container === void 0 ? void 0 : container.current) {
203
+ tabTrappingKey(event, container.current);
204
+ }
205
+ };
206
+
207
+ if (isBrowser) {
208
+ document.addEventListener('keydown', handleKeyEvent);
209
+ } // On mount we focus on the first focusable element in the modal if there is one
210
+
211
+
212
+ if (isBrowser && (container === null || container === void 0 ? void 0 : container.current)) {
213
+ var allTabbingElements = getAllTabbingElements(container.current);
214
+
215
+ if (allTabbingElements[0]) {
216
+ // First we save the last focused element
217
+ // only if it's a focusable element
218
+ if (candidateSelectors.findIndex(function (selector) {
219
+ var _document$activeEleme;
220
+
221
+ return (_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.matches(selector);
222
+ }) !== -1) {
223
+ refLastFocus.current = document.activeElement;
224
+ }
225
+
226
+ allTabbingElements[0].focus();
227
+ }
228
+ }
229
+
230
+ return function () {
231
+ if (isBrowser) {
232
+ var _refLastFocus$current;
233
+
234
+ document.removeEventListener('keydown', handleKeyEvent); // On unmount we restore the focus to the last focused element
235
+
236
+ (_refLastFocus$current = refLastFocus.current) === null || _refLastFocus$current === void 0 ? void 0 : _refLastFocus$current.focus();
237
+ }
238
+ };
239
+ }, [container]);
240
+ return null;
241
+ };
242
+
243
+ var classes = {
244
+ overlay: 'react-responsive-modal-overlay',
245
+ modal: 'react-responsive-modal-modal',
246
+ modalCenter: 'react-responsive-modal-modalCenter',
247
+ closeButton: 'react-responsive-modal-closeButton',
248
+ animationIn: 'react-responsive-modal-fadeIn',
249
+ animationOut: 'react-responsive-modal-fadeOut'
250
+ };
251
+ var Modal = function Modal(_ref) {
252
+ var _classNames$animation, _classNames$animation2;
253
+
254
+ var open = _ref.open,
255
+ center = _ref.center,
256
+ _ref$blockScroll = _ref.blockScroll,
257
+ blockScroll = _ref$blockScroll === void 0 ? true : _ref$blockScroll,
258
+ _ref$closeOnEsc = _ref.closeOnEsc,
259
+ closeOnEsc = _ref$closeOnEsc === void 0 ? true : _ref$closeOnEsc,
260
+ _ref$closeOnOverlayCl = _ref.closeOnOverlayClick,
261
+ closeOnOverlayClick = _ref$closeOnOverlayCl === void 0 ? true : _ref$closeOnOverlayCl,
262
+ container = _ref.container,
263
+ _ref$showCloseIcon = _ref.showCloseIcon,
264
+ showCloseIcon = _ref$showCloseIcon === void 0 ? true : _ref$showCloseIcon,
265
+ closeIconId = _ref.closeIconId,
266
+ closeIcon = _ref.closeIcon,
267
+ _ref$focusTrapped = _ref.focusTrapped,
268
+ focusTrapped = _ref$focusTrapped === void 0 ? true : _ref$focusTrapped,
269
+ _ref$animationDuratio = _ref.animationDuration,
270
+ animationDuration = _ref$animationDuratio === void 0 ? 500 : _ref$animationDuratio,
271
+ classNames = _ref.classNames,
272
+ styles = _ref.styles,
273
+ _ref$role = _ref.role,
274
+ role = _ref$role === void 0 ? 'dialog' : _ref$role,
275
+ ariaDescribedby = _ref.ariaDescribedby,
276
+ ariaLabelledby = _ref.ariaLabelledby,
277
+ modalId = _ref.modalId,
278
+ onClose = _ref.onClose,
279
+ onEscKeyDown = _ref.onEscKeyDown,
280
+ onOverlayClick = _ref.onOverlayClick,
281
+ onAnimationEnd = _ref.onAnimationEnd,
282
+ children = _ref.children;
283
+ var refModal = React.useRef(null);
284
+ var refShouldClose = React.useRef(null);
285
+ var refContainer = React.useRef(null); // Lazily create the ref instance
286
+ // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
287
+
288
+ if (refContainer.current === null && isBrowser) {
289
+ refContainer.current = document.createElement('div');
290
+ }
291
+
292
+ var _useState = React.useState(open),
293
+ showPortal = _useState[0],
294
+ setShowPortal = _useState[1];
295
+
296
+ var handleOpen = function handleOpen() {
297
+ modalManager.add(refContainer.current, blockScroll);
298
+
299
+ if (blockScroll) {
300
+ blockNoScroll();
301
+ }
302
+
303
+ if (refContainer.current && !container && !document.body.contains(refContainer.current)) {
304
+ document.body.appendChild(refContainer.current);
305
+ }
306
+
307
+ document.addEventListener('keydown', handleKeydown);
308
+ };
309
+
310
+ var handleClose = function handleClose() {
311
+ modalManager.remove(refContainer.current);
312
+
313
+ if (blockScroll) {
314
+ unblockNoScroll();
315
+ }
316
+
317
+ if (refContainer.current && !container && document.body.contains(refContainer.current)) {
318
+ document.body.removeChild(refContainer.current);
319
+ }
320
+
321
+ document.removeEventListener('keydown', handleKeydown);
322
+ };
323
+
324
+ var handleKeydown = function handleKeydown(event) {
325
+ // Only the last modal need to be escaped when pressing the esc key
326
+ if (event.keyCode !== 27 || !modalManager.isTopModal(refContainer.current)) {
327
+ return;
328
+ }
329
+
330
+ if (onEscKeyDown) {
331
+ onEscKeyDown(event);
332
+ }
333
+
334
+ if (closeOnEsc) {
335
+ onClose();
336
+ }
337
+ };
338
+
339
+ React.useEffect(function () {
340
+ // When the modal is rendered first time we want to block the scroll
341
+ if (open) {
342
+ handleOpen();
343
+ }
344
+
345
+ return function () {
346
+ // When the component is unmounted directly we want to unblock the scroll
347
+ if (showPortal) {
348
+ handleClose();
349
+ }
350
+ };
351
+ }, []);
352
+ React.useEffect(function () {
353
+ // If the open prop is changing, we need to open the modal
354
+ if (open && !showPortal) {
355
+ setShowPortal(true);
356
+ handleOpen();
357
+ }
358
+ }, [open]);
359
+
360
+ var handleClickOverlay = function handleClickOverlay(event) {
361
+ if (refShouldClose.current === null) {
362
+ refShouldClose.current = true;
363
+ }
364
+
365
+ if (!refShouldClose.current) {
366
+ refShouldClose.current = null;
367
+ return;
368
+ }
369
+
370
+ if (onOverlayClick) {
371
+ onOverlayClick(event);
372
+ }
373
+
374
+ if (closeOnOverlayClick) {
375
+ onClose();
376
+ }
377
+
378
+ refShouldClose.current = null;
379
+ };
380
+
381
+ var handleModalEvent = function handleModalEvent() {
382
+ refShouldClose.current = false;
383
+ };
384
+
385
+ var handleClickCloseIcon = function handleClickCloseIcon() {
386
+ onClose();
387
+ };
388
+
389
+ var handleAnimationEnd = function handleAnimationEnd() {
390
+ if (!open) {
391
+ setShowPortal(false);
392
+ handleClose();
393
+ }
394
+
395
+ if (blockScroll) {
396
+ unblockNoScroll();
397
+ }
398
+
399
+ if (onAnimationEnd) {
400
+ onAnimationEnd();
401
+ }
402
+ };
403
+
404
+ return showPortal ? ReactDom.createPortal(React__default.createElement("div", {
405
+ style: _extends({
406
+ animation: (open ? (_classNames$animation = classNames === null || classNames === void 0 ? void 0 : classNames.animationIn) !== null && _classNames$animation !== void 0 ? _classNames$animation : classes.animationIn : (_classNames$animation2 = classNames === null || classNames === void 0 ? void 0 : classNames.animationOut) !== null && _classNames$animation2 !== void 0 ? _classNames$animation2 : classes.animationOut) + " " + animationDuration + "ms"
407
+ }, styles === null || styles === void 0 ? void 0 : styles.overlay),
408
+ className: cx(classes.overlay, classNames === null || classNames === void 0 ? void 0 : classNames.overlay),
409
+ onClick: handleClickOverlay,
410
+ onAnimationEnd: handleAnimationEnd,
411
+ "data-testid": "overlay"
412
+ }, React__default.createElement("div", {
413
+ ref: refModal,
414
+ className: cx(classes.modal, center && classes.modalCenter, classNames === null || classNames === void 0 ? void 0 : classNames.modal),
415
+ style: styles === null || styles === void 0 ? void 0 : styles.modal,
416
+ onMouseDown: handleModalEvent,
417
+ onMouseUp: handleModalEvent,
418
+ onClick: handleModalEvent,
419
+ id: modalId,
420
+ role: role,
421
+ "aria-modal": "true",
422
+ "aria-labelledby": ariaLabelledby,
423
+ "aria-describedby": ariaDescribedby,
424
+ "data-testid": "modal"
425
+ }, focusTrapped && React__default.createElement(FocusTrap, {
426
+ container: refModal
427
+ }), children, showCloseIcon && React__default.createElement(CloseIcon, {
428
+ classes: classes,
429
+ classNames: classNames,
430
+ styles: styles,
431
+ closeIcon: closeIcon,
432
+ onClickCloseIcon: handleClickCloseIcon,
433
+ id: closeIconId
434
+ }))), container || refContainer.current) : null;
435
+ };
436
+
437
+ exports.Modal = Modal;
438
+ exports.default = Modal;
439
+ //# sourceMappingURL=react-responsive-modal.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-responsive-modal.cjs.development.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (newModal: HTMLDivElement, blockScroll: boolean) => {\n if (modals.findIndex((modal) => modal.element === newModal) === -1) {\n modals.push({ element: newModal, blockScroll });\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (oldModal: HTMLDivElement) => {\n const index = modals.findIndex((modal) => modal.element === oldModal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1]?.element === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n // We filter the modals that are not affecting the scroll\n const modals = modalManager.modals().filter((modal) => modal.blockScroll);\n if (modals.length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!, blockScroll);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classes","classNames","styles","id","closeIcon","onClickCloseIcon","React","className","cx","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","add","newModal","blockScroll","findIndex","modal","element","push","remove","oldModal","index","splice","isTopModal","length","isBrowser","window","blockNoScroll","noScroll","on","unblockNoScroll","modalManager","filter","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","tabTrappingKey","event","key","contains","process","console","warn","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","current","document","addEventListener","selector","activeElement","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","body","appendChild","handleKeydown","handleClose","removeChild","keyCode","handleClickOverlay","handleModalEvent","handleClickCloseIcon","handleAnimationEnd","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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BA,UAAlB,uBAAkBA,UAAU,CAAEuF,OAA9B;AACb7E,IAAAA,OAAO,EAAEiH;AACThB,IAAAA,cAAc,EAAEmB;mBACJ;GAZd,EAcEzH,4BAAA,MAAA;AACE6H,IAAAA,GAAG,EAAErB;AACLvG,IAAAA,SAAS,EAAEC,EAAE,CACXR,OAAO,CAACsB,KADG,EAEXwE,MAAM,IAAI9F,OAAO,CAACyF,WAFP,EAGXxF,UAHW,aAGXA,UAHW,uBAGXA,UAAU,CAAEqB,KAHD;AAKbZ,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEoB;AACf8G,IAAAA,WAAW,EAAEP;AACbQ,IAAAA,SAAS,EAAER;AACXlH,IAAAA,OAAO,EAAEkH;AACT1H,IAAAA,EAAE,EAAEqG;AACJH,IAAAA,IAAI,EAAEA;kBACK;uBACME;wBACCD;mBACN;GAhBd,EAkBGH,YAAY,IAAI7F,4BAAA,CAACqE,SAAD;AAAWC,IAAAA,SAAS,EAAEkC;GAAtB,CAlBnB,EAmBGD,QAnBH,EAoBGZ,aAAa,IACZ3F,4BAAA,CAACP,SAAD;AACEC,IAAAA,OAAO,EAAEA;AACTC,IAAAA,UAAU,EAAEA;AACZC,IAAAA,MAAM,EAAEA;AACRE,IAAAA,SAAS,EAAEA;AACXC,IAAAA,gBAAgB,EAAEyH;AAClB3H,IAAAA,EAAE,EAAE+F;GANN,CArBJ,CAdF,CADF,EA+CEtB,SAAS,IAAIoC,YAAY,CAAC/B,OA/C5B,CADa,GAkDb,IAlDJ;AAmDD,CAzMM;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),o=e(require("react-dom")),r=e(require("classnames")),l=e(require("no-scroll"));function a(){return(a=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}var c=function(e){var n=e.classNames,o=e.styles,l=e.closeIcon,a=e.onClickCloseIcon;return t.createElement("button",{id:e.id,className:r(e.classes.closeButton,null==n?void 0:n.closeButton),style:null==o?void 0:o.closeButton,onClick:a,"data-testid":"close-button"},l||t.createElement("svg",{className:null==n?void 0:n.closeIcon,style:null==o?void 0:o.closeIcon,xmlns:"http://www.w3.org/2000/svg",width:28,height:28,viewBox:"0 0 36 36","data-testid":"close-icon"},t.createElement("path",{d:"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z"})))},i=[],u="undefined"!=typeof window,s=function(){0===i.filter((function(e){return e.blockScroll})).length&&l.off()},d=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])'];function v(e){return null===e.offsetParent||"hidden"===getComputedStyle(e).visibility}function f(e){for(var n=e.querySelectorAll(d.join(",")),t=[],o=0;o<n.length;o++){var r=n[o];!r.disabled&&m(r)>-1&&!v(r)&&t.push(r)}return t}function m(e){var n=parseInt(e.getAttribute("tabindex"),10);return isNaN(n)?function(e){return e.getAttribute("contentEditable")}(e)?0:e.tabIndex:n}var y=function(e){var t=e.container,o=n.useRef();return n.useEffect((function(){var e=function(e){(null==t?void 0:t.current)&&function(e,n){if(e&&"Tab"===e.key){if(!n||!n.contains)return process,!1;if(!n.contains(e.target))return!1;var t=f(n),o=t[0],r=t[t.length-1];e.shiftKey&&e.target===o?(r.focus(),e.preventDefault()):!e.shiftKey&&e.target===r&&(o.focus(),e.preventDefault())}}(e,t.current)};if(u&&document.addEventListener("keydown",e),u&&(null==t?void 0:t.current)){var n=f(t.current);n[0]&&(-1!==d.findIndex((function(e){var n;return null===(n=document.activeElement)||void 0===n?void 0:n.matches(e)}))&&(o.current=document.activeElement),n[0].focus())}return function(){var n;u&&(document.removeEventListener("keydown",e),null===(n=o.current)||void 0===n||n.focus())}}),[t]),null},p={overlay:"react-responsive-modal-overlay",modal:"react-responsive-modal-modal",modalCenter:"react-responsive-modal-modalCenter",closeButton:"react-responsive-modal-closeButton",animationIn:"react-responsive-modal-fadeIn",animationOut:"react-responsive-modal-fadeOut"},b=function(e){var d,v,f=e.open,m=e.center,b=e.blockScroll,h=void 0===b||b,E=e.closeOnEsc,I=void 0===E||E,g=e.closeOnOverlayClick,C=void 0===g||g,k=e.container,w=e.showCloseIcon,x=void 0===w||w,O=e.closeIconId,N=e.closeIcon,L=e.focusTrapped,B=void 0===L||L,D=e.animationDuration,S=void 0===D?500:D,j=e.classNames,q=e.styles,A=e.role,M=void 0===A?"dialog":A,P=e.ariaDescribedby,R=e.ariaLabelledby,K=e.modalId,T=e.onClose,_=e.onEscKeyDown,z=e.onOverlayClick,U=e.onAnimationEnd,F=e.children,G=n.useRef(null),H=n.useRef(null),J=n.useRef(null);null===J.current&&u&&(J.current=document.createElement("div"));var Q=n.useState(f),V=Q[0],W=Q[1],X=function(){(function(e,n){-1===i.findIndex((function(n){return n.element===e}))&&i.push({element:e,blockScroll:n})})(J.current,h),h&&l.on(),!J.current||k||document.body.contains(J.current)||document.body.appendChild(J.current),document.addEventListener("keydown",Z)},Y=function(){var e,n;e=J.current,-1!==(n=i.findIndex((function(n){return n.element===e})))&&i.splice(n,1),h&&s(),J.current&&!k&&document.body.contains(J.current)&&document.body.removeChild(J.current),document.removeEventListener("keydown",Z)},Z=function(e){var n;27===e.keyCode&&i.length&&(null===(n=i[i.length-1])||void 0===n?void 0:n.element)===J.current&&(_&&_(e),I&&T())};n.useEffect((function(){return f&&X(),function(){V&&Y()}}),[]),n.useEffect((function(){f&&!V&&(W(!0),X())}),[f]);var $=function(){H.current=!1};return V?o.createPortal(t.createElement("div",{style:a({animation:(f?null!==(d=null==j?void 0:j.animationIn)&&void 0!==d?d:p.animationIn:null!==(v=null==j?void 0:j.animationOut)&&void 0!==v?v:p.animationOut)+" "+S+"ms"},null==q?void 0:q.overlay),className:r(p.overlay,null==j?void 0:j.overlay),onClick:function(e){null===H.current&&(H.current=!0),H.current?(z&&z(e),C&&T(),H.current=null):H.current=null},onAnimationEnd:function(){f||(W(!1),Y()),h&&s(),U&&U()},"data-testid":"overlay"},t.createElement("div",{ref:G,className:r(p.modal,m&&p.modalCenter,null==j?void 0:j.modal),style:null==q?void 0:q.modal,onMouseDown:$,onMouseUp:$,onClick:$,id:K,role:M,"aria-modal":"true","aria-labelledby":R,"aria-describedby":P,"data-testid":"modal"},B&&t.createElement(y,{container:G}),F,x&&t.createElement(c,{classes:p,classNames:j,styles:q,closeIcon:N,onClickCloseIcon:function(){T()},id:O}))),k||J.current):null};exports.Modal=b,exports.default=b;
2
+ //# sourceMappingURL=react-responsive-modal.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-responsive-modal.cjs.production.min.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (newModal: HTMLDivElement, blockScroll: boolean) => {\n if (modals.findIndex((modal) => modal.element === newModal) === -1) {\n modals.push({ element: newModal, blockScroll });\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (oldModal: HTMLDivElement) => {\n const index = modals.findIndex((modal) => modal.element === oldModal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1]?.element === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n // We filter the modals that are not affecting the scroll\n const modals = modalManager.modals().filter((modal) => modal.blockScroll);\n if (modals.length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!, blockScroll);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classNames","styles","closeIcon","onClickCloseIcon","React","id","className","cx","classes","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","isBrowser","window","unblockNoScroll","filter","modal","blockScroll","length","noScroll","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","push","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","event","current","key","contains","process","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabTrappingKey","document","addEventListener","findIndex","selector","activeElement","_document$activeEleme","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","newModal","element","modalManager","on","body","appendChild","handleKeydown","handleClose","oldModal","index","splice","removeChild","keyCode","handleModalEvent","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":"scAoBA,IAAMA,EAAY,gBAEhBC,IAAAA,WACAC,IAAAA,OAEAC,IAAAA,UACAC,IAAAA,wBAEAC,0BACEC,KALFA,GAMEC,UAAWC,IATbC,QASwBC,YAAaT,MAAAA,SAAAA,EAAYS,aAC/CC,MAAOT,MAAAA,SAAAA,EAAQQ,YACfE,QAASR,gBACG,gBAEXD,GAGCE,uBACEE,UAAWN,MAAAA,SAAAA,EAAYE,UACvBQ,MAAOT,MAAAA,SAAAA,EAAQC,UACfU,MAAM,6BACNC,MAAO,GACPC,OAAQ,GACRC,QAAQ,0BACI,cAEZX,wBAAMY,EAAE,2HC/CVC,EAA8D,GCGvDC,EAA8B,oBAAXC,OAMnBC,EAAkB,WAIP,IDHRH,ECEuBI,QAAO,SAACC,UAAUA,EAAMC,eAClDC,QACTC,EAASC,OCZAC,EAAqB,CAChC,QACA,SACA,WACA,UACA,SACA,aACA,kBACA,kBACA,oDAGF,SAASC,EAASC,UAIQ,OAAtBA,EAAKC,cAA+D,WAAtCC,iBAAiBF,GAAMG,oBAIzCC,EAAsBC,WAChCC,EAAgBD,EAAWE,iBAAiBT,EAAmBU,KAAK,MACpEC,EAAe,GACVC,EAAI,EAAGA,EAAIJ,EAAcX,OAAQe,IAAK,KACzCV,EAAOM,EAAcI,IACpBV,EAAKW,UAAYC,EAAYZ,IAAS,IAAMD,EAASC,IACxDS,EAAaI,KAAKb,UAGfS,EAkCT,SAASG,EAAYZ,OACfc,EAAeC,SAASf,EAAKgB,aAAa,YAAa,WAEtDC,MAAMH,GAQb,SAA2Bd,UAClBA,EAAKgB,aA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