@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
42 lines • 1.54 kB
JavaScript
var _Td;
import React, { useCallback } from 'react';
import Td from "../TableTd.js";
import { TableContext } from "../TableContext.js";
import { TableClickableButtonTd, TableClickableHead, TableIconSrTh, isTableHead, onClickTr } from "../TableClickableHead.js";
import { jsx as _jsx } from "react/jsx-runtime";
export function TableNavigationHead(allProps) {
const {
children,
onClick,
...props
} = allProps;
const tableContext = React.useContext(TableContext);
const content = Array.isArray(children) ? [...children] : [children];
const hasOnClick = typeof onClick === 'function';
const tableContextAllProps = React.useContext(TableContext)?.allProps;
const onClickHandler = useCallback((event, allowInteractiveElement) => {
onClickTr(event, allowInteractiveElement, onClick);
}, [onClick]);
if (hasOnClick) {
content.push(_jsx(TableClickableButtonTd, {
ariaLabel: tableContextAllProps?.navigationButtonSR,
icon: "chevron_right",
onClick: onClickHandler
}, "td-icon"));
} else if (isTableHead(content)) {
content.push(_jsx(TableIconSrTh, {
text: tableContext?.allProps?.navigationButtonSR
}, "th-icon"));
} else if (!hasOnClick) {
content.push(_Td || (_Td = _jsx(Td, {}, "empty-td")));
}
return _jsx(TableClickableHead, {
clickable: hasOnClick,
onClick: onClickHandler,
onKeyDown: onClick,
ariaLabel: tableContextAllProps?.navigationButtonSR,
...props,
children: content
});
}
//# sourceMappingURL=TableNavigationHead.js.map