1 | // @mui
|
---|
2 | import { Theme, SxProps } from '@mui/material/styles';
|
---|
3 | import Box from '@mui/material/Box';
|
---|
4 | import TableRow from '@mui/material/TableRow';
|
---|
5 | import TableHead from '@mui/material/TableHead';
|
---|
6 | import TableCell from '@mui/material/TableCell';
|
---|
7 | import TableSortLabel from '@mui/material/TableSortLabel';
|
---|
8 |
|
---|
9 | // ----------------------------------------------------------------------
|
---|
10 |
|
---|
11 | const visuallyHidden = {
|
---|
12 | border: 0,
|
---|
13 | margin: -1,
|
---|
14 | padding: 0,
|
---|
15 | width: '1px',
|
---|
16 | height: '1px',
|
---|
17 | overflow: 'hidden',
|
---|
18 | position: 'absolute',
|
---|
19 | whiteSpace: 'nowrap',
|
---|
20 | clip: 'rect(0 0 0 0)',
|
---|
21 | } as const;
|
---|
22 |
|
---|
23 | // ----------------------------------------------------------------------
|
---|
24 |
|
---|
25 | type Props = {
|
---|
26 | order?: 'asc' | 'desc';
|
---|
27 | orderBy?: string;
|
---|
28 | headLabel: any[];
|
---|
29 | rowCount?: number;
|
---|
30 | numSelected?: number;
|
---|
31 | onSort?: (id: string) => void;
|
---|
32 | onSelectAllRows?: (checked: boolean) => void;
|
---|
33 | sx?: SxProps<Theme>;
|
---|
34 | };
|
---|
35 |
|
---|
36 | export default function TableHeadCustom({
|
---|
37 | order,
|
---|
38 | orderBy,
|
---|
39 | rowCount = 0,
|
---|
40 | headLabel,
|
---|
41 | numSelected = 0,
|
---|
42 | onSort,
|
---|
43 | onSelectAllRows,
|
---|
44 | sx,
|
---|
45 | }: Props) {
|
---|
46 | return (
|
---|
47 | <TableHead sx={sx}>
|
---|
48 | <TableRow>
|
---|
49 | {/* {onSelectAllRows && (
|
---|
50 | <TableCell padding="checkbox">
|
---|
51 | <Checkbox
|
---|
52 | indeterminate={!!numSelected && numSelected < rowCount}
|
---|
53 | checked={!!rowCount && numSelected === rowCount}
|
---|
54 | onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
|
---|
55 | onSelectAllRows(event.target.checked)
|
---|
56 | }
|
---|
57 | />
|
---|
58 | </TableCell>
|
---|
59 | )} */}
|
---|
60 |
|
---|
61 | {headLabel.map((headCell) => (
|
---|
62 | <TableCell
|
---|
63 | key={headCell.id}
|
---|
64 | align={headCell.align || 'left'}
|
---|
65 | sortDirection={orderBy === headCell.id ? order : false}
|
---|
66 | sx={{ width: headCell.width, minWidth: headCell.minWidth }}
|
---|
67 | >
|
---|
68 | {onSort ? (
|
---|
69 | <TableSortLabel
|
---|
70 | hideSortIcon
|
---|
71 | active={orderBy === headCell.id}
|
---|
72 | direction={orderBy === headCell.id ? order : 'asc'}
|
---|
73 | onClick={() => onSort(headCell.id)}
|
---|
74 | >
|
---|
75 | {headCell.label}
|
---|
76 |
|
---|
77 | {orderBy === headCell.id ? (
|
---|
78 | <Box sx={{ ...visuallyHidden }}>
|
---|
79 | {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
|
---|
80 | </Box>
|
---|
81 | ) : null}
|
---|
82 | </TableSortLabel>
|
---|
83 | ) : (
|
---|
84 | headCell.label
|
---|
85 | )}
|
---|
86 | </TableCell>
|
---|
87 | ))}
|
---|
88 | </TableRow>
|
---|
89 | </TableHead>
|
---|
90 | );
|
---|
91 | }
|
---|