Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

97 rindas
2.4KB

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