@cutting/material-react-table 5.0.0-beta.2 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +1 -4
  2. package/dist/index.d.ts +189 -524
  3. package/dist/index.js +329 -345
  4. package/dist/index.js.map +1 -1
  5. package/locales/ar/index.mjs +1 -2
  6. package/locales/az/index.mjs +1 -2
  7. package/locales/bg/index.mjs +1 -2
  8. package/locales/cs/index.mjs +1 -2
  9. package/locales/da/index.mjs +1 -2
  10. package/locales/de/index.mjs +1 -2
  11. package/locales/el/index.mjs +1 -2
  12. package/locales/en/index.mjs +1 -2
  13. package/locales/es/index.mjs +1 -2
  14. package/locales/et/index.mjs +1 -2
  15. package/locales/fa/index.mjs +1 -2
  16. package/locales/fi/index.mjs +1 -2
  17. package/locales/fr/index.mjs +1 -2
  18. package/locales/he/index.mjs +1 -2
  19. package/locales/hr/index.mjs +1 -2
  20. package/locales/hu/index.mjs +1 -2
  21. package/locales/hy/index.mjs +1 -2
  22. package/locales/id/index.mjs +1 -2
  23. package/locales/it/index.mjs +1 -2
  24. package/locales/ja/index.mjs +1 -2
  25. package/locales/ko/index.mjs +1 -2
  26. package/locales/nl/index.mjs +1 -2
  27. package/locales/no/index.mjs +1 -2
  28. package/locales/np/index.mjs +1 -2
  29. package/locales/pl/index.mjs +1 -2
  30. package/locales/pt/index.mjs +1 -2
  31. package/locales/pt-BR/index.mjs +1 -2
  32. package/locales/ro/index.mjs +1 -2
  33. package/locales/ru/index.mjs +1 -2
  34. package/locales/sk/index.mjs +1 -2
  35. package/locales/sr-Cyrl-RS/index.mjs +1 -2
  36. package/locales/sr-Latn-RS/index.mjs +1 -2
  37. package/locales/sv/index.mjs +1 -2
  38. package/locales/tr/index.mjs +1 -2
  39. package/locales/uk/index.mjs +1 -2
  40. package/locales/vi/index.mjs +1 -2
  41. package/locales/zh-Hans/index.mjs +1 -2
  42. package/locales/zh-Hant/index.mjs +1 -2
  43. package/package.json +32 -40
  44. package/src/MaterialReactTable.smoke.test.tsx +3 -9
  45. package/src/components/MaterialReactTable.tsx +13 -21
  46. package/src/components/body/MRT_TableBody.tsx +67 -82
  47. package/src/components/body/MRT_TableBodyCell.tsx +38 -80
  48. package/src/components/body/MRT_TableBodyCellValue.tsx +5 -14
  49. package/src/components/body/MRT_TableBodyRow.tsx +55 -102
  50. package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +2 -6
  51. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -9
  52. package/src/components/body/MRT_TableBodyRowPinButton.tsx +8 -14
  53. package/src/components/body/MRT_TableDetailPanel.test.tsx +3 -9
  54. package/src/components/body/MRT_TableDetailPanel.tsx +8 -14
  55. package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +6 -16
  56. package/src/components/buttons/MRT_ColumnPinningButtons.tsx +6 -12
  57. package/src/components/buttons/MRT_CopyButton.tsx +7 -15
  58. package/src/components/buttons/MRT_EditActionButtons.test.tsx +2 -6
  59. package/src/components/buttons/MRT_EditActionButtons.tsx +15 -37
  60. package/src/components/buttons/MRT_ExpandAllButton.tsx +8 -16
  61. package/src/components/buttons/MRT_ExpandButton.tsx +9 -21
  62. package/src/components/buttons/MRT_GrabHandleButton.tsx +6 -10
  63. package/src/components/buttons/MRT_RowPinButton.tsx +8 -23
  64. package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +5 -18
  65. package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +4 -12
  66. package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +4 -11
  67. package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +4 -13
  68. package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -5
  69. package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +3 -11
  70. package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +4 -9
  71. package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -5
  72. package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -15
  73. package/src/components/footer/MRT_TableFooter.tsx +9 -16
  74. package/src/components/footer/MRT_TableFooterCell.tsx +9 -32
  75. package/src/components/footer/MRT_TableFooterRow.tsx +18 -32
  76. package/src/components/head/MRT_TableHead.tsx +8 -18
  77. package/src/components/head/MRT_TableHeadCell.tsx +46 -100
  78. package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -30
  79. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -15
  80. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +20 -54
  81. package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +5 -19
  82. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +9 -38
  83. package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +3 -13
  84. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +10 -24
  85. package/src/components/head/MRT_TableHeadCellSortLabel.tsx +10 -26
  86. package/src/components/head/MRT_TableHeadRow.tsx +24 -36
  87. package/src/components/inputs/MRT_EditCellTextField.test.tsx +2 -9
  88. package/src/components/inputs/MRT_EditCellTextField.tsx +9 -28
  89. package/src/components/inputs/MRT_FilterCheckbox.tsx +9 -23
  90. package/src/components/inputs/MRT_FilterRangeFields.tsx +6 -15
  91. package/src/components/inputs/MRT_FilterRangeSlider.tsx +24 -32
  92. package/src/components/inputs/MRT_FilterTextField.test.tsx +72 -14
  93. package/src/components/inputs/MRT_FilterTextField.tsx +77 -138
  94. package/src/components/inputs/MRT_GlobalFilterTextField.tsx +10 -32
  95. package/src/components/inputs/MRT_SelectCheckbox.test.tsx +4 -11
  96. package/src/components/inputs/MRT_SelectCheckbox.tsx +17 -36
  97. package/src/components/menus/MRT_ActionMenuItem.tsx +6 -15
  98. package/src/components/menus/MRT_CellActionMenu.tsx +6 -9
  99. package/src/components/menus/MRT_ColumnActionMenu.tsx +22 -57
  100. package/src/components/menus/MRT_FilterOptionMenu.tsx +38 -65
  101. package/src/components/menus/MRT_RowActionMenu.tsx +33 -22
  102. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +29 -65
  103. package/src/components/menus/MRT_ShowHideColumnsMenuItems.test.tsx +43 -0
  104. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +14 -50
  105. package/src/components/modals/MRT_EditRowModal.test.tsx +5 -21
  106. package/src/components/modals/MRT_EditRowModal.tsx +8 -26
  107. package/src/components/table/MRT_Table.tsx +12 -20
  108. package/src/components/table/MRT_TableContainer.test.tsx +147 -0
  109. package/src/components/table/MRT_TableContainer.tsx +33 -37
  110. package/src/components/table/MRT_TableLoadingOverlay.tsx +3 -5
  111. package/src/components/table/MRT_TablePaper.tsx +7 -14
  112. package/src/components/toolbar/MRT_BottomToolbar.tsx +11 -23
  113. package/src/components/toolbar/MRT_LinearProgressBar.tsx +4 -11
  114. package/src/components/toolbar/MRT_TablePagination.tsx +33 -40
  115. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +21 -50
  116. package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +26 -10
  117. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +23 -21
  118. package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +11 -21
  119. package/src/components/toolbar/MRT_TopToolbar.tsx +12 -28
  120. package/src/fns/aggregationFns.test.tsx +1 -3
  121. package/src/fns/filterFns.test.tsx +9 -37
  122. package/src/fns/filterFns.ts +73 -96
  123. package/src/fns/sortingFns.test.tsx +39 -0
  124. package/src/fns/sortingFns.ts +15 -15
  125. package/src/fns/tableFeatures.test.tsx +6 -29
  126. package/src/fns/tableFeatures.ts +5 -4
  127. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +2 -11
  128. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +2 -10
  129. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +8 -17
  130. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +3 -8
  131. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +2 -8
  132. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +3 -13
  133. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -5
  134. package/src/hooks/useMRT_ColumnVirtualizer.ts +28 -49
  135. package/src/hooks/useMRT_Effects.test.tsx +114 -0
  136. package/src/hooks/useMRT_Effects.ts +26 -27
  137. package/src/hooks/useMRT_RowVirtualizer.ts +18 -33
  138. package/src/hooks/useMRT_Rows.ts +3 -42
  139. package/src/hooks/useMRT_TableInstance.ts +63 -129
  140. package/src/hooks/useMRT_TableOptions.ts +15 -29
  141. package/src/hooks/useMaterialReactTable.ts +2 -7
  142. package/src/icons.ts +38 -1
  143. package/src/index.ts +0 -4
  144. package/src/locales/ar.ts +1 -2
  145. package/src/locales/az.ts +1 -2
  146. package/src/locales/bg.ts +1 -2
  147. package/src/locales/cs.ts +2 -4
  148. package/src/locales/da.ts +1 -2
  149. package/src/locales/de.ts +1 -2
  150. package/src/locales/el.ts +1 -2
  151. package/src/locales/en.ts +1 -2
  152. package/src/locales/es.ts +1 -2
  153. package/src/locales/et.ts +2 -4
  154. package/src/locales/fa.ts +1 -2
  155. package/src/locales/fi.ts +2 -4
  156. package/src/locales/fr.ts +1 -2
  157. package/src/locales/he.ts +1 -2
  158. package/src/locales/hr.ts +1 -2
  159. package/src/locales/hu.ts +1 -2
  160. package/src/locales/hy.ts +1 -2
  161. package/src/locales/id.ts +2 -4
  162. package/src/locales/it.ts +1 -2
  163. package/src/locales/ja.ts +1 -2
  164. package/src/locales/ko.ts +1 -2
  165. package/src/locales/nl.ts +1 -2
  166. package/src/locales/no.ts +2 -4
  167. package/src/locales/np.ts +2 -4
  168. package/src/locales/pl.ts +1 -2
  169. package/src/locales/pt-BR.ts +1 -2
  170. package/src/locales/pt.ts +1 -2
  171. package/src/locales/ro.ts +1 -2
  172. package/src/locales/ru.ts +1 -2
  173. package/src/locales/sk.ts +2 -4
  174. package/src/locales/sr-Cyrl-RS.ts +1 -2
  175. package/src/locales/sr-Latn-RS.ts +1 -2
  176. package/src/locales/sv.ts +1 -2
  177. package/src/locales/tr.ts +1 -2
  178. package/src/locales/uk.ts +1 -2
  179. package/src/locales/vi.ts +1 -2
  180. package/src/types.ts +156 -349
  181. package/src/utils/cell.utils.ts +30 -68
  182. package/src/utils/column.utils.ts +61 -49
  183. package/src/utils/displayColumn.utils.ts +16 -38
  184. package/src/utils/highlight.utils.ts +7 -11
  185. package/src/utils/row.utils.ts +40 -65
  186. package/src/utils/slotProps.utils.ts +1 -4
  187. package/src/utils/style.utils.ts +18 -46
  188. package/src/utils/tanstack.helpers.ts +10 -17
  189. package/src/utils/utils.ts +6 -10
  190. package/src/utils/virtualization.utils.ts +5 -9
@@ -1,13 +1,7 @@
1
- import { IconButton, type IconButtonProps } from '@mui/material';
2
- import { Tooltip } from '@mui/material';
1
+ import { IconButton, type IconButtonProps, Tooltip } from '@mui/material';
3
2
  import { type MouseEvent, useState } from 'react';
4
3
 
5
- import {
6
- type MRT_Cell,
7
- type MRT_Row,
8
- type MRT_RowData,
9
- type MRT_TableInstance,
10
- } from '../../types';
4
+ import { type MRT_Cell, type MRT_Row, type MRT_RowData, type MRT_TableInstance } from '../../types';
11
5
  import { getCommonTooltipProps } from '../../utils/style.utils';
12
6
  import { parseFromValuesOrFunc } from '../../utils/utils';
13
7
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
@@ -24,8 +18,7 @@ const commonIconButtonStyles = {
24
18
  width: '2rem',
25
19
  };
26
20
 
27
- export interface MRT_ToggleRowActionMenuButtonProps<TData extends MRT_RowData>
28
- extends IconButtonProps {
21
+ export interface MRT_ToggleRowActionMenuButtonProps<TData extends MRT_RowData> extends IconButtonProps {
29
22
  cell: MRT_Cell<TData>;
30
23
  row: MRT_Row<TData>;
31
24
  staticRowIndex?: number;
@@ -38,7 +31,7 @@ export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
38
31
  staticRowIndex,
39
32
  table,
40
33
  ...rest
41
- }: MRT_ToggleRowActionMenuButtonProps<TData>) => {
34
+ }: MRT_ToggleRowActionMenuButtonProps<TData>): JSX.Element => {
42
35
  const {
43
36
  options: {
44
37
  createDisplayMode,
@@ -57,9 +50,7 @@ export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
57
50
  const isCreating = creatingRow?.id === row.id;
58
51
  const isEditing = editingRow?.id === row.id;
59
52
 
60
- const showEditActionButtons =
61
- (isCreating && createDisplayMode === 'row') ||
62
- (isEditing && editDisplayMode === 'row');
53
+ const showEditActionButtons = (isCreating && createDisplayMode === 'row') || (isEditing && editDisplayMode === 'row');
63
54
 
64
55
  const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
65
56
 
@@ -96,9 +87,10 @@ export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
96
87
  </Tooltip>
97
88
  ) : renderRowActionMenuItems?.({
98
89
  row,
90
+ closeMenu: () => {},
99
91
  staticRowIndex,
100
92
  table,
101
- } as any)?.length ? (
93
+ })?.length ? (
102
94
  <>
103
95
  <Tooltip {...getCommonTooltipProps()} title={localization.rowActions}>
104
96
  <IconButton
@@ -1,15 +1,11 @@
1
1
  import { TableFooter, type TableFooterProps } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
2
3
 
3
- import {
4
- type MRT_ColumnVirtualizer,
5
- type MRT_RowData,
6
- type MRT_TableInstance,
7
- } from '../../types';
4
+ import { type MRT_ColumnVirtualizer, type MRT_RowData, type MRT_TableInstance } from '../../types';
8
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
9
6
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
10
7
 
11
- export interface MRT_TableFooterProps<TData extends MRT_RowData>
12
- extends TableFooterProps {
8
+ export interface MRT_TableFooterProps<TData extends MRT_RowData> extends TableFooterProps {
13
9
  columnVirtualizer?: MRT_ColumnVirtualizer;
14
10
  table: MRT_TableInstance<TData>;
15
11
  }
@@ -18,7 +14,7 @@ export const MRT_TableFooter = <TData extends MRT_RowData>({
18
14
  columnVirtualizer,
19
15
  table,
20
16
  ...rest
21
- }: MRT_TableFooterProps<TData>) => {
17
+ }: MRT_TableFooterProps<TData>): JSX.Element | null => {
22
18
  const {
23
19
  options: { enableStickyFooter, layoutMode, muiTableFooterProps },
24
20
  refs: { tableFooterRef },
@@ -32,8 +28,7 @@ export const MRT_TableFooter = <TData extends MRT_RowData>({
32
28
  ...rest,
33
29
  };
34
30
 
35
- const stickFooter =
36
- (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
31
+ const stickFooter = (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
37
32
 
38
33
  const footerGroups = table.getFooterGroups();
39
34
 
@@ -42,8 +37,7 @@ export const MRT_TableFooter = <TData extends MRT_RowData>({
42
37
  !footerGroups.some((footerGroup) =>
43
38
  footerGroup.headers?.some(
44
39
  (header) =>
45
- (typeof header.column.columnDef.footer === 'string' &&
46
- !!header.column.columnDef.footer) ||
40
+ (typeof header.column.columnDef.footer === 'string' && !!header.column.columnDef.footer) ||
47
41
  header.column.columnDef.Footer,
48
42
  ),
49
43
  )
@@ -56,8 +50,7 @@ export const MRT_TableFooter = <TData extends MRT_RowData>({
56
50
  {...tableFooterProps}
57
51
  ref={(ref: HTMLTableSectionElement) => {
58
52
  tableFooterRef.current = ref;
59
- if (tableFooterProps?.ref) {
60
- // @ts-expect-error
53
+ if (tableFooterProps?.ref && typeof tableFooterProps.ref === 'object') {
61
54
  tableFooterProps.ref.current = ref;
62
55
  }
63
56
  }}
@@ -72,13 +65,13 @@ export const MRT_TableFooter = <TData extends MRT_RowData>({
72
65
  : undefined,
73
66
  position: stickFooter ? 'sticky' : 'relative',
74
67
  zIndex: stickFooter ? 1 : undefined,
75
- ...(parseFromValuesOrFunc(tableFooterProps?.sx, theme) as any),
68
+ ...(parseFromValuesOrFunc(tableFooterProps?.sx, theme) as CSSObject),
76
69
  })}
77
70
  >
78
71
  {footerGroups.map((footerGroup) => (
79
72
  <MRT_TableFooterRow
80
73
  columnVirtualizer={columnVirtualizer}
81
- footerGroup={footerGroup as any}
74
+ footerGroup={footerGroup}
82
75
  key={footerGroup.id}
83
76
  table={table}
84
77
  />
@@ -1,17 +1,12 @@
1
1
  import { TableCell, type TableCellProps } from '@mui/material';
2
- import { useTheme } from '@mui/material/styles';
2
+ import { type CSSObject, useTheme } from '@mui/material/styles';
3
3
 
4
- import {
5
- type MRT_Header,
6
- type MRT_RowData,
7
- type MRT_TableInstance,
8
- } from '../../types';
4
+ import { type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
9
5
  import { cellKeyboardShortcuts } from '../../utils/cell.utils';
10
6
  import { getCommonMRTCellStyles } from '../../utils/style.utils';
11
7
  import { parseFromValuesOrFunc } from '../../utils/utils';
12
8
 
13
- export interface MRT_TableFooterCellProps<TData extends MRT_RowData>
14
- extends TableCellProps {
9
+ export interface MRT_TableFooterCellProps<TData extends MRT_RowData> extends TableCellProps {
15
10
  footer: MRT_Header<TData>;
16
11
  staticColumnIndex?: number;
17
12
  table: MRT_TableInstance<TData>;
@@ -22,24 +17,17 @@ export const MRT_TableFooterCell = <TData extends MRT_RowData>({
22
17
  staticColumnIndex,
23
18
  table,
24
19
  ...rest
25
- }: MRT_TableFooterCellProps<TData>) => {
20
+ }: MRT_TableFooterCellProps<TData>): JSX.Element => {
26
21
  const theme = useTheme();
27
22
  const {
28
- options: {
29
- enableColumnPinning,
30
- enableKeyboardShortcuts,
31
- muiTableFooterCellProps,
32
- },
23
+ options: { enableColumnPinning, enableKeyboardShortcuts, muiTableFooterCellProps },
33
24
  } = table;
34
25
  const { density } = table.state;
35
26
  const { column } = footer;
36
27
  const { columnDef } = column;
37
28
  const { columnDefType } = columnDef;
38
29
 
39
- const isColumnPinned =
40
- enableColumnPinning &&
41
- columnDef.columnDefType !== 'group' &&
42
- column.getIsPinned();
30
+ const isColumnPinned = enableColumnPinning && columnDef.columnDefType !== 'group' && column.getIsPinned();
43
31
 
44
32
  const args = { column, table };
45
33
  const tableCellProps = {
@@ -59,13 +47,7 @@ export const MRT_TableFooterCell = <TData extends MRT_RowData>({
59
47
 
60
48
  return (
61
49
  <TableCell
62
- align={
63
- columnDefType === 'group'
64
- ? 'center'
65
- : theme.direction === 'rtl'
66
- ? 'right'
67
- : 'left'
68
- }
50
+ align={columnDefType === 'group' ? 'center' : theme.direction === 'rtl' ? 'right' : 'left'}
69
51
  colSpan={footer.colSpan}
70
52
  data-index={staticColumnIndex}
71
53
  data-pinned={!!isColumnPinned || undefined}
@@ -75,12 +57,7 @@ export const MRT_TableFooterCell = <TData extends MRT_RowData>({
75
57
  onKeyDown={handleKeyDown}
76
58
  sx={(theme) => ({
77
59
  fontWeight: 'bold',
78
- p:
79
- density === 'compact'
80
- ? '0.5rem'
81
- : density === 'comfortable'
82
- ? '1rem'
83
- : '1.5rem',
60
+ p: density === 'compact' ? '0.5rem' : density === 'comfortable' ? '1rem' : '1.5rem',
84
61
  verticalAlign: 'top',
85
62
  ...getCommonMRTCellStyles({
86
63
  column,
@@ -89,7 +66,7 @@ export const MRT_TableFooterCell = <TData extends MRT_RowData>({
89
66
  tableCellProps,
90
67
  theme,
91
68
  }),
92
- ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
69
+ ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as CSSObject),
93
70
  })}
94
71
  >
95
72
  {tableCellProps.children ??
@@ -1,4 +1,5 @@
1
1
  import { TableRow, type TableRowProps } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
2
3
 
3
4
  import {
4
5
  type MRT_ColumnVirtualizer,
@@ -11,8 +12,7 @@ import {
11
12
  import { parseFromValuesOrFunc } from '../../utils/utils';
12
13
  import { MRT_TableFooterCell } from './MRT_TableFooterCell';
13
14
 
14
- export interface MRT_TableFooterRowProps<TData extends MRT_RowData>
15
- extends TableRowProps {
15
+ export interface MRT_TableFooterRowProps<TData extends MRT_RowData> extends TableRowProps {
16
16
  columnVirtualizer?: MRT_ColumnVirtualizer;
17
17
  footerGroup: MRT_HeaderGroup<TData>;
18
18
  table: MRT_TableInstance<TData>;
@@ -23,7 +23,7 @@ export const MRT_TableFooterRow = <TData extends MRT_RowData>({
23
23
  footerGroup,
24
24
  table,
25
25
  ...rest
26
- }: MRT_TableFooterRowProps<TData>) => {
26
+ }: MRT_TableFooterRowProps<TData>): JSX.Element | null => {
27
27
  const {
28
28
  options: {
29
29
  layoutMode,
@@ -32,15 +32,13 @@ export const MRT_TableFooterRow = <TData extends MRT_RowData>({
32
32
  },
33
33
  } = table;
34
34
 
35
- const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
36
- columnVirtualizer ?? {};
35
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
37
36
 
38
37
  // if no content in row, skip row
39
38
  if (
40
39
  !footerGroup.headers?.some(
41
40
  (header) =>
42
- (typeof header.column.columnDef.footer === 'string' &&
43
- !!header.column.columnDef.footer) ||
41
+ (typeof header.column.columnDef.footer === 'string' && !!header.column.columnDef.footer) ||
44
42
  header.column.columnDef.Footer,
45
43
  )
46
44
  ) {
@@ -63,34 +61,22 @@ export const MRT_TableFooterRow = <TData extends MRT_RowData>({
63
61
  display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
64
62
  position: 'relative',
65
63
  width: '100%',
66
- ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as any),
64
+ ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as CSSObject),
67
65
  })}
68
66
  >
69
- {virtualPaddingLeft ? (
70
- <th style={{ display: 'flex', width: virtualPaddingLeft }} />
71
- ) : null}
72
- {(virtualColumns ?? footerGroup.headers).map(
73
- (footerOrVirtualFooter, staticColumnIndex) => {
74
- let footer = footerOrVirtualFooter as MRT_Header<TData>;
75
- if (columnVirtualizer) {
76
- staticColumnIndex = (footerOrVirtualFooter as MRT_VirtualItem)
77
- .index;
78
- footer = footerGroup.headers[staticColumnIndex];
79
- }
67
+ {virtualPaddingLeft ? <th style={{ display: 'flex', width: virtualPaddingLeft }} /> : null}
68
+ {(virtualColumns ?? footerGroup.headers).map((footerOrVirtualFooter, staticColumnIndex) => {
69
+ let footer = footerOrVirtualFooter as MRT_Header<TData>;
70
+ if (columnVirtualizer) {
71
+ staticColumnIndex = (footerOrVirtualFooter as MRT_VirtualItem).index;
72
+ footer = footerGroup.headers[staticColumnIndex];
73
+ }
80
74
 
81
- return footer ? (
82
- <MRT_TableFooterCell
83
- footer={footer}
84
- key={footer.id}
85
- staticColumnIndex={staticColumnIndex}
86
- table={table}
87
- />
88
- ) : null;
89
- },
90
- )}
91
- {virtualPaddingRight ? (
92
- <th style={{ display: 'flex', width: virtualPaddingRight }} />
93
- ) : null}
75
+ return footer ? (
76
+ <MRT_TableFooterCell footer={footer} key={footer.id} staticColumnIndex={staticColumnIndex} table={table} />
77
+ ) : null;
78
+ })}
79
+ {virtualPaddingRight ? <th style={{ display: 'flex', width: virtualPaddingRight }} /> : null}
94
80
  </TableRow>
95
81
  );
96
82
  };
@@ -1,16 +1,12 @@
1
1
  import { TableHead, type TableHeadProps } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
2
3
 
3
- import {
4
- type MRT_ColumnVirtualizer,
5
- type MRT_RowData,
6
- type MRT_TableInstance,
7
- } from '../../types';
4
+ import { type MRT_ColumnVirtualizer, type MRT_RowData, type MRT_TableInstance } from '../../types';
8
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
9
6
  import { MRT_ToolbarAlertBanner } from '../toolbar/MRT_ToolbarAlertBanner';
10
7
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
11
8
 
12
- export interface MRT_TableHeadProps<TData extends MRT_RowData>
13
- extends TableHeadProps {
9
+ export interface MRT_TableHeadProps<TData extends MRT_RowData> extends TableHeadProps {
14
10
  columnVirtualizer?: MRT_ColumnVirtualizer;
15
11
  table: MRT_TableInstance<TData>;
16
12
  }
@@ -19,14 +15,9 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
19
15
  columnVirtualizer,
20
16
  table,
21
17
  ...rest
22
- }: MRT_TableHeadProps<TData>) => {
18
+ }: MRT_TableHeadProps<TData>): JSX.Element => {
23
19
  const {
24
- options: {
25
- enableStickyHeader,
26
- layoutMode,
27
- muiTableHeadProps,
28
- positionToolbarAlertBanner,
29
- },
20
+ options: { enableStickyHeader, layoutMode, muiTableHeadProps, positionToolbarAlertBanner },
30
21
  refs: { tableHeadRef },
31
22
  } = table;
32
23
  const { isFullScreen, showAlertBanner } = table.state;
@@ -43,8 +34,7 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
43
34
  {...tableHeadProps}
44
35
  ref={(ref: HTMLTableSectionElement) => {
45
36
  tableHeadRef.current = ref;
46
- if (tableHeadProps?.ref) {
47
- // @ts-expect-error
37
+ if (tableHeadProps?.ref && typeof tableHeadProps.ref === 'object') {
48
38
  tableHeadProps.ref.current = ref;
49
39
  }
50
40
  }}
@@ -54,7 +44,7 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
54
44
  position: stickyHeader ? 'sticky' : 'relative',
55
45
  top: stickyHeader && layoutMode?.startsWith('grid') ? 0 : undefined,
56
46
  zIndex: stickyHeader ? 2 : undefined,
57
- ...(parseFromValuesOrFunc(tableHeadProps?.sx, theme) as any),
47
+ ...(parseFromValuesOrFunc(tableHeadProps?.sx, theme) as CSSObject),
58
48
  })}
59
49
  >
60
50
  {positionToolbarAlertBanner === 'head-overlay' &&
@@ -80,7 +70,7 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
80
70
  .map((headerGroup) => (
81
71
  <MRT_TableHeadRow
82
72
  columnVirtualizer={columnVirtualizer}
83
- headerGroup={headerGroup as any}
73
+ headerGroup={headerGroup}
84
74
  key={headerGroup.id}
85
75
  table={table}
86
76
  />
@@ -1,15 +1,9 @@
1
- import { Box } from '@mui/material';
2
- import { TableCell, type TableCellProps } from '@mui/material';
1
+ import { Box, TableCell, type TableCellProps } from '@mui/material';
3
2
  import { useTheme } from '@mui/material/styles';
4
3
  import { type Theme } from '@mui/material/styles';
5
4
  import { type DragEvent, useCallback, useMemo, useRef } from 'react';
6
5
 
7
- import {
8
- type MRT_ColumnVirtualizer,
9
- type MRT_Header,
10
- type MRT_RowData,
11
- type MRT_TableInstance,
12
- } from '../../types';
6
+ import { type MRT_ColumnVirtualizer, type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../../types';
13
7
  import { cellKeyboardShortcuts } from '../../utils/cell.utils';
14
8
  import { getCommonMRTCellStyles } from '../../utils/style.utils';
15
9
  import { parseFromValuesOrFunc } from '../../utils/utils';
@@ -20,8 +14,7 @@ import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
20
14
  import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
21
15
  import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
22
16
 
23
- export interface MRT_TableHeadCellProps<TData extends MRT_RowData>
24
- extends TableCellProps {
17
+ export interface MRT_TableHeadCellProps<TData extends MRT_RowData> extends TableCellProps {
25
18
  columnVirtualizer?: MRT_ColumnVirtualizer;
26
19
  header: MRT_Header<TData>;
27
20
  staticColumnIndex?: number;
@@ -34,7 +27,7 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
34
27
  staticColumnIndex,
35
28
  table,
36
29
  ...rest
37
- }: MRT_TableHeadCellProps<TData>) => {
30
+ }: MRT_TableHeadCellProps<TData>): JSX.Element => {
38
31
  const theme = useTheme();
39
32
  const {
40
33
  options: {
@@ -55,14 +48,7 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
55
48
  refs: { tableHeadCellRefs },
56
49
  setHoveredColumn,
57
50
  } = table;
58
- const {
59
- columnResizing,
60
- density,
61
- draggingColumn,
62
- grouping,
63
- hoveredColumn,
64
- showColumnFilters,
65
- } = table.state;
51
+ const { columnResizing, density, draggingColumn, grouping, hoveredColumn, showColumnFilters } = table.state;
66
52
  const { column } = header;
67
53
  const { columnDef } = column;
68
54
  const { columnDefType } = columnDef;
@@ -76,37 +62,35 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
76
62
  ...rest,
77
63
  };
78
64
 
79
- const isColumnPinned =
80
- enableColumnPinning &&
81
- columnDef.columnDefType !== 'group' &&
82
- column.getIsPinned();
65
+ const isColumnPinned = enableColumnPinning && columnDef.columnDefType !== 'group' && column.getIsPinned();
83
66
 
84
67
  const showColumnActions =
85
- (enableColumnActions || columnDef.enableColumnActions) &&
86
- columnDef.enableColumnActions !== false;
68
+ (enableColumnActions || columnDef.enableColumnActions) && columnDef.enableColumnActions !== false;
87
69
 
88
70
  const showDragHandle =
89
71
  enableColumnDragging !== false &&
90
72
  columnDef.enableColumnDragging !== false &&
91
73
  (enableColumnDragging ||
92
74
  (enableColumnOrdering && columnDef.enableColumnOrdering !== false) ||
93
- (enableGrouping &&
94
- columnDef.enableGrouping !== false &&
95
- !grouping.includes(column.id)));
75
+ (enableGrouping && columnDef.enableGrouping !== false && !grouping.includes(column.id)));
96
76
 
97
77
  const headerPL = useMemo(() => {
98
78
  let pl = 0;
99
- if (column.getCanSort()) pl += 1;
100
- if (showColumnActions) pl += 1.75;
101
- if (showDragHandle) pl += 1.5;
79
+ if (column.getCanSort()) {
80
+ pl += 1;
81
+ }
82
+ if (showColumnActions) {
83
+ pl += 1.75;
84
+ }
85
+ if (showDragHandle) {
86
+ pl += 1.5;
87
+ }
102
88
  return pl;
103
- }, [showColumnActions, showDragHandle]);
89
+ }, [column, showColumnActions, showDragHandle]);
104
90
 
105
91
  const draggingBorders = useMemo(() => {
106
92
  const showResizeBorder =
107
- columnResizing.isResizingColumn === column.id &&
108
- columnResizeMode === 'onChange' &&
109
- !header.subHeaders.length;
93
+ columnResizing.isResizingColumn === column.id && columnResizeMode === 'onChange' && !header.subHeaders.length;
110
94
 
111
95
  const borderStyle = showResizeBorder
112
96
  ? `2px solid ${draggingBorderColor} !important`
@@ -117,9 +101,7 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
117
101
  : undefined;
118
102
 
119
103
  if (showResizeBorder) {
120
- return columnResizeDirection === 'ltr'
121
- ? { borderRight: borderStyle }
122
- : { borderLeft: borderStyle };
104
+ return columnResizeDirection === 'ltr' ? { borderRight: borderStyle } : { borderLeft: borderStyle };
123
105
  }
124
106
  const draggingBorders = borderStyle
125
107
  ? {
@@ -130,16 +112,24 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
130
112
  : undefined;
131
113
 
132
114
  return draggingBorders;
133
- }, [draggingColumn, hoveredColumn, columnResizing.isResizingColumn]);
115
+ }, [
116
+ column.id,
117
+ columnResizeDirection,
118
+ columnResizeMode,
119
+ columnResizing.isResizingColumn,
120
+ draggingBorderColor,
121
+ draggingColumn,
122
+ header.subHeaders.length,
123
+ hoveredColumn,
124
+ theme.palette.grey,
125
+ ]);
134
126
 
135
127
  const handleDragEnter = (_e: DragEvent) => {
136
128
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
137
129
  setHoveredColumn(null);
138
130
  }
139
131
  if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
140
- setHoveredColumn(
141
- columnDef.enableColumnOrdering !== false ? column : null,
142
- );
132
+ setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
143
133
  }
144
134
  };
145
135
 
@@ -185,20 +175,8 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
185
175
 
186
176
  return (
187
177
  <TableCell
188
- align={
189
- columnDefType === 'group'
190
- ? 'center'
191
- : theme.direction === 'rtl'
192
- ? 'right'
193
- : 'left'
194
- }
195
- aria-sort={
196
- column.getIsSorted()
197
- ? column.getIsSorted() === 'asc'
198
- ? 'ascending'
199
- : 'descending'
200
- : 'none'
201
- }
178
+ align={columnDefType === 'group' ? 'center' : theme.direction === 'rtl' ? 'right' : 'left'}
179
+ aria-sort={column.getIsSorted() ? (column.getIsSorted() === 'asc' ? 'ascending' : 'descending') : 'none'}
202
180
  colSpan={header.colSpan}
203
181
  data-can-sort={column.getCanSort() || undefined}
204
182
  data-index={staticColumnIndex}
@@ -229,12 +207,7 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
229
207
  : columnDefType === 'display'
230
208
  ? '1rem 1.25rem'
231
209
  : '1.5rem',
232
- pb:
233
- columnDefType === 'display'
234
- ? 0
235
- : showColumnFilters || density === 'compact'
236
- ? '0.4rem'
237
- : '0.6rem',
210
+ pb: columnDefType === 'display' ? 0 : showColumnFilters || density === 'compact' ? '0.4rem' : '0.6rem',
238
211
  pt:
239
212
  columnDefType === 'group' || density === 'compact'
240
213
  ? '0.25rem'
@@ -261,11 +234,9 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
261
234
  sx={{
262
235
  alignItems: 'center',
263
236
  display: 'flex',
264
- flexDirection:
265
- tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
237
+ flexDirection: tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
266
238
  justifyContent:
267
- columnDefType === 'group' ||
268
- tableCellProps?.align === 'center'
239
+ columnDefType === 'group' || tableCellProps?.align === 'center'
269
240
  ? 'center'
270
241
  : column.getCanResize()
271
242
  ? 'space-between'
@@ -279,18 +250,11 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
279
250
  onClick={column.getToggleSortingHandler()}
280
251
  sx={{
281
252
  alignItems: 'center',
282
- cursor:
283
- column.getCanSort() && columnDefType !== 'group'
284
- ? 'pointer'
285
- : undefined,
253
+ cursor: column.getCanSort() && columnDefType !== 'group' ? 'pointer' : undefined,
286
254
  display: 'flex',
287
- flexDirection:
288
- tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
255
+ flexDirection: tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
289
256
  overflow: columnDefType === 'data' ? 'hidden' : undefined,
290
- pl:
291
- tableCellProps?.align === 'center'
292
- ? `${headerPL}rem`
293
- : undefined,
257
+ pl: tableCellProps?.align === 'center' ? `${headerPL}rem` : undefined,
294
258
  }}
295
259
  >
296
260
  <Box
@@ -302,20 +266,13 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
302
266
  minWidth: `${Math.min(columnDef.header?.length ?? 0, 4)}ch`,
303
267
  overflow: columnDefType === 'data' ? 'hidden' : undefined,
304
268
  textOverflow: 'ellipsis',
305
- whiteSpace:
306
- (columnDef.header?.length ?? 0) < 20
307
- ? 'nowrap'
308
- : 'normal',
269
+ whiteSpace: (columnDef.header?.length ?? 0) < 20 ? 'nowrap' : 'normal',
309
270
  }}
310
271
  >
311
272
  {HeaderElement}
312
273
  </Box>
313
- {column.getCanFilter() && (
314
- <MRT_TableHeadCellFilterLabel header={header} table={table} />
315
- )}
316
- {column.getCanSort() && (
317
- <MRT_TableHeadCellSortLabel header={header} table={table} />
318
- )}
274
+ {column.getCanFilter() && <MRT_TableHeadCellFilterLabel header={header} table={table} />}
275
+ {column.getCanSort() && <MRT_TableHeadCellSortLabel header={header} table={table} />}
319
276
  </Box>
320
277
  {columnDefType !== 'group' && (
321
278
  <Box
@@ -325,23 +282,12 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
325
282
  }}
326
283
  >
327
284
  {showDragHandle && (
328
- <MRT_TableHeadCellGrabHandle
329
- column={column}
330
- table={table}
331
- tableHeadCellRef={tableHeadCellRef}
332
- />
333
- )}
334
- {showColumnActions && (
335
- <MRT_TableHeadCellColumnActionsButton
336
- header={header}
337
- table={table}
338
- />
285
+ <MRT_TableHeadCellGrabHandle column={column} table={table} tableHeadCellRef={tableHeadCellRef} />
339
286
  )}
287
+ {showColumnActions && <MRT_TableHeadCellColumnActionsButton header={header} table={table} />}
340
288
  </Box>
341
289
  )}
342
- {column.getCanResize() && (
343
- <MRT_TableHeadCellResizeHandle header={header} table={table} />
344
- )}
290
+ {column.getCanResize() && <MRT_TableHeadCellResizeHandle header={header} table={table} />}
345
291
  </Box>
346
292
  ))}
347
293
  {columnFilterDisplayMode === 'subheader' && column.getCanFilter() && (