@enact/limestone 1.3.0 → 1.9.4

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 (166) hide show
  1. package/.github/workflows/ci-branch.yml +21 -0
  2. package/.github/workflows/ci-pull-request.yml +16 -0
  3. package/.github/workflows/ci-reusable.yml +73 -0
  4. package/ActionGuide/ActionGuide.d.ts +5 -4
  5. package/ActionGuide/ActionGuide.module.css +1 -1
  6. package/Alert/Alert.d.ts +4 -2
  7. package/Alert/Alert.js +4 -1
  8. package/Alert/Alert.module.css +36 -0
  9. package/BodyText/BodyText.d.ts +5 -4
  10. package/BodyText/BodyText.module.css +7 -7
  11. package/Button/Button.d.ts +17 -12
  12. package/Button/Button.js +1 -1
  13. package/Button/Button.module.css +195 -268
  14. package/CHANGELOG.md +226 -0
  15. package/Card/Card.d.ts +36 -8
  16. package/Card/Card.js +157 -20
  17. package/Card/Card.module.css +277 -58
  18. package/Card/tests/Card-specs.js +30 -0
  19. package/Checkbox/Checkbox.d.ts +8 -7
  20. package/Checkbox/Checkbox.js +3 -1
  21. package/Checkbox/Checkbox.module.css +213 -120
  22. package/Checkbox/tests/Checkbox-specs.js +1 -1
  23. package/CheckboxItem/CheckboxItem.d.ts +22 -7
  24. package/CheckboxItem/CheckboxItem.js +69 -4
  25. package/Chips/Chip.js +60 -7
  26. package/Chips/Chip.module.css +3 -3
  27. package/Chips/Chips.js +26 -12
  28. package/Chips/Chips.module.css +1 -1
  29. package/Chips/tests/Chip-specs.js +19 -9
  30. package/Chips/tests/Chips-specs.js +19 -19
  31. package/ContextualMenuDecorator/ContextualMenuDecorator.d.ts +4 -5
  32. package/ContextualPopupDecorator/ContextualPopup.module.css +34 -34
  33. package/ContextualPopupDecorator/ContextualPopupDecorator.js +557 -549
  34. package/DatePicker/DatePicker.d.ts +4 -5
  35. package/DayPicker/DayPicker.d.ts +8 -7
  36. package/Dropdown/Dropdown.d.ts +11 -13
  37. package/Dropdown/Dropdown.module.css +9 -9
  38. package/Dropdown/DropdownList.js +16 -11
  39. package/FixedPopupPanels/FixedPopupPanels.d.ts +4 -2
  40. package/FixedPopupPanels/FixedPopupPanels.module.css +18 -18
  41. package/FlexiblePopupPanels/FlexiblePopupPanels.module.css +23 -23
  42. package/FormCheckboxItem/FormCheckboxItem.d.ts +5 -4
  43. package/Heading/Heading.d.ts +8 -7
  44. package/Heading/Heading.module.css +5 -5
  45. package/Icon/Icon.d.ts +14 -4
  46. package/Icon/Icon.js +48 -2
  47. package/Icon/Icon.module.css +1 -1
  48. package/Icon/IconList.js +25 -1
  49. package/IconItem/IconItem.d.ts +13 -12
  50. package/IconItem/IconItem.js +15 -0
  51. package/IconItem/IconItem.module.css +107 -1
  52. package/Image/Image.d.ts +5 -4
  53. package/ImageItem/ImageItem.d.ts +11 -10
  54. package/ImageItem/ImageItem.js +37 -31
  55. package/ImageItem/ImageItem.module.css +30 -30
  56. package/ImageItem/tests/ImageItem-specs.js +3 -10
  57. package/Input/Input.js +9 -2
  58. package/Input/Input.module.css +37 -8
  59. package/Input/InputField.js +5 -1
  60. package/Input/InputField.module.css +17 -2
  61. package/Input/InputFieldSpotlightDecorator.js +213 -229
  62. package/Input/index.d.ts +15 -18
  63. package/Input/tests/InputField-specs.js +21 -0
  64. package/Item/Item.d.ts +16 -9
  65. package/Item/Item.js +20 -2
  66. package/Item/Item.module.css +1 -1
  67. package/KeyGuide/KeyGuide.d.ts +8 -7
  68. package/KeyGuide/KeyGuide.module.css +25 -1
  69. package/Marquee/Marquee.d.ts +2 -4
  70. package/MediaOverlay/MediaOverlay.d.ts +12 -11
  71. package/MediaOverlay/MediaOverlay.js +43 -21
  72. package/MediaOverlay/MediaOverlay.module.css +114 -15
  73. package/MediaPlayer/MediaControls.js +195 -13
  74. package/MediaPlayer/MediaControls.module.css +3 -2
  75. package/MediaPlayer/MediaSlider.module.css +7 -20
  76. package/MediaPlayer/index.d.ts +59 -7
  77. package/PageViews/PageViews.js +165 -80
  78. package/PageViews/PageViewsRouter.js +9 -0
  79. package/PageViews/tests/PageViews-specs.js +84 -0
  80. package/Panels/Header.js +48 -30
  81. package/Panels/Header.module.css +83 -31
  82. package/Panels/Panel.module.css +1 -1
  83. package/Panels/index.d.ts +7 -8
  84. package/Picker/Picker.d.ts +4 -5
  85. package/Picker/Picker.module.css +2 -2
  86. package/Popup/Popup.js +242 -240
  87. package/Popup/Popup.module.css +24 -24
  88. package/PopupTabLayout/PopupTabLayout.d.ts +5 -7
  89. package/PopupTabLayout/PopupTabLayout.js +15 -9
  90. package/PopupTabLayout/PopupTabLayout.module.css +53 -16
  91. package/PopupTabLayout/PopupTabLayoutStateContext.js +8 -0
  92. package/ProgressBar/ProgressBar.d.ts +5 -4
  93. package/ProgressBar/ProgressBarTooltip.module.css +12 -12
  94. package/ProgressButton/ProgressButton.d.ts +4 -5
  95. package/QuickGuidePanels/QuickGuidePanels.module.css +2 -2
  96. package/RadioItem/RadioItem.d.ts +18 -5
  97. package/RadioItem/RadioItem.js +67 -2
  98. package/RadioItem/RadioItem.module.css +36 -36
  99. package/RangePicker/RangePicker.module.css +2 -2
  100. package/Scroller/EditableWrapper.js +11 -4
  101. package/Scroller/Scroller.d.ts +20 -16
  102. package/Scroller/Scroller.js +9 -3
  103. package/Scroller/Scroller.module.css +4 -4
  104. package/Slider/Slider.d.ts +16 -14
  105. package/Slider/Slider.js +37 -4
  106. package/Slider/Slider.module.css +314 -91
  107. package/Slider/tests/Slider-specs.js +2 -1
  108. package/Spinner/Spinner.d.ts +5 -4
  109. package/Spinner/Spinner.module.css +9 -9
  110. package/Steps/Steps.d.ts +5 -4
  111. package/Steps/Steps.js +9 -5
  112. package/Switch/Switch.d.ts +8 -7
  113. package/Switch/Switch.module.css +100 -13
  114. package/SwitchItem/SwitchItem.d.ts +9 -6
  115. package/TabLayout/RefocusDecorator.js +15 -9
  116. package/TabLayout/TabGroup.js +3 -2
  117. package/TabLayout/TabGroup.module.css +2 -2
  118. package/TabLayout/TabLayout.d.ts +6 -0
  119. package/TabLayout/TabLayout.js +11 -1
  120. package/TabLayout/TabLayout.module.css +18 -0
  121. package/TabLayout/tests/TabLayout-specs.js +52 -0
  122. package/ThemeDecorator/ThemeDecorator.d.ts +9 -10
  123. package/ThemeDecorator/fontGenerator.js +1 -1
  124. package/ThemeDecorator/screenTypes.json +1 -0
  125. package/TimePicker/TimePicker.module.css +1 -1
  126. package/TooltipDecorator/Tooltip.module.css +1 -2
  127. package/TooltipDecorator/tests/util-specs.js +12 -0
  128. package/TooltipDecorator/useTooltip.js +1 -1
  129. package/TooltipDecorator/util.js +18 -11
  130. package/VideoPlayer/Feedback.js +3 -0
  131. package/VideoPlayer/Feedback.module.css +5 -9
  132. package/VideoPlayer/FeedbackIcons.js +1 -1
  133. package/VideoPlayer/FeedbackTooltip.module.css +55 -11
  134. package/VideoPlayer/VideoPlayer.d.ts +44 -18
  135. package/VideoPlayer/VideoPlayer.js +128 -23
  136. package/VideoPlayer/VideoPlayer.module.css +28 -11
  137. package/VirtualList/VirtualList.d.ts +9 -2
  138. package/VirtualList/VirtualList.js +31 -6
  139. package/VirtualList/tests/VirtualGridList-translate-specs.js +3 -0
  140. package/VirtualList/tests/VirtualList-specs.js +28 -1
  141. package/VirtualList/tests/VirtualList-translate-specs.js +4 -1
  142. package/VirtualList/tests/useEvent-specs.js +39 -0
  143. package/VirtualList/useEvent.js +45 -10
  144. package/VirtualList/useThemeVirtualList.js +3 -0
  145. package/WizardPanels/WizardPanels.module.css +2 -2
  146. package/WizardPanels/index.d.ts +4 -2
  147. package/fonts/Limestone_Icons.ttf +0 -0
  148. package/internal/$L/$L.js +3 -3
  149. package/internal/DateComponentPicker/DateComponentPicker.module.css +2 -2
  150. package/internal/DateTime/DateTime.module.css +1 -0
  151. package/internal/Panels/PanelsRouter.js +16 -5
  152. package/internal/Picker/Picker.module.css +2 -2
  153. package/internal/SharedStateDecorator/SharedStateDecorator.js +76 -99
  154. package/internal/validators/validators.js +21 -2
  155. package/package.json +14 -14
  156. package/styles/colors-highcontrast.less +9 -1
  157. package/styles/colors.less +11 -7
  158. package/styles/motion-mixins.less +66 -0
  159. package/styles/motions.less +78 -0
  160. package/styles/variables.less +176 -150
  161. package/useScroll/HoverToScroll.js +8 -5
  162. package/useScroll/ScrollbarTrack.module.css +8 -8
  163. package/useScroll/useEvent.js +7 -1
  164. package/useScroll/useScroll.js +2 -0
  165. package/useScroll/useScroll.module.css +6 -6
  166. package/.travis.yml +0 -40
package/Popup/Popup.js CHANGED
@@ -4,24 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.PopupBase = exports.Popup = void 0;
7
- var _keymap = require("@enact/core/keymap");
8
7
  var _dispatcher = require("@enact/core/dispatcher");
9
- var _FloatingLayer = _interopRequireDefault(require("@enact/ui/FloatingLayer"));
8
+ var _handle = require("@enact/core/handle");
9
+ var _keymap = require("@enact/core/keymap");
10
10
  var _kind = _interopRequireDefault(require("@enact/core/kind"));
11
- var _react = require("react");
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
+ var _util = require("@enact/core/util");
13
12
  var _spotlight = _interopRequireWildcard(require("@enact/spotlight"));
14
13
  var _Pause = _interopRequireDefault(require("@enact/spotlight/Pause"));
15
14
  var _SpotlightContainerDecorator = _interopRequireDefault(require("@enact/spotlight/SpotlightContainerDecorator"));
16
15
  var _container = require("@enact/spotlight/src/container");
16
+ var _FloatingLayer = _interopRequireDefault(require("@enact/ui/FloatingLayer"));
17
17
  var _Transition = _interopRequireDefault(require("@enact/ui/Transition"));
18
- var _handle = require("@enact/core/handle");
18
+ var _propTypes = _interopRequireDefault(require("prop-types"));
19
+ var _react = require("react");
19
20
  var _warning = _interopRequireDefault(require("warning"));
20
21
  var _Skinnable = _interopRequireDefault(require("../Skinnable"));
21
22
  var _PopupModule = _interopRequireDefault(require("./Popup.module.css"));
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
24
  var _excluded = ["children", "css", "direction", "noAnimation", "onHide", "onShow", "open", "position", "spotlightId", "spotlightRestrict", "transitionContainerClassName"],
24
- _excluded2 = ["noAutoDismiss", "scrimType"];
25
+ _excluded2 = ["noAnimation", "noAutoDismiss", "no5WayClose", "onClose", "open", "position", "scrimType", "spotlightRestrict"];
25
26
  /**
26
27
  * Modal component that appears at the bottom of the screen and takes up the full screen width.
27
28
  *
@@ -34,16 +35,12 @@ var _excluded = ["children", "css", "direction", "noAnimation", "onHide", "onSho
34
35
  */
35
36
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
36
37
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
37
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
38
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
39
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
40
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
41
- function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
42
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
43
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
44
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
45
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
46
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
38
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
39
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
40
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
41
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
42
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
43
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
47
44
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
48
45
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
49
46
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -304,257 +301,270 @@ var OpenState = {
304
301
  OPENING: 1,
305
302
  OPEN: 2
306
303
  };
304
+ var popupDefaultProps = {
305
+ noAnimation: false,
306
+ noAutoDismiss: false,
307
+ open: false,
308
+ position: 'bottom',
309
+ scrimType: 'translucent',
310
+ spotlightRestrict: 'self-only'
311
+ };
307
312
 
308
313
  /**
309
314
  * A stateful component that renders a popup in a
310
315
  * {@link ui/FloatingLayer.FloatingLayer|FloatingLayer}.
311
316
  *
312
- * @class Popup
317
+ * @function Popup
313
318
  * @memberof limestone/Popup
314
319
  * @extends limestone/Popup.PopupBase
315
320
  * @ui
316
321
  * @public
317
322
  */
318
- var Popup = exports.Popup = /*#__PURE__*/function (_Component) {
319
- function Popup(props) {
320
- var _this;
321
- _classCallCheck(this, Popup);
322
- _this = _callSuper(this, Popup, [props]);
323
- _this.handleFloatingLayerOpen = function () {
324
- if (!_this.props.noAnimation && _this.state.popupOpen !== OpenState.OPEN) {
325
- _this.setState({
326
- popupOpen: OpenState.OPENING
327
- });
328
- } else if (_this.state.popupOpen === OpenState.OPEN && _this.props.open) {
329
- _this.spotPopupContent();
330
- }
331
- };
332
- _this.handleKeyDown = function (ev) {
333
- var _this$props = _this.props,
334
- onClose = _this$props.onClose,
335
- no5WayClose = _this$props.no5WayClose,
336
- position = _this$props.position,
337
- spotlightRestrict = _this$props.spotlightRestrict;
338
- if (no5WayClose) return;
339
- var containerId = _this.state.containerId;
340
- var keyCode = ev.keyCode;
341
- var direction = (0, _spotlight.getDirection)(keyCode);
342
- var spottables = _spotlight["default"].getSpottableDescendants(containerId).length;
343
- var current = _spotlight["default"].getCurrent();
344
- if (direction && (!spottables || current && getContainerNode(containerId).contains(current))) {
345
- // explicitly restrict navigation in order to manage focus state when attempting to leave the popup
346
- _spotlight["default"].set(containerId, {
347
- restrict: 'self-only'
348
- });
349
- if (onClose) {
350
- var focusChanged;
351
- if (spottables && current && spotlightRestrict !== 'self-only') {
352
- focusChanged = _spotlight["default"].move(direction);
353
- if (focusChanged) {
354
- // stop propagation to prevent default spotlight behavior
355
- ev.stopPropagation();
356
- }
323
+ var Popup = exports.Popup = function Popup(props) {
324
+ var componentProps = (0, _util.setDefaultProps)(props, popupDefaultProps);
325
+ var noAnimation = componentProps.noAnimation,
326
+ noAutoDismiss = componentProps.noAutoDismiss,
327
+ no5WayClose = componentProps.no5WayClose,
328
+ onClose = componentProps.onClose,
329
+ open = componentProps.open,
330
+ position = componentProps.position,
331
+ scrimType = componentProps.scrimType,
332
+ spotlightRestrict = componentProps.spotlightRestrict,
333
+ rest = _objectWithoutProperties(componentProps, _excluded2);
334
+
335
+ // Assign the needed props to the rest object for the child component
336
+ Object.assign(rest, {
337
+ noAnimation: noAnimation,
338
+ position: position,
339
+ spotlightRestrict: spotlightRestrict
340
+ });
341
+ var _useState = (0, _react.useState)(null),
342
+ _useState2 = _slicedToArray(_useState, 2),
343
+ activator = _useState2[0],
344
+ setActivator = _useState2[1];
345
+ var _useState3 = (0, _react.useState)(false),
346
+ _useState4 = _slicedToArray(_useState3, 2),
347
+ addKeyDownListener = _useState4[0],
348
+ setAddKeyDownListener = _useState4[1];
349
+ var _useState5 = (0, _react.useState)(open),
350
+ _useState6 = _slicedToArray(_useState5, 2),
351
+ floatLayerOpen = _useState6[0],
352
+ setFloatLayerOpen = _useState6[1];
353
+ var _useState7 = (0, _react.useState)(open ? OpenState.OPEN : OpenState.CLOSED),
354
+ _useState8 = _slicedToArray(_useState7, 2),
355
+ popupOpen = _useState8[0],
356
+ setPopupOpen = _useState8[1];
357
+ var _useState9 = (0, _react.useState)(open),
358
+ _useState0 = _slicedToArray(_useState9, 2),
359
+ prevOpen = _useState0[0],
360
+ setPrevOpen = _useState0[1];
361
+ var containerIdRef = (0, _react.useRef)(null);
362
+ var pausedRef = (0, _react.useRef)(new _Pause["default"]('Popup'));
363
+ if (!containerIdRef.current) {
364
+ containerIdRef.current = _spotlight["default"].add();
365
+ }
366
+ var getDerivedStateFromProps = (0, _react.useCallback)(function () {
367
+ if (open !== prevOpen) {
368
+ if (open) {
369
+ setPopupOpen(noAnimation || floatLayerOpen ? OpenState.OPEN : OpenState.CLOSED);
370
+ setFloatLayerOpen(true);
371
+ setActivator(_spotlight["default"].getCurrent());
372
+ setPrevOpen(open);
373
+ } else {
374
+ // Disables the spotlight container of popup when `noAnimation` set
375
+ if (noAnimation) {
376
+ var node = getContainerNode(containerIdRef.current);
377
+ if (node) {
378
+ node.dataset['spotlightContainerDisabled'] = true;
357
379
  }
358
- if (!spottables || focusChanged === false && (position === 'center' || isUp(keyCode) && position === 'bottom' || isDown(keyCode) && position === 'top' || isRight(keyCode) && position === 'left' || isLeft(keyCode) && position === 'right')) {
359
- // prevent default page scrolling
360
- ev.preventDefault();
380
+ }
381
+ setPopupOpen(OpenState.CLOSED);
382
+ setFloatLayerOpen(popupOpen === OpenState.OPEN ? !noAnimation : false);
383
+ setActivator(noAnimation ? null : activator);
384
+ setPrevOpen(open);
385
+ }
386
+ }
387
+ return null;
388
+ }, [activator, floatLayerOpen, noAnimation, open, popupOpen, prevOpen]);
389
+ var handleKeyDown = (0, _react.useCallback)(function (ev) {
390
+ if (no5WayClose) return;
391
+ var keyCode = ev.keyCode;
392
+ var direction = (0, _spotlight.getDirection)(keyCode);
393
+ var spottables = _spotlight["default"].getSpottableDescendants(containerIdRef.current).length;
394
+ var current = _spotlight["default"].getCurrent();
395
+ if (direction && (!spottables || current && getContainerNode(containerIdRef.current).contains(current))) {
396
+ // explicitly restrict navigation in order to manage focus state when attempting to leave the popup
397
+ _spotlight["default"].set(containerIdRef.current, {
398
+ restrict: 'self-only'
399
+ });
400
+ if (onClose) {
401
+ var focusChanged;
402
+ if (spottables && current && spotlightRestrict !== 'self-only') {
403
+ focusChanged = _spotlight["default"].move(direction);
404
+ if (focusChanged) {
361
405
  // stop propagation to prevent default spotlight behavior
362
406
  ev.stopPropagation();
363
- // set the pointer mode to false on keydown
364
- _spotlight["default"].setPointerMode(false);
365
- (0, _handle.forwardCustom)('onClose')(null, _this.props);
366
407
  }
367
408
  }
368
- }
369
- };
370
- _this.handleDismiss = function (ev) {
371
- (0, _handle.forwardCustom)('onClose', function () {
372
- return {
373
- detail: ev === null || ev === void 0 ? void 0 : ev.detail
374
- };
375
- })(null, _this.props);
376
- };
377
- _this.handlePopupHide = function (ev) {
378
- forwardHide(ev, _this.props);
379
- _this.setState({
380
- floatLayerOpen: false
381
- }, function () {
382
- if (!ev.currentTarget || ev.currentTarget.getAttribute('data-spotlight-id') === _this.state.containerId) {
383
- _this.spotActivator(_this.state.activator);
409
+ if (!spottables || focusChanged === false && (position === 'center' || isUp(keyCode) && position === 'bottom' || isDown(keyCode) && position === 'top' || isRight(keyCode) && position === 'left' || isLeft(keyCode) && position === 'right')) {
410
+ // prevent default page scrolling
411
+ ev.preventDefault();
412
+ // stop propagation to prevent default spotlight behavior
413
+ ev.stopPropagation();
414
+ // set the pointer mode to false on keydown
415
+ _spotlight["default"].setPointerMode(false);
416
+ (0, _handle.forwardCustom)('onClose')(null, componentProps);
384
417
  }
385
- _this.setState({
386
- activator: null
387
- });
388
- });
389
- };
390
- _this.handlePopupShow = function (ev) {
391
- forwardShow(ev, _this.props);
392
- _this.setState({
393
- popupOpen: OpenState.OPEN
394
- });
395
- if (!ev.currentTarget || ev.currentTarget.getAttribute('data-spotlight-id') === _this.state.containerId) {
396
- _this.spotPopupContent();
397
418
  }
398
- };
399
- _this.spotActivator = function (activator) {
400
- _this.paused.resume();
419
+ }
420
+ }, [componentProps, no5WayClose, onClose, position, spotlightRestrict]);
421
+ var spotActivator = (0, _react.useCallback)(function () {
422
+ pausedRef.current.resume();
401
423
 
402
- // only spot the activator if the popup is closed
403
- if (_this.props.open) return;
404
- var current = _spotlight["default"].getCurrent();
405
- var containerNode = getContainerNode(_this.state.containerId);
406
- var lastContainerId = (0, _container.getLastContainer)();
407
- (0, _dispatcher.off)('keydown', _this.handleKeyDown);
424
+ // only spot the activator if the popup is closed
425
+ if (open) return;
426
+ var current = _spotlight["default"].getCurrent();
427
+ var containerNode = getContainerNode(containerIdRef.current);
428
+ var lastContainerId = (0, _container.getLastContainer)();
429
+ setAddKeyDownListener(false);
408
430
 
409
- // if there is no currently-spotted control, or it is wrapped by the popup's container, we
410
- // know it's safe to change focus
411
- if (!current || containerNode && containerNode.contains(current)) {
412
- // attempt to set focus to the activator, if available
413
- if (!_spotlight["default"].isPaused()) {
414
- if (activator) {
415
- if (!_spotlight["default"].focus(activator)) {
416
- _spotlight["default"].focus();
417
- }
418
- } else {
419
- _spotlight["default"].disableSelector(lastContainerId);
431
+ // if there is no currently-spotted control, or it is wrapped by the popup's container, we
432
+ // know it's safe to change focus
433
+ if (!current || containerNode && containerNode.contains(current)) {
434
+ // attempt to set focus to the activator, if available
435
+ if (!_spotlight["default"].isPaused() || !pausedRef.current.isPaused()) {
436
+ if (activator) {
437
+ if (!_spotlight["default"].focus(activator)) {
420
438
  _spotlight["default"].focus();
421
- _spotlight["default"].enableSelector(lastContainerId);
422
439
  }
440
+ } else {
441
+ _spotlight["default"].disableSelector(lastContainerId);
442
+ _spotlight["default"].focus();
443
+ _spotlight["default"].enableSelector(lastContainerId);
423
444
  }
424
445
  }
425
- };
426
- _this.spotPopupContent = function () {
427
- _this.paused.resume();
446
+ }
447
+ }, [activator, open]);
448
+ var spotPopupContent = (0, _react.useCallback)(function () {
449
+ pausedRef.current.resume();
428
450
 
429
- // only spot the activator if the popup is open
430
- if (!_this.props.open) return;
431
- var containerId = _this.state.containerId;
432
- (0, _dispatcher.on)('keydown', _this.handleKeyDown);
433
- if (!_spotlight["default"].isPaused() && !_spotlight["default"].focus(containerId)) {
434
- var current = _spotlight["default"].getCurrent();
451
+ // only spot the activator if the popup is open
452
+ if (!open) return;
453
+ setAddKeyDownListener(true);
454
+ if (!_spotlight["default"].isPaused() && !_spotlight["default"].focus(containerIdRef.current)) {
455
+ var current = _spotlight["default"].getCurrent();
435
456
 
436
- // In cases where the container contains no spottable controls, or we're in pointer-mode, focus
437
- // cannot inherently set the active container or blur the active control, so we must do that
438
- // here.
439
- if (current) {
440
- current.blur();
441
- }
442
- _spotlight["default"].setActiveContainer(containerId);
457
+ // In cases where the container contains no spottable controls, or we're in pointer-mode, focus
458
+ // cannot inherently set the active container or blur the active control, so we must do that
459
+ // here.
460
+ if (current) {
461
+ current.blur();
443
462
  }
444
- };
445
- _this.paused = new _Pause["default"]('Popup');
446
- _this.state = {
447
- floatLayerOpen: _this.props.open,
448
- popupOpen: _this.props.open ? OpenState.OPEN : OpenState.CLOSED,
449
- prevOpen: _this.props.open,
450
- containerId: _spotlight["default"].add(),
451
- activator: null
452
- };
453
- checkScrimNone(_this.props);
454
- return _this;
455
- }
456
-
457
- // Spot the content after it's mounted.
458
- _inherits(Popup, _Component);
459
- return _createClass(Popup, [{
460
- key: "componentDidMount",
461
- value: function componentDidMount() {
462
- if (this.props.open) {
463
- // If the popup is open on mount, we need to pause spotlight so nothing steals focus
464
- // while the popup is rendering.
465
- this.paused.pause();
466
- if (getContainerNode(this.state.containerId)) {
467
- this.spotPopupContent();
468
- }
463
+ _spotlight["default"].setActiveContainer(containerIdRef.current);
464
+ }
465
+ }, [open]);
466
+ var handleFloatingLayerOpen = (0, _react.useCallback)(function () {
467
+ if (!noAnimation && popupOpen !== OpenState.OPEN) {
468
+ setPopupOpen(OpenState.OPENING);
469
+ } else if (popupOpen === OpenState.OPEN && open) {
470
+ spotPopupContent();
471
+ }
472
+ }, [noAnimation, open, popupOpen, spotPopupContent]);
473
+ var handleDismiss = (0, _react.useCallback)(function (ev) {
474
+ (0, _handle.forwardCustom)('onClose', function () {
475
+ return {
476
+ detail: ev === null || ev === void 0 ? void 0 : ev.detail
477
+ };
478
+ })(null, componentProps);
479
+ }, [componentProps]);
480
+ var handlePopupHide = (0, _react.useCallback)(function (ev) {
481
+ forwardHide(ev, componentProps);
482
+ setFloatLayerOpen(function () {
483
+ if (!ev.currentTarget || ev.currentTarget.getAttribute('data-spotlight-id') === containerIdRef.current) {
484
+ spotActivator();
469
485
  }
486
+ setActivator(null);
487
+ return false;
488
+ });
489
+ }, [componentProps, spotActivator]);
490
+ var handlePopupShow = (0, _react.useCallback)(function (ev) {
491
+ forwardShow(ev, componentProps);
492
+ setPopupOpen(OpenState.OPEN);
493
+ if (!ev.currentTarget || ev.currentTarget.getAttribute('data-spotlight-id') === containerIdRef.current) {
494
+ spotPopupContent();
470
495
  }
471
- }, {
472
- key: "componentDidUpdate",
473
- value: function componentDidUpdate(prevProps, prevState) {
474
- if (this.props.open !== prevProps.open) {
475
- if (!this.props.noAnimation) {
476
- if (!this.props.open && this.state.popupOpen === OpenState.CLOSED) {
477
- // If the popup is supposed to be closed (!this.props.open) and is actually
478
- // fully closed (OpenState.CLOSED), we must resume spotlight navigation. This
479
- // can occur when quickly toggling a Popup open and closed.
480
- this.paused.resume();
481
- } else {
482
- // Otherwise, we pause spotlight so it is locked until the popup is ready
483
- this.paused.pause();
484
- }
485
- } else if (this.props.open) {
486
- forwardShow(null, this.props);
487
- this.spotPopupContent();
488
- } else if (prevProps.open) {
489
- forwardHide(null, this.props);
490
- this.spotActivator(prevState.activator);
496
+ }, [componentProps, spotPopupContent]);
497
+ (0, _react.useLayoutEffect)(function () {
498
+ getDerivedStateFromProps();
499
+ }, [getDerivedStateFromProps]);
500
+ (0, _react.useEffect)(function () {
501
+ if (open !== prevOpen) {
502
+ if (!noAnimation) {
503
+ if (!open && (popupOpen === OpenState.OPENING || popupOpen === OpenState.OPEN)) {
504
+ // If the popup is supposed to be closed (!open) and is actually not fully
505
+ // closed (OpenState.OPENING or OpenState.OPEN), we must resume spotlight navigation. This
506
+ // can occur when quickly toggling a Popup open and closed.
507
+ pausedRef.current.resume();
508
+ } else {
509
+ // Otherwise, we pause spotlight so it is locked until the popup is ready
510
+ pausedRef.current.pause();
491
511
  }
512
+ } else if (open) {
513
+ forwardShow(null, componentProps);
514
+ spotPopupContent();
515
+ } else if (prevOpen) {
516
+ forwardHide(null, componentProps);
517
+ spotActivator();
492
518
  }
493
- checkScrimNone(this.props);
494
519
  }
495
- }, {
496
- key: "componentWillUnmount",
497
- value: function componentWillUnmount() {
498
- if (this.props.open) {
499
- (0, _dispatcher.off)('keydown', this.handleKeyDown);
520
+ checkScrimNone(componentProps);
521
+ }, [componentProps, noAnimation, open, popupOpen, prevOpen, spotActivator, spotPopupContent]);
522
+ (0, _react.useEffect)(function () {
523
+ checkScrimNone(componentProps);
524
+
525
+ // Spot the content after it's mounted.
526
+ if (open) {
527
+ // If the popup is open on mount, we need to pause spotlight so nothing steals focus
528
+ // while the popup is rendering.
529
+ pausedRef.current.pause();
530
+ if (getContainerNode(containerIdRef.current)) {
531
+ spotPopupContent();
500
532
  }
501
- _spotlight["default"].remove(this.state.containerId);
502
- }
503
- }, {
504
- key: "render",
505
- value: function render() {
506
- var _this$props2 = this.props,
507
- noAutoDismiss = _this$props2.noAutoDismiss,
508
- scrimType = _this$props2.scrimType,
509
- rest = _objectWithoutProperties(_this$props2, _excluded2);
510
- delete rest.no5WayClose;
511
- delete rest.onClose;
512
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FloatingLayer["default"], {
513
- noAutoDismiss: noAutoDismiss,
514
- open: this.state.floatLayerOpen,
515
- onOpen: this.handleFloatingLayerOpen,
516
- onDismiss: this.handleDismiss,
517
- scrimType: scrimType,
518
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(SkinnedPopupBase, _objectSpread(_objectSpread({}, rest), {}, {
519
- "data-webos-voice-exclusive": true,
520
- onHide: this.handlePopupHide,
521
- onShow: this.handlePopupShow,
522
- open: this.state.popupOpen >= OpenState.OPENING,
523
- spotlightId: this.state.containerId
524
- }))
525
- });
526
533
  }
527
- }], [{
528
- key: "getDerivedStateFromProps",
529
- value: function getDerivedStateFromProps(props, state) {
530
- if (props.open !== state.prevOpen) {
531
- if (props.open) {
532
- return {
533
- popupOpen: props.noAnimation || state.floatLayerOpen ? OpenState.OPEN : OpenState.CLOSED,
534
- floatLayerOpen: true,
535
- activator: _spotlight["default"].getCurrent(),
536
- prevOpen: props.open
537
- };
538
- } else {
539
- // Disables the spotlight conatiner of popup when `noAnimation` set
540
- if (props.noAnimation) {
541
- var node = getContainerNode(state.containerId);
542
- if (node) {
543
- node.dataset['spotlightContainerDisabled'] = true;
544
- }
545
- }
546
- return {
547
- popupOpen: OpenState.CLOSED,
548
- floatLayerOpen: state.popupOpen === OpenState.OPEN ? !props.noAnimation : false,
549
- activator: props.noAnimation ? null : state.activator,
550
- prevOpen: props.open
551
- };
552
- }
534
+ return function () {
535
+ if (open) {
536
+ (0, _dispatcher.off)('keydown', handleKeyDown);
553
537
  }
554
- return null;
538
+ _spotlight["default"].remove(containerIdRef.current);
539
+ };
540
+ // eslint-disable-next-line react-hooks/exhaustive-deps
541
+ }, []);
542
+ (0, _react.useEffect)(function () {
543
+ if (addKeyDownListener) {
544
+ (0, _dispatcher.on)('keydown', handleKeyDown);
545
+ } else {
546
+ (0, _dispatcher.off)('keydown', handleKeyDown);
555
547
  }
556
- }]);
557
- }(_react.Component);
548
+ return function () {
549
+ (0, _dispatcher.off)('keydown', handleKeyDown);
550
+ };
551
+ }, [addKeyDownListener, handleKeyDown]);
552
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FloatingLayer["default"], {
553
+ noAutoDismiss: noAutoDismiss,
554
+ open: floatLayerOpen,
555
+ onOpen: handleFloatingLayerOpen,
556
+ onDismiss: handleDismiss,
557
+ scrimType: scrimType,
558
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(SkinnedPopupBase, _objectSpread(_objectSpread({}, rest), {}, {
559
+ "data-webos-voice-exclusive": true,
560
+ onHide: handlePopupHide,
561
+ onShow: handlePopupShow,
562
+ open: popupOpen >= OpenState.OPENING,
563
+ spotlightId: containerIdRef.current
564
+ }))
565
+ });
566
+ };
567
+ Popup.displayName = 'Popup';
558
568
  Popup.propTypes = /** @lends limestone/Popup.Popup.prototype */{
559
569
  /**
560
570
  * Prevents closing the popup via 5-way navigation out of the content.
@@ -679,12 +689,4 @@ Popup.propTypes = /** @lends limestone/Popup.Popup.prototype */{
679
689
  */
680
690
  spotlightRestrict: _propTypes["default"].oneOf(['self-first', 'self-only'])
681
691
  };
682
- Popup.defaultProps = {
683
- noAnimation: false,
684
- noAutoDismiss: false,
685
- open: false,
686
- position: 'bottom',
687
- scrimType: 'translucent',
688
- spotlightRestrict: 'self-only'
689
- };
690
692
  var _default = exports["default"] = Popup;