import React from 'react'; import { TableColumnProps } from './types'; import { HeaderGroup, TableSortByToggleProps } from 'react-table'; import MaterialUITableHead from '@material-ui/core/TableHead'; import TableRow from '@material-ui/core/TableRow'; import TableCell from '@material-ui/core/TableCell'; import TableSortLabel from '@material-ui/core/TableSortLabel'; import Checkbox from '@material-ui/core/Checkbox'; import Box from '@material-ui/core/Box'; import makeStyles from '@material-ui/core/styles/makeStyles'; import { TableFilterColumn } from './TableFilterColumn'; const useStyles = makeStyles((theme) => ({ checkBox: { margin: '-9px 0', }, head: { '& > *': { position: 'sticky', top: '0px', zIndex: 1, background: theme.palette.background.paper, }, }, })); type TableTHeadProps = { headerGroups: HeaderGroup[]; onSortChange?: (column: TableColumnProps) => void; onFilterChange?: (column: TableColumnProps, filterValue?: any) => void; toggleAllRowsSelected?: (value: boolean) => void; isAllRowsSelected?: boolean; selectedFlatRows?: T[]; }; export const TableHead: React.FC> = (props: TableTHeadProps) => { const { headerGroups, onSortChange, onFilterChange, toggleAllRowsSelected, selectedFlatRows, isAllRowsSelected, } = props; const classes = useStyles(); return ( {headerGroups.map((headerGroup) => ( {headerGroup.headers.map((c) => { const column = c as TableColumnProps; if (column.id === 'selection') { return ( 0} checked={isAllRowsSelected} onChange={() => toggleAllRowsSelected?.(!isAllRowsSelected)} /> ); } return ( ) => ({ ...p, onClick: column.canSort ? () => onSortChange?.(column) : undefined, })), )}> {column.canSort ? ( {column.render('Header')} ) : ( <>{column.render('Header')} )} {column.canFilter && } ); })} ))} ); };