@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
97 lines (95 loc) • 5.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pickGroupItemProps = exports["default"] = exports.GroupItemBase = exports.GroupItem = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _selection = require("../internal/selection");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["$$GroupItem", "handleSelect"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
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; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : 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); } /*
* Exports the {@link ui/Group.GroupItem} and {@link ui/Group.GroupItemBase}
* components as well as the `pickGroupItemProps` method. The default export is {@link ui/Group.GroupItem}.
* `GroupItem` is stateless and is the same as `GroupItemBase`.
* NOTE: not jsdoc on purpose.
*/ /**
* Pick the `GroupItem`-specific props into a {@link /developer-guide/glossary/#private|private} `itemProps` key to be extracted by
* `GroupItem` before passing the remaining on to the repeated `childComponent`
*
* @function
* @param {Object} props `Group` props
* @returns {Object} `GroupItem` props
* @private
*/
var pickGroupItemProps = exports.pickGroupItemProps = function pickGroupItemProps(props) {
return {
$$GroupItem: {
childComponent: props.childComponent,
childProp: props.childProp,
childSelect: props.childSelect,
indexProp: props.indexProp,
onSelect: props.onSelect,
select: props.select,
selected: props.selected,
selectedEventProp: props.selectedEventProp,
selectedProp: props.selectedProp
}
};
};
/**
* {@link ui/Group.GroupItem} is a stateless component that is used within a
* {@link ui/Group.Group}. It supports passing the configurable selected property and
* handler to its configured `childComponent`.
*
* **Note**: It receives its properties through the `$$GroupItem` property passed from `Group`'s
* {@link ui/Repeater.Repeater}.
*
* @class GroupItemBase
* @memberof ui/Group
* @ui
* @private
*/
var GroupItemBase = exports.GroupItemBase = exports.GroupItem = (0, _kind["default"])({
name: 'GroupItem',
handlers: {
handleSelect: function handleSelect(ev, props) {
var _props$$$GroupItem = props.$$GroupItem,
childProp = _props$$$GroupItem.childProp,
indexProp = _props$$$GroupItem.indexProp,
onSelect = _props$$$GroupItem.onSelect,
select = _props$$$GroupItem.select,
selected = _props$$$GroupItem.selected,
selectedEventProp = _props$$$GroupItem.selectedEventProp;
if (onSelect) {
var index = props[indexProp];
onSelect(_defineProperty(_defineProperty({}, selectedEventProp, props[childProp]), "selected", (0, _selection.select)(select, index, selected)));
}
}
},
render: function render(props) {
var _props$$$GroupItem2 = props.$$GroupItem,
Component = _props$$$GroupItem2.childComponent,
childSelect = _props$$$GroupItem2.childSelect,
indexProp = _props$$$GroupItem2.indexProp,
selected = _props$$$GroupItem2.selected,
selectedProp = _props$$$GroupItem2.selectedProp,
handleSelect = props.handleSelect,
rest = _objectWithoutProperties(props, _excluded);
if (selectedProp) {
var index = rest[indexProp];
rest[selectedProp] = (0, _selection.isSelected)(index, selected);
}
if (childSelect) {
rest[childSelect] = handleSelect;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread({}, rest));
}
});
var _default = exports["default"] = GroupItemBase;