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.
- package/LICENSE +1 -1
- package/README.md +4 -35
- package/dist/CloseIcon.d.ts +19 -0
- package/dist/FocusTrap.d.ts +6 -0
- package/dist/focusTrapJs.d.ts +3 -0
- package/dist/index.d.ts +118 -0
- package/dist/index.js +8 -0
- package/dist/modalManager.d.ts +26 -0
- package/dist/react-responsive-modal.cjs.development.js +439 -0
- package/dist/react-responsive-modal.cjs.development.js.map +1 -0
- package/dist/react-responsive-modal.cjs.production.min.js +2 -0
- package/dist/react-responsive-modal.cjs.production.min.js.map +1 -0
- package/dist/react-responsive-modal.esm.js +432 -0
- package/dist/react-responsive-modal.esm.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/package.json +57 -85
- package/src/CloseIcon.tsx +54 -0
- package/src/FocusTrap.tsx +54 -0
- package/src/focusTrapJs.ts +79 -0
- package/src/index.tsx +339 -0
- package/src/modalManager.ts +37 -0
- package/src/utils.ts +17 -0
- package/{src/styles.css → styles.css} +25 -19
- package/lib/index.es.js +0 -629
- package/lib/index.es.js.map +0 -1
- package/lib/index.js +0 -634
- package/lib/index.js.map +0 -1
- package/src/close-icon.js +0 -47
- package/src/index.js +0 -3
- package/src/modal-manager.js +0 -36
- package/src/modal.js +0 -394
- package/types/index.d.ts +0 -113
- package/types/test.tsx +0 -29
- package/types/tsconfig.json +0 -16
- package/types/tslint.json +0 -3
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
2
|
+
import ReactDom from 'react-dom';
|
|
3
|
+
import cx from 'classnames';
|
|
4
|
+
import noScroll from 'no-scroll';
|
|
5
|
+
|
|
6
|
+
function _extends() {
|
|
7
|
+
_extends = Object.assign || function (target) {
|
|
8
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
|
|
11
|
+
for (var key in source) {
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
13
|
+
target[key] = source[key];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return _extends.apply(this, arguments);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var CloseIcon = function CloseIcon(_ref) {
|
|
25
|
+
var classes = _ref.classes,
|
|
26
|
+
classNames = _ref.classNames,
|
|
27
|
+
styles = _ref.styles,
|
|
28
|
+
id = _ref.id,
|
|
29
|
+
closeIcon = _ref.closeIcon,
|
|
30
|
+
onClickCloseIcon = _ref.onClickCloseIcon;
|
|
31
|
+
return React.createElement("button", {
|
|
32
|
+
id: id,
|
|
33
|
+
className: cx(classes.closeButton, classNames === null || classNames === void 0 ? void 0 : classNames.closeButton),
|
|
34
|
+
style: styles === null || styles === void 0 ? void 0 : styles.closeButton,
|
|
35
|
+
onClick: onClickCloseIcon,
|
|
36
|
+
"data-testid": "close-button"
|
|
37
|
+
}, closeIcon ? closeIcon : React.createElement("svg", {
|
|
38
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.closeIcon,
|
|
39
|
+
style: styles === null || styles === void 0 ? void 0 : styles.closeIcon,
|
|
40
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
41
|
+
width: 28,
|
|
42
|
+
height: 28,
|
|
43
|
+
viewBox: "0 0 36 36",
|
|
44
|
+
"data-testid": "close-icon"
|
|
45
|
+
}, React.createElement("path", {
|
|
46
|
+
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"
|
|
47
|
+
})));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var _modals = [];
|
|
51
|
+
/**
|
|
52
|
+
* Handle the order of the modals.
|
|
53
|
+
* Inspired by the material-ui implementation.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
var modalManager = {
|
|
57
|
+
/**
|
|
58
|
+
* Return the modals array
|
|
59
|
+
*/
|
|
60
|
+
modals: function modals() {
|
|
61
|
+
return _modals;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Register a new modal
|
|
66
|
+
*/
|
|
67
|
+
add: function add(newModal, blockScroll) {
|
|
68
|
+
if (_modals.findIndex(function (modal) {
|
|
69
|
+
return modal.element === newModal;
|
|
70
|
+
}) === -1) {
|
|
71
|
+
_modals.push({
|
|
72
|
+
element: newModal,
|
|
73
|
+
blockScroll: blockScroll
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Remove a modal
|
|
80
|
+
*/
|
|
81
|
+
remove: function remove(oldModal) {
|
|
82
|
+
var index = _modals.findIndex(function (modal) {
|
|
83
|
+
return modal.element === oldModal;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (index !== -1) {
|
|
87
|
+
_modals.splice(index, 1);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Check if the modal is the first one on the screen
|
|
93
|
+
*/
|
|
94
|
+
isTopModal: function isTopModal(modal) {
|
|
95
|
+
var _modals2;
|
|
96
|
+
|
|
97
|
+
return !!_modals.length && ((_modals2 = _modals[_modals.length - 1]) === null || _modals2 === void 0 ? void 0 : _modals2.element) === modal;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var isBrowser = typeof window !== 'undefined';
|
|
102
|
+
var blockNoScroll = function blockNoScroll() {
|
|
103
|
+
noScroll.on();
|
|
104
|
+
};
|
|
105
|
+
var unblockNoScroll = function unblockNoScroll() {
|
|
106
|
+
// Restore the scroll only if there is no modal on the screen
|
|
107
|
+
// We filter the modals that are not affecting the scroll
|
|
108
|
+
var modals = modalManager.modals().filter(function (modal) {
|
|
109
|
+
return modal.blockScroll;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (modals.length === 0) {
|
|
113
|
+
noScroll.off();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9
|
|
118
|
+
var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'];
|
|
119
|
+
|
|
120
|
+
function isHidden(node) {
|
|
121
|
+
// offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,
|
|
122
|
+
// as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.
|
|
123
|
+
return node.offsetParent === null || getComputedStyle(node).visibility === 'hidden';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getAllTabbingElements(parentElem) {
|
|
127
|
+
var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));
|
|
128
|
+
var onlyTabbable = [];
|
|
129
|
+
|
|
130
|
+
for (var i = 0; i < tabbableNodes.length; i++) {
|
|
131
|
+
var node = tabbableNodes[i];
|
|
132
|
+
|
|
133
|
+
if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {
|
|
134
|
+
onlyTabbable.push(node);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return onlyTabbable;
|
|
139
|
+
}
|
|
140
|
+
function tabTrappingKey(event, parentElem) {
|
|
141
|
+
// check if current event keyCode is tab
|
|
142
|
+
if (!event || event.key !== 'Tab') return;
|
|
143
|
+
|
|
144
|
+
if (!parentElem || !parentElem.contains) {
|
|
145
|
+
if (process && process.env.NODE_ENV === 'development') {
|
|
146
|
+
console.warn('focus-trap-js: parent element is not defined');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!parentElem.contains(event.target)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var allTabbingElements = getAllTabbingElements(parentElem);
|
|
157
|
+
var firstFocusableElement = allTabbingElements[0];
|
|
158
|
+
var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];
|
|
159
|
+
|
|
160
|
+
if (event.shiftKey && event.target === firstFocusableElement) {
|
|
161
|
+
lastFocusableElement.focus();
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
return true;
|
|
164
|
+
} else if (!event.shiftKey && event.target === lastFocusableElement) {
|
|
165
|
+
firstFocusableElement.focus();
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function getTabindex(node) {
|
|
174
|
+
var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);
|
|
175
|
+
if (!isNaN(tabindexAttr)) return tabindexAttr; // Browsers do not return tabIndex correctly for contentEditable nodes;
|
|
176
|
+
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
|
177
|
+
|
|
178
|
+
if (isContentEditable(node)) return 0;
|
|
179
|
+
return node.tabIndex;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function isContentEditable(node) {
|
|
183
|
+
return node.getAttribute('contentEditable');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var FocusTrap = function FocusTrap(_ref) {
|
|
187
|
+
var container = _ref.container;
|
|
188
|
+
var refLastFocus = useRef();
|
|
189
|
+
/**
|
|
190
|
+
* Handle focus lock on the modal
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
useEffect(function () {
|
|
194
|
+
var handleKeyEvent = function handleKeyEvent(event) {
|
|
195
|
+
if (container === null || container === void 0 ? void 0 : container.current) {
|
|
196
|
+
tabTrappingKey(event, container.current);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
if (isBrowser) {
|
|
201
|
+
document.addEventListener('keydown', handleKeyEvent);
|
|
202
|
+
} // On mount we focus on the first focusable element in the modal if there is one
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
if (isBrowser && (container === null || container === void 0 ? void 0 : container.current)) {
|
|
206
|
+
var allTabbingElements = getAllTabbingElements(container.current);
|
|
207
|
+
|
|
208
|
+
if (allTabbingElements[0]) {
|
|
209
|
+
// First we save the last focused element
|
|
210
|
+
// only if it's a focusable element
|
|
211
|
+
if (candidateSelectors.findIndex(function (selector) {
|
|
212
|
+
var _document$activeEleme;
|
|
213
|
+
|
|
214
|
+
return (_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.matches(selector);
|
|
215
|
+
}) !== -1) {
|
|
216
|
+
refLastFocus.current = document.activeElement;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
allTabbingElements[0].focus();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return function () {
|
|
224
|
+
if (isBrowser) {
|
|
225
|
+
var _refLastFocus$current;
|
|
226
|
+
|
|
227
|
+
document.removeEventListener('keydown', handleKeyEvent); // On unmount we restore the focus to the last focused element
|
|
228
|
+
|
|
229
|
+
(_refLastFocus$current = refLastFocus.current) === null || _refLastFocus$current === void 0 ? void 0 : _refLastFocus$current.focus();
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}, [container]);
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
var classes = {
|
|
237
|
+
overlay: 'react-responsive-modal-overlay',
|
|
238
|
+
modal: 'react-responsive-modal-modal',
|
|
239
|
+
modalCenter: 'react-responsive-modal-modalCenter',
|
|
240
|
+
closeButton: 'react-responsive-modal-closeButton',
|
|
241
|
+
animationIn: 'react-responsive-modal-fadeIn',
|
|
242
|
+
animationOut: 'react-responsive-modal-fadeOut'
|
|
243
|
+
};
|
|
244
|
+
var Modal = function Modal(_ref) {
|
|
245
|
+
var _classNames$animation, _classNames$animation2;
|
|
246
|
+
|
|
247
|
+
var open = _ref.open,
|
|
248
|
+
center = _ref.center,
|
|
249
|
+
_ref$blockScroll = _ref.blockScroll,
|
|
250
|
+
blockScroll = _ref$blockScroll === void 0 ? true : _ref$blockScroll,
|
|
251
|
+
_ref$closeOnEsc = _ref.closeOnEsc,
|
|
252
|
+
closeOnEsc = _ref$closeOnEsc === void 0 ? true : _ref$closeOnEsc,
|
|
253
|
+
_ref$closeOnOverlayCl = _ref.closeOnOverlayClick,
|
|
254
|
+
closeOnOverlayClick = _ref$closeOnOverlayCl === void 0 ? true : _ref$closeOnOverlayCl,
|
|
255
|
+
container = _ref.container,
|
|
256
|
+
_ref$showCloseIcon = _ref.showCloseIcon,
|
|
257
|
+
showCloseIcon = _ref$showCloseIcon === void 0 ? true : _ref$showCloseIcon,
|
|
258
|
+
closeIconId = _ref.closeIconId,
|
|
259
|
+
closeIcon = _ref.closeIcon,
|
|
260
|
+
_ref$focusTrapped = _ref.focusTrapped,
|
|
261
|
+
focusTrapped = _ref$focusTrapped === void 0 ? true : _ref$focusTrapped,
|
|
262
|
+
_ref$animationDuratio = _ref.animationDuration,
|
|
263
|
+
animationDuration = _ref$animationDuratio === void 0 ? 500 : _ref$animationDuratio,
|
|
264
|
+
classNames = _ref.classNames,
|
|
265
|
+
styles = _ref.styles,
|
|
266
|
+
_ref$role = _ref.role,
|
|
267
|
+
role = _ref$role === void 0 ? 'dialog' : _ref$role,
|
|
268
|
+
ariaDescribedby = _ref.ariaDescribedby,
|
|
269
|
+
ariaLabelledby = _ref.ariaLabelledby,
|
|
270
|
+
modalId = _ref.modalId,
|
|
271
|
+
onClose = _ref.onClose,
|
|
272
|
+
onEscKeyDown = _ref.onEscKeyDown,
|
|
273
|
+
onOverlayClick = _ref.onOverlayClick,
|
|
274
|
+
onAnimationEnd = _ref.onAnimationEnd,
|
|
275
|
+
children = _ref.children;
|
|
276
|
+
var refModal = useRef(null);
|
|
277
|
+
var refShouldClose = useRef(null);
|
|
278
|
+
var refContainer = useRef(null); // Lazily create the ref instance
|
|
279
|
+
// https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
|
|
280
|
+
|
|
281
|
+
if (refContainer.current === null && isBrowser) {
|
|
282
|
+
refContainer.current = document.createElement('div');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
var _useState = useState(open),
|
|
286
|
+
showPortal = _useState[0],
|
|
287
|
+
setShowPortal = _useState[1];
|
|
288
|
+
|
|
289
|
+
var handleOpen = function handleOpen() {
|
|
290
|
+
modalManager.add(refContainer.current, blockScroll);
|
|
291
|
+
|
|
292
|
+
if (blockScroll) {
|
|
293
|
+
blockNoScroll();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (refContainer.current && !container && !document.body.contains(refContainer.current)) {
|
|
297
|
+
document.body.appendChild(refContainer.current);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
document.addEventListener('keydown', handleKeydown);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
var handleClose = function handleClose() {
|
|
304
|
+
modalManager.remove(refContainer.current);
|
|
305
|
+
|
|
306
|
+
if (blockScroll) {
|
|
307
|
+
unblockNoScroll();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (refContainer.current && !container && document.body.contains(refContainer.current)) {
|
|
311
|
+
document.body.removeChild(refContainer.current);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
document.removeEventListener('keydown', handleKeydown);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
var handleKeydown = function handleKeydown(event) {
|
|
318
|
+
// Only the last modal need to be escaped when pressing the esc key
|
|
319
|
+
if (event.keyCode !== 27 || !modalManager.isTopModal(refContainer.current)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (onEscKeyDown) {
|
|
324
|
+
onEscKeyDown(event);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (closeOnEsc) {
|
|
328
|
+
onClose();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
useEffect(function () {
|
|
333
|
+
// When the modal is rendered first time we want to block the scroll
|
|
334
|
+
if (open) {
|
|
335
|
+
handleOpen();
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return function () {
|
|
339
|
+
// When the component is unmounted directly we want to unblock the scroll
|
|
340
|
+
if (showPortal) {
|
|
341
|
+
handleClose();
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}, []);
|
|
345
|
+
useEffect(function () {
|
|
346
|
+
// If the open prop is changing, we need to open the modal
|
|
347
|
+
if (open && !showPortal) {
|
|
348
|
+
setShowPortal(true);
|
|
349
|
+
handleOpen();
|
|
350
|
+
}
|
|
351
|
+
}, [open]);
|
|
352
|
+
|
|
353
|
+
var handleClickOverlay = function handleClickOverlay(event) {
|
|
354
|
+
if (refShouldClose.current === null) {
|
|
355
|
+
refShouldClose.current = true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (!refShouldClose.current) {
|
|
359
|
+
refShouldClose.current = null;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (onOverlayClick) {
|
|
364
|
+
onOverlayClick(event);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (closeOnOverlayClick) {
|
|
368
|
+
onClose();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
refShouldClose.current = null;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
var handleModalEvent = function handleModalEvent() {
|
|
375
|
+
refShouldClose.current = false;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
var handleClickCloseIcon = function handleClickCloseIcon() {
|
|
379
|
+
onClose();
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
var handleAnimationEnd = function handleAnimationEnd() {
|
|
383
|
+
if (!open) {
|
|
384
|
+
setShowPortal(false);
|
|
385
|
+
handleClose();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (blockScroll) {
|
|
389
|
+
unblockNoScroll();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (onAnimationEnd) {
|
|
393
|
+
onAnimationEnd();
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
return showPortal ? ReactDom.createPortal(React.createElement("div", {
|
|
398
|
+
style: _extends({
|
|
399
|
+
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"
|
|
400
|
+
}, styles === null || styles === void 0 ? void 0 : styles.overlay),
|
|
401
|
+
className: cx(classes.overlay, classNames === null || classNames === void 0 ? void 0 : classNames.overlay),
|
|
402
|
+
onClick: handleClickOverlay,
|
|
403
|
+
onAnimationEnd: handleAnimationEnd,
|
|
404
|
+
"data-testid": "overlay"
|
|
405
|
+
}, React.createElement("div", {
|
|
406
|
+
ref: refModal,
|
|
407
|
+
className: cx(classes.modal, center && classes.modalCenter, classNames === null || classNames === void 0 ? void 0 : classNames.modal),
|
|
408
|
+
style: styles === null || styles === void 0 ? void 0 : styles.modal,
|
|
409
|
+
onMouseDown: handleModalEvent,
|
|
410
|
+
onMouseUp: handleModalEvent,
|
|
411
|
+
onClick: handleModalEvent,
|
|
412
|
+
id: modalId,
|
|
413
|
+
role: role,
|
|
414
|
+
"aria-modal": "true",
|
|
415
|
+
"aria-labelledby": ariaLabelledby,
|
|
416
|
+
"aria-describedby": ariaDescribedby,
|
|
417
|
+
"data-testid": "modal"
|
|
418
|
+
}, focusTrapped && React.createElement(FocusTrap, {
|
|
419
|
+
container: refModal
|
|
420
|
+
}), children, showCloseIcon && React.createElement(CloseIcon, {
|
|
421
|
+
classes: classes,
|
|
422
|
+
classNames: classNames,
|
|
423
|
+
styles: styles,
|
|
424
|
+
closeIcon: closeIcon,
|
|
425
|
+
onClickCloseIcon: handleClickCloseIcon,
|
|
426
|
+
id: closeIconId
|
|
427
|
+
}))), container || refContainer.current) : null;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
export default Modal;
|
|
431
|
+
export { Modal };
|
|
432
|
+
//# sourceMappingURL=react-responsive-modal.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-responsive-modal.esm.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","env","NODE_ENV","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","handleAnimationEn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AAM,CAAEwF,OANR;AAQLnF,IAAAA,SAAS,EAAEC,EAAE,CAACR,OAAO,CAAC0F,OAAT,EAAkBzF,UAAlB,aAAkBA,UAAlB,uBAAkBA,UAAU,CAAEyF,OAA9B;AACb/E,IAAAA,OAAO,EAAEmH;AACThB,IAAAA,cAAc,EAAEmB;mBACJ;GAZd,EAcE3H,mBAAA,MAAA;AACE+H,IAAAA,GAAG,EAAErB;AACLzG,IAAAA,SAAS,EAAEC,EAAE,CACXR,OAAO,CAACsB,KADG,EAEX0E,MAAM,IAAIhG,OAAO,CAAC2F,WAFP,EAGX1F,UAHW,aAGXA,UAHW,uBAGXA,UAAU,CAAEqB,KAHD;AAKbZ,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEoB;AACfgH,IAAAA,WAAW,EAAEP;AACbQ,IAAAA,SAAS,EAAER;AACXpH,IAAAA,OAAO,EAAEoH;AACT5H,IAAAA,EAAE,EAAEuG;AACJH,IAAAA,IAAI,EAAEA;kBACK;uBACME;wBACCD;mBACN;GAhBd,EAkBGH,YAAY,IAAI/F,mBAAA,CAACuE,SAAD;AAAWC,IAAAA,SAAS,EAAEkC;GAAtB,CAlBnB,EAmBGD,QAnBH,EAoBGZ,aAAa,IACZ7F,mBAAA,CAACP,SAAD;AACEC,IAAAA,OAAO,EAAEA;AACTC,IAAAA,UAAU,EAAEA;AACZC,IAAAA,MAAM,EAAEA;AACRE,IAAAA,SAAS,EAAEA;AACXC,IAAAA,gBAAgB,EAAE2H;AAClB7H,IAAAA,EAAE,EAAEiG;GANN,CArBJ,CAdF,CADF,EA+CEtB,SAAS,IAAIoC,YAAY,CAAC/B,OA/C5B,CADa,GAkDb,IAlDJ;AAmDD,CAzMM;;;;;"}
|
package/dist/utils.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,51 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-responsive-modal",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A simple responsive and accessible react modal",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
3
|
+
"version": "5.0.3",
|
|
4
|
+
"description": "A simple responsive and accessible react modal compatible with React 16 and ready for React 17",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/mylib.esm.js",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"start": "tsdx watch",
|
|
11
|
+
"build": "tsdx build",
|
|
12
|
+
"test": "tsdx test --passWithNoTests",
|
|
13
|
+
"lint": "tsdx lint",
|
|
14
|
+
"prepare": "tsdx build",
|
|
10
15
|
"docz:dev": "docz dev",
|
|
11
16
|
"docz:build": "docz build",
|
|
12
|
-
"build": "rollup -c",
|
|
13
|
-
"build:watch": "rollup -c -w",
|
|
14
|
-
"lint": "eslint 'src' '__tests__'",
|
|
15
|
-
"test": "yarn test:coverage && yarn lint && yarn build && yarn dtslint && yarn size && yarn docz:build",
|
|
16
|
-
"test:only": "jest __tests__",
|
|
17
|
-
"test:coverage": "yarn test:only --coverage",
|
|
18
17
|
"size": "size-limit",
|
|
19
|
-
"prettier": "prettier --write \"**/*.{js,ts,tsx,css,scss,json,md,mdx}\""
|
|
20
|
-
"dtslint": "dtslint types",
|
|
21
|
-
"generate-props": "node scripts/generateReactPropsTable.js src/modal.js && yarn prettier"
|
|
18
|
+
"prettier": "prettier --write \"**/*.{js,ts,tsx,css,scss,json,md,mdx}\""
|
|
22
19
|
},
|
|
23
20
|
"files": [
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
21
|
+
"dist",
|
|
22
|
+
"src",
|
|
23
|
+
"styles.css"
|
|
27
24
|
],
|
|
28
25
|
"jest": {
|
|
29
26
|
"setupFilesAfterEnv": [
|
|
30
|
-
"./__tests__/setupTests.
|
|
31
|
-
]
|
|
32
|
-
"testPathIgnorePatterns": [
|
|
33
|
-
"<rootDir>/node_modules/",
|
|
34
|
-
"<rootDir>/docs/",
|
|
35
|
-
"<rootDir>/__tests__/setupTests.js"
|
|
36
|
-
],
|
|
37
|
-
"moduleNameMapper": {
|
|
38
|
-
"\\.(css)$": "identity-obj-proxy"
|
|
39
|
-
}
|
|
27
|
+
"./__tests__/setupTests.ts"
|
|
28
|
+
]
|
|
40
29
|
},
|
|
41
30
|
"prettier": {
|
|
42
|
-
"singleQuote": true
|
|
43
|
-
|
|
31
|
+
"singleQuote": true
|
|
32
|
+
},
|
|
33
|
+
"husky": {
|
|
34
|
+
"hooks": {
|
|
35
|
+
"pre-commit": "tsdx lint"
|
|
36
|
+
}
|
|
44
37
|
},
|
|
45
38
|
"keywords": [
|
|
46
39
|
"react",
|
|
47
40
|
"responsive",
|
|
48
41
|
"modal",
|
|
42
|
+
"mobile",
|
|
49
43
|
"flex"
|
|
50
44
|
],
|
|
51
45
|
"repository": "git+https://github.com/pradel/react-responsive-modal.git",
|
|
@@ -53,64 +47,42 @@
|
|
|
53
47
|
"bugs": {
|
|
54
48
|
"url": "https://github.com/pradel/react-responsive-modal/issues"
|
|
55
49
|
},
|
|
56
|
-
"homepage": "https://
|
|
50
|
+
"homepage": "https://react-responsive-modal.leopradel.com/",
|
|
51
|
+
"size-limit": [
|
|
52
|
+
{
|
|
53
|
+
"path": "dist/index.js",
|
|
54
|
+
"limit": "3.1 KB"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"classnames": "^2.2.6",
|
|
59
|
-
"
|
|
60
|
-
"no-scroll": "^2.1.1",
|
|
61
|
-
"prop-types": "^15.6.2",
|
|
62
|
-
"react-transition-group": "^4.0.0"
|
|
59
|
+
"no-scroll": "^2.1.1"
|
|
63
60
|
},
|
|
64
61
|
"peerDependencies": {
|
|
65
|
-
"react": "^16.
|
|
66
|
-
"react-dom": "^16.
|
|
62
|
+
"react": "^16.8.0",
|
|
63
|
+
"react-dom": "^16.8.0"
|
|
67
64
|
},
|
|
68
65
|
"devDependencies": {
|
|
69
|
-
"@
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@types/
|
|
75
|
-
"@types/react
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"docz": "
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"eslint-plugin-jsx-a11y": "6.2.1",
|
|
93
|
-
"eslint-plugin-jsx-import": "0.0.1",
|
|
94
|
-
"eslint-plugin-react": "7.13.0",
|
|
95
|
-
"identity-obj-proxy": "3.0.0",
|
|
96
|
-
"jest": "24.8.0",
|
|
97
|
-
"jest-enzyme": "7.0.2",
|
|
98
|
-
"prettier": "1.17.0",
|
|
99
|
-
"react": "16.8.6",
|
|
100
|
-
"react-docgen": "2.21.0",
|
|
101
|
-
"react-dom": "16.8.6",
|
|
102
|
-
"react-hot-loader": "4.8.4",
|
|
103
|
-
"rollup": "1.11.3",
|
|
104
|
-
"rollup-plugin-babel": "4.3.2",
|
|
105
|
-
"rollup-plugin-peer-deps-external": "2.2.0",
|
|
106
|
-
"rollup-plugin-postcss": "2.0.3",
|
|
107
|
-
"size-limit": "1.3.1"
|
|
108
|
-
},
|
|
109
|
-
"size-limit": [
|
|
110
|
-
{
|
|
111
|
-
"path": "lib/index.js",
|
|
112
|
-
"limit": "8 KB"
|
|
113
|
-
}
|
|
114
|
-
],
|
|
115
|
-
"license": "MIT"
|
|
116
|
-
}
|
|
66
|
+
"@size-limit/preset-small-lib": "4.5.6",
|
|
67
|
+
"@testing-library/jest-dom": "5.11.3",
|
|
68
|
+
"@testing-library/react": "10.4.8",
|
|
69
|
+
"@types/classnames": "2.2.10",
|
|
70
|
+
"@types/no-scroll": "2.1.0",
|
|
71
|
+
"@types/node": "14.0.27",
|
|
72
|
+
"@types/react": "16.9.39",
|
|
73
|
+
"@types/react-dom": "16.9.8",
|
|
74
|
+
"@types/react-transition-group": "4.4.0",
|
|
75
|
+
"codecov": "3.7.2",
|
|
76
|
+
"docz": "2.3.1",
|
|
77
|
+
"gatsby": "2.23.11",
|
|
78
|
+
"gatsby-theme-docz": "2.3.1",
|
|
79
|
+
"husky": "4.2.5",
|
|
80
|
+
"prettier": "2.0.5",
|
|
81
|
+
"react": "16.13.1",
|
|
82
|
+
"react-dom": "16.13.1",
|
|
83
|
+
"size-limit": "4.5.6",
|
|
84
|
+
"tsdx": "0.13.2",
|
|
85
|
+
"tslib": "2.0.1",
|
|
86
|
+
"typescript": "^3.9.7"
|
|
87
|
+
}
|
|
88
|
+
}
|