@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
99 lines • 2.64 kB
JavaScript
import React, { createElement as _createElement } from 'react';
import clsx from 'clsx';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export function DrawerListItem(props) {
const {
onClick,
role = 'option',
hash = '',
children,
className = null,
selected,
active = null,
value = null,
disabled,
ref,
...rest
} = props;
const params = {
className: clsx(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 (_createElement("li", {
...params,
...rest,
ref: ref,
key: 'li' + hash,
onClick: () => onClick({
selected,
value,
...rest
})
}, _jsx("span", {
className: "dnb-drawer-list__option__inner",
children: _jsx(ItemContent, {
hash: hash,
children: children
})
}))
);
}
export 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) => _jsx(DrawerListOptionItem, {
className: `item-nr-${n + 1}`,
children: isDataObject && children.render ? children.render(contentItem, hash + n) : contentItem
}, hash + n));
} else {
renderedContent = _jsx(DrawerListOptionItem, {
children: isDataObject && children.render ? children.render(content, hash) : content
});
}
}
return _jsxs(_Fragment, {
children: [renderedContent, isDataObject && children.suffixValue && _jsx(DrawerListOptionItem, {
className: "dnb-drawer-list__option__suffix",
children: children.suffixValue
})]
});
}
function DrawerListOptionItem({
children = undefined,
className = null,
...props
}) {
return _jsx("span", {
className: clsx('dnb-drawer-list__option__item', className),
...props,
children: children
});
}
export function DrawerListHorizontalItem({
className,
...props
}) {
return _jsx(DrawerListOptionItem, {
className: clsx('dnb-drawer-list__option__item--horizontal', className),
...props
});
}
//# sourceMappingURL=DrawerListItem.js.map