@khanacademy/wonder-blocks-modal 3.0.7 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/components/close-button.d.ts +31 -0
  3. package/dist/components/close-button.js.flow +43 -0
  4. package/dist/components/focus-trap.d.ts +57 -0
  5. package/dist/components/focus-trap.js.flow +69 -0
  6. package/dist/components/modal-backdrop.d.ts +50 -0
  7. package/dist/components/modal-backdrop.js.flow +63 -0
  8. package/dist/components/modal-content.d.ts +23 -0
  9. package/dist/components/modal-content.js.flow +39 -0
  10. package/dist/components/modal-context.d.ts +6 -0
  11. package/dist/components/modal-context.js.flow +14 -0
  12. package/dist/components/modal-dialog.d.ts +60 -0
  13. package/dist/components/modal-dialog.js.flow +75 -0
  14. package/dist/components/modal-footer.d.ts +27 -0
  15. package/dist/components/modal-footer.js.flow +34 -0
  16. package/dist/components/modal-header.d.ts +93 -0
  17. package/dist/components/modal-header.js.flow +110 -0
  18. package/dist/components/modal-launcher.d.ts +17 -0
  19. package/dist/components/modal-launcher.js.flow +34 -0
  20. package/dist/components/modal-panel.d.ts +84 -0
  21. package/dist/components/modal-panel.js.flow +102 -0
  22. package/dist/components/one-pane-dialog.d.ts +124 -0
  23. package/dist/components/one-pane-dialog.js.flow +153 -0
  24. package/dist/components/scroll-disabler.d.ts +24 -0
  25. package/dist/components/scroll-disabler.js.flow +21 -0
  26. package/dist/es/index.js +222 -210
  27. package/dist/index.d.ts +8 -0
  28. package/dist/index.js +237 -226
  29. package/dist/index.js.flow +23 -2
  30. package/dist/util/constants.d.ts +5 -0
  31. package/dist/util/constants.js.flow +12 -0
  32. package/dist/util/find-focusable-nodes.d.ts +1 -0
  33. package/dist/util/find-focusable-nodes.js.flow +10 -0
  34. package/dist/util/maybe-get-portal-mounted-modal-host-element.d.ts +9 -0
  35. package/dist/util/maybe-get-portal-mounted-modal-host-element.js.flow +18 -0
  36. package/dist/util/types.d.ts +12 -0
  37. package/dist/util/types.js.flow +20 -0
  38. package/package.json +13 -13
  39. package/src/components/__tests__/{close-button.test.js → close-button.test.tsx} +0 -1
  40. package/src/components/__tests__/{focus-trap.test.js → focus-trap.test.tsx} +0 -1
  41. package/src/components/__tests__/{modal-backdrop.test.js → modal-backdrop.test.tsx} +0 -1
  42. package/src/components/__tests__/{modal-header.test.js → modal-header.test.tsx} +3 -2
  43. package/src/components/__tests__/{modal-launcher.test.js → modal-launcher.test.tsx} +11 -15
  44. package/src/components/__tests__/{modal-panel.test.js → modal-panel.test.tsx} +0 -1
  45. package/src/components/__tests__/{one-pane-dialog.test.js → one-pane-dialog.test.tsx} +0 -1
  46. package/src/components/{close-button.js → close-button.tsx} +7 -11
  47. package/src/components/{focus-trap.js → focus-trap.tsx} +12 -12
  48. package/src/components/{modal-backdrop.js → modal-backdrop.tsx} +20 -18
  49. package/src/components/{modal-content.js → modal-content.tsx} +11 -12
  50. package/src/components/modal-context.ts +13 -0
  51. package/src/components/{modal-dialog.js → modal-dialog.tsx} +15 -23
  52. package/src/components/{modal-footer.js → modal-footer.tsx} +5 -6
  53. package/src/components/{modal-header.js → modal-header.tsx} +20 -26
  54. package/src/components/{modal-launcher.js → modal-launcher.tsx} +29 -50
  55. package/src/components/{modal-panel.js → modal-panel.tsx} +27 -28
  56. package/src/components/{one-pane-dialog.js → one-pane-dialog.tsx} +37 -45
  57. package/src/components/{scroll-disabler.js → scroll-disabler.ts} +3 -4
  58. package/src/{index.js → index.ts} +0 -1
  59. package/src/util/{constants.js → constants.ts} +0 -2
  60. package/src/util/{find-focusable-nodes.js → find-focusable-nodes.ts} +0 -2
  61. package/src/util/{maybe-get-portal-mounted-modal-host-element.test.js → maybe-get-portal-mounted-modal-host-element.test.tsx} +4 -5
  62. package/src/util/{maybe-get-portal-mounted-modal-host-element.js → maybe-get-portal-mounted-modal-host-element.ts} +5 -4
  63. package/src/util/{types.js → types.ts} +3 -2
  64. package/tsconfig.json +20 -0
  65. package/tsconfig.tsbuildinfo +1 -0
  66. package/src/components/__docs__/modal-dialog.stories.js +0 -308
  67. package/src/components/__docs__/modal-footer.stories.js +0 -337
  68. package/src/components/__docs__/modal-header.argtypes.js +0 -76
  69. package/src/components/__docs__/modal-header.stories.js +0 -294
  70. package/src/components/__docs__/modal-launcher.argtypes.js +0 -78
  71. package/src/components/__docs__/modal-launcher.stories.js +0 -513
  72. package/src/components/__docs__/modal-panel.stories.js +0 -414
  73. package/src/components/__docs__/one-pane-dialog.argtypes.js +0 -108
  74. package/src/components/__docs__/one-pane-dialog.stories.js +0 -582
  75. package/src/components/modal-context.js +0 -14
package/dist/index.js CHANGED
@@ -11,39 +11,56 @@ var Color = require('@khanacademy/wonder-blocks-color');
11
11
  var wonderBlocksTypography = require('@khanacademy/wonder-blocks-typography');
12
12
  var ReactDOM = require('react-dom');
13
13
  var wonderBlocksTiming = require('@khanacademy/wonder-blocks-timing');
14
- var _extends = require('@babel/runtime/helpers/extends');
15
14
  var wonderBlocksIcon = require('@khanacademy/wonder-blocks-icon');
16
15
  var IconButton = require('@khanacademy/wonder-blocks-icon-button');
17
16
 
18
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
18
 
20
19
  function _interopNamespace(e) {
21
- if (e && e.__esModule) return e;
22
- var n = Object.create(null);
23
- if (e) {
24
- Object.keys(e).forEach(function (k) {
25
- if (k !== 'default') {
26
- var d = Object.getOwnPropertyDescriptor(e, k);
27
- Object.defineProperty(n, k, d.get ? d : {
28
- enumerable: true,
29
- get: function () { return e[k]; }
30
- });
31
- }
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]; }
32
29
  });
33
- }
34
- n["default"] = e;
35
- return Object.freeze(n);
30
+ }
31
+ });
32
+ }
33
+ n["default"] = e;
34
+ return Object.freeze(n);
36
35
  }
37
36
 
38
37
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
38
  var Spacing__default = /*#__PURE__*/_interopDefaultLegacy(Spacing);
40
39
  var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
41
40
  var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
42
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
43
41
  var IconButton__default = /*#__PURE__*/_interopDefaultLegacy(IconButton);
44
42
 
45
- class ModalDialog extends React__namespace.Component {
46
- render() {
43
+ function _setPrototypeOf(o, p) {
44
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
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() {
47
64
  const {
48
65
  above,
49
66
  below,
@@ -78,9 +95,9 @@ class ModalDialog extends React__namespace.Component {
78
95
  }, children), above && React__namespace.createElement(wonderBlocksCore.View, {
79
96
  style: styles.above
80
97
  }, above))));
81
- }
82
-
83
- }
98
+ };
99
+ return ModalDialog;
100
+ }(React__namespace.Component);
84
101
  ModalDialog.defaultProps = {
85
102
  role: "dialog"
86
103
  };
@@ -127,21 +144,25 @@ const styleSheets$3 = {
127
144
  })
128
145
  };
129
146
 
130
- class ModalFooter extends React__namespace.Component {
131
- static isClassOf(instance) {
132
- return instance && instance.type && instance.type.__IS_MODAL_FOOTER__;
147
+ let ModalFooter = function (_React$Component) {
148
+ _inheritsLoose(ModalFooter, _React$Component);
149
+ function ModalFooter() {
150
+ return _React$Component.apply(this, arguments) || this;
133
151
  }
134
-
135
- render() {
152
+ ModalFooter.isClassOf = function isClassOf(instance) {
153
+ return instance && instance.type && instance.type.__IS_MODAL_FOOTER__;
154
+ };
155
+ var _proto = ModalFooter.prototype;
156
+ _proto.render = function render() {
136
157
  const {
137
158
  children
138
159
  } = this.props;
139
160
  return React__namespace.createElement(wonderBlocksCore.View, {
140
161
  style: styles$3.footer
141
162
  }, children);
142
- }
143
-
144
- }
163
+ };
164
+ return ModalFooter;
165
+ }(React__namespace.Component);
145
166
  ModalFooter.__IS_MODAL_FOOTER__ = true;
146
167
  const styles$3 = aphrodite.StyleSheet.create({
147
168
  footer: {
@@ -160,8 +181,13 @@ const styles$3 = aphrodite.StyleSheet.create({
160
181
  }
161
182
  });
162
183
 
163
- class ModalHeader extends React__namespace.Component {
164
- render() {
184
+ let ModalHeader = function (_React$Component) {
185
+ _inheritsLoose(ModalHeader, _React$Component);
186
+ function ModalHeader() {
187
+ return _React$Component.apply(this, arguments) || this;
188
+ }
189
+ var _proto = ModalHeader.prototype;
190
+ _proto.render = function render() {
165
191
  const {
166
192
  breadcrumbs = undefined,
167
193
  light,
@@ -170,11 +196,9 @@ class ModalHeader extends React__namespace.Component {
170
196
  title,
171
197
  titleId
172
198
  } = this.props;
173
-
174
199
  if (subtitle && breadcrumbs) {
175
200
  throw new Error("'subtitle' and 'breadcrumbs' can't be used together");
176
201
  }
177
-
178
202
  return React__namespace.createElement(wonderBlocksLayout.MediaLayout, {
179
203
  styleSheets: styleSheets$2
180
204
  }, ({
@@ -192,9 +216,9 @@ class ModalHeader extends React__namespace.Component {
192
216
  style: light && styles.subtitle,
193
217
  testId: testId && `${testId}-subtitle`
194
218
  }, subtitle)));
195
- }
196
-
197
- }
219
+ };
220
+ return ModalHeader;
221
+ }(React__namespace.Component);
198
222
  ModalHeader.defaultProps = {
199
223
  light: true
200
224
  };
@@ -237,52 +261,47 @@ const styleSheets$2 = {
237
261
  };
238
262
 
239
263
  const FOCUSABLE_ELEMENTS$1 = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
240
- class FocusTrap extends React__namespace.Component {
241
- constructor(...args) {
242
- super(...args);
243
-
244
- this.getModalRoot = node => {
264
+ let FocusTrap = function (_React$Component) {
265
+ _inheritsLoose(FocusTrap, _React$Component);
266
+ function FocusTrap(...args) {
267
+ var _this;
268
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
269
+ _this.modalRoot = void 0;
270
+ _this.getModalRoot = node => {
245
271
  if (!node) {
246
272
  return;
247
273
  }
248
-
249
274
  const modalRoot = ReactDOM__namespace.findDOMNode(node);
250
-
251
275
  if (!modalRoot) {
252
276
  throw new Error("Assertion error: modal root should exist after mount");
253
277
  }
254
-
255
- this.modalRoot = modalRoot;
278
+ _this.modalRoot = modalRoot;
256
279
  };
257
-
258
- this.handleFocusMoveToLast = () => {
259
- this.focusElementIn(false);
280
+ _this.handleFocusMoveToLast = () => {
281
+ _this.focusElementIn(false);
260
282
  };
261
-
262
- this.handleFocusMoveToFirst = () => {
263
- this.focusElementIn(true);
283
+ _this.handleFocusMoveToFirst = () => {
284
+ _this.focusElementIn(true);
264
285
  };
286
+ return _this;
265
287
  }
266
-
267
- tryToFocus(node) {
288
+ var _proto = FocusTrap.prototype;
289
+ _proto.tryToFocus = function tryToFocus(node) {
268
290
  if (node instanceof HTMLElement) {
269
291
  try {
270
292
  node.focus();
271
293
  } catch (e) {}
272
-
273
294
  return document.activeElement === node;
274
295
  }
275
- }
276
-
277
- focusElementIn(isLast) {
296
+ };
297
+ _proto.focusElementIn = function focusElementIn(isLast) {
278
298
  const modalRootAsHtmlEl = this.modalRoot;
279
299
  const focusableNodes = Array.from(modalRootAsHtmlEl.querySelectorAll(FOCUSABLE_ELEMENTS$1));
280
300
  const nodeIndex = !isLast ? focusableNodes.length - 1 : 0;
281
301
  const focusableNode = focusableNodes[nodeIndex];
282
302
  this.tryToFocus(focusableNode);
283
- }
284
-
285
- render() {
303
+ };
304
+ _proto.render = function render() {
286
305
  const {
287
306
  style
288
307
  } = this.props;
@@ -304,8 +323,23 @@ class FocusTrap extends React__namespace.Component {
304
323
  position: "fixed"
305
324
  }
306
325
  }));
307
- }
308
-
326
+ };
327
+ return FocusTrap;
328
+ }(React__namespace.Component);
329
+
330
+ function _extends() {
331
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
332
+ for (var i = 1; i < arguments.length; i++) {
333
+ var source = arguments[i];
334
+ for (var key in source) {
335
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
336
+ target[key] = source[key];
337
+ }
338
+ }
339
+ }
340
+ return target;
341
+ };
342
+ return _extends.apply(this, arguments);
309
343
  }
310
344
 
311
345
  const ModalLauncherPortalAttributeName = "data-modal-launcher-portal";
@@ -315,67 +349,56 @@ function findFocusableNodes(root) {
315
349
  return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
316
350
  }
317
351
 
318
- class ModalBackdrop extends React__namespace.Component {
319
- constructor(...args) {
320
- super(...args);
321
- this._mousePressedOutside = false;
322
-
323
- this.handleMouseDown = e => {
324
- this._mousePressedOutside = e.target === e.currentTarget;
352
+ let ModalBackdrop = function (_React$Component) {
353
+ _inheritsLoose(ModalBackdrop, _React$Component);
354
+ function ModalBackdrop(...args) {
355
+ var _this;
356
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
357
+ _this._mousePressedOutside = false;
358
+ _this.handleMouseDown = e => {
359
+ _this._mousePressedOutside = e.target === e.currentTarget;
325
360
  };
326
-
327
- this.handleMouseUp = e => {
328
- if (e.target === e.currentTarget && this._mousePressedOutside) {
329
- this.props.onCloseModal();
361
+ _this.handleMouseUp = e => {
362
+ if (e.target === e.currentTarget && _this._mousePressedOutside) {
363
+ _this.props.onCloseModal();
330
364
  }
331
-
332
- this._mousePressedOutside = false;
365
+ _this._mousePressedOutside = false;
333
366
  };
367
+ return _this;
334
368
  }
335
-
336
- componentDidMount() {
369
+ var _proto = ModalBackdrop.prototype;
370
+ _proto.componentDidMount = function componentDidMount() {
337
371
  const node = ReactDOM__namespace.findDOMNode(this);
338
-
339
372
  if (!node) {
340
373
  return;
341
374
  }
342
-
343
375
  const firstFocusableElement = this._getInitialFocusElement(node) || this._getFirstFocusableElement(node) || this._getDialogElement(node);
344
-
345
376
  setTimeout(() => {
346
377
  firstFocusableElement.focus();
347
378
  }, 0);
348
- }
349
-
350
- _getInitialFocusElement(node) {
379
+ };
380
+ _proto._getInitialFocusElement = function _getInitialFocusElement(node) {
351
381
  const {
352
382
  initialFocusId
353
383
  } = this.props;
354
-
355
384
  if (!initialFocusId) {
356
385
  return null;
357
386
  }
358
-
359
387
  return ReactDOM__namespace.findDOMNode(node.querySelector(`#${initialFocusId}`));
360
- }
361
-
362
- _getFirstFocusableElement(node) {
388
+ };
389
+ _proto._getFirstFocusableElement = function _getFirstFocusableElement(node) {
363
390
  const focusableElements = findFocusableNodes(node);
364
-
365
391
  if (!focusableElements) {
366
392
  return null;
367
393
  }
368
-
369
394
  return focusableElements[0];
370
- }
371
-
372
- _getDialogElement(node) {
395
+ };
396
+ _proto._getDialogElement = function _getDialogElement(node) {
373
397
  const dialogElement = ReactDOM__namespace.findDOMNode(node.querySelector('[role="dialog"]'));
374
398
  dialogElement.tabIndex = -1;
375
399
  return dialogElement;
376
- }
377
-
378
- render() {
400
+ };
401
+ _proto.render = function render() {
379
402
  const {
380
403
  children,
381
404
  testId
@@ -383,15 +406,15 @@ class ModalBackdrop extends React__namespace.Component {
383
406
  const backdropProps = {
384
407
  [ModalLauncherPortalAttributeName]: true
385
408
  };
386
- return React__namespace.createElement(wonderBlocksCore.View, _extends__default["default"]({
409
+ return React__namespace.createElement(wonderBlocksCore.View, _extends({
387
410
  style: styles$2.modalPositioner,
388
411
  onMouseDown: this.handleMouseDown,
389
412
  onMouseUp: this.handleMouseUp,
390
413
  testId: testId
391
414
  }, backdropProps), children);
392
- }
393
-
394
- }
415
+ };
416
+ return ModalBackdrop;
417
+ }(React__namespace.Component);
395
418
  const styles$2 = aphrodite.StyleSheet.create({
396
419
  modalPositioner: {
397
420
  position: "fixed",
@@ -410,71 +433,65 @@ const needsHackyMobileSafariScrollDisabler = (() => {
410
433
  if (typeof window === "undefined") {
411
434
  return false;
412
435
  }
413
-
414
436
  const userAgent = window.navigator.userAgent;
415
437
  return userAgent.indexOf("iPad") > -1 || userAgent.indexOf("iPhone") > -1;
416
438
  })();
417
-
418
- class ScrollDisabler extends React__namespace.Component {
419
- componentDidMount() {
439
+ let ScrollDisabler = function (_React$Component) {
440
+ _inheritsLoose(ScrollDisabler, _React$Component);
441
+ function ScrollDisabler() {
442
+ return _React$Component.apply(this, arguments) || this;
443
+ }
444
+ var _proto = ScrollDisabler.prototype;
445
+ _proto.componentDidMount = function componentDidMount() {
420
446
  if (ScrollDisabler.numModalsOpened === 0) {
421
447
  const body = document.body;
422
-
423
448
  if (!body) {
424
449
  throw new Error("couldn't find document.body");
425
450
  }
426
-
427
451
  ScrollDisabler.oldOverflow = body.style.overflow;
428
452
  ScrollDisabler.oldScrollY = window.scrollY;
429
-
430
453
  if (needsHackyMobileSafariScrollDisabler) {
431
454
  ScrollDisabler.oldPosition = body.style.position;
432
455
  ScrollDisabler.oldWidth = body.style.width;
433
456
  ScrollDisabler.oldTop = body.style.top;
434
457
  }
435
-
436
458
  body.style.overflow = "hidden";
437
-
438
459
  if (needsHackyMobileSafariScrollDisabler) {
439
460
  body.style.position = "fixed";
440
461
  body.style.width = "100%";
441
462
  body.style.top = `${-ScrollDisabler.oldScrollY}px`;
442
463
  }
443
464
  }
444
-
445
465
  ScrollDisabler.numModalsOpened++;
446
- }
447
-
448
- componentWillUnmount() {
466
+ };
467
+ _proto.componentWillUnmount = function componentWillUnmount() {
449
468
  ScrollDisabler.numModalsOpened--;
450
-
451
469
  if (ScrollDisabler.numModalsOpened === 0) {
452
470
  const body = document.body;
453
-
454
471
  if (!body) {
455
472
  throw new Error("couldn't find document.body");
456
473
  }
457
-
458
474
  body.style.overflow = ScrollDisabler.oldOverflow;
459
-
460
475
  if (needsHackyMobileSafariScrollDisabler) {
461
476
  body.style.position = ScrollDisabler.oldPosition;
462
477
  body.style.width = ScrollDisabler.oldWidth;
463
478
  body.style.top = ScrollDisabler.oldTop;
464
479
  }
465
-
466
480
  if (typeof window !== "undefined" && window.scrollTo) {
467
481
  window.scrollTo(0, ScrollDisabler.oldScrollY);
468
482
  }
469
483
  }
470
- }
471
-
472
- render() {
484
+ };
485
+ _proto.render = function render() {
473
486
  return null;
474
- }
475
-
476
- }
477
-
487
+ };
488
+ return ScrollDisabler;
489
+ }(React__namespace.Component);
490
+ ScrollDisabler.oldOverflow = void 0;
491
+ ScrollDisabler.oldPosition = void 0;
492
+ ScrollDisabler.oldScrollY = void 0;
493
+ ScrollDisabler.oldWidth = void 0;
494
+ ScrollDisabler.oldTop = void 0;
478
495
  ScrollDisabler.numModalsOpened = 0;
479
496
 
480
497
  const defaultContext = {
@@ -482,35 +499,32 @@ const defaultContext = {
482
499
  };
483
500
  var ModalContext = React__namespace.createContext(defaultContext);
484
501
 
485
- class ModalLauncher extends React__namespace.Component {
486
- constructor(...args) {
487
- super(...args);
488
- this.state = {
502
+ let ModalLauncher = function (_React$Component) {
503
+ _inheritsLoose(ModalLauncher, _React$Component);
504
+ function ModalLauncher(...args) {
505
+ var _this;
506
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
507
+ _this.lastElementFocusedOutsideModal = void 0;
508
+ _this.state = {
489
509
  opened: false
490
510
  };
491
-
492
- this._saveLastElementFocused = () => {
493
- this.lastElementFocusedOutsideModal = document.activeElement;
511
+ _this._saveLastElementFocused = () => {
512
+ _this.lastElementFocusedOutsideModal = document.activeElement;
494
513
  };
495
-
496
- this._openModal = () => {
497
- this._saveLastElementFocused();
498
-
499
- this.setState({
514
+ _this._openModal = () => {
515
+ _this._saveLastElementFocused();
516
+ _this.setState({
500
517
  opened: true
501
518
  });
502
519
  };
503
-
504
- this._returnFocus = () => {
520
+ _this._returnFocus = () => {
505
521
  const {
506
522
  closedFocusId,
507
523
  schedule
508
- } = this.props;
509
- const lastElement = this.lastElementFocusedOutsideModal;
510
-
524
+ } = _this.props;
525
+ const lastElement = _this.lastElementFocusedOutsideModal;
511
526
  if (closedFocusId) {
512
527
  const focusElement = ReactDOM__namespace.findDOMNode(document.getElementById(closedFocusId));
513
-
514
528
  if (focusElement) {
515
529
  schedule.animationFrame(() => {
516
530
  focusElement.focus();
@@ -518,53 +532,46 @@ class ModalLauncher extends React__namespace.Component {
518
532
  return;
519
533
  }
520
534
  }
521
-
522
535
  if (lastElement != null) {
523
536
  schedule.animationFrame(() => {
524
537
  lastElement.focus();
525
538
  });
526
539
  }
527
540
  };
528
-
529
- this.handleCloseModal = () => {
530
- this.setState({
541
+ _this.handleCloseModal = () => {
542
+ _this.setState({
531
543
  opened: false
532
544
  }, () => {
533
545
  const {
534
546
  onClose
535
- } = this.props;
536
- onClose && onClose();
537
-
538
- this._returnFocus();
547
+ } = _this.props;
548
+ onClose == null ? void 0 : onClose();
549
+ _this._returnFocus();
539
550
  });
540
551
  };
552
+ return _this;
541
553
  }
542
-
543
- static getDerivedStateFromProps(props, state) {
554
+ ModalLauncher.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
544
555
  if (typeof props.opened === "boolean" && props.children) {
545
556
  console.warn("'children' and 'opened' can't be used together");
546
557
  }
547
-
548
558
  if (typeof props.opened === "boolean" && !props.onClose) {
549
559
  console.warn("'onClose' should be used with 'opened'");
550
560
  }
551
-
552
561
  if (typeof props.opened !== "boolean" && !props.children) {
553
562
  console.warn("either 'children' or 'opened' must be set");
554
563
  }
555
-
556
564
  return {
557
565
  opened: typeof props.opened === "boolean" ? props.opened : state.opened
558
566
  };
559
- }
560
-
561
- componentDidUpdate(prevProps) {
567
+ };
568
+ var _proto = ModalLauncher.prototype;
569
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
562
570
  if (!prevProps.opened && this.props.opened) {
563
571
  this._saveLastElementFocused();
564
572
  }
565
- }
566
-
567
- _renderModal() {
573
+ };
574
+ _proto._renderModal = function _renderModal() {
568
575
  if (typeof this.props.modal === "function") {
569
576
  return this.props.modal({
570
577
  closeModal: this.handleCloseModal
@@ -572,20 +579,17 @@ class ModalLauncher extends React__namespace.Component {
572
579
  } else {
573
580
  return this.props.modal;
574
581
  }
575
- }
576
-
577
- render() {
582
+ };
583
+ _proto.render = function render() {
578
584
  const renderedChildren = this.props.children ? this.props.children({
579
585
  openModal: this._openModal
580
586
  }) : null;
581
587
  const {
582
588
  body
583
589
  } = document;
584
-
585
590
  if (!body) {
586
591
  return null;
587
592
  }
588
-
589
593
  return React__namespace.createElement(ModalContext.Provider, {
590
594
  value: {
591
595
  closeModal: this.handleCloseModal
@@ -599,41 +603,38 @@ class ModalLauncher extends React__namespace.Component {
599
603
  }, this._renderModal())), body), this.state.opened && React__namespace.createElement(ModalLauncherKeypressListener, {
600
604
  onClose: this.handleCloseModal
601
605
  }), this.state.opened && React__namespace.createElement(ScrollDisabler, null));
602
- }
603
-
604
- }
605
-
606
+ };
607
+ return ModalLauncher;
608
+ }(React__namespace.Component);
606
609
  ModalLauncher.defaultProps = {
607
610
  backdropDismissEnabled: true
608
611
  };
609
-
610
- class ModalLauncherKeypressListener extends React__namespace.Component {
611
- constructor(...args) {
612
- super(...args);
613
-
614
- this._handleKeyup = e => {
612
+ let ModalLauncherKeypressListener = function (_React$Component2) {
613
+ _inheritsLoose(ModalLauncherKeypressListener, _React$Component2);
614
+ function ModalLauncherKeypressListener(...args) {
615
+ var _this2;
616
+ _this2 = _React$Component2.call.apply(_React$Component2, [this].concat(args)) || this;
617
+ _this2._handleKeyup = e => {
615
618
  if (e.key === "Escape") {
616
619
  e.preventDefault();
617
620
  e.stopPropagation();
618
- this.props.onClose();
621
+ _this2.props.onClose();
619
622
  }
620
623
  };
624
+ return _this2;
621
625
  }
622
-
623
- componentDidMount() {
626
+ var _proto2 = ModalLauncherKeypressListener.prototype;
627
+ _proto2.componentDidMount = function componentDidMount() {
624
628
  window.addEventListener("keyup", this._handleKeyup);
625
- }
626
-
627
- componentWillUnmount() {
629
+ };
630
+ _proto2.componentWillUnmount = function componentWillUnmount() {
628
631
  window.removeEventListener("keyup", this._handleKeyup);
629
- }
630
-
631
- render() {
632
+ };
633
+ _proto2.render = function render() {
632
634
  return null;
633
- }
634
-
635
- }
636
-
635
+ };
636
+ return ModalLauncherKeypressListener;
637
+ }(React__namespace.Component);
637
638
  const styles$1 = aphrodite.StyleSheet.create({
638
639
  container: {
639
640
  zIndex: 1080
@@ -641,12 +642,16 @@ const styles$1 = aphrodite.StyleSheet.create({
641
642
  });
642
643
  var modalLauncher = wonderBlocksTiming.withActionScheduler(ModalLauncher);
643
644
 
644
- class ModalContent extends React__namespace.Component {
645
- static isClassOf(instance) {
646
- return instance && instance.type && instance.type.__IS_MODAL_CONTENT__;
645
+ let ModalContent = function (_React$Component) {
646
+ _inheritsLoose(ModalContent, _React$Component);
647
+ function ModalContent() {
648
+ return _React$Component.apply(this, arguments) || this;
647
649
  }
648
-
649
- render() {
650
+ ModalContent.isClassOf = function isClassOf(instance) {
651
+ return instance && instance.type && instance.type.__IS_MODAL_CONTENT__;
652
+ };
653
+ var _proto = ModalContent.prototype;
654
+ _proto.render = function render() {
650
655
  const {
651
656
  scrollOverflow,
652
657
  style,
@@ -661,9 +666,9 @@ class ModalContent extends React__namespace.Component {
661
666
  }, React__namespace.createElement(wonderBlocksCore.View, {
662
667
  style: [styles.content, style]
663
668
  }, children)));
664
- }
665
-
666
- }
669
+ };
670
+ return ModalContent;
671
+ }(React__namespace.Component);
667
672
  ModalContent.defaultProps = {
668
673
  scrollOverflow: true
669
674
  };
@@ -691,8 +696,13 @@ const styleSheets$1 = {
691
696
  })
692
697
  };
693
698
 
694
- class CloseButton extends React__namespace.Component {
695
- render() {
699
+ let CloseButton = function (_React$Component) {
700
+ _inheritsLoose(CloseButton, _React$Component);
701
+ function CloseButton() {
702
+ return _React$Component.apply(this, arguments) || this;
703
+ }
704
+ var _proto = CloseButton.prototype;
705
+ _proto.render = function render() {
696
706
  const {
697
707
  light,
698
708
  onClick,
@@ -705,7 +715,6 @@ class CloseButton extends React__namespace.Component {
705
715
  if (closeModal && onClick) {
706
716
  throw new Error("You've specified 'onClose' on a modal when using ModalLauncher. Please specify 'onClose' on the ModalLauncher instead");
707
717
  }
708
-
709
718
  return React__namespace.createElement(IconButton__default["default"], {
710
719
  icon: wonderBlocksIcon.icons.dismiss,
711
720
  "aria-label": "Close modal",
@@ -716,30 +725,32 @@ class CloseButton extends React__namespace.Component {
716
725
  testId: testId
717
726
  });
718
727
  });
719
- }
720
-
721
- }
728
+ };
729
+ return CloseButton;
730
+ }(React__namespace.Component);
722
731
 
723
- class ModalPanel extends React__namespace.Component {
724
- renderMainContent() {
732
+ let ModalPanel = function (_React$Component) {
733
+ _inheritsLoose(ModalPanel, _React$Component);
734
+ function ModalPanel() {
735
+ return _React$Component.apply(this, arguments) || this;
736
+ }
737
+ var _proto = ModalPanel.prototype;
738
+ _proto.renderMainContent = function renderMainContent() {
725
739
  const {
726
740
  content,
727
741
  footer,
728
742
  scrollOverflow
729
743
  } = this.props;
730
744
  const mainContent = ModalContent.isClassOf(content) ? content : React__namespace.createElement(ModalContent, null, content);
731
-
732
745
  if (!mainContent) {
733
746
  return mainContent;
734
747
  }
735
-
736
748
  return React__namespace.cloneElement(mainContent, {
737
749
  scrollOverflow,
738
750
  style: [!!footer && styles.hasFooter, mainContent.props.style]
739
751
  });
740
- }
741
-
742
- render() {
752
+ };
753
+ _proto.render = function render() {
743
754
  const {
744
755
  closeButtonVisible,
745
756
  footer,
@@ -759,9 +770,9 @@ class ModalPanel extends React__namespace.Component {
759
770
  style: styles.closeButton,
760
771
  testId: testId && `${testId}-close`
761
772
  }), header, mainContent, !footer || ModalFooter.isClassOf(footer) ? footer : React__namespace.createElement(ModalFooter, null, footer));
762
- }
763
-
764
- }
773
+ };
774
+ return ModalPanel;
775
+ }(React__namespace.Component);
765
776
  ModalPanel.defaultProps = {
766
777
  closeButtonVisible: true,
767
778
  scrollOverflow: true,
@@ -794,15 +805,19 @@ const styles = aphrodite.StyleSheet.create({
794
805
  }
795
806
  });
796
807
 
797
- class OnePaneDialog extends React__namespace.Component {
798
- renderHeader(uniqueId) {
808
+ let OnePaneDialog = function (_React$Component) {
809
+ _inheritsLoose(OnePaneDialog, _React$Component);
810
+ function OnePaneDialog() {
811
+ return _React$Component.apply(this, arguments) || this;
812
+ }
813
+ var _proto = OnePaneDialog.prototype;
814
+ _proto.renderHeader = function renderHeader(uniqueId) {
799
815
  const {
800
816
  title,
801
817
  breadcrumbs = undefined,
802
818
  subtitle = undefined,
803
819
  testId
804
820
  } = this.props;
805
-
806
821
  if (breadcrumbs) {
807
822
  return React__namespace.createElement(ModalHeader, {
808
823
  title: title,
@@ -824,9 +839,8 @@ class OnePaneDialog extends React__namespace.Component {
824
839
  testId: testId && `${testId}-header`
825
840
  });
826
841
  }
827
- }
828
-
829
- render() {
842
+ };
843
+ _proto.render = function render() {
830
844
  const {
831
845
  onClose,
832
846
  footer,
@@ -863,9 +877,9 @@ class OnePaneDialog extends React__namespace.Component {
863
877
  closeButtonVisible: closeButtonVisible,
864
878
  testId: testId
865
879
  }))));
866
- }
867
-
868
- }
880
+ };
881
+ return OnePaneDialog;
882
+ }(React__namespace.Component);
869
883
  OnePaneDialog.defaultProps = {
870
884
  closeButtonVisible: true
871
885
  };
@@ -889,14 +903,11 @@ const styleSheets = {
889
903
 
890
904
  function maybeGetNextAncestorModalLauncherPortal(element) {
891
905
  let candidateElement = element && element.parentElement;
892
-
893
906
  while (candidateElement && !candidateElement.hasAttribute(ModalLauncherPortalAttributeName)) {
894
907
  candidateElement = candidateElement.parentElement;
895
908
  }
896
-
897
909
  return candidateElement;
898
910
  }
899
-
900
911
  function maybeGetPortalMountedModalHostElement(element) {
901
912
  return maybeGetNextAncestorModalLauncherPortal(element);
902
913
  }