import { LongArrowAltDownIcon } from '@patternfly/react-icons/dist/esm/icons/long-arrow-alt-down-icon'; import { LongArrowAltUpIcon } from '@patternfly/react-icons/dist/esm/icons/long-arrow-alt-up-icon'; import { Thead, Tr, Th, type ThProps } from '@patternfly/react-table'; import { flexRender, type Table } from '@tanstack/react-table'; import { type ColumnWidth } from './column-widths'; /** Props for the {@link TableHeader} component. */ interface TableHeaderProps { /** The TanStack Table instance. */ table: Table; /** Computed column widths from `computeColumnWidths`. */ columnWidths: ColumnWidth[]; /** Whether to render an empty expand/collapse header cell. */ enableExpansion?: boolean; /** Whether to render an empty row selection header cell. */ enableRowSelection?: boolean; } /** * Renders the table header row with column labels, widths, and read-only * sort indicators. * * Sort indicators are non-interactive icons displayed inline after the * header text. Sorting is controlled by the {@link SortDropdown} component * rather than by clicking column headers. * * @typeParam TData - The row data type */ export const TableHeader = ({ table, columnWidths, enableExpansion, enableRowSelection, }: TableHeaderProps) => { const widthMap = new Map(columnWidths.map((w) => [w.id, w])); return ( {table.getHeaderGroups().map((headerGroup) => ( {enableRowSelection && } {enableExpansion && } {headerGroup.headers.map((header) => { const colWidth = widthMap.get(header.column.id); const widthProps: Partial = {}; if (colWidth?.type === 'flex') { widthProps.style = { width: `${colWidth.widthPercent}%` }; } else if (colWidth?.type === 'fixed') { widthProps.style = { width: colWidth.fixedWidth }; } const sortDirection = header.column.getIsSorted(); const ariaSort = sortDirection === 'asc' ? 'ascending' : sortDirection === 'desc' ? 'descending' : undefined; return ( {flexRender(header.column.columnDef.header, header.getContext())} {sortDirection && ( {sortDirection === 'asc' ? : } )} ); })} ))} ); };