2024-12-13 13:55:11 +03:00
|
|
|
'use no memo';
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
import { flexRender, Header, HeaderGroup, Table } from '@tanstack/react-table';
|
|
|
|
|
|
|
|
import SelectAll from './SelectAll';
|
|
|
|
import SortingIcon from './SortingIcon';
|
|
|
|
|
|
|
|
interface TableHeaderProps<TData> {
|
|
|
|
table: Table<TData>;
|
|
|
|
headPosition?: string;
|
|
|
|
enableRowSelection?: boolean;
|
|
|
|
enableSorting?: boolean;
|
2024-11-21 00:26:04 +03:00
|
|
|
resetLastSelected: () => void;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function TableHeader<TData>({
|
|
|
|
table,
|
|
|
|
headPosition,
|
|
|
|
enableRowSelection,
|
|
|
|
enableSorting,
|
2024-11-21 00:26:04 +03:00
|
|
|
resetLastSelected
|
2024-06-07 20:17:03 +03:00
|
|
|
}: TableHeaderProps<TData>) {
|
|
|
|
return (
|
|
|
|
<thead
|
2024-12-16 23:51:31 +03:00
|
|
|
className='bg-app-100 cc-shadow-border'
|
2024-06-07 20:17:03 +03:00
|
|
|
style={{
|
|
|
|
top: headPosition,
|
|
|
|
position: 'sticky'
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{table.getHeaderGroups().map((headerGroup: HeaderGroup<TData>) => (
|
|
|
|
<tr key={headerGroup.id}>
|
|
|
|
{enableRowSelection ? (
|
|
|
|
<th className='pl-3 pr-1 align-middle'>
|
2024-11-21 00:26:04 +03:00
|
|
|
<SelectAll table={table} resetLastSelected={resetLastSelected} />
|
2024-06-07 20:17:03 +03:00
|
|
|
</th>
|
|
|
|
) : null}
|
|
|
|
{headerGroup.headers.map((header: Header<TData, unknown>) => (
|
|
|
|
<th
|
|
|
|
key={header.id}
|
|
|
|
colSpan={header.colSpan}
|
|
|
|
className='pl-2 py-2 text-xs font-medium select-none whitespace-nowrap'
|
|
|
|
style={{
|
|
|
|
paddingRight: enableSorting && header.column.getCanSort() ? '0px' : '2px',
|
|
|
|
textAlign: 'start',
|
2024-09-27 15:28:52 +03:00
|
|
|
width: `calc(var(--header-${header?.id}-size) * 1px)`,
|
2024-06-07 20:17:03 +03:00
|
|
|
cursor: enableSorting && header.column.getCanSort() ? 'pointer' : 'auto'
|
|
|
|
}}
|
|
|
|
onClick={enableSorting ? header.column.getToggleSortingHandler() : undefined}
|
|
|
|
>
|
|
|
|
{!header.isPlaceholder ? (
|
|
|
|
<span className='inline-flex align-middle gap-1'>
|
|
|
|
{flexRender(header.column.columnDef.header, header.getContext())}
|
|
|
|
{enableSorting && header.column.getCanSort() ? <SortingIcon column={header.column} /> : null}
|
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
</th>
|
|
|
|
))}
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</thead>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TableHeader;
|