@khanacademy/wonder-blocks-popover 2.0.5 → 2.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @khanacademy/wonder-blocks-popover
2
2
 
3
+ ## 2.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - c20f48f3: Don't transpile classes when building bundles
8
+ - Updated dependencies [c20f48f3]
9
+ - @khanacademy/wonder-blocks-core@5.0.4
10
+ - @khanacademy/wonder-blocks-icon@2.0.6
11
+ - @khanacademy/wonder-blocks-icon-button@4.0.6
12
+ - @khanacademy/wonder-blocks-modal@4.0.6
13
+ - @khanacademy/wonder-blocks-tooltip@2.0.6
14
+ - @khanacademy/wonder-blocks-typography@2.0.6
15
+
3
16
  ## 2.0.5
4
17
 
5
18
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -25,39 +25,20 @@ function _extends() {
25
25
  return _extends.apply(this, arguments);
26
26
  }
27
27
 
28
- function _setPrototypeOf(o, p) {
29
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
30
- o.__proto__ = p;
31
- return o;
32
- };
33
- return _setPrototypeOf(o, p);
34
- }
35
-
36
- function _inheritsLoose(subClass, superClass) {
37
- subClass.prototype = Object.create(superClass.prototype);
38
- subClass.prototype.constructor = subClass;
39
- _setPrototypeOf(subClass, superClass);
40
- }
41
-
42
28
  const defaultContext = {
43
29
  close: undefined,
44
30
  placement: "top"
45
31
  };
46
32
  var PopoverContext = React.createContext(defaultContext);
47
33
 
48
- let PopoverAnchor = function (_React$Component) {
49
- _inheritsLoose(PopoverAnchor, _React$Component);
50
- function PopoverAnchor() {
51
- return _React$Component.apply(this, arguments) || this;
52
- }
53
- var _proto = PopoverAnchor.prototype;
54
- _proto.componentDidMount = function componentDidMount() {
34
+ class PopoverAnchor extends React.Component {
35
+ componentDidMount() {
55
36
  const anchorNode = ReactDOM.findDOMNode(this);
56
37
  if (anchorNode) {
57
38
  this.props.anchorRef(anchorNode);
58
39
  }
59
- };
60
- _proto.render = function render() {
40
+ }
41
+ render() {
61
42
  const {
62
43
  children,
63
44
  id,
@@ -84,22 +65,16 @@ let PopoverAnchor = function (_React$Component) {
84
65
  } : onClick
85
66
  }));
86
67
  }
87
- };
88
- return PopoverAnchor;
89
- }(React.Component);
90
-
91
- let PopoverDialog = function (_React$Component) {
92
- _inheritsLoose(PopoverDialog, _React$Component);
93
- function PopoverDialog() {
94
- return _React$Component.apply(this, arguments) || this;
95
68
  }
96
- var _proto = PopoverDialog.prototype;
97
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
69
+ }
70
+
71
+ class PopoverDialog extends React.Component {
72
+ componentDidUpdate(prevProps) {
98
73
  if (prevProps.placement !== this.props.placement) {
99
74
  this.props.onUpdate(this.props.placement);
100
75
  }
101
- };
102
- _proto.render = function render() {
76
+ }
77
+ render() {
103
78
  const {
104
79
  placement,
105
80
  children,
@@ -126,9 +101,8 @@ let PopoverDialog = function (_React$Component) {
126
101
  placement: placement,
127
102
  offset: tailOffset
128
103
  })));
129
- };
130
- return PopoverDialog;
131
- }(React.Component);
104
+ }
105
+ }
132
106
  const styles$2 = StyleSheet.create({
133
107
  hide: {
134
108
  pointerEvents: "none",
@@ -155,13 +129,11 @@ function findFocusableNodes(root) {
155
129
  return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
156
130
  }
157
131
 
158
- let InitialFocus = function (_React$Component) {
159
- _inheritsLoose(InitialFocus, _React$Component);
160
- function InitialFocus(...args) {
161
- var _this;
162
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
163
- _this.setInitialFocusableElement = node => {
164
- const firstFocusableElement = _this.maybeGetInitialFocusElement(node) || _this.maybeGetFirstFocusableElement(node) || node;
132
+ class InitialFocus extends React.Component {
133
+ constructor(...args) {
134
+ super(...args);
135
+ this.setInitialFocusableElement = node => {
136
+ const firstFocusableElement = this.maybeGetInitialFocusElement(node) || this.maybeGetFirstFocusableElement(node) || node;
165
137
  if (firstFocusableElement === node) {
166
138
  node.tabIndex = -1;
167
139
  }
@@ -169,17 +141,15 @@ let InitialFocus = function (_React$Component) {
169
141
  firstFocusableElement.focus();
170
142
  }, 0);
171
143
  };
172
- return _this;
173
144
  }
174
- var _proto = InitialFocus.prototype;
175
- _proto.componentDidMount = function componentDidMount() {
145
+ componentDidMount() {
176
146
  const node = ReactDOM.findDOMNode(this);
177
147
  if (!node) {
178
148
  return;
179
149
  }
180
150
  this.setInitialFocusableElement(node);
181
- };
182
- _proto.maybeGetInitialFocusElement = function maybeGetInitialFocusElement(node) {
151
+ }
152
+ maybeGetInitialFocusElement(node) {
183
153
  const {
184
154
  initialFocusId
185
155
  } = this.props;
@@ -187,45 +157,42 @@ let InitialFocus = function (_React$Component) {
187
157
  return null;
188
158
  }
189
159
  return node.querySelector(`#${initialFocusId}`);
190
- };
191
- _proto.maybeGetFirstFocusableElement = function maybeGetFirstFocusableElement(node) {
160
+ }
161
+ maybeGetFirstFocusableElement(node) {
192
162
  const focusableElements = findFocusableNodes(node);
193
163
  if (!focusableElements.length) {
194
164
  return null;
195
165
  }
196
166
  return focusableElements[0];
197
- };
198
- _proto.render = function render() {
167
+ }
168
+ render() {
199
169
  return this.props.children;
200
- };
201
- return InitialFocus;
202
- }(React.Component);
170
+ }
171
+ }
203
172
 
204
- let FocusManager = function (_React$Component) {
205
- _inheritsLoose(FocusManager, _React$Component);
206
- function FocusManager(...args) {
207
- var _this;
208
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
209
- _this.nextElementAfterPopover = void 0;
210
- _this.rootNode = void 0;
211
- _this.focusableElementsInPopover = [];
212
- _this.addEventListeners = () => {
173
+ class FocusManager extends React.Component {
174
+ constructor(...args) {
175
+ super(...args);
176
+ this.nextElementAfterPopover = void 0;
177
+ this.rootNode = void 0;
178
+ this.focusableElementsInPopover = [];
179
+ this.addEventListeners = () => {
213
180
  const {
214
181
  anchorElement
215
- } = _this.props;
182
+ } = this.props;
216
183
  if (anchorElement) {
217
- anchorElement.addEventListener("keydown", _this.handleKeydownPreviousFocusableElement, true);
184
+ anchorElement.addEventListener("keydown", this.handleKeydownPreviousFocusableElement, true);
218
185
  }
219
- _this.nextElementAfterPopover = _this.getNextFocusableElement();
220
- if (_this.nextElementAfterPopover) {
221
- _this.nextElementAfterPopover.addEventListener("keydown", _this.handleKeydownNextFocusableElement, true);
186
+ this.nextElementAfterPopover = this.getNextFocusableElement();
187
+ if (this.nextElementAfterPopover) {
188
+ this.nextElementAfterPopover.addEventListener("keydown", this.handleKeydownNextFocusableElement, true);
222
189
  }
223
190
  };
224
- _this.getNextFocusableElement = () => {
191
+ this.getNextFocusableElement = () => {
225
192
  const {
226
193
  anchorElement
227
- } = _this.props;
228
- if (!anchorElement || _this.nextElementAfterPopover) {
194
+ } = this.props;
195
+ if (!anchorElement || this.nextElementAfterPopover) {
229
196
  return;
230
197
  }
231
198
  const focusableElements = findFocusableNodes(document);
@@ -236,7 +203,7 @@ let FocusManager = function (_React$Component) {
236
203
  }
237
204
  return;
238
205
  };
239
- _this.getComponentRootNode = node => {
206
+ this.getComponentRootNode = node => {
240
207
  if (!node) {
241
208
  return;
242
209
  }
@@ -244,42 +211,40 @@ let FocusManager = function (_React$Component) {
244
211
  if (!rootNode) {
245
212
  throw new Error("Assertion error: root node should exist after mount");
246
213
  }
247
- _this.rootNode = rootNode;
248
- _this.focusableElementsInPopover = findFocusableNodes(_this.rootNode);
214
+ this.rootNode = rootNode;
215
+ this.focusableElementsInPopover = findFocusableNodes(this.rootNode);
249
216
  };
250
- _this.handleFocusPreviousFocusableElement = () => {
251
- if (_this.props.anchorElement) {
252
- _this.props.anchorElement.focus();
217
+ this.handleFocusPreviousFocusableElement = () => {
218
+ if (this.props.anchorElement) {
219
+ this.props.anchorElement.focus();
253
220
  }
254
221
  };
255
- _this.handleFocusNextFocusableElement = () => {
256
- if (_this.nextElementAfterPopover) {
257
- _this.nextElementAfterPopover.focus();
222
+ this.handleFocusNextFocusableElement = () => {
223
+ if (this.nextElementAfterPopover) {
224
+ this.nextElementAfterPopover.focus();
258
225
  }
259
226
  };
260
- _this.handleKeydownPreviousFocusableElement = e => {
227
+ this.handleKeydownPreviousFocusableElement = e => {
261
228
  if (e.key === "Tab" && !e.shiftKey) {
262
229
  e.preventDefault();
263
- _this.focusableElementsInPopover[0].focus();
230
+ this.focusableElementsInPopover[0].focus();
264
231
  }
265
232
  };
266
- _this.handleKeydownNextFocusableElement = e => {
233
+ this.handleKeydownNextFocusableElement = e => {
267
234
  if (e.key === "Tab" && e.shiftKey) {
268
235
  e.preventDefault();
269
- const lastElementIndex = _this.focusableElementsInPopover.length - 1;
270
- _this.focusableElementsInPopover[lastElementIndex].focus();
236
+ const lastElementIndex = this.focusableElementsInPopover.length - 1;
237
+ this.focusableElementsInPopover[lastElementIndex].focus();
271
238
  }
272
239
  };
273
- return _this;
274
240
  }
275
- var _proto = FocusManager.prototype;
276
- _proto.componentDidMount = function componentDidMount() {
241
+ componentDidMount() {
277
242
  this.addEventListeners();
278
- };
279
- _proto.componentDidUpdate = function componentDidUpdate() {
243
+ }
244
+ componentDidUpdate() {
280
245
  this.addEventListeners();
281
- };
282
- _proto.componentWillUnmount = function componentWillUnmount() {
246
+ }
247
+ componentWillUnmount() {
283
248
  const {
284
249
  anchorElement
285
250
  } = this.props;
@@ -290,8 +255,8 @@ let FocusManager = function (_React$Component) {
290
255
  if (this.nextElementAfterPopover) {
291
256
  this.nextElementAfterPopover.removeEventListener("keydown", this.handleKeydownNextFocusableElement, true);
292
257
  }
293
- };
294
- _proto.render = function render() {
258
+ }
259
+ render() {
295
260
  const {
296
261
  children
297
262
  } = this.props;
@@ -312,103 +277,94 @@ let FocusManager = function (_React$Component) {
312
277
  position: "fixed"
313
278
  }
314
279
  }));
315
- };
316
- return FocusManager;
317
- }(React.Component);
280
+ }
281
+ }
318
282
 
319
- let PopoverEventListener = function (_React$Component) {
320
- _inheritsLoose(PopoverEventListener, _React$Component);
321
- function PopoverEventListener(...args) {
322
- var _this;
323
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
324
- _this.state = {
283
+ class PopoverEventListener extends React.Component {
284
+ constructor(...args) {
285
+ super(...args);
286
+ this.state = {
325
287
  isFirstClick: true
326
288
  };
327
- _this._handleKeyup = e => {
289
+ this._handleKeyup = e => {
328
290
  if (e.key === "Escape") {
329
291
  e.preventDefault();
330
292
  e.stopPropagation();
331
- _this.props.onClose();
293
+ this.props.onClose();
332
294
  }
333
295
  };
334
- _this._handleClick = e => {
296
+ this._handleClick = e => {
335
297
  var _this$props$contentRe;
336
- if (_this.state.isFirstClick) {
337
- _this.setState({
298
+ if (this.state.isFirstClick) {
299
+ this.setState({
338
300
  isFirstClick: false
339
301
  });
340
302
  return;
341
303
  }
342
- const node = ReactDOM.findDOMNode((_this$props$contentRe = _this.props.contentRef) == null ? void 0 : _this$props$contentRe.current);
304
+ const node = ReactDOM.findDOMNode((_this$props$contentRe = this.props.contentRef) == null ? void 0 : _this$props$contentRe.current);
343
305
  if (node && !node.contains(e.target)) {
344
306
  e.preventDefault();
345
307
  e.stopPropagation();
346
- _this.props.onClose();
308
+ this.props.onClose();
347
309
  }
348
310
  };
349
- return _this;
350
311
  }
351
- var _proto = PopoverEventListener.prototype;
352
- _proto.componentDidMount = function componentDidMount() {
312
+ componentDidMount() {
353
313
  window.addEventListener("keyup", this._handleKeyup);
354
314
  window.addEventListener("click", this._handleClick);
355
- };
356
- _proto.componentWillUnmount = function componentWillUnmount() {
315
+ }
316
+ componentWillUnmount() {
357
317
  window.removeEventListener("keyup", this._handleKeyup);
358
318
  window.removeEventListener("click", this._handleClick);
359
- };
360
- _proto.render = function render() {
319
+ }
320
+ render() {
361
321
  return null;
362
- };
363
- return PopoverEventListener;
364
- }(React.Component);
322
+ }
323
+ }
365
324
 
366
- let Popover = function (_React$Component) {
367
- _inheritsLoose(Popover, _React$Component);
368
- function Popover(...args) {
369
- var _this;
370
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
371
- _this.state = {
372
- opened: !!_this.props.opened,
325
+ class Popover extends React.Component {
326
+ constructor(...args) {
327
+ super(...args);
328
+ this.state = {
329
+ opened: !!this.props.opened,
373
330
  anchorElement: null,
374
- placement: _this.props.placement
331
+ placement: this.props.placement
375
332
  };
376
- _this.contentRef = React.createRef();
377
- _this.handleClose = () => {
378
- _this.setState({
333
+ this.contentRef = React.createRef();
334
+ this.handleClose = () => {
335
+ this.setState({
379
336
  opened: false
380
337
  }, () => {
381
- _this.props.onClose == null ? void 0 : _this.props.onClose();
338
+ var _this$props$onClose, _this$props;
339
+ (_this$props$onClose = (_this$props = this.props).onClose) == null ? void 0 : _this$props$onClose.call(_this$props);
382
340
  });
383
341
  };
384
- _this.handleOpen = () => {
385
- if (_this.props.dismissEnabled && _this.state.opened) {
386
- _this.setState({
342
+ this.handleOpen = () => {
343
+ if (this.props.dismissEnabled && this.state.opened) {
344
+ this.setState({
387
345
  opened: false
388
346
  });
389
347
  } else {
390
- _this.setState({
348
+ this.setState({
391
349
  opened: true
392
350
  });
393
351
  }
394
352
  };
395
- _this.updateRef = ref => {
353
+ this.updateRef = ref => {
396
354
  const actualRef = ref && ReactDOM.findDOMNode(ref);
397
- if (actualRef && _this.state.anchorElement !== actualRef) {
398
- _this.setState({
355
+ if (actualRef && this.state.anchorElement !== actualRef) {
356
+ this.setState({
399
357
  anchorElement: actualRef
400
358
  });
401
359
  }
402
360
  };
403
- return _this;
404
361
  }
405
- Popover.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
362
+ static getDerivedStateFromProps(props, state) {
406
363
  return {
407
364
  opened: typeof props.opened === "boolean" ? props.opened : state.opened
408
365
  };
409
- };
410
- var _proto = Popover.prototype;
411
- _proto.renderContent = function renderContent() {
366
+ }
367
+ renderContent() {
412
368
  const {
413
369
  content
414
370
  } = this.props;
@@ -418,8 +374,8 @@ let Popover = function (_React$Component) {
418
374
  return React.cloneElement(popoverContents, {
419
375
  ref: this.contentRef
420
376
  });
421
- };
422
- _proto.renderPopper = function renderPopper(uniqueId) {
377
+ }
378
+ renderPopper(uniqueId) {
423
379
  const {
424
380
  initialFocusId,
425
381
  placement
@@ -440,11 +396,11 @@ let Popover = function (_React$Component) {
440
396
  placement
441
397
  })
442
398
  }), this.renderContent())));
443
- };
444
- _proto.getHost = function getHost() {
399
+ }
400
+ getHost() {
445
401
  return maybeGetPortalMountedModalHostElement(this.state.anchorElement) || document.body;
446
- };
447
- _proto.render = function render() {
402
+ }
403
+ render() {
448
404
  const {
449
405
  children,
450
406
  dismissEnabled,
@@ -473,20 +429,14 @@ let Popover = function (_React$Component) {
473
429
  onClose: this.handleClose,
474
430
  contentRef: this.contentRef
475
431
  }));
476
- };
477
- return Popover;
478
- }(React.Component);
432
+ }
433
+ }
479
434
  Popover.defaultProps = {
480
435
  placement: "top"
481
436
  };
482
437
 
483
- let CloseButton = function (_React$Component) {
484
- _inheritsLoose(CloseButton, _React$Component);
485
- function CloseButton() {
486
- return _React$Component.apply(this, arguments) || this;
487
- }
488
- var _proto = CloseButton.prototype;
489
- _proto.render = function render() {
438
+ class CloseButton extends React.Component {
439
+ render() {
490
440
  const {
491
441
  light,
492
442
  "aria-label": ariaLabel,
@@ -506,21 +456,15 @@ let CloseButton = function (_React$Component) {
506
456
  testId: testId
507
457
  });
508
458
  });
509
- };
510
- return CloseButton;
511
- }(React.Component);
459
+ }
460
+ }
512
461
  CloseButton.defaultProps = {
513
462
  light: true,
514
463
  "aria-label": "Close Popover"
515
464
  };
516
465
 
517
- let PopoverContentCore = function (_React$Component) {
518
- _inheritsLoose(PopoverContentCore, _React$Component);
519
- function PopoverContentCore() {
520
- return _React$Component.apply(this, arguments) || this;
521
- }
522
- var _proto = PopoverContentCore.prototype;
523
- _proto.render = function render() {
466
+ class PopoverContentCore extends React.Component {
467
+ render() {
524
468
  const {
525
469
  children,
526
470
  closeButtonLight,
@@ -539,9 +483,8 @@ let PopoverContentCore = function (_React$Component) {
539
483
  style: styles$1.closeButton,
540
484
  testId: `${testId || "popover"}-close-btn`
541
485
  }), children);
542
- };
543
- return PopoverContentCore;
544
- }(React.Component);
486
+ }
487
+ }
545
488
  PopoverContentCore.defaultProps = {
546
489
  color: "white",
547
490
  closeButtonLight: false,
@@ -576,17 +519,15 @@ const styles$1 = StyleSheet.create({
576
519
  });
577
520
 
578
521
  const StyledImage = addStyle("img");
579
- let PopoverContent = function (_React$Component) {
580
- _inheritsLoose(PopoverContent, _React$Component);
581
- function PopoverContent(...args) {
582
- var _this;
583
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
584
- _this.maybeRenderImage = ({
522
+ class PopoverContent extends React.Component {
523
+ constructor(...args) {
524
+ super(...args);
525
+ this.maybeRenderImage = ({
585
526
  placement
586
527
  }) => {
587
528
  const {
588
529
  image
589
- } = _this.props;
530
+ } = this.props;
590
531
  if (!image) {
591
532
  return null;
592
533
  }
@@ -594,10 +535,10 @@ let PopoverContent = function (_React$Component) {
594
535
  style: [styles.image, placement === "bottom" && styles.imageToBottom]
595
536
  }, image);
596
537
  };
597
- _this.maybeRenderIcon = () => {
538
+ this.maybeRenderIcon = () => {
598
539
  const {
599
540
  icon
600
- } = _this.props;
541
+ } = this.props;
601
542
  if (!icon) {
602
543
  return null;
603
544
  }
@@ -608,10 +549,10 @@ let PopoverContent = function (_React$Component) {
608
549
  style: styles.icon
609
550
  }));
610
551
  };
611
- _this.maybeRenderActions = close => {
552
+ this.maybeRenderActions = close => {
612
553
  const {
613
554
  actions
614
- } = _this.props;
555
+ } = this.props;
615
556
  if (!actions) {
616
557
  return null;
617
558
  }
@@ -621,10 +562,8 @@ let PopoverContent = function (_React$Component) {
621
562
  close: close
622
563
  }) : actions);
623
564
  };
624
- return _this;
625
565
  }
626
- var _proto = PopoverContent.prototype;
627
- _proto.componentDidMount = function componentDidMount() {
566
+ componentDidMount() {
628
567
  const {
629
568
  icon,
630
569
  image
@@ -632,15 +571,15 @@ let PopoverContent = function (_React$Component) {
632
571
  if (image && icon) {
633
572
  throw new Error("'image' and 'icon' cannot be used at the same time. You can fix this by either removing 'image' or 'icon' from your instance.");
634
573
  }
635
- };
636
- _proto.validateProps = function validateProps({
574
+ }
575
+ validateProps({
637
576
  placement
638
577
  }) {
639
578
  if (this.props.image && (placement === "left" || placement === "right")) {
640
579
  throw new Error("'image' can only be vertically placed. You can fix this by either changing `placement` to `top` or `bottom` or removing the `image` prop inside `content`.");
641
580
  }
642
- };
643
- _proto.render = function render() {
581
+ }
582
+ render() {
644
583
  const {
645
584
  closeButtonLabel,
646
585
  closeButtonVisible,
@@ -677,9 +616,8 @@ let PopoverContent = function (_React$Component) {
677
616
  style: styles.title
678
617
  }, title), React.createElement(Body, null, content))), this.maybeRenderActions(close));
679
618
  });
680
- };
681
- return PopoverContent;
682
- }(React.Component);
619
+ }
620
+ }
683
621
  PopoverContent.defaultProps = {
684
622
  closeButtonVisible: false
685
623
  };
package/dist/index.js CHANGED
@@ -55,39 +55,20 @@ function _extends() {
55
55
  return _extends.apply(this, arguments);
56
56
  }
57
57
 
58
- function _setPrototypeOf(o, p) {
59
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
60
- o.__proto__ = p;
61
- return o;
62
- };
63
- return _setPrototypeOf(o, p);
64
- }
65
-
66
- function _inheritsLoose(subClass, superClass) {
67
- subClass.prototype = Object.create(superClass.prototype);
68
- subClass.prototype.constructor = subClass;
69
- _setPrototypeOf(subClass, superClass);
70
- }
71
-
72
58
  const defaultContext = {
73
59
  close: undefined,
74
60
  placement: "top"
75
61
  };
76
62
  var PopoverContext = React__namespace.createContext(defaultContext);
77
63
 
78
- let PopoverAnchor = function (_React$Component) {
79
- _inheritsLoose(PopoverAnchor, _React$Component);
80
- function PopoverAnchor() {
81
- return _React$Component.apply(this, arguments) || this;
82
- }
83
- var _proto = PopoverAnchor.prototype;
84
- _proto.componentDidMount = function componentDidMount() {
64
+ class PopoverAnchor extends React__namespace.Component {
65
+ componentDidMount() {
85
66
  const anchorNode = ReactDOM__namespace.findDOMNode(this);
86
67
  if (anchorNode) {
87
68
  this.props.anchorRef(anchorNode);
88
69
  }
89
- };
90
- _proto.render = function render() {
70
+ }
71
+ render() {
91
72
  const {
92
73
  children,
93
74
  id,
@@ -114,22 +95,16 @@ let PopoverAnchor = function (_React$Component) {
114
95
  } : onClick
115
96
  }));
116
97
  }
117
- };
118
- return PopoverAnchor;
119
- }(React__namespace.Component);
120
-
121
- let PopoverDialog = function (_React$Component) {
122
- _inheritsLoose(PopoverDialog, _React$Component);
123
- function PopoverDialog() {
124
- return _React$Component.apply(this, arguments) || this;
125
98
  }
126
- var _proto = PopoverDialog.prototype;
127
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
99
+ }
100
+
101
+ class PopoverDialog extends React__namespace.Component {
102
+ componentDidUpdate(prevProps) {
128
103
  if (prevProps.placement !== this.props.placement) {
129
104
  this.props.onUpdate(this.props.placement);
130
105
  }
131
- };
132
- _proto.render = function render() {
106
+ }
107
+ render() {
133
108
  const {
134
109
  placement,
135
110
  children,
@@ -156,9 +131,8 @@ let PopoverDialog = function (_React$Component) {
156
131
  placement: placement,
157
132
  offset: tailOffset
158
133
  })));
159
- };
160
- return PopoverDialog;
161
- }(React__namespace.Component);
134
+ }
135
+ }
162
136
  const styles$2 = aphrodite.StyleSheet.create({
163
137
  hide: {
164
138
  pointerEvents: "none",
@@ -185,13 +159,11 @@ function findFocusableNodes(root) {
185
159
  return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
186
160
  }
187
161
 
188
- let InitialFocus = function (_React$Component) {
189
- _inheritsLoose(InitialFocus, _React$Component);
190
- function InitialFocus(...args) {
191
- var _this;
192
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
193
- _this.setInitialFocusableElement = node => {
194
- const firstFocusableElement = _this.maybeGetInitialFocusElement(node) || _this.maybeGetFirstFocusableElement(node) || node;
162
+ class InitialFocus extends React__namespace.Component {
163
+ constructor(...args) {
164
+ super(...args);
165
+ this.setInitialFocusableElement = node => {
166
+ const firstFocusableElement = this.maybeGetInitialFocusElement(node) || this.maybeGetFirstFocusableElement(node) || node;
195
167
  if (firstFocusableElement === node) {
196
168
  node.tabIndex = -1;
197
169
  }
@@ -199,17 +171,15 @@ let InitialFocus = function (_React$Component) {
199
171
  firstFocusableElement.focus();
200
172
  }, 0);
201
173
  };
202
- return _this;
203
174
  }
204
- var _proto = InitialFocus.prototype;
205
- _proto.componentDidMount = function componentDidMount() {
175
+ componentDidMount() {
206
176
  const node = ReactDOM__namespace.findDOMNode(this);
207
177
  if (!node) {
208
178
  return;
209
179
  }
210
180
  this.setInitialFocusableElement(node);
211
- };
212
- _proto.maybeGetInitialFocusElement = function maybeGetInitialFocusElement(node) {
181
+ }
182
+ maybeGetInitialFocusElement(node) {
213
183
  const {
214
184
  initialFocusId
215
185
  } = this.props;
@@ -217,45 +187,42 @@ let InitialFocus = function (_React$Component) {
217
187
  return null;
218
188
  }
219
189
  return node.querySelector(`#${initialFocusId}`);
220
- };
221
- _proto.maybeGetFirstFocusableElement = function maybeGetFirstFocusableElement(node) {
190
+ }
191
+ maybeGetFirstFocusableElement(node) {
222
192
  const focusableElements = findFocusableNodes(node);
223
193
  if (!focusableElements.length) {
224
194
  return null;
225
195
  }
226
196
  return focusableElements[0];
227
- };
228
- _proto.render = function render() {
197
+ }
198
+ render() {
229
199
  return this.props.children;
230
- };
231
- return InitialFocus;
232
- }(React__namespace.Component);
200
+ }
201
+ }
233
202
 
234
- let FocusManager = function (_React$Component) {
235
- _inheritsLoose(FocusManager, _React$Component);
236
- function FocusManager(...args) {
237
- var _this;
238
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
239
- _this.nextElementAfterPopover = void 0;
240
- _this.rootNode = void 0;
241
- _this.focusableElementsInPopover = [];
242
- _this.addEventListeners = () => {
203
+ class FocusManager extends React__namespace.Component {
204
+ constructor(...args) {
205
+ super(...args);
206
+ this.nextElementAfterPopover = void 0;
207
+ this.rootNode = void 0;
208
+ this.focusableElementsInPopover = [];
209
+ this.addEventListeners = () => {
243
210
  const {
244
211
  anchorElement
245
- } = _this.props;
212
+ } = this.props;
246
213
  if (anchorElement) {
247
- anchorElement.addEventListener("keydown", _this.handleKeydownPreviousFocusableElement, true);
214
+ anchorElement.addEventListener("keydown", this.handleKeydownPreviousFocusableElement, true);
248
215
  }
249
- _this.nextElementAfterPopover = _this.getNextFocusableElement();
250
- if (_this.nextElementAfterPopover) {
251
- _this.nextElementAfterPopover.addEventListener("keydown", _this.handleKeydownNextFocusableElement, true);
216
+ this.nextElementAfterPopover = this.getNextFocusableElement();
217
+ if (this.nextElementAfterPopover) {
218
+ this.nextElementAfterPopover.addEventListener("keydown", this.handleKeydownNextFocusableElement, true);
252
219
  }
253
220
  };
254
- _this.getNextFocusableElement = () => {
221
+ this.getNextFocusableElement = () => {
255
222
  const {
256
223
  anchorElement
257
- } = _this.props;
258
- if (!anchorElement || _this.nextElementAfterPopover) {
224
+ } = this.props;
225
+ if (!anchorElement || this.nextElementAfterPopover) {
259
226
  return;
260
227
  }
261
228
  const focusableElements = findFocusableNodes(document);
@@ -266,7 +233,7 @@ let FocusManager = function (_React$Component) {
266
233
  }
267
234
  return;
268
235
  };
269
- _this.getComponentRootNode = node => {
236
+ this.getComponentRootNode = node => {
270
237
  if (!node) {
271
238
  return;
272
239
  }
@@ -274,42 +241,40 @@ let FocusManager = function (_React$Component) {
274
241
  if (!rootNode) {
275
242
  throw new Error("Assertion error: root node should exist after mount");
276
243
  }
277
- _this.rootNode = rootNode;
278
- _this.focusableElementsInPopover = findFocusableNodes(_this.rootNode);
244
+ this.rootNode = rootNode;
245
+ this.focusableElementsInPopover = findFocusableNodes(this.rootNode);
279
246
  };
280
- _this.handleFocusPreviousFocusableElement = () => {
281
- if (_this.props.anchorElement) {
282
- _this.props.anchorElement.focus();
247
+ this.handleFocusPreviousFocusableElement = () => {
248
+ if (this.props.anchorElement) {
249
+ this.props.anchorElement.focus();
283
250
  }
284
251
  };
285
- _this.handleFocusNextFocusableElement = () => {
286
- if (_this.nextElementAfterPopover) {
287
- _this.nextElementAfterPopover.focus();
252
+ this.handleFocusNextFocusableElement = () => {
253
+ if (this.nextElementAfterPopover) {
254
+ this.nextElementAfterPopover.focus();
288
255
  }
289
256
  };
290
- _this.handleKeydownPreviousFocusableElement = e => {
257
+ this.handleKeydownPreviousFocusableElement = e => {
291
258
  if (e.key === "Tab" && !e.shiftKey) {
292
259
  e.preventDefault();
293
- _this.focusableElementsInPopover[0].focus();
260
+ this.focusableElementsInPopover[0].focus();
294
261
  }
295
262
  };
296
- _this.handleKeydownNextFocusableElement = e => {
263
+ this.handleKeydownNextFocusableElement = e => {
297
264
  if (e.key === "Tab" && e.shiftKey) {
298
265
  e.preventDefault();
299
- const lastElementIndex = _this.focusableElementsInPopover.length - 1;
300
- _this.focusableElementsInPopover[lastElementIndex].focus();
266
+ const lastElementIndex = this.focusableElementsInPopover.length - 1;
267
+ this.focusableElementsInPopover[lastElementIndex].focus();
301
268
  }
302
269
  };
303
- return _this;
304
270
  }
305
- var _proto = FocusManager.prototype;
306
- _proto.componentDidMount = function componentDidMount() {
271
+ componentDidMount() {
307
272
  this.addEventListeners();
308
- };
309
- _proto.componentDidUpdate = function componentDidUpdate() {
273
+ }
274
+ componentDidUpdate() {
310
275
  this.addEventListeners();
311
- };
312
- _proto.componentWillUnmount = function componentWillUnmount() {
276
+ }
277
+ componentWillUnmount() {
313
278
  const {
314
279
  anchorElement
315
280
  } = this.props;
@@ -320,8 +285,8 @@ let FocusManager = function (_React$Component) {
320
285
  if (this.nextElementAfterPopover) {
321
286
  this.nextElementAfterPopover.removeEventListener("keydown", this.handleKeydownNextFocusableElement, true);
322
287
  }
323
- };
324
- _proto.render = function render() {
288
+ }
289
+ render() {
325
290
  const {
326
291
  children
327
292
  } = this.props;
@@ -342,103 +307,94 @@ let FocusManager = function (_React$Component) {
342
307
  position: "fixed"
343
308
  }
344
309
  }));
345
- };
346
- return FocusManager;
347
- }(React__namespace.Component);
310
+ }
311
+ }
348
312
 
349
- let PopoverEventListener = function (_React$Component) {
350
- _inheritsLoose(PopoverEventListener, _React$Component);
351
- function PopoverEventListener(...args) {
352
- var _this;
353
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
354
- _this.state = {
313
+ class PopoverEventListener extends React__namespace.Component {
314
+ constructor(...args) {
315
+ super(...args);
316
+ this.state = {
355
317
  isFirstClick: true
356
318
  };
357
- _this._handleKeyup = e => {
319
+ this._handleKeyup = e => {
358
320
  if (e.key === "Escape") {
359
321
  e.preventDefault();
360
322
  e.stopPropagation();
361
- _this.props.onClose();
323
+ this.props.onClose();
362
324
  }
363
325
  };
364
- _this._handleClick = e => {
326
+ this._handleClick = e => {
365
327
  var _this$props$contentRe;
366
- if (_this.state.isFirstClick) {
367
- _this.setState({
328
+ if (this.state.isFirstClick) {
329
+ this.setState({
368
330
  isFirstClick: false
369
331
  });
370
332
  return;
371
333
  }
372
- const node = ReactDOM__namespace.findDOMNode((_this$props$contentRe = _this.props.contentRef) == null ? void 0 : _this$props$contentRe.current);
334
+ const node = ReactDOM__namespace.findDOMNode((_this$props$contentRe = this.props.contentRef) == null ? void 0 : _this$props$contentRe.current);
373
335
  if (node && !node.contains(e.target)) {
374
336
  e.preventDefault();
375
337
  e.stopPropagation();
376
- _this.props.onClose();
338
+ this.props.onClose();
377
339
  }
378
340
  };
379
- return _this;
380
341
  }
381
- var _proto = PopoverEventListener.prototype;
382
- _proto.componentDidMount = function componentDidMount() {
342
+ componentDidMount() {
383
343
  window.addEventListener("keyup", this._handleKeyup);
384
344
  window.addEventListener("click", this._handleClick);
385
- };
386
- _proto.componentWillUnmount = function componentWillUnmount() {
345
+ }
346
+ componentWillUnmount() {
387
347
  window.removeEventListener("keyup", this._handleKeyup);
388
348
  window.removeEventListener("click", this._handleClick);
389
- };
390
- _proto.render = function render() {
349
+ }
350
+ render() {
391
351
  return null;
392
- };
393
- return PopoverEventListener;
394
- }(React__namespace.Component);
352
+ }
353
+ }
395
354
 
396
- let Popover = function (_React$Component) {
397
- _inheritsLoose(Popover, _React$Component);
398
- function Popover(...args) {
399
- var _this;
400
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
401
- _this.state = {
402
- opened: !!_this.props.opened,
355
+ class Popover extends React__namespace.Component {
356
+ constructor(...args) {
357
+ super(...args);
358
+ this.state = {
359
+ opened: !!this.props.opened,
403
360
  anchorElement: null,
404
- placement: _this.props.placement
361
+ placement: this.props.placement
405
362
  };
406
- _this.contentRef = React__namespace.createRef();
407
- _this.handleClose = () => {
408
- _this.setState({
363
+ this.contentRef = React__namespace.createRef();
364
+ this.handleClose = () => {
365
+ this.setState({
409
366
  opened: false
410
367
  }, () => {
411
- _this.props.onClose == null ? void 0 : _this.props.onClose();
368
+ var _this$props$onClose, _this$props;
369
+ (_this$props$onClose = (_this$props = this.props).onClose) == null ? void 0 : _this$props$onClose.call(_this$props);
412
370
  });
413
371
  };
414
- _this.handleOpen = () => {
415
- if (_this.props.dismissEnabled && _this.state.opened) {
416
- _this.setState({
372
+ this.handleOpen = () => {
373
+ if (this.props.dismissEnabled && this.state.opened) {
374
+ this.setState({
417
375
  opened: false
418
376
  });
419
377
  } else {
420
- _this.setState({
378
+ this.setState({
421
379
  opened: true
422
380
  });
423
381
  }
424
382
  };
425
- _this.updateRef = ref => {
383
+ this.updateRef = ref => {
426
384
  const actualRef = ref && ReactDOM__namespace.findDOMNode(ref);
427
- if (actualRef && _this.state.anchorElement !== actualRef) {
428
- _this.setState({
385
+ if (actualRef && this.state.anchorElement !== actualRef) {
386
+ this.setState({
429
387
  anchorElement: actualRef
430
388
  });
431
389
  }
432
390
  };
433
- return _this;
434
391
  }
435
- Popover.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
392
+ static getDerivedStateFromProps(props, state) {
436
393
  return {
437
394
  opened: typeof props.opened === "boolean" ? props.opened : state.opened
438
395
  };
439
- };
440
- var _proto = Popover.prototype;
441
- _proto.renderContent = function renderContent() {
396
+ }
397
+ renderContent() {
442
398
  const {
443
399
  content
444
400
  } = this.props;
@@ -448,8 +404,8 @@ let Popover = function (_React$Component) {
448
404
  return React__namespace.cloneElement(popoverContents, {
449
405
  ref: this.contentRef
450
406
  });
451
- };
452
- _proto.renderPopper = function renderPopper(uniqueId) {
407
+ }
408
+ renderPopper(uniqueId) {
453
409
  const {
454
410
  initialFocusId,
455
411
  placement
@@ -470,11 +426,11 @@ let Popover = function (_React$Component) {
470
426
  placement
471
427
  })
472
428
  }), this.renderContent())));
473
- };
474
- _proto.getHost = function getHost() {
429
+ }
430
+ getHost() {
475
431
  return wonderBlocksModal.maybeGetPortalMountedModalHostElement(this.state.anchorElement) || document.body;
476
- };
477
- _proto.render = function render() {
432
+ }
433
+ render() {
478
434
  const {
479
435
  children,
480
436
  dismissEnabled,
@@ -503,20 +459,14 @@ let Popover = function (_React$Component) {
503
459
  onClose: this.handleClose,
504
460
  contentRef: this.contentRef
505
461
  }));
506
- };
507
- return Popover;
508
- }(React__namespace.Component);
462
+ }
463
+ }
509
464
  Popover.defaultProps = {
510
465
  placement: "top"
511
466
  };
512
467
 
513
- let CloseButton = function (_React$Component) {
514
- _inheritsLoose(CloseButton, _React$Component);
515
- function CloseButton() {
516
- return _React$Component.apply(this, arguments) || this;
517
- }
518
- var _proto = CloseButton.prototype;
519
- _proto.render = function render() {
468
+ class CloseButton extends React__namespace.Component {
469
+ render() {
520
470
  const {
521
471
  light,
522
472
  "aria-label": ariaLabel,
@@ -536,21 +486,15 @@ let CloseButton = function (_React$Component) {
536
486
  testId: testId
537
487
  });
538
488
  });
539
- };
540
- return CloseButton;
541
- }(React__namespace.Component);
489
+ }
490
+ }
542
491
  CloseButton.defaultProps = {
543
492
  light: true,
544
493
  "aria-label": "Close Popover"
545
494
  };
546
495
 
547
- let PopoverContentCore = function (_React$Component) {
548
- _inheritsLoose(PopoverContentCore, _React$Component);
549
- function PopoverContentCore() {
550
- return _React$Component.apply(this, arguments) || this;
551
- }
552
- var _proto = PopoverContentCore.prototype;
553
- _proto.render = function render() {
496
+ class PopoverContentCore extends React__namespace.Component {
497
+ render() {
554
498
  const {
555
499
  children,
556
500
  closeButtonLight,
@@ -569,9 +513,8 @@ let PopoverContentCore = function (_React$Component) {
569
513
  style: styles$1.closeButton,
570
514
  testId: `${testId || "popover"}-close-btn`
571
515
  }), children);
572
- };
573
- return PopoverContentCore;
574
- }(React__namespace.Component);
516
+ }
517
+ }
575
518
  PopoverContentCore.defaultProps = {
576
519
  color: "white",
577
520
  closeButtonLight: false,
@@ -606,17 +549,15 @@ const styles$1 = aphrodite.StyleSheet.create({
606
549
  });
607
550
 
608
551
  const StyledImage = wonderBlocksCore.addStyle("img");
609
- let PopoverContent = function (_React$Component) {
610
- _inheritsLoose(PopoverContent, _React$Component);
611
- function PopoverContent(...args) {
612
- var _this;
613
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
614
- _this.maybeRenderImage = ({
552
+ class PopoverContent extends React__namespace.Component {
553
+ constructor(...args) {
554
+ super(...args);
555
+ this.maybeRenderImage = ({
615
556
  placement
616
557
  }) => {
617
558
  const {
618
559
  image
619
- } = _this.props;
560
+ } = this.props;
620
561
  if (!image) {
621
562
  return null;
622
563
  }
@@ -624,10 +565,10 @@ let PopoverContent = function (_React$Component) {
624
565
  style: [styles.image, placement === "bottom" && styles.imageToBottom]
625
566
  }, image);
626
567
  };
627
- _this.maybeRenderIcon = () => {
568
+ this.maybeRenderIcon = () => {
628
569
  const {
629
570
  icon
630
- } = _this.props;
571
+ } = this.props;
631
572
  if (!icon) {
632
573
  return null;
633
574
  }
@@ -638,10 +579,10 @@ let PopoverContent = function (_React$Component) {
638
579
  style: styles.icon
639
580
  }));
640
581
  };
641
- _this.maybeRenderActions = close => {
582
+ this.maybeRenderActions = close => {
642
583
  const {
643
584
  actions
644
- } = _this.props;
585
+ } = this.props;
645
586
  if (!actions) {
646
587
  return null;
647
588
  }
@@ -651,10 +592,8 @@ let PopoverContent = function (_React$Component) {
651
592
  close: close
652
593
  }) : actions);
653
594
  };
654
- return _this;
655
595
  }
656
- var _proto = PopoverContent.prototype;
657
- _proto.componentDidMount = function componentDidMount() {
596
+ componentDidMount() {
658
597
  const {
659
598
  icon,
660
599
  image
@@ -662,15 +601,15 @@ let PopoverContent = function (_React$Component) {
662
601
  if (image && icon) {
663
602
  throw new Error("'image' and 'icon' cannot be used at the same time. You can fix this by either removing 'image' or 'icon' from your instance.");
664
603
  }
665
- };
666
- _proto.validateProps = function validateProps({
604
+ }
605
+ validateProps({
667
606
  placement
668
607
  }) {
669
608
  if (this.props.image && (placement === "left" || placement === "right")) {
670
609
  throw new Error("'image' can only be vertically placed. You can fix this by either changing `placement` to `top` or `bottom` or removing the `image` prop inside `content`.");
671
610
  }
672
- };
673
- _proto.render = function render() {
611
+ }
612
+ render() {
674
613
  const {
675
614
  closeButtonLabel,
676
615
  closeButtonVisible,
@@ -707,9 +646,8 @@ let PopoverContent = function (_React$Component) {
707
646
  style: styles.title
708
647
  }, title), React__namespace.createElement(wonderBlocksTypography.Body, null, content))), this.maybeRenderActions(close));
709
648
  });
710
- };
711
- return PopoverContent;
712
- }(React__namespace.Component);
649
+ }
650
+ }
713
651
  PopoverContent.defaultProps = {
714
652
  closeButtonVisible: false
715
653
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-popover",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,13 +17,13 @@
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
19
  "@khanacademy/wonder-blocks-color": "^2.0.1",
20
- "@khanacademy/wonder-blocks-core": "^5.0.3",
21
- "@khanacademy/wonder-blocks-icon": "^2.0.5",
22
- "@khanacademy/wonder-blocks-icon-button": "^4.0.5",
23
- "@khanacademy/wonder-blocks-modal": "^4.0.5",
20
+ "@khanacademy/wonder-blocks-core": "^5.0.4",
21
+ "@khanacademy/wonder-blocks-icon": "^2.0.6",
22
+ "@khanacademy/wonder-blocks-icon-button": "^4.0.6",
23
+ "@khanacademy/wonder-blocks-modal": "^4.0.6",
24
24
  "@khanacademy/wonder-blocks-spacing": "^4.0.1",
25
- "@khanacademy/wonder-blocks-tooltip": "^2.0.5",
26
- "@khanacademy/wonder-blocks-typography": "^2.0.5"
25
+ "@khanacademy/wonder-blocks-tooltip": "^2.0.6",
26
+ "@khanacademy/wonder-blocks-typography": "^2.0.6"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@popperjs/core": "^2.10.1",
@@ -33,6 +33,6 @@
33
33
  "react-popper": "^2.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "wb-dev-build-settings": "^0.9.4"
36
+ "wb-dev-build-settings": "^0.9.5"
37
37
  }
38
38
  }