UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

108 lines (107 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DrawerListHorizontalItem = DrawerListHorizontalItem; exports.DrawerListItem = DrawerListItem; exports.ItemContent = ItemContent; var _clsx = _interopRequireDefault(require("clsx")); var _jsxRuntime = require("react/jsx-runtime"); var _react = require("react"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } 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