import { Box, Center, Checkbox, Flex } from '@mantine/core'; import { flexRender } from '@tanstack/react-table'; import { useCallback, useMemo } from 'react'; const CustomTableHeader = ({ getHeaderGroups, allRowIds, selectedTableIds, headerCellRenderFns, onSelectAllChange, tableCellProps, headerPinned = true, }) => { const renderHeaderCell = (header) => { if (headerCellRenderFns[header.id]) { return headerCellRenderFns[header.id](header); } switch (header.id) { case 'select': return (
0 && selectedTableIds.length !== allRowIds.length } onChange={onSelectAllChange} />
); default: return flexRender(header.column.columnDef.header, header.getContext()); } }; // Get header groups for dependency tracking const headerGroups = getHeaderGroups(); // Calculate minimum width based only on fixed-size columns const minTableWidth = useMemo(() => { if (!headerGroups || headerGroups.length === 0) return 0; const width = headerGroups[0]?.headers.reduce((total, header) => { // Only count columns with fixed sizes, flexible columns will expand const columnSize = header.column.columnDef.size ? header.getSize() : header.column.columnDef.minSize || 150; // Default min for flexible columns return total + columnSize; }, 0) || 0; return width; }, [headerGroups]); // Memoize the style object to ensure it updates when headerPinned changes const headerStyle = useMemo( () => ({ position: headerPinned ? 'sticky' : 'relative', top: headerPinned ? 0 : 'auto', backgroundColor: '#3E3E45', zIndex: headerPinned ? 10 : 1, }), [headerPinned] ); return ( {getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {renderHeaderCell(header)} {header.column.getCanResize() && (
{ e.target.style.opacity = '1'; e.target.style.backgroundColor = '#6b7280'; }} onMouseLeave={(e) => { if (!header.column.getIsResizing()) { e.target.style.opacity = '0.5'; e.target.style.backgroundColor = 'transparent'; } }} /> )} ); })} ))} ); }; export default CustomTableHeader;