import { Box, Center, Checkbox, Flex } from '@mantine/core'; import { flexRender } from '@tanstack/react-table'; import { useMemo } from 'react'; import MultiSelectHeaderWrapper from './MultiSelectHeaderWrapper'; import useChannelsTableStore from '../../../store/channelsTable'; const CustomTableHeader = ({ getHeaderGroups, allRowIds, selectedTableIds, headerCellRenderFns, onSelectAllChange, tableCellProps, headerPinned = true, enableDragDrop = false, }) => { const isUnlocked = useChannelsTableStore((s) => s.isUnlocked); const shouldEnableDrag = enableDragDrop && isUnlocked; const renderHeaderCell = (header) => { let content; if (headerCellRenderFns[header.id]) { content = headerCellRenderFns[header.id](header); } else { switch (header.id) { case 'select': content = (
0 && selectedTableIds.length !== allRowIds.length } onChange={onSelectAllChange} />
); break; default: content = flexRender( header.column.columnDef.header, header.getContext() ); } } // Automatically wrap content to enhance MultiSelect components return {content}; }; // 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;