@enact/moonstone
Version:
Large-screen/TV support library for Enact, containing a variety of UI components.
245 lines (242 loc) • 9.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.SlotItemDecorator = exports.SlotItemBase = exports.SlotItem = void 0;
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _ForwardRef = _interopRequireDefault(require("@enact/ui/ForwardRef"));
var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _UiSlotItemModule = _interopRequireDefault(require("./UiSlotItem.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "component", "componentRef", "inline", "slotAfter", "slotBefore"];
/**
* An unstyled item component that accepts multiple positions of children.
*
* Using the usual `children` prop, as well as two additional props: `slotBefore`, and `slotAfter`.
* It is able to be customized by a theme or application.
*
* @module moonstone/UiSlotItem
* @exports SlotItem
* @exports SlotItemBase
* @exports SlotItemDecorator
*/
/**
* An ui-styled `SlotItem` without any behavior.
*
* @class SlotItemBase
* @memberof moonstone/UiSlotItem
* @ui
* @public
*/
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 SlotItemBase = exports.SlotItemBase = (0, _kind["default"])({
name: 'SlotItem',
propTypes: /** @lends moonstone/UiSlotItem.SlotItemBase.prototype */{
/**
* The type of component to use to render the item.
*
* This component will receive the `inline` prop and any additional unhandled props provided
* to `SlotItem`. A derivative of {@link ui/Item.Item|Item} is recommended.
*
* @type {String|Component}
* @default 'div'
* @required
* @public
*/
component: _propTypes["default"].component.isRequired,
/**
* Controls the visibility state of the slots.
*
* One, both, or neither slot can be shown. Choosing `'after'` will leave `slotBefore`
* visible at all times; only `slotAfter` will have its visibility toggled. Valid values
* are `'before'`, `'after'` and `'both'`. Omitting the property will result in
* no-auto-hiding for either slot so they will both be present.
*
* In order for `autoHide` to have a visual affect, the `hidden` class must be tied to
* another condition such as focus.
*
* ```
* .slot.hidden:not(:focus) {
* display: none;
* }
* ```
*
* @type {Boolean}
* @public
*/
autoHide: _propTypes2["default"].oneOf(['after', 'before', 'both']),
/**
* Called with a reference to the root component.
*
* When using {@link moonstone/UiSlotItem.SlotItem}, the `ref` prop is forwarded to this component
* as `componentRef`.
*
* @type {Object|Function}
* @public
*/
componentRef: _propTypes["default"].ref,
/**
* 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:
*
* * `slotItem` - The root class name
* * `slot` - Applied to both slots
* * `after` - Applied to the slot that falls after the content
* * `before` - Applied to the slot that falls before the content
* * `hidden` - Applied to a slot when that slot is supposed to be hidden, according to
* `autoHide` prop
*
* @type {Object}
* @public
*/
css: _propTypes2["default"].object,
/**
* Applies inline styling to the component.
*
* @type {Boolean}
* @default false
* @public
*/
inline: _propTypes2["default"].bool,
/**
* The layout technique for `SlotItem`.
*
* `"flex"` is applied as a default and gives basic flex support to the wrapping elements.
* This may be set to `null` to define your own layout method.
*
* @type {String}
* @default 'flex'
* @public
*/
layout: _propTypes2["default"].oneOf(['flex']),
/**
* Nodes to be inserted after `children` and hidden using `autoHide`.
*
* If nothing is specified, nothing, not even an empty container, is rendered in this place.
*
* @type {Node}
* @public
*/
slotAfter: _propTypes2["default"].node,
/**
* Nodes to be inserted before `children` and hidden using `autoHide`.
*
* If nothing is specified, nothing, not even an empty container, is rendered in this place.
*
* @type {Node}
* @public
*/
slotBefore: _propTypes2["default"].node
},
defaultProps: {
component: 'div',
inline: false,
layout: 'flex'
},
styles: {
css: _UiSlotItemModule["default"],
className: 'slotItem',
publicClassNames: true
},
computed: {
className: function className(_ref) {
var inline = _ref.inline,
layout = _ref.layout,
styler = _ref.styler;
return styler.append(layout, {
inline: inline
});
},
slotBefore: function slotBefore(_ref2) {
var _slotBefore = _ref2.slotBefore,
autoHide = _ref2.autoHide,
styler = _ref2.styler;
return _slotBefore ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: styler.join('slot', 'before', {
hidden: autoHide === 'before' || autoHide === 'both'
}),
children: _slotBefore
}) : null;
},
slotAfter: function slotAfter(_ref3) {
var _slotAfter = _ref3.slotAfter,
autoHide = _ref3.autoHide,
styler = _ref3.styler;
return _slotAfter ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: styler.join('slot', 'after', {
hidden: autoHide === 'after' || autoHide === 'both'
}),
children: _slotAfter
}) : null;
}
},
render: function render(_ref4) {
var children = _ref4.children,
Component = _ref4.component,
componentRef = _ref4.componentRef,
inline = _ref4.inline,
slotAfter = _ref4.slotAfter,
slotBefore = _ref4.slotBefore,
rest = _objectWithoutProperties(_ref4, _excluded);
delete rest.autoHide;
delete rest.layout;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Component, _objectSpread(_objectSpread({
ref: componentRef
}, rest), {}, {
inline: inline,
children: [slotBefore, children, slotAfter]
}));
}
});
/**
* An ui-specific higher-order component (HOC) with slot behaviors to apply to {@link moonstone/UiSlotItem.SlotItemBase|SlotItem}.
*
* @class SlotItemDecorator
* @memberof moonstone/UiSlotItem
* @mixes ui/Slottable.Slottable
* @mixes ui/ForwardRef.ForwardRef
* @hoc
* @public
*/
var SlotItemDecorator = exports.SlotItemDecorator = (0, _compose["default"])((0, _ForwardRef["default"])({
prop: 'componentRef'
}), (0, _Slottable["default"])({
slots: ['slotAfter', 'slotBefore']
}));
/**
* An ui-styled item with built-in support for slots.
*
* Example:
* ```
* <SlotItem component={Item} autoHide="both">
* <slotBefore>
* <Icon>flag</Icon>
* <Icon>star</Icon>
* </slotBefore>
* An Item that will show some icons slotBefore and slotAfter this text when spotted
* <Icon slot="slotAfter">trash</Icon>
* </SlotItem>
* ```
*
* @class SlotItem
* @memberof moonstone/UiSlotItem
* @extends moonstone/UiSlotItem.SlotItemBase
* @mixes moonstone/UiSlotItem.SlotItemDecorator
* @omit componentRef
* @ui
* @public
*/
var SlotItem = exports.SlotItem = SlotItemDecorator(SlotItemBase);
var _default = exports["default"] = SlotItem;