UNPKG

@enact/sandstone

Version:

Large-screen/TV support library for Enact, containing a variety of UI components.

188 lines (184 loc) 8.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.KeyGuideDecorator = exports.KeyGuideBase = exports.KeyGuide = void 0; var _kind = _interopRequireDefault(require("@enact/core/kind")); var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types")); var _FloatingLayer = _interopRequireDefault(require("@enact/ui/FloatingLayer")); var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure")); var _Repeater = _interopRequireDefault(require("@enact/ui/Repeater")); var _propTypes2 = _interopRequireDefault(require("prop-types")); var _compose = _interopRequireDefault(require("ramda/src/compose")); var _Icon = _interopRequireDefault(require("../Icon")); var _Item = require("../Item"); var _Marquee = require("../Marquee"); var _Skinnable = _interopRequireDefault(require("../Skinnable")); var _KeyGuideModule = _interopRequireDefault(require("./KeyGuide.module.css")); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["icon"], _excluded2 = ["open", "css"]; /** * Sandstone styled key guide component and behaviors. * * @example * <KeyGuide * open * > * {[ * {icon: 'star', children: 'start label', key: 1}, * {icon: 'plus', children: 'plus label', key: 2}, * {icon: 'minus', children: 'minus label', key: 3} * ]} * </KeyGuide> * * @module sandstone/KeyGuide * @exports KeyGuide * @exports KeyGuideBase * @exports KeyGuideDecorator */ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 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; } 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; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var colorKeys = ['red', 'green', 'yellow', 'blue']; /** * A Key Guide component. * * This component is most often not used directly but may be composed within another component as it * is within {@link sandstone/KeyGuide.KeyGuide|KeyGuide}. * * @class KeyGuideBase * @memberof sandstone/KeyGuide * @ui * @public */ var KeyGuideBase = exports.KeyGuideBase = (0, _kind["default"])({ name: 'KeyGuide', propTypes: /** @lends sandstone/KeyGuide.KeyGuideBase.prototype */{ /** * The items to be displayed in the `KeyGuide` when `open`. * * Takes an array of objects. The properties will be passed onto an `Item` component. * The object requires `children`, and a unique `key` property. If the `icon` property is one * of `'red'`, `'green'`, `'yellow'` or '`blue'`, a corresponding color bar is shown. * * @type {Array.<{children: (String|Component), key: (Number|String), icon: (String|Object|'red'|'green'|'yellow'|'blue')}>} * @public */ children: _propTypes2["default"].arrayOf(_propTypes2["default"].shape({ children: _propTypes["default"].renderable.isRequired, key: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].number]).isRequired, icon: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].object]) })), /** * Customizes the component by mapping the supplied collection of CSS class names to the * corresponding internal elements and states of this component. * * The following classes are supported: * * * `keyGuide` - The root component class * * @type {Object} * @public */ css: _propTypes2["default"].object, /** * Controls the visibility of the KeyGuide. * * @type {Boolean} * @public */ open: _propTypes2["default"].bool }, computed: { children: function children(_ref) { var _children = _ref.children, css = _ref.css; return _children ? _children.map(function (_ref2) { var icon = _ref2.icon, child = _objectWithoutProperties(_ref2, _excluded); var isColorKey = colorKeys.includes(icon); return _objectSpread(_objectSpread({}, child), {}, { slotBefore: isColorKey ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: css[icon] }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], { className: css.icon, children: icon }) }); }) : []; }, open: function open(_ref3) { var children = _ref3.children, _open = _ref3.open; return children && children.length > 0 && _open; } }, styles: { css: _KeyGuideModule["default"], className: 'keyGuide', publicClassNames: ['keyGuide'] }, render: function render(_ref4) { var open = _ref4.open, css = _ref4.css, rest = _objectWithoutProperties(_ref4, _excluded2); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FloatingLayer["default"], { noAutoDismiss: true, open: open, scrimType: "none", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Repeater["default"], _objectSpread(_objectSpread({}, rest), {}, { component: "div", childComponent: _Item.ItemBase, itemProps: { css: css, marqueeOn: 'render' } })) }); } }); /** * Applies Sandstone specific behaviors to {@link sandstone/KeyGuide.KeyGuideBase|KeyGuide}. * * @hoc * @memberof sandstone/KeyGuide * @mixes sandstone/Marquee.MarqueeController * @mixes sandstone/Skinnable.Skinnable * @public */ var KeyGuideDecorator = exports.KeyGuideDecorator = (0, _compose["default"])((0, _Marquee.MarqueeController)({ marqueeOnFocus: true }), _Pure["default"], _Skinnable["default"]); /** * A Key Guide component, ready to use in Sandstone applications. * * `KeyGuide' may be used to display list of text with icons to describe key behavior. * * Usage: * ``` * <KeyGuide * open * > * {[ * {icon: 'star', children: 'start label', key: 1}, * {icon: 'plus', children: 'plus label', key: 2}, * {icon: 'minus', children: 'minus label', key: 3} * ]} * </KeyGuide> * ``` * * @class KeyGuide * @memberof sandstone/KeyGuide * @extends sandstone/KeyGuide.KeyGuideBase * @mixes sandstone/KeyGuide.KeyGuideDecorator * @ui * @public */ var KeyGuide = exports.KeyGuide = KeyGuideDecorator(KeyGuideBase); var _default = exports["default"] = KeyGuide;