import { ACTIONS_COLUMN_ID } from './constants.ts'; import { useDataTableHandle } from './hooks.ts'; import { flexRender } from './utils.tsx'; export const DataTableHead = () => { const headerGroups = useDataTableHandle('headerGroups'); const rowCount = useDataTableHandle('rowCount'); return (
{headerGroups.map((headerGroup) => (
{headerGroup.headers.map((header) => { const style: React.CSSProperties = { // TODO - add more robust solution - should be able to block centering also - also set correct typing justifyContent: header.column.columnDef.meta?.centered ? 'center' : 'start', width: `calc(var(--header-${header?.id}-size) * 1px)` }; if (header.column.getIsPinned() === 'left') { style.left = `${header.column.getStart('left')}px`; style.position = 'sticky'; style.zIndex = 20; } else if (header.column.getIsPinned() === 'right') { style.right = `${header.column.getAfter('right')}px`; style.position = 'sticky'; style.zIndex = 20; } const nextHeader = headerGroup.headers[header.index + 1]; if (nextHeader?.column.id === ACTIONS_COLUMN_ID) { style.borderRight = 'none'; } return (
{!header.isPlaceholder && flexRender(header.column.columnDef.header, header.getContext())} {header.column.getCanResize() && (
)}
); })}
))}
); };