UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

48 lines 2.25 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _Td; const _excluded = ["children", "onClick"]; import React, { useCallback } from 'react'; import Td from '../TableTd'; import { TableContext } from '../TableContext'; import { TableClickableButtonTd, TableClickableHead, TableIconSrTh, isTableHead, onClickTr } from '../TableClickableHead'; export function TableNavigationHead(allProps) { var _React$useContext; const { children, onClick } = allProps, props = _objectWithoutProperties(allProps, _excluded); const tableContext = React.useContext(TableContext); const content = React.Children.toArray(children); const hasOnClick = typeof onClick === 'function'; const tableContextAllProps = (_React$useContext = React.useContext(TableContext)) === null || _React$useContext === void 0 ? void 0 : _React$useContext.allProps; const onClickHandler = useCallback((event, allowInteractiveElement) => { onClickTr(event, allowInteractiveElement, onClick); }, [onClick]); if (hasOnClick) { content.push(React.createElement(TableClickableButtonTd, { key: "td-icon", ariaLabel: tableContextAllProps === null || tableContextAllProps === void 0 ? void 0 : tableContextAllProps.navigationButtonSR, icon: "chevron_right", onClick: onClickHandler })); } else if (isTableHead(content)) { var _tableContext$allProp; content.push(React.createElement(TableIconSrTh, { key: "th-icon", text: tableContext === null || tableContext === void 0 ? void 0 : (_tableContext$allProp = tableContext.allProps) === null || _tableContext$allProp === void 0 ? void 0 : _tableContext$allProp.navigationButtonSR })); } else if (!hasOnClick) { content.push(_Td || (_Td = React.createElement(Td, { key: "empty-td" }))); } return React.createElement(TableClickableHead, _extends({ clickable: hasOnClick, onClick: onClickHandler, onKeyDown: onClick, ariaLabel: tableContextAllProps === null || tableContextAllProps === void 0 ? void 0 : tableContextAllProps.navigationButtonSR }, props), content); } //# sourceMappingURL=TableNavigationHead.js.map