@khanacademy/wonder-blocks-modal 4.0.5 → 4.0.6
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/CHANGELOG.md +14 -0
- package/dist/es/index.js +120 -202
- package/dist/index.js +134 -216
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-modal
|
|
2
2
|
|
|
3
|
+
## 4.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c20f48f3: Don't transpile classes when building bundles
|
|
8
|
+
- Updated dependencies [c20f48f3]
|
|
9
|
+
- @khanacademy/wonder-blocks-breadcrumbs@2.0.6
|
|
10
|
+
- @khanacademy/wonder-blocks-core@5.0.4
|
|
11
|
+
- @khanacademy/wonder-blocks-icon@2.0.6
|
|
12
|
+
- @khanacademy/wonder-blocks-icon-button@4.0.6
|
|
13
|
+
- @khanacademy/wonder-blocks-layout@2.0.6
|
|
14
|
+
- @khanacademy/wonder-blocks-timing@3.0.2
|
|
15
|
+
- @khanacademy/wonder-blocks-typography@2.0.6
|
|
16
|
+
|
|
3
17
|
## 4.0.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -10,27 +10,8 @@ import { withActionScheduler } from '@khanacademy/wonder-blocks-timing';
|
|
|
10
10
|
import { icons } from '@khanacademy/wonder-blocks-icon';
|
|
11
11
|
import IconButton from '@khanacademy/wonder-blocks-icon-button';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
o.__proto__ = p;
|
|
16
|
-
return o;
|
|
17
|
-
};
|
|
18
|
-
return _setPrototypeOf(o, p);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _inheritsLoose(subClass, superClass) {
|
|
22
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
23
|
-
subClass.prototype.constructor = subClass;
|
|
24
|
-
_setPrototypeOf(subClass, superClass);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let ModalDialog = function (_React$Component) {
|
|
28
|
-
_inheritsLoose(ModalDialog, _React$Component);
|
|
29
|
-
function ModalDialog() {
|
|
30
|
-
return _React$Component.apply(this, arguments) || this;
|
|
31
|
-
}
|
|
32
|
-
var _proto = ModalDialog.prototype;
|
|
33
|
-
_proto.render = function render() {
|
|
13
|
+
class ModalDialog extends React.Component {
|
|
14
|
+
render() {
|
|
34
15
|
const {
|
|
35
16
|
above,
|
|
36
17
|
below,
|
|
@@ -65,9 +46,8 @@ let ModalDialog = function (_React$Component) {
|
|
|
65
46
|
}, children), above && React.createElement(View, {
|
|
66
47
|
style: styles.above
|
|
67
48
|
}, above))));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}(React.Component);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
71
51
|
ModalDialog.defaultProps = {
|
|
72
52
|
role: "dialog"
|
|
73
53
|
};
|
|
@@ -114,25 +94,19 @@ const styleSheets$3 = {
|
|
|
114
94
|
})
|
|
115
95
|
};
|
|
116
96
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
function ModalFooter() {
|
|
120
|
-
return _React$Component.apply(this, arguments) || this;
|
|
121
|
-
}
|
|
122
|
-
ModalFooter.isClassOf = function isClassOf(instance) {
|
|
97
|
+
class ModalFooter extends React.Component {
|
|
98
|
+
static isClassOf(instance) {
|
|
123
99
|
return instance && instance.type && instance.type.__IS_MODAL_FOOTER__;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
_proto.render = function render() {
|
|
100
|
+
}
|
|
101
|
+
render() {
|
|
127
102
|
const {
|
|
128
103
|
children
|
|
129
104
|
} = this.props;
|
|
130
105
|
return React.createElement(View, {
|
|
131
106
|
style: styles$3.footer
|
|
132
107
|
}, children);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
}(React.Component);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
136
110
|
ModalFooter.__IS_MODAL_FOOTER__ = true;
|
|
137
111
|
const styles$3 = StyleSheet.create({
|
|
138
112
|
footer: {
|
|
@@ -151,13 +125,8 @@ const styles$3 = StyleSheet.create({
|
|
|
151
125
|
}
|
|
152
126
|
});
|
|
153
127
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
function ModalHeader() {
|
|
157
|
-
return _React$Component.apply(this, arguments) || this;
|
|
158
|
-
}
|
|
159
|
-
var _proto = ModalHeader.prototype;
|
|
160
|
-
_proto.render = function render() {
|
|
128
|
+
class ModalHeader extends React.Component {
|
|
129
|
+
render() {
|
|
161
130
|
const {
|
|
162
131
|
breadcrumbs = undefined,
|
|
163
132
|
light,
|
|
@@ -186,9 +155,8 @@ let ModalHeader = function (_React$Component) {
|
|
|
186
155
|
style: light && styles.subtitle,
|
|
187
156
|
testId: testId && `${testId}-subtitle`
|
|
188
157
|
}, subtitle)));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
}(React.Component);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
192
160
|
ModalHeader.defaultProps = {
|
|
193
161
|
light: true
|
|
194
162
|
};
|
|
@@ -231,13 +199,11 @@ const styleSheets$2 = {
|
|
|
231
199
|
};
|
|
232
200
|
|
|
233
201
|
const FOCUSABLE_ELEMENTS$1 = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
_this.modalRoot = void 0;
|
|
240
|
-
_this.getModalRoot = node => {
|
|
202
|
+
class FocusTrap extends React.Component {
|
|
203
|
+
constructor(...args) {
|
|
204
|
+
super(...args);
|
|
205
|
+
this.modalRoot = void 0;
|
|
206
|
+
this.getModalRoot = node => {
|
|
241
207
|
if (!node) {
|
|
242
208
|
return;
|
|
243
209
|
}
|
|
@@ -245,33 +211,31 @@ let FocusTrap = function (_React$Component) {
|
|
|
245
211
|
if (!modalRoot) {
|
|
246
212
|
throw new Error("Assertion error: modal root should exist after mount");
|
|
247
213
|
}
|
|
248
|
-
|
|
214
|
+
this.modalRoot = modalRoot;
|
|
249
215
|
};
|
|
250
|
-
|
|
251
|
-
|
|
216
|
+
this.handleFocusMoveToLast = () => {
|
|
217
|
+
this.focusElementIn(false);
|
|
252
218
|
};
|
|
253
|
-
|
|
254
|
-
|
|
219
|
+
this.handleFocusMoveToFirst = () => {
|
|
220
|
+
this.focusElementIn(true);
|
|
255
221
|
};
|
|
256
|
-
return _this;
|
|
257
222
|
}
|
|
258
|
-
|
|
259
|
-
_proto.tryToFocus = function tryToFocus(node) {
|
|
223
|
+
tryToFocus(node) {
|
|
260
224
|
if (node instanceof HTMLElement) {
|
|
261
225
|
try {
|
|
262
226
|
node.focus();
|
|
263
227
|
} catch (e) {}
|
|
264
228
|
return document.activeElement === node;
|
|
265
229
|
}
|
|
266
|
-
}
|
|
267
|
-
|
|
230
|
+
}
|
|
231
|
+
focusElementIn(isLast) {
|
|
268
232
|
const modalRootAsHtmlEl = this.modalRoot;
|
|
269
233
|
const focusableNodes = Array.from(modalRootAsHtmlEl.querySelectorAll(FOCUSABLE_ELEMENTS$1));
|
|
270
234
|
const nodeIndex = !isLast ? focusableNodes.length - 1 : 0;
|
|
271
235
|
const focusableNode = focusableNodes[nodeIndex];
|
|
272
236
|
this.tryToFocus(focusableNode);
|
|
273
|
-
}
|
|
274
|
-
|
|
237
|
+
}
|
|
238
|
+
render() {
|
|
275
239
|
const {
|
|
276
240
|
style
|
|
277
241
|
} = this.props;
|
|
@@ -293,9 +257,8 @@ let FocusTrap = function (_React$Component) {
|
|
|
293
257
|
position: "fixed"
|
|
294
258
|
}
|
|
295
259
|
}));
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
}(React.Component);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
299
262
|
|
|
300
263
|
function _extends() {
|
|
301
264
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -319,25 +282,21 @@ function findFocusableNodes(root) {
|
|
|
319
282
|
return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
|
|
320
283
|
}
|
|
321
284
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
_this.handleMouseDown = e => {
|
|
329
|
-
_this._mousePressedOutside = e.target === e.currentTarget;
|
|
285
|
+
class ModalBackdrop extends React.Component {
|
|
286
|
+
constructor(...args) {
|
|
287
|
+
super(...args);
|
|
288
|
+
this._mousePressedOutside = false;
|
|
289
|
+
this.handleMouseDown = e => {
|
|
290
|
+
this._mousePressedOutside = e.target === e.currentTarget;
|
|
330
291
|
};
|
|
331
|
-
|
|
332
|
-
if (e.target === e.currentTarget &&
|
|
333
|
-
|
|
292
|
+
this.handleMouseUp = e => {
|
|
293
|
+
if (e.target === e.currentTarget && this._mousePressedOutside) {
|
|
294
|
+
this.props.onCloseModal();
|
|
334
295
|
}
|
|
335
|
-
|
|
296
|
+
this._mousePressedOutside = false;
|
|
336
297
|
};
|
|
337
|
-
return _this;
|
|
338
298
|
}
|
|
339
|
-
|
|
340
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
299
|
+
componentDidMount() {
|
|
341
300
|
const node = ReactDOM.findDOMNode(this);
|
|
342
301
|
if (!node) {
|
|
343
302
|
return;
|
|
@@ -346,8 +305,8 @@ let ModalBackdrop = function (_React$Component) {
|
|
|
346
305
|
setTimeout(() => {
|
|
347
306
|
firstFocusableElement.focus();
|
|
348
307
|
}, 0);
|
|
349
|
-
}
|
|
350
|
-
|
|
308
|
+
}
|
|
309
|
+
_getInitialFocusElement(node) {
|
|
351
310
|
const {
|
|
352
311
|
initialFocusId
|
|
353
312
|
} = this.props;
|
|
@@ -355,20 +314,20 @@ let ModalBackdrop = function (_React$Component) {
|
|
|
355
314
|
return null;
|
|
356
315
|
}
|
|
357
316
|
return ReactDOM.findDOMNode(node.querySelector(`#${initialFocusId}`));
|
|
358
|
-
}
|
|
359
|
-
|
|
317
|
+
}
|
|
318
|
+
_getFirstFocusableElement(node) {
|
|
360
319
|
const focusableElements = findFocusableNodes(node);
|
|
361
320
|
if (!focusableElements) {
|
|
362
321
|
return null;
|
|
363
322
|
}
|
|
364
323
|
return focusableElements[0];
|
|
365
|
-
}
|
|
366
|
-
|
|
324
|
+
}
|
|
325
|
+
_getDialogElement(node) {
|
|
367
326
|
const dialogElement = ReactDOM.findDOMNode(node.querySelector('[role="dialog"]'));
|
|
368
327
|
dialogElement.tabIndex = -1;
|
|
369
328
|
return dialogElement;
|
|
370
|
-
}
|
|
371
|
-
|
|
329
|
+
}
|
|
330
|
+
render() {
|
|
372
331
|
const {
|
|
373
332
|
children,
|
|
374
333
|
testId
|
|
@@ -382,9 +341,8 @@ let ModalBackdrop = function (_React$Component) {
|
|
|
382
341
|
onMouseUp: this.handleMouseUp,
|
|
383
342
|
testId: testId
|
|
384
343
|
}, backdropProps), children);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
}(React.Component);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
388
346
|
const styles$2 = StyleSheet.create({
|
|
389
347
|
modalPositioner: {
|
|
390
348
|
position: "fixed",
|
|
@@ -406,13 +364,8 @@ const needsHackyMobileSafariScrollDisabler = (() => {
|
|
|
406
364
|
const userAgent = window.navigator.userAgent;
|
|
407
365
|
return userAgent.indexOf("iPad") > -1 || userAgent.indexOf("iPhone") > -1;
|
|
408
366
|
})();
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
function ScrollDisabler() {
|
|
412
|
-
return _React$Component.apply(this, arguments) || this;
|
|
413
|
-
}
|
|
414
|
-
var _proto = ScrollDisabler.prototype;
|
|
415
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
367
|
+
class ScrollDisabler extends React.Component {
|
|
368
|
+
componentDidMount() {
|
|
416
369
|
if (ScrollDisabler.numModalsOpened === 0) {
|
|
417
370
|
const body = document.body;
|
|
418
371
|
if (!body) {
|
|
@@ -433,8 +386,8 @@ let ScrollDisabler = function (_React$Component) {
|
|
|
433
386
|
}
|
|
434
387
|
}
|
|
435
388
|
ScrollDisabler.numModalsOpened++;
|
|
436
|
-
}
|
|
437
|
-
|
|
389
|
+
}
|
|
390
|
+
componentWillUnmount() {
|
|
438
391
|
ScrollDisabler.numModalsOpened--;
|
|
439
392
|
if (ScrollDisabler.numModalsOpened === 0) {
|
|
440
393
|
const body = document.body;
|
|
@@ -451,12 +404,11 @@ let ScrollDisabler = function (_React$Component) {
|
|
|
451
404
|
window.scrollTo(0, ScrollDisabler.oldScrollY);
|
|
452
405
|
}
|
|
453
406
|
}
|
|
454
|
-
}
|
|
455
|
-
|
|
407
|
+
}
|
|
408
|
+
render() {
|
|
456
409
|
return null;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
}(React.Component);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
460
412
|
ScrollDisabler.oldOverflow = void 0;
|
|
461
413
|
ScrollDisabler.oldPosition = void 0;
|
|
462
414
|
ScrollDisabler.oldScrollY = void 0;
|
|
@@ -469,30 +421,28 @@ const defaultContext = {
|
|
|
469
421
|
};
|
|
470
422
|
var ModalContext = React.createContext(defaultContext);
|
|
471
423
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
_this.lastElementFocusedOutsideModal = void 0;
|
|
478
|
-
_this.state = {
|
|
424
|
+
class ModalLauncher extends React.Component {
|
|
425
|
+
constructor(...args) {
|
|
426
|
+
super(...args);
|
|
427
|
+
this.lastElementFocusedOutsideModal = void 0;
|
|
428
|
+
this.state = {
|
|
479
429
|
opened: false
|
|
480
430
|
};
|
|
481
|
-
|
|
482
|
-
|
|
431
|
+
this._saveLastElementFocused = () => {
|
|
432
|
+
this.lastElementFocusedOutsideModal = document.activeElement;
|
|
483
433
|
};
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
434
|
+
this._openModal = () => {
|
|
435
|
+
this._saveLastElementFocused();
|
|
436
|
+
this.setState({
|
|
487
437
|
opened: true
|
|
488
438
|
});
|
|
489
439
|
};
|
|
490
|
-
|
|
440
|
+
this._returnFocus = () => {
|
|
491
441
|
const {
|
|
492
442
|
closedFocusId,
|
|
493
443
|
schedule
|
|
494
|
-
} =
|
|
495
|
-
const lastElement =
|
|
444
|
+
} = this.props;
|
|
445
|
+
const lastElement = this.lastElementFocusedOutsideModal;
|
|
496
446
|
if (closedFocusId) {
|
|
497
447
|
const focusElement = ReactDOM.findDOMNode(document.getElementById(closedFocusId));
|
|
498
448
|
if (focusElement) {
|
|
@@ -508,20 +458,19 @@ let ModalLauncher = function (_React$Component) {
|
|
|
508
458
|
});
|
|
509
459
|
}
|
|
510
460
|
};
|
|
511
|
-
|
|
512
|
-
|
|
461
|
+
this.handleCloseModal = () => {
|
|
462
|
+
this.setState({
|
|
513
463
|
opened: false
|
|
514
464
|
}, () => {
|
|
515
465
|
const {
|
|
516
466
|
onClose
|
|
517
|
-
} =
|
|
467
|
+
} = this.props;
|
|
518
468
|
onClose == null ? void 0 : onClose();
|
|
519
|
-
|
|
469
|
+
this._returnFocus();
|
|
520
470
|
});
|
|
521
471
|
};
|
|
522
|
-
return _this;
|
|
523
472
|
}
|
|
524
|
-
|
|
473
|
+
static getDerivedStateFromProps(props, state) {
|
|
525
474
|
if (typeof props.opened === "boolean" && props.children) {
|
|
526
475
|
console.warn("'children' and 'opened' can't be used together");
|
|
527
476
|
}
|
|
@@ -534,14 +483,13 @@ let ModalLauncher = function (_React$Component) {
|
|
|
534
483
|
return {
|
|
535
484
|
opened: typeof props.opened === "boolean" ? props.opened : state.opened
|
|
536
485
|
};
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
486
|
+
}
|
|
487
|
+
componentDidUpdate(prevProps) {
|
|
540
488
|
if (!prevProps.opened && this.props.opened) {
|
|
541
489
|
this._saveLastElementFocused();
|
|
542
490
|
}
|
|
543
|
-
}
|
|
544
|
-
|
|
491
|
+
}
|
|
492
|
+
_renderModal() {
|
|
545
493
|
if (typeof this.props.modal === "function") {
|
|
546
494
|
return this.props.modal({
|
|
547
495
|
closeModal: this.handleCloseModal
|
|
@@ -549,8 +497,8 @@ let ModalLauncher = function (_React$Component) {
|
|
|
549
497
|
} else {
|
|
550
498
|
return this.props.modal;
|
|
551
499
|
}
|
|
552
|
-
}
|
|
553
|
-
|
|
500
|
+
}
|
|
501
|
+
render() {
|
|
554
502
|
const renderedChildren = this.props.children ? this.props.children({
|
|
555
503
|
openModal: this._openModal
|
|
556
504
|
}) : null;
|
|
@@ -573,38 +521,32 @@ let ModalLauncher = function (_React$Component) {
|
|
|
573
521
|
}, this._renderModal())), body), this.state.opened && React.createElement(ModalLauncherKeypressListener, {
|
|
574
522
|
onClose: this.handleCloseModal
|
|
575
523
|
}), this.state.opened && React.createElement(ScrollDisabler, null));
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
}(React.Component);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
579
526
|
ModalLauncher.defaultProps = {
|
|
580
527
|
backdropDismissEnabled: true
|
|
581
528
|
};
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
_this2 = _React$Component2.call.apply(_React$Component2, [this].concat(args)) || this;
|
|
587
|
-
_this2._handleKeyup = e => {
|
|
529
|
+
class ModalLauncherKeypressListener extends React.Component {
|
|
530
|
+
constructor(...args) {
|
|
531
|
+
super(...args);
|
|
532
|
+
this._handleKeyup = e => {
|
|
588
533
|
if (e.key === "Escape") {
|
|
589
534
|
e.preventDefault();
|
|
590
535
|
e.stopPropagation();
|
|
591
|
-
|
|
536
|
+
this.props.onClose();
|
|
592
537
|
}
|
|
593
538
|
};
|
|
594
|
-
return _this2;
|
|
595
539
|
}
|
|
596
|
-
|
|
597
|
-
_proto2.componentDidMount = function componentDidMount() {
|
|
540
|
+
componentDidMount() {
|
|
598
541
|
window.addEventListener("keyup", this._handleKeyup);
|
|
599
|
-
}
|
|
600
|
-
|
|
542
|
+
}
|
|
543
|
+
componentWillUnmount() {
|
|
601
544
|
window.removeEventListener("keyup", this._handleKeyup);
|
|
602
|
-
}
|
|
603
|
-
|
|
545
|
+
}
|
|
546
|
+
render() {
|
|
604
547
|
return null;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
}(React.Component);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
608
550
|
const styles$1 = StyleSheet.create({
|
|
609
551
|
container: {
|
|
610
552
|
zIndex: 1080
|
|
@@ -612,16 +554,11 @@ const styles$1 = StyleSheet.create({
|
|
|
612
554
|
});
|
|
613
555
|
var modalLauncher = withActionScheduler(ModalLauncher);
|
|
614
556
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
function ModalContent() {
|
|
618
|
-
return _React$Component.apply(this, arguments) || this;
|
|
619
|
-
}
|
|
620
|
-
ModalContent.isClassOf = function isClassOf(instance) {
|
|
557
|
+
class ModalContent extends React.Component {
|
|
558
|
+
static isClassOf(instance) {
|
|
621
559
|
return instance && instance.type && instance.type.__IS_MODAL_CONTENT__;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
_proto.render = function render() {
|
|
560
|
+
}
|
|
561
|
+
render() {
|
|
625
562
|
const {
|
|
626
563
|
scrollOverflow,
|
|
627
564
|
style,
|
|
@@ -636,9 +573,8 @@ let ModalContent = function (_React$Component) {
|
|
|
636
573
|
}, React.createElement(View, {
|
|
637
574
|
style: [styles.content, style]
|
|
638
575
|
}, children)));
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
}(React.Component);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
642
578
|
ModalContent.defaultProps = {
|
|
643
579
|
scrollOverflow: true
|
|
644
580
|
};
|
|
@@ -666,13 +602,8 @@ const styleSheets$1 = {
|
|
|
666
602
|
})
|
|
667
603
|
};
|
|
668
604
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
function CloseButton() {
|
|
672
|
-
return _React$Component.apply(this, arguments) || this;
|
|
673
|
-
}
|
|
674
|
-
var _proto = CloseButton.prototype;
|
|
675
|
-
_proto.render = function render() {
|
|
605
|
+
class CloseButton extends React.Component {
|
|
606
|
+
render() {
|
|
676
607
|
const {
|
|
677
608
|
light,
|
|
678
609
|
onClick,
|
|
@@ -695,17 +626,11 @@ let CloseButton = function (_React$Component) {
|
|
|
695
626
|
testId: testId
|
|
696
627
|
});
|
|
697
628
|
});
|
|
698
|
-
};
|
|
699
|
-
return CloseButton;
|
|
700
|
-
}(React.Component);
|
|
701
|
-
|
|
702
|
-
let ModalPanel = function (_React$Component) {
|
|
703
|
-
_inheritsLoose(ModalPanel, _React$Component);
|
|
704
|
-
function ModalPanel() {
|
|
705
|
-
return _React$Component.apply(this, arguments) || this;
|
|
706
629
|
}
|
|
707
|
-
|
|
708
|
-
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
class ModalPanel extends React.Component {
|
|
633
|
+
renderMainContent() {
|
|
709
634
|
const {
|
|
710
635
|
content,
|
|
711
636
|
footer,
|
|
@@ -719,8 +644,8 @@ let ModalPanel = function (_React$Component) {
|
|
|
719
644
|
scrollOverflow,
|
|
720
645
|
style: [!!footer && styles.hasFooter, mainContent.props.style]
|
|
721
646
|
});
|
|
722
|
-
}
|
|
723
|
-
|
|
647
|
+
}
|
|
648
|
+
render() {
|
|
724
649
|
const {
|
|
725
650
|
closeButtonVisible,
|
|
726
651
|
footer,
|
|
@@ -740,9 +665,8 @@ let ModalPanel = function (_React$Component) {
|
|
|
740
665
|
style: styles.closeButton,
|
|
741
666
|
testId: testId && `${testId}-close`
|
|
742
667
|
}), header, mainContent, !footer || ModalFooter.isClassOf(footer) ? footer : React.createElement(ModalFooter, null, footer));
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
}(React.Component);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
746
670
|
ModalPanel.defaultProps = {
|
|
747
671
|
closeButtonVisible: true,
|
|
748
672
|
scrollOverflow: true,
|
|
@@ -775,13 +699,8 @@ const styles = StyleSheet.create({
|
|
|
775
699
|
}
|
|
776
700
|
});
|
|
777
701
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
function OnePaneDialog() {
|
|
781
|
-
return _React$Component.apply(this, arguments) || this;
|
|
782
|
-
}
|
|
783
|
-
var _proto = OnePaneDialog.prototype;
|
|
784
|
-
_proto.renderHeader = function renderHeader(uniqueId) {
|
|
702
|
+
class OnePaneDialog extends React.Component {
|
|
703
|
+
renderHeader(uniqueId) {
|
|
785
704
|
const {
|
|
786
705
|
title,
|
|
787
706
|
breadcrumbs = undefined,
|
|
@@ -809,8 +728,8 @@ let OnePaneDialog = function (_React$Component) {
|
|
|
809
728
|
testId: testId && `${testId}-header`
|
|
810
729
|
});
|
|
811
730
|
}
|
|
812
|
-
}
|
|
813
|
-
|
|
731
|
+
}
|
|
732
|
+
render() {
|
|
814
733
|
const {
|
|
815
734
|
onClose,
|
|
816
735
|
footer,
|
|
@@ -847,9 +766,8 @@ let OnePaneDialog = function (_React$Component) {
|
|
|
847
766
|
closeButtonVisible: closeButtonVisible,
|
|
848
767
|
testId: testId
|
|
849
768
|
}))));
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
}(React.Component);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
853
771
|
OnePaneDialog.defaultProps = {
|
|
854
772
|
closeButtonVisible: true
|
|
855
773
|
};
|
package/dist/index.js
CHANGED
|
@@ -17,21 +17,21 @@ var IconButton = require('@khanacademy/wonder-blocks-icon-button');
|
|
|
17
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
18
|
|
|
19
19
|
function _interopNamespace(e) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
if (e && e.__esModule) return e;
|
|
21
|
+
var n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
Object.keys(e).forEach(function (k) {
|
|
24
|
+
if (k !== 'default') {
|
|
25
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return e[k]; }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
29
31
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
n["default"] = e;
|
|
34
|
-
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
n["default"] = e;
|
|
34
|
+
return Object.freeze(n);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
@@ -40,27 +40,8 @@ var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
|
|
|
40
40
|
var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
|
|
41
41
|
var IconButton__default = /*#__PURE__*/_interopDefaultLegacy(IconButton);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
o.__proto__ = p;
|
|
46
|
-
return o;
|
|
47
|
-
};
|
|
48
|
-
return _setPrototypeOf(o, p);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function _inheritsLoose(subClass, superClass) {
|
|
52
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
53
|
-
subClass.prototype.constructor = subClass;
|
|
54
|
-
_setPrototypeOf(subClass, superClass);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let ModalDialog = function (_React$Component) {
|
|
58
|
-
_inheritsLoose(ModalDialog, _React$Component);
|
|
59
|
-
function ModalDialog() {
|
|
60
|
-
return _React$Component.apply(this, arguments) || this;
|
|
61
|
-
}
|
|
62
|
-
var _proto = ModalDialog.prototype;
|
|
63
|
-
_proto.render = function render() {
|
|
43
|
+
class ModalDialog extends React__namespace.Component {
|
|
44
|
+
render() {
|
|
64
45
|
const {
|
|
65
46
|
above,
|
|
66
47
|
below,
|
|
@@ -95,9 +76,8 @@ let ModalDialog = function (_React$Component) {
|
|
|
95
76
|
}, children), above && React__namespace.createElement(wonderBlocksCore.View, {
|
|
96
77
|
style: styles.above
|
|
97
78
|
}, above))));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}(React__namespace.Component);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
101
81
|
ModalDialog.defaultProps = {
|
|
102
82
|
role: "dialog"
|
|
103
83
|
};
|
|
@@ -144,25 +124,19 @@ const styleSheets$3 = {
|
|
|
144
124
|
})
|
|
145
125
|
};
|
|
146
126
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
function ModalFooter() {
|
|
150
|
-
return _React$Component.apply(this, arguments) || this;
|
|
151
|
-
}
|
|
152
|
-
ModalFooter.isClassOf = function isClassOf(instance) {
|
|
127
|
+
class ModalFooter extends React__namespace.Component {
|
|
128
|
+
static isClassOf(instance) {
|
|
153
129
|
return instance && instance.type && instance.type.__IS_MODAL_FOOTER__;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
_proto.render = function render() {
|
|
130
|
+
}
|
|
131
|
+
render() {
|
|
157
132
|
const {
|
|
158
133
|
children
|
|
159
134
|
} = this.props;
|
|
160
135
|
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
161
136
|
style: styles$3.footer
|
|
162
137
|
}, children);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
}(React__namespace.Component);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
166
140
|
ModalFooter.__IS_MODAL_FOOTER__ = true;
|
|
167
141
|
const styles$3 = aphrodite.StyleSheet.create({
|
|
168
142
|
footer: {
|
|
@@ -181,13 +155,8 @@ const styles$3 = aphrodite.StyleSheet.create({
|
|
|
181
155
|
}
|
|
182
156
|
});
|
|
183
157
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
function ModalHeader() {
|
|
187
|
-
return _React$Component.apply(this, arguments) || this;
|
|
188
|
-
}
|
|
189
|
-
var _proto = ModalHeader.prototype;
|
|
190
|
-
_proto.render = function render() {
|
|
158
|
+
class ModalHeader extends React__namespace.Component {
|
|
159
|
+
render() {
|
|
191
160
|
const {
|
|
192
161
|
breadcrumbs = undefined,
|
|
193
162
|
light,
|
|
@@ -216,9 +185,8 @@ let ModalHeader = function (_React$Component) {
|
|
|
216
185
|
style: light && styles.subtitle,
|
|
217
186
|
testId: testId && `${testId}-subtitle`
|
|
218
187
|
}, subtitle)));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
}(React__namespace.Component);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
222
190
|
ModalHeader.defaultProps = {
|
|
223
191
|
light: true
|
|
224
192
|
};
|
|
@@ -261,13 +229,11 @@ const styleSheets$2 = {
|
|
|
261
229
|
};
|
|
262
230
|
|
|
263
231
|
const FOCUSABLE_ELEMENTS$1 = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
_this.modalRoot = void 0;
|
|
270
|
-
_this.getModalRoot = node => {
|
|
232
|
+
class FocusTrap extends React__namespace.Component {
|
|
233
|
+
constructor(...args) {
|
|
234
|
+
super(...args);
|
|
235
|
+
this.modalRoot = void 0;
|
|
236
|
+
this.getModalRoot = node => {
|
|
271
237
|
if (!node) {
|
|
272
238
|
return;
|
|
273
239
|
}
|
|
@@ -275,33 +241,31 @@ let FocusTrap = function (_React$Component) {
|
|
|
275
241
|
if (!modalRoot) {
|
|
276
242
|
throw new Error("Assertion error: modal root should exist after mount");
|
|
277
243
|
}
|
|
278
|
-
|
|
244
|
+
this.modalRoot = modalRoot;
|
|
279
245
|
};
|
|
280
|
-
|
|
281
|
-
|
|
246
|
+
this.handleFocusMoveToLast = () => {
|
|
247
|
+
this.focusElementIn(false);
|
|
282
248
|
};
|
|
283
|
-
|
|
284
|
-
|
|
249
|
+
this.handleFocusMoveToFirst = () => {
|
|
250
|
+
this.focusElementIn(true);
|
|
285
251
|
};
|
|
286
|
-
return _this;
|
|
287
252
|
}
|
|
288
|
-
|
|
289
|
-
_proto.tryToFocus = function tryToFocus(node) {
|
|
253
|
+
tryToFocus(node) {
|
|
290
254
|
if (node instanceof HTMLElement) {
|
|
291
255
|
try {
|
|
292
256
|
node.focus();
|
|
293
257
|
} catch (e) {}
|
|
294
258
|
return document.activeElement === node;
|
|
295
259
|
}
|
|
296
|
-
}
|
|
297
|
-
|
|
260
|
+
}
|
|
261
|
+
focusElementIn(isLast) {
|
|
298
262
|
const modalRootAsHtmlEl = this.modalRoot;
|
|
299
263
|
const focusableNodes = Array.from(modalRootAsHtmlEl.querySelectorAll(FOCUSABLE_ELEMENTS$1));
|
|
300
264
|
const nodeIndex = !isLast ? focusableNodes.length - 1 : 0;
|
|
301
265
|
const focusableNode = focusableNodes[nodeIndex];
|
|
302
266
|
this.tryToFocus(focusableNode);
|
|
303
|
-
}
|
|
304
|
-
|
|
267
|
+
}
|
|
268
|
+
render() {
|
|
305
269
|
const {
|
|
306
270
|
style
|
|
307
271
|
} = this.props;
|
|
@@ -323,9 +287,8 @@ let FocusTrap = function (_React$Component) {
|
|
|
323
287
|
position: "fixed"
|
|
324
288
|
}
|
|
325
289
|
}));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
}(React__namespace.Component);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
329
292
|
|
|
330
293
|
function _extends() {
|
|
331
294
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -349,25 +312,21 @@ function findFocusableNodes(root) {
|
|
|
349
312
|
return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
|
|
350
313
|
}
|
|
351
314
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
_this.handleMouseDown = e => {
|
|
359
|
-
_this._mousePressedOutside = e.target === e.currentTarget;
|
|
315
|
+
class ModalBackdrop extends React__namespace.Component {
|
|
316
|
+
constructor(...args) {
|
|
317
|
+
super(...args);
|
|
318
|
+
this._mousePressedOutside = false;
|
|
319
|
+
this.handleMouseDown = e => {
|
|
320
|
+
this._mousePressedOutside = e.target === e.currentTarget;
|
|
360
321
|
};
|
|
361
|
-
|
|
362
|
-
if (e.target === e.currentTarget &&
|
|
363
|
-
|
|
322
|
+
this.handleMouseUp = e => {
|
|
323
|
+
if (e.target === e.currentTarget && this._mousePressedOutside) {
|
|
324
|
+
this.props.onCloseModal();
|
|
364
325
|
}
|
|
365
|
-
|
|
326
|
+
this._mousePressedOutside = false;
|
|
366
327
|
};
|
|
367
|
-
return _this;
|
|
368
328
|
}
|
|
369
|
-
|
|
370
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
329
|
+
componentDidMount() {
|
|
371
330
|
const node = ReactDOM__namespace.findDOMNode(this);
|
|
372
331
|
if (!node) {
|
|
373
332
|
return;
|
|
@@ -376,8 +335,8 @@ let ModalBackdrop = function (_React$Component) {
|
|
|
376
335
|
setTimeout(() => {
|
|
377
336
|
firstFocusableElement.focus();
|
|
378
337
|
}, 0);
|
|
379
|
-
}
|
|
380
|
-
|
|
338
|
+
}
|
|
339
|
+
_getInitialFocusElement(node) {
|
|
381
340
|
const {
|
|
382
341
|
initialFocusId
|
|
383
342
|
} = this.props;
|
|
@@ -385,20 +344,20 @@ let ModalBackdrop = function (_React$Component) {
|
|
|
385
344
|
return null;
|
|
386
345
|
}
|
|
387
346
|
return ReactDOM__namespace.findDOMNode(node.querySelector(`#${initialFocusId}`));
|
|
388
|
-
}
|
|
389
|
-
|
|
347
|
+
}
|
|
348
|
+
_getFirstFocusableElement(node) {
|
|
390
349
|
const focusableElements = findFocusableNodes(node);
|
|
391
350
|
if (!focusableElements) {
|
|
392
351
|
return null;
|
|
393
352
|
}
|
|
394
353
|
return focusableElements[0];
|
|
395
|
-
}
|
|
396
|
-
|
|
354
|
+
}
|
|
355
|
+
_getDialogElement(node) {
|
|
397
356
|
const dialogElement = ReactDOM__namespace.findDOMNode(node.querySelector('[role="dialog"]'));
|
|
398
357
|
dialogElement.tabIndex = -1;
|
|
399
358
|
return dialogElement;
|
|
400
|
-
}
|
|
401
|
-
|
|
359
|
+
}
|
|
360
|
+
render() {
|
|
402
361
|
const {
|
|
403
362
|
children,
|
|
404
363
|
testId
|
|
@@ -412,9 +371,8 @@ let ModalBackdrop = function (_React$Component) {
|
|
|
412
371
|
onMouseUp: this.handleMouseUp,
|
|
413
372
|
testId: testId
|
|
414
373
|
}, backdropProps), children);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
}(React__namespace.Component);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
418
376
|
const styles$2 = aphrodite.StyleSheet.create({
|
|
419
377
|
modalPositioner: {
|
|
420
378
|
position: "fixed",
|
|
@@ -436,13 +394,8 @@ const needsHackyMobileSafariScrollDisabler = (() => {
|
|
|
436
394
|
const userAgent = window.navigator.userAgent;
|
|
437
395
|
return userAgent.indexOf("iPad") > -1 || userAgent.indexOf("iPhone") > -1;
|
|
438
396
|
})();
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
function ScrollDisabler() {
|
|
442
|
-
return _React$Component.apply(this, arguments) || this;
|
|
443
|
-
}
|
|
444
|
-
var _proto = ScrollDisabler.prototype;
|
|
445
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
397
|
+
class ScrollDisabler extends React__namespace.Component {
|
|
398
|
+
componentDidMount() {
|
|
446
399
|
if (ScrollDisabler.numModalsOpened === 0) {
|
|
447
400
|
const body = document.body;
|
|
448
401
|
if (!body) {
|
|
@@ -463,8 +416,8 @@ let ScrollDisabler = function (_React$Component) {
|
|
|
463
416
|
}
|
|
464
417
|
}
|
|
465
418
|
ScrollDisabler.numModalsOpened++;
|
|
466
|
-
}
|
|
467
|
-
|
|
419
|
+
}
|
|
420
|
+
componentWillUnmount() {
|
|
468
421
|
ScrollDisabler.numModalsOpened--;
|
|
469
422
|
if (ScrollDisabler.numModalsOpened === 0) {
|
|
470
423
|
const body = document.body;
|
|
@@ -481,12 +434,11 @@ let ScrollDisabler = function (_React$Component) {
|
|
|
481
434
|
window.scrollTo(0, ScrollDisabler.oldScrollY);
|
|
482
435
|
}
|
|
483
436
|
}
|
|
484
|
-
}
|
|
485
|
-
|
|
437
|
+
}
|
|
438
|
+
render() {
|
|
486
439
|
return null;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
}(React__namespace.Component);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
490
442
|
ScrollDisabler.oldOverflow = void 0;
|
|
491
443
|
ScrollDisabler.oldPosition = void 0;
|
|
492
444
|
ScrollDisabler.oldScrollY = void 0;
|
|
@@ -499,30 +451,28 @@ const defaultContext = {
|
|
|
499
451
|
};
|
|
500
452
|
var ModalContext = React__namespace.createContext(defaultContext);
|
|
501
453
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
_this.lastElementFocusedOutsideModal = void 0;
|
|
508
|
-
_this.state = {
|
|
454
|
+
class ModalLauncher extends React__namespace.Component {
|
|
455
|
+
constructor(...args) {
|
|
456
|
+
super(...args);
|
|
457
|
+
this.lastElementFocusedOutsideModal = void 0;
|
|
458
|
+
this.state = {
|
|
509
459
|
opened: false
|
|
510
460
|
};
|
|
511
|
-
|
|
512
|
-
|
|
461
|
+
this._saveLastElementFocused = () => {
|
|
462
|
+
this.lastElementFocusedOutsideModal = document.activeElement;
|
|
513
463
|
};
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
464
|
+
this._openModal = () => {
|
|
465
|
+
this._saveLastElementFocused();
|
|
466
|
+
this.setState({
|
|
517
467
|
opened: true
|
|
518
468
|
});
|
|
519
469
|
};
|
|
520
|
-
|
|
470
|
+
this._returnFocus = () => {
|
|
521
471
|
const {
|
|
522
472
|
closedFocusId,
|
|
523
473
|
schedule
|
|
524
|
-
} =
|
|
525
|
-
const lastElement =
|
|
474
|
+
} = this.props;
|
|
475
|
+
const lastElement = this.lastElementFocusedOutsideModal;
|
|
526
476
|
if (closedFocusId) {
|
|
527
477
|
const focusElement = ReactDOM__namespace.findDOMNode(document.getElementById(closedFocusId));
|
|
528
478
|
if (focusElement) {
|
|
@@ -538,20 +488,19 @@ let ModalLauncher = function (_React$Component) {
|
|
|
538
488
|
});
|
|
539
489
|
}
|
|
540
490
|
};
|
|
541
|
-
|
|
542
|
-
|
|
491
|
+
this.handleCloseModal = () => {
|
|
492
|
+
this.setState({
|
|
543
493
|
opened: false
|
|
544
494
|
}, () => {
|
|
545
495
|
const {
|
|
546
496
|
onClose
|
|
547
|
-
} =
|
|
497
|
+
} = this.props;
|
|
548
498
|
onClose == null ? void 0 : onClose();
|
|
549
|
-
|
|
499
|
+
this._returnFocus();
|
|
550
500
|
});
|
|
551
501
|
};
|
|
552
|
-
return _this;
|
|
553
502
|
}
|
|
554
|
-
|
|
503
|
+
static getDerivedStateFromProps(props, state) {
|
|
555
504
|
if (typeof props.opened === "boolean" && props.children) {
|
|
556
505
|
console.warn("'children' and 'opened' can't be used together");
|
|
557
506
|
}
|
|
@@ -564,14 +513,13 @@ let ModalLauncher = function (_React$Component) {
|
|
|
564
513
|
return {
|
|
565
514
|
opened: typeof props.opened === "boolean" ? props.opened : state.opened
|
|
566
515
|
};
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
516
|
+
}
|
|
517
|
+
componentDidUpdate(prevProps) {
|
|
570
518
|
if (!prevProps.opened && this.props.opened) {
|
|
571
519
|
this._saveLastElementFocused();
|
|
572
520
|
}
|
|
573
|
-
}
|
|
574
|
-
|
|
521
|
+
}
|
|
522
|
+
_renderModal() {
|
|
575
523
|
if (typeof this.props.modal === "function") {
|
|
576
524
|
return this.props.modal({
|
|
577
525
|
closeModal: this.handleCloseModal
|
|
@@ -579,8 +527,8 @@ let ModalLauncher = function (_React$Component) {
|
|
|
579
527
|
} else {
|
|
580
528
|
return this.props.modal;
|
|
581
529
|
}
|
|
582
|
-
}
|
|
583
|
-
|
|
530
|
+
}
|
|
531
|
+
render() {
|
|
584
532
|
const renderedChildren = this.props.children ? this.props.children({
|
|
585
533
|
openModal: this._openModal
|
|
586
534
|
}) : null;
|
|
@@ -603,38 +551,32 @@ let ModalLauncher = function (_React$Component) {
|
|
|
603
551
|
}, this._renderModal())), body), this.state.opened && React__namespace.createElement(ModalLauncherKeypressListener, {
|
|
604
552
|
onClose: this.handleCloseModal
|
|
605
553
|
}), this.state.opened && React__namespace.createElement(ScrollDisabler, null));
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
}(React__namespace.Component);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
609
556
|
ModalLauncher.defaultProps = {
|
|
610
557
|
backdropDismissEnabled: true
|
|
611
558
|
};
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
_this2 = _React$Component2.call.apply(_React$Component2, [this].concat(args)) || this;
|
|
617
|
-
_this2._handleKeyup = e => {
|
|
559
|
+
class ModalLauncherKeypressListener extends React__namespace.Component {
|
|
560
|
+
constructor(...args) {
|
|
561
|
+
super(...args);
|
|
562
|
+
this._handleKeyup = e => {
|
|
618
563
|
if (e.key === "Escape") {
|
|
619
564
|
e.preventDefault();
|
|
620
565
|
e.stopPropagation();
|
|
621
|
-
|
|
566
|
+
this.props.onClose();
|
|
622
567
|
}
|
|
623
568
|
};
|
|
624
|
-
return _this2;
|
|
625
569
|
}
|
|
626
|
-
|
|
627
|
-
_proto2.componentDidMount = function componentDidMount() {
|
|
570
|
+
componentDidMount() {
|
|
628
571
|
window.addEventListener("keyup", this._handleKeyup);
|
|
629
|
-
}
|
|
630
|
-
|
|
572
|
+
}
|
|
573
|
+
componentWillUnmount() {
|
|
631
574
|
window.removeEventListener("keyup", this._handleKeyup);
|
|
632
|
-
}
|
|
633
|
-
|
|
575
|
+
}
|
|
576
|
+
render() {
|
|
634
577
|
return null;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
}(React__namespace.Component);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
638
580
|
const styles$1 = aphrodite.StyleSheet.create({
|
|
639
581
|
container: {
|
|
640
582
|
zIndex: 1080
|
|
@@ -642,16 +584,11 @@ const styles$1 = aphrodite.StyleSheet.create({
|
|
|
642
584
|
});
|
|
643
585
|
var modalLauncher = wonderBlocksTiming.withActionScheduler(ModalLauncher);
|
|
644
586
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
function ModalContent() {
|
|
648
|
-
return _React$Component.apply(this, arguments) || this;
|
|
649
|
-
}
|
|
650
|
-
ModalContent.isClassOf = function isClassOf(instance) {
|
|
587
|
+
class ModalContent extends React__namespace.Component {
|
|
588
|
+
static isClassOf(instance) {
|
|
651
589
|
return instance && instance.type && instance.type.__IS_MODAL_CONTENT__;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
_proto.render = function render() {
|
|
590
|
+
}
|
|
591
|
+
render() {
|
|
655
592
|
const {
|
|
656
593
|
scrollOverflow,
|
|
657
594
|
style,
|
|
@@ -666,9 +603,8 @@ let ModalContent = function (_React$Component) {
|
|
|
666
603
|
}, React__namespace.createElement(wonderBlocksCore.View, {
|
|
667
604
|
style: [styles.content, style]
|
|
668
605
|
}, children)));
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
}(React__namespace.Component);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
672
608
|
ModalContent.defaultProps = {
|
|
673
609
|
scrollOverflow: true
|
|
674
610
|
};
|
|
@@ -696,13 +632,8 @@ const styleSheets$1 = {
|
|
|
696
632
|
})
|
|
697
633
|
};
|
|
698
634
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
function CloseButton() {
|
|
702
|
-
return _React$Component.apply(this, arguments) || this;
|
|
703
|
-
}
|
|
704
|
-
var _proto = CloseButton.prototype;
|
|
705
|
-
_proto.render = function render() {
|
|
635
|
+
class CloseButton extends React__namespace.Component {
|
|
636
|
+
render() {
|
|
706
637
|
const {
|
|
707
638
|
light,
|
|
708
639
|
onClick,
|
|
@@ -725,17 +656,11 @@ let CloseButton = function (_React$Component) {
|
|
|
725
656
|
testId: testId
|
|
726
657
|
});
|
|
727
658
|
});
|
|
728
|
-
};
|
|
729
|
-
return CloseButton;
|
|
730
|
-
}(React__namespace.Component);
|
|
731
|
-
|
|
732
|
-
let ModalPanel = function (_React$Component) {
|
|
733
|
-
_inheritsLoose(ModalPanel, _React$Component);
|
|
734
|
-
function ModalPanel() {
|
|
735
|
-
return _React$Component.apply(this, arguments) || this;
|
|
736
659
|
}
|
|
737
|
-
|
|
738
|
-
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
class ModalPanel extends React__namespace.Component {
|
|
663
|
+
renderMainContent() {
|
|
739
664
|
const {
|
|
740
665
|
content,
|
|
741
666
|
footer,
|
|
@@ -749,8 +674,8 @@ let ModalPanel = function (_React$Component) {
|
|
|
749
674
|
scrollOverflow,
|
|
750
675
|
style: [!!footer && styles.hasFooter, mainContent.props.style]
|
|
751
676
|
});
|
|
752
|
-
}
|
|
753
|
-
|
|
677
|
+
}
|
|
678
|
+
render() {
|
|
754
679
|
const {
|
|
755
680
|
closeButtonVisible,
|
|
756
681
|
footer,
|
|
@@ -770,9 +695,8 @@ let ModalPanel = function (_React$Component) {
|
|
|
770
695
|
style: styles.closeButton,
|
|
771
696
|
testId: testId && `${testId}-close`
|
|
772
697
|
}), header, mainContent, !footer || ModalFooter.isClassOf(footer) ? footer : React__namespace.createElement(ModalFooter, null, footer));
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
}(React__namespace.Component);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
776
700
|
ModalPanel.defaultProps = {
|
|
777
701
|
closeButtonVisible: true,
|
|
778
702
|
scrollOverflow: true,
|
|
@@ -805,13 +729,8 @@ const styles = aphrodite.StyleSheet.create({
|
|
|
805
729
|
}
|
|
806
730
|
});
|
|
807
731
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
function OnePaneDialog() {
|
|
811
|
-
return _React$Component.apply(this, arguments) || this;
|
|
812
|
-
}
|
|
813
|
-
var _proto = OnePaneDialog.prototype;
|
|
814
|
-
_proto.renderHeader = function renderHeader(uniqueId) {
|
|
732
|
+
class OnePaneDialog extends React__namespace.Component {
|
|
733
|
+
renderHeader(uniqueId) {
|
|
815
734
|
const {
|
|
816
735
|
title,
|
|
817
736
|
breadcrumbs = undefined,
|
|
@@ -839,8 +758,8 @@ let OnePaneDialog = function (_React$Component) {
|
|
|
839
758
|
testId: testId && `${testId}-header`
|
|
840
759
|
});
|
|
841
760
|
}
|
|
842
|
-
}
|
|
843
|
-
|
|
761
|
+
}
|
|
762
|
+
render() {
|
|
844
763
|
const {
|
|
845
764
|
onClose,
|
|
846
765
|
footer,
|
|
@@ -877,9 +796,8 @@ let OnePaneDialog = function (_React$Component) {
|
|
|
877
796
|
closeButtonVisible: closeButtonVisible,
|
|
878
797
|
testId: testId
|
|
879
798
|
}))));
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
}(React__namespace.Component);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
883
801
|
OnePaneDialog.defaultProps = {
|
|
884
802
|
closeButtonVisible: true
|
|
885
803
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-modal",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"design": "v2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-breadcrumbs": "^2.0.
|
|
19
|
+
"@khanacademy/wonder-blocks-breadcrumbs": "^2.0.6",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^2.0.1",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^5.0.
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^2.0.
|
|
23
|
-
"@khanacademy/wonder-blocks-icon-button": "^4.0.
|
|
24
|
-
"@khanacademy/wonder-blocks-layout": "^2.0.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^5.0.4",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^2.0.6",
|
|
23
|
+
"@khanacademy/wonder-blocks-icon-button": "^4.0.6",
|
|
24
|
+
"@khanacademy/wonder-blocks-layout": "^2.0.6",
|
|
25
25
|
"@khanacademy/wonder-blocks-spacing": "^4.0.1",
|
|
26
|
-
"@khanacademy/wonder-blocks-timing": "^3.0.
|
|
27
|
-
"@khanacademy/wonder-blocks-typography": "^2.0.
|
|
26
|
+
"@khanacademy/wonder-blocks-timing": "^3.0.2",
|
|
27
|
+
"@khanacademy/wonder-blocks-typography": "^2.0.6"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"aphrodite": "^1.2.5",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"react-dom": "16.14.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@khanacademy/wonder-blocks-breadcrumbs": "^2.0.
|
|
36
|
-
"wb-dev-build-settings": "^0.9.
|
|
35
|
+
"@khanacademy/wonder-blocks-breadcrumbs": "^2.0.6",
|
|
36
|
+
"wb-dev-build-settings": "^0.9.5"
|
|
37
37
|
}
|
|
38
38
|
}
|