UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

109 lines (108 loc) 3.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DrawerListHorizontalItem = DrawerListHorizontalItem; exports.DrawerListItem = DrawerListItem; exports.ItemContent = ItemContent; var _react = _interopRequireWildcard(require("react")); var _clsx = _interopRequireDefault(require("clsx")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); } function DrawerListItem(props) { const { onClick, role = 'option', hash = '', children, className = null, selected, active = null, value = null, disabled, ref, ...rest } = props; const params = { className: (0, _clsx.default)(className, 'dnb-drawer-list__option', selected && 'dnb-drawer-list__option--selected', active && 'dnb-drawer-list__option--focus'), role, tabIndex: selected ? 0 : -1, disabled, 'aria-selected': !!selected, 'aria-disabled': disabled, onClick: () => onClick({ selected, value, ...rest }) }; if (active) { params['aria-current'] = true; } return ((0, _react.createElement)("li", { ...params, ...rest, ref: ref, key: 'li' + hash, onClick: () => onClick({ selected, value, ...rest }) }, (0, _jsxRuntime.jsx)("span", { className: "dnb-drawer-list__option__inner", children: (0, _jsxRuntime.jsx)(ItemContent, { hash: hash, children: children }) })) ); } function ItemContent({ hash = '', children }) { let renderedContent = undefined; const isDataObject = typeof children === 'object' && 'content' in children; const content = isDataObject ? children.content : children; if (content) { if (Array.isArray(content)) { renderedContent = content.map((contentItem, n) => (0, _jsxRuntime.jsx)(DrawerListOptionItem, { className: `item-nr-${n + 1}`, children: isDataObject && children.render ? children.render(contentItem, hash + n) : contentItem }, hash + n)); } else { renderedContent = (0, _jsxRuntime.jsx)(DrawerListOptionItem, { children: isDataObject && children.render ? children.render(content, hash) : content }); } } return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [renderedContent, isDataObject && children.suffixValue && (0, _jsxRuntime.jsx)(DrawerListOptionItem, { className: "dnb-drawer-list__option__suffix", children: children.suffixValue })] }); } function DrawerListOptionItem({ children = undefined, className = null, ...props }) { return (0, _jsxRuntime.jsx)("span", { className: (0, _clsx.default)('dnb-drawer-list__option__item', className), ...props, children: children }); } function DrawerListHorizontalItem({ className, ...props }) { return (0, _jsxRuntime.jsx)(DrawerListOptionItem, { className: (0, _clsx.default)('dnb-drawer-list__option__item--horizontal', className), ...props }); } //# sourceMappingURL=DrawerListItem.js.map