@cutting/material-react-table 5.0.0 → 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 +186 -524
  3. package/dist/index.js +323 -342
  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 +19 -27
  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 +8 -37
  122. package/src/fns/filterFns.ts +71 -96
  123. package/src/fns/sortingFns.test.tsx +5 -21
  124. package/src/fns/sortingFns.ts +10 -14
  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,7 +1,7 @@
1
1
  import { TableRow, type TableRowProps } from '@mui/material';
2
- import { alpha, darken, lighten, type Theme, useTheme } from '@mui/material/styles';
2
+ import { alpha, type CSSObject, darken, lighten, type Theme, useTheme } from '@mui/material/styles';
3
3
  import { type VirtualItem } from '@tanstack/react-virtual';
4
- import { type DragEvent, memo, useMemo, useRef } from 'react';
4
+ import { type DragEvent, memo, useRef } from 'react';
5
5
 
6
6
  import {
7
7
  type MRT_Cell,
@@ -13,16 +13,12 @@ import {
13
13
  type MRT_VirtualItem,
14
14
  } from '../../types';
15
15
  import { getIsRowSelected } from '../../utils/row.utils';
16
- import {
17
- commonCellBeforeAfterStyles,
18
- getCommonPinnedCellStyles,
19
- } from '../../utils/style.utils';
16
+ import { commonCellBeforeAfterStyles, getCommonPinnedCellStyles } from '../../utils/style.utils';
20
17
  import { parseFromValuesOrFunc } from '../../utils/utils';
21
18
  import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
22
19
  import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
23
20
 
24
- export interface MRT_TableBodyRowProps<TData extends MRT_RowData>
25
- extends TableRowProps {
21
+ export interface MRT_TableBodyRowProps<TData extends MRT_RowData> extends TableRowProps {
26
22
  columnVirtualizer?: MRT_ColumnVirtualizer;
27
23
  numRows?: number;
28
24
  pinnedRowIds?: string[];
@@ -43,7 +39,7 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
43
39
  table,
44
40
  virtualRow,
45
41
  ...rest
46
- }: MRT_TableBodyRowProps<TData>) => {
42
+ }: MRT_TableBodyRowProps<TData>): JSX.Element => {
47
43
  const theme = useTheme();
48
44
 
49
45
  const {
@@ -54,11 +50,7 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
54
50
  enableStickyHeader,
55
51
  layoutMode,
56
52
  memoMode,
57
- mrtTheme: {
58
- baseBackgroundColor,
59
- pinnedRowBackgroundColor,
60
- selectedRowBackgroundColor,
61
- },
53
+ mrtTheme: { baseBackgroundColor, pinnedRowBackgroundColor, selectedRowBackgroundColor },
62
54
  muiTableBodyRowProps,
63
55
  renderDetailPanel,
64
56
  rowPinningDisplayMode,
@@ -66,21 +58,11 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
66
58
  refs: { tableFooterRef, tableHeadRef },
67
59
  setHoveredRow,
68
60
  } = table;
69
- const {
70
- density,
71
- draggingColumn,
72
- draggingRow,
73
- editingCell,
74
- editingRow,
75
- hoveredRow,
76
- isFullScreen,
77
- rowPinning,
78
- } = table.state;
61
+ const { density, draggingColumn, draggingRow, editingCell, editingRow, hoveredRow, isFullScreen } = table.state;
79
62
 
80
63
  const visibleCells = row.getVisibleCells();
81
64
 
82
- const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
83
- columnVirtualizer ?? {};
65
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
84
66
 
85
67
  const isRowSelected = getIsRowSelected({ row, table });
86
68
  const isRowPinned = enableRowPinning && row.getIsPinned();
@@ -96,35 +78,22 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
96
78
  ...rest,
97
79
  };
98
80
 
99
- const [bottomPinnedIndex, topPinnedIndex] = useMemo(() => {
100
- if (
101
- !enableRowPinning ||
102
- !rowPinningDisplayMode?.includes('sticky') ||
103
- !pinnedRowIds ||
104
- !row.getIsPinned()
105
- )
81
+ const getPinnedIndexes = (): number[] => {
82
+ if (!enableRowPinning || !rowPinningDisplayMode?.includes('sticky') || !pinnedRowIds || !row.getIsPinned()) {
106
83
  return [];
107
- return [
108
- [...pinnedRowIds].reverse().indexOf(row.id),
109
- pinnedRowIds.indexOf(row.id),
110
- ];
111
- }, [pinnedRowIds, rowPinning]);
84
+ }
85
+ return [[...pinnedRowIds].reverse().indexOf(row.id), pinnedRowIds.indexOf(row.id)];
86
+ };
87
+ const [bottomPinnedIndex, topPinnedIndex] = getPinnedIndexes();
112
88
 
113
- const tableHeadHeight =
114
- ((enableStickyHeader || isFullScreen) &&
115
- tableHeadRef.current?.clientHeight) ||
116
- 0;
117
- const tableFooterHeight =
118
- (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
89
+ const tableHeadHeight = ((enableStickyHeader || isFullScreen) && tableHeadRef.current?.clientHeight) || 0;
90
+ const tableFooterHeight = (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
119
91
 
120
- const sx = parseFromValuesOrFunc(tableRowProps?.sx, theme as any);
92
+ const sx = parseFromValuesOrFunc(tableRowProps?.sx, theme) as CSSObject | undefined;
121
93
 
122
- const defaultRowHeight =
123
- density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69;
94
+ const defaultRowHeight = density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69;
124
95
 
125
- const customRowHeight =
126
- // @ts-expect-error
127
- parseInt(tableRowProps?.style?.height ?? sx?.height, 10) || undefined;
96
+ const customRowHeight = parseInt(String(tableRowProps?.style?.height ?? sx?.height), 10) || undefined;
128
97
 
129
98
  const rowHeight = customRowHeight || defaultRowHeight;
130
99
 
@@ -172,9 +141,7 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
172
141
  selected={isRowSelected}
173
142
  {...tableRowProps}
174
143
  style={{
175
- transform: virtualRow
176
- ? `translateY(${virtualRow.start}px)`
177
- : undefined,
144
+ transform: virtualRow ? `translateY(${virtualRow.start}px)` : undefined,
178
145
  ...tableRowProps?.style,
179
146
  }}
180
147
  sx={(theme: Theme) => ({
@@ -187,10 +154,7 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
187
154
  backgroundColor: `${baseBackgroundColor} !important`,
188
155
  bottom:
189
156
  !virtualRow && bottomPinnedIndex !== undefined && isRowPinned
190
- ? `${
191
- bottomPinnedIndex * rowHeight +
192
- (enableStickyFooter ? tableFooterHeight - 1 : 0)
193
- }px`
157
+ ? `${bottomPinnedIndex * rowHeight + (enableStickyFooter ? tableFooterHeight - 1 : 0)}px`
194
158
  : undefined,
195
159
  boxSizing: 'border-box',
196
160
  display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
@@ -212,54 +176,44 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
212
176
  top: virtualRow
213
177
  ? 0
214
178
  : topPinnedIndex !== undefined && isRowPinned
215
- ? `${
216
- topPinnedIndex * rowHeight +
217
- (enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0)
218
- }px`
179
+ ? `${topPinnedIndex * rowHeight + (enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0)}px`
219
180
  : undefined,
220
181
  transition: virtualRow ? 'none' : 'all 150ms ease-in-out',
221
182
  width: '100%',
222
- zIndex:
223
- rowPinningDisplayMode?.includes('sticky') && isRowPinned ? 2 : 0,
224
- ...(sx as any),
183
+ zIndex: rowPinningDisplayMode?.includes('sticky') && isRowPinned ? 2 : 0,
184
+ ...sx,
225
185
  })}
226
186
  >
227
- {virtualPaddingLeft ? (
228
- <td style={{ display: 'flex', width: virtualPaddingLeft }} />
229
- ) : null}
230
- {(virtualColumns ?? visibleCells).map(
231
- (cellOrVirtualCell, staticColumnIndex) => {
232
- let cell = cellOrVirtualCell as MRT_Cell<TData>;
233
- if (columnVirtualizer) {
234
- staticColumnIndex = (cellOrVirtualCell as MRT_VirtualItem).index;
235
- cell = visibleCells[staticColumnIndex];
236
- }
237
- const props = {
238
- cell,
239
- numRows,
240
- rowRef,
241
- staticColumnIndex,
242
- staticRowIndex,
243
- table,
244
- };
245
- const key = `${cell.id}-${staticRowIndex}`;
246
- return cell ? (
247
- memoMode === 'cells' &&
248
- cell.column.columnDef.columnDefType === 'data' &&
249
- !draggingColumn &&
250
- !draggingRow &&
251
- editingCell?.id !== cell.id &&
252
- editingRow?.id !== row.id ? (
253
- <Memo_MRT_TableBodyCell key={key} {...props} />
254
- ) : (
255
- <MRT_TableBodyCell key={key} {...props} />
256
- )
257
- ) : null;
258
- },
259
- )}
260
- {virtualPaddingRight ? (
261
- <td style={{ display: 'flex', width: virtualPaddingRight }} />
262
- ) : null}
187
+ {virtualPaddingLeft ? <td style={{ display: 'flex', width: virtualPaddingLeft }} /> : null}
188
+ {(virtualColumns ?? visibleCells).map((cellOrVirtualCell, staticColumnIndex) => {
189
+ let cell = cellOrVirtualCell as MRT_Cell<TData>;
190
+ if (columnVirtualizer) {
191
+ staticColumnIndex = (cellOrVirtualCell as MRT_VirtualItem).index;
192
+ cell = visibleCells[staticColumnIndex];
193
+ }
194
+ const props = {
195
+ cell,
196
+ numRows,
197
+ rowRef,
198
+ staticColumnIndex,
199
+ staticRowIndex,
200
+ table,
201
+ };
202
+ const key = `${cell.id}-${staticRowIndex}`;
203
+ return cell ? (
204
+ memoMode === 'cells' &&
205
+ cell.column.columnDef.columnDefType === 'data' &&
206
+ !draggingColumn &&
207
+ !draggingRow &&
208
+ editingCell?.id !== cell.id &&
209
+ editingRow?.id !== row.id ? (
210
+ <Memo_MRT_TableBodyCell key={key} {...props} />
211
+ ) : (
212
+ <MRT_TableBodyCell key={key} {...props} />
213
+ )
214
+ ) : null;
215
+ })}
216
+ {virtualPaddingRight ? <td style={{ display: 'flex', width: virtualPaddingRight }} /> : null}
263
217
  </TableRow>
264
218
  {renderDetailPanel && !row.getIsGrouped() && (
265
219
  <MRT_TableDetailPanel
@@ -277,6 +231,5 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
277
231
 
278
232
  export const Memo_MRT_TableBodyRow = memo(
279
233
  MRT_TableBodyRow,
280
- (prev, next) =>
281
- prev.row === next.row && prev.staticRowIndex === next.staticRowIndex,
234
+ (prev, next) => prev.row === next.row && prev.staticRowIndex === next.staticRowIndex,
282
235
  ) as typeof MRT_TableBodyRow;
@@ -10,9 +10,7 @@ interface Person {
10
10
 
11
11
  const data: Person[] = [{ name: 'Alice' }, { name: 'Bob' }];
12
12
 
13
- const columns = (): MRT_ColumnDef<Person>[] => [
14
- { accessorKey: 'name', header: 'Name' },
15
- ];
13
+ const columns = (): MRT_ColumnDef<Person>[] => [{ accessorKey: 'name', header: 'Name' }];
16
14
 
17
15
  describe('row ordering', () => {
18
16
  test('dragging a row over another reports both rows to the drop handler', () => {
@@ -26,9 +24,7 @@ describe('row ordering', () => {
26
24
  />,
27
25
  );
28
26
 
29
- const handles = container.querySelectorAll<HTMLElement>(
30
- 'tbody button[aria-label="Move"]',
31
- );
27
+ const handles = container.querySelectorAll<HTMLElement>('tbody button[aria-label="Move"]');
32
28
  const rows = container.querySelectorAll<HTMLElement>('tbody tr');
33
29
 
34
30
  fireEvent.dragStart(handles[0], {
@@ -1,16 +1,11 @@
1
1
  import { type IconButtonProps } from '@mui/material/IconButton';
2
2
  import { type DragEvent, type RefObject } from 'react';
3
3
 
4
- import {
5
- type MRT_Row,
6
- type MRT_RowData,
7
- type MRT_TableInstance,
8
- } from '../../types';
4
+ import { type MRT_Row, type MRT_RowData, type MRT_TableInstance } from '../../types';
9
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
10
6
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
11
7
 
12
- export interface MRT_TableBodyRowGrabHandleProps<TData extends MRT_RowData>
13
- extends IconButtonProps {
8
+ export interface MRT_TableBodyRowGrabHandleProps<TData extends MRT_RowData> extends IconButtonProps {
14
9
  row: MRT_Row<TData>;
15
10
  rowRef: RefObject<HTMLTableRowElement | null>;
16
11
  table: MRT_TableInstance<TData>;
@@ -21,7 +16,7 @@ export const MRT_TableBodyRowGrabHandle = <TData extends MRT_RowData>({
21
16
  rowRef,
22
17
  table,
23
18
  ...rest
24
- }: MRT_TableBodyRowGrabHandleProps<TData>) => {
19
+ }: MRT_TableBodyRowGrabHandleProps<TData>): JSX.Element => {
25
20
  const {
26
21
  options: { muiRowDragHandleProps },
27
22
  } = table;
@@ -41,7 +36,7 @@ export const MRT_TableBodyRowGrabHandle = <TData extends MRT_RowData>({
41
36
  } catch (e) {
42
37
  console.error(e);
43
38
  }
44
- table.setDraggingRow(row as any);
39
+ table.setDraggingRow(row);
45
40
  };
46
41
 
47
42
  const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
@@ -1,16 +1,11 @@
1
1
  import { Box } from '@mui/material';
2
2
  import { type IconButtonProps } from '@mui/material/IconButton';
3
3
 
4
- import {
5
- type MRT_Row,
6
- type MRT_RowData,
7
- type MRT_TableInstance,
8
- } from '../../types';
4
+ import { type MRT_Row, type MRT_RowData, type MRT_TableInstance } from '../../types';
9
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
10
6
  import { MRT_RowPinButton } from '../buttons/MRT_RowPinButton';
11
7
 
12
- export interface MRT_TableBodyRowPinButtonProps<TData extends MRT_RowData>
13
- extends IconButtonProps {
8
+ export interface MRT_TableBodyRowPinButtonProps<TData extends MRT_RowData> extends IconButtonProps {
14
9
  row: MRT_Row<TData>;
15
10
  table: MRT_TableInstance<TData>;
16
11
  }
@@ -19,15 +14,17 @@ export const MRT_TableBodyRowPinButton = <TData extends MRT_RowData>({
19
14
  row,
20
15
  table,
21
16
  ...rest
22
- }: MRT_TableBodyRowPinButtonProps<TData>) => {
17
+ }: MRT_TableBodyRowPinButtonProps<TData>): JSX.Element | null => {
23
18
  const {
24
19
  options: { enableRowPinning, rowPinningDisplayMode },
25
20
  } = table;
26
21
  const { density } = table.state;
27
22
 
28
- const canPin = parseFromValuesOrFunc(enableRowPinning, row as any);
23
+ const canPin = parseFromValuesOrFunc(enableRowPinning, row);
29
24
 
30
- if (!canPin) return null;
25
+ if (!canPin) {
26
+ return null;
27
+ }
31
28
 
32
29
  const rowPinButtonProps = {
33
30
  row,
@@ -50,9 +47,6 @@ export const MRT_TableBodyRowPinButton = <TData extends MRT_RowData>({
50
47
  }
51
48
 
52
49
  return (
53
- <MRT_RowPinButton
54
- pinningPosition={rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top'}
55
- {...rowPinButtonProps}
56
- />
50
+ <MRT_RowPinButton pinningPosition={rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top'} {...rowPinButtonProps} />
57
51
  );
58
52
  };
@@ -12,9 +12,7 @@ interface Person {
12
12
 
13
13
  const data: Person[] = [{ city: 'Glasgow', name: 'Alice' }];
14
14
 
15
- const columns = (): MRT_ColumnDef<Person>[] => [
16
- { accessorKey: 'name', header: 'Name' },
17
- ];
15
+ const columns = (): MRT_ColumnDef<Person>[] => [{ accessorKey: 'name', header: 'Name' }];
18
16
 
19
17
  describe('detail panel', () => {
20
18
  test('reveals the panel content when the expand button is clicked', async () => {
@@ -23,17 +21,13 @@ describe('detail panel', () => {
23
21
  <MaterialReactTable
24
22
  columns={columns()}
25
23
  data={data}
26
- renderDetailPanel={({ row }) => (
27
- <span>Lives in {row.original.city}</span>
28
- )}
24
+ renderDetailPanel={({ row }) => <span>Lives in {row.original.city}</span>}
29
25
  />,
30
26
  );
31
27
 
32
28
  expect(container.textContent).not.toContain('Lives in Glasgow');
33
29
 
34
- await user.click(
35
- container.querySelector('tbody button[aria-label="Expand"]') as HTMLElement,
36
- );
30
+ await user.click(container.querySelector('tbody button[aria-label="Expand"]') as HTMLElement);
37
31
 
38
32
  expect(container.textContent).toContain('Lives in Glasgow');
39
33
  });
@@ -1,6 +1,5 @@
1
- import { Collapse } from '@mui/material';
2
- import { TableCell, type TableCellProps } from '@mui/material';
3
- import { TableRow } from '@mui/material';
1
+ import { Collapse, TableCell, type TableCellProps, TableRow } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
4
3
  import { type RefObject } from 'react';
5
4
 
6
5
  import {
@@ -12,8 +11,7 @@ import {
12
11
  } from '../../types';
13
12
  import { parseFromValuesOrFunc } from '../../utils/utils';
14
13
 
15
- export interface MRT_TableDetailPanelProps<TData extends MRT_RowData>
16
- extends TableCellProps {
14
+ export interface MRT_TableDetailPanelProps<TData extends MRT_RowData> extends TableCellProps {
17
15
  parentRowRef: RefObject<HTMLTableRowElement | null>;
18
16
  row: MRT_Row<TData>;
19
17
  rowVirtualizer?: MRT_RowVirtualizer;
@@ -30,7 +28,7 @@ export const MRT_TableDetailPanel = <TData extends MRT_RowData>({
30
28
  table,
31
29
  virtualRow,
32
30
  ...rest
33
- }: MRT_TableDetailPanelProps<TData>) => {
31
+ }: MRT_TableDetailPanelProps<TData>): JSX.Element => {
34
32
  const {
35
33
  getVisibleLeafColumns,
36
34
  options: {
@@ -73,14 +71,10 @@ export const MRT_TableDetailPanel = <TData extends MRT_RowData>({
73
71
  sx={(theme) => ({
74
72
  display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
75
73
  position: virtualRow ? 'absolute' : undefined,
76
- top: virtualRow
77
- ? `${parentRowRef.current?.getBoundingClientRect()?.height}px`
78
- : undefined,
79
- transform: virtualRow
80
- ? `translateY(${virtualRow?.start}px)`
81
- : undefined,
74
+ top: virtualRow ? `${parentRowRef.current?.getBoundingClientRect()?.height}px` : undefined,
75
+ transform: virtualRow ? `translateY(${virtualRow?.start}px)` : undefined,
82
76
  width: '100%',
83
- ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as any),
77
+ ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as CSSObject),
84
78
  })}
85
79
  >
86
80
  <TableCell
@@ -94,7 +88,7 @@ export const MRT_TableDetailPanel = <TData extends MRT_RowData>({
94
88
  py: !!DetailPanel && row.getIsExpanded() ? '1rem' : 0,
95
89
  transition: !virtualRow ? 'all 150ms ease-in-out' : undefined,
96
90
  width: `100%`,
97
- ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
91
+ ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as CSSObject),
98
92
  })}
99
93
  >
100
94
  {virtualRow ? (
@@ -18,33 +18,23 @@ const columns = (): MRT_ColumnDef<Person>[] => [
18
18
  ];
19
19
 
20
20
  const headerOrder = (container: HTMLElement) =>
21
- Array.from(container.querySelectorAll('thead th')).map((th) =>
22
- th.textContent?.replace(/[^A-Za-z]/g, ''),
23
- );
21
+ Array.from(container.querySelectorAll('thead th')).map((th) => th.textContent?.replace(/[^A-Za-z]/g, ''));
24
22
 
25
23
  describe('column pinning', () => {
26
24
  test('pinning to start moves the column to the front', async () => {
27
25
  const user = userEvent.setup();
28
26
  const { baseElement, container } = render(
29
- <MaterialReactTable
30
- columns={columns()}
31
- data={data}
32
- enableColumnPinning
33
- />,
27
+ <MaterialReactTable columns={columns()} data={data} enableColumnPinning />,
34
28
  );
35
29
 
36
30
  expect(headerOrder(container)).toEqual(['Name', 'City']);
37
31
 
38
- const cityHeader = Array.from(
39
- container.querySelectorAll<HTMLElement>('thead th'),
40
- ).find((th) => th.textContent?.includes('City'));
41
-
42
- await user.click(
43
- cityHeader?.querySelector(
44
- 'button[aria-label="Column Actions"]',
45
- ) as HTMLElement,
32
+ const cityHeader = Array.from(container.querySelectorAll<HTMLElement>('thead th')).find((th) =>
33
+ th.textContent?.includes('City'),
46
34
  );
47
35
 
36
+ await user.click(cityHeader?.querySelector('button[aria-label="Column Actions"]') as HTMLElement);
37
+
48
38
  await user.click(
49
39
  Array.from(baseElement.querySelectorAll<HTMLElement>('li')).find((li) =>
50
40
  li.textContent?.includes('Pin to left'),
@@ -1,16 +1,10 @@
1
- import { Box, type BoxProps } from '@mui/material';
2
- import { IconButton } from '@mui/material';
3
- import { Tooltip } from '@mui/material';
1
+ import { Box, type BoxProps, IconButton, Tooltip } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
4
3
 
5
- import {
6
- type MRT_Column,
7
- type MRT_RowData,
8
- type MRT_TableInstance,
9
- } from '../../types';
4
+ import { type MRT_Column, type MRT_RowData, type MRT_TableInstance } from '../../types';
10
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
11
6
 
12
- export interface MRT_ColumnPinningButtonsProps<TData extends MRT_RowData>
13
- extends BoxProps {
7
+ export interface MRT_ColumnPinningButtonsProps<TData extends MRT_RowData> extends BoxProps {
14
8
  column: MRT_Column<TData>;
15
9
  table: MRT_TableInstance<TData>;
16
10
  }
@@ -19,7 +13,7 @@ export const MRT_ColumnPinningButtons = <TData extends MRT_RowData>({
19
13
  column,
20
14
  table,
21
15
  ...rest
22
- }: MRT_ColumnPinningButtonsProps<TData>) => {
16
+ }: MRT_ColumnPinningButtonsProps<TData>): JSX.Element => {
23
17
  const {
24
18
  options: {
25
19
  icons: { PushPinIcon },
@@ -37,7 +31,7 @@ export const MRT_ColumnPinningButtons = <TData extends MRT_RowData>({
37
31
  sx={(theme) => ({
38
32
  minWidth: '70px',
39
33
  textAlign: 'center',
40
- ...(parseFromValuesOrFunc(rest?.sx, theme) as any),
34
+ ...(parseFromValuesOrFunc(rest?.sx, theme) as CSSObject),
41
35
  })}
42
36
  >
43
37
  {column.getIsPinned() ? (
@@ -1,17 +1,12 @@
1
- import { Button, type ButtonProps } from '@mui/material';
2
- import { Tooltip } from '@mui/material';
1
+ import { Button, type ButtonProps, Tooltip } from '@mui/material';
2
+ import { type CSSObject } from '@mui/material/styles';
3
3
  import { type MouseEvent, useState } from 'react';
4
4
 
5
- import {
6
- type MRT_Cell,
7
- type MRT_RowData,
8
- type MRT_TableInstance,
9
- } from '../../types';
5
+ import { type MRT_Cell, type MRT_RowData, type MRT_TableInstance } from '../../types';
10
6
  import { getCommonTooltipProps } from '../../utils/style.utils';
11
7
  import { parseFromValuesOrFunc } from '../../utils/utils';
12
8
 
13
- export interface MRT_CopyButtonProps<TData extends MRT_RowData>
14
- extends ButtonProps {
9
+ export interface MRT_CopyButtonProps<TData extends MRT_RowData> extends ButtonProps {
15
10
  cell: MRT_Cell<TData>;
16
11
  table: MRT_TableInstance<TData>;
17
12
  }
@@ -20,7 +15,7 @@ export const MRT_CopyButton = <TData extends MRT_RowData>({
20
15
  cell,
21
16
  table,
22
17
  ...rest
23
- }: MRT_CopyButtonProps<TData>) => {
18
+ }: MRT_CopyButtonProps<TData>): JSX.Element => {
24
19
  const {
25
20
  options: { localization, muiCopyButtonProps },
26
21
  } = table;
@@ -55,10 +50,7 @@ export const MRT_CopyButton = <TData extends MRT_RowData>({
55
50
  return (
56
51
  <Tooltip
57
52
  {...getCommonTooltipProps('top')}
58
- title={
59
- buttonProps?.title ??
60
- (copied ? localization.copiedToClipboard : localization.clickToCopy)
61
- }
53
+ title={buttonProps?.title ?? (copied ? localization.copiedToClipboard : localization.clickToCopy)}
62
54
  >
63
55
  <Button
64
56
  onClick={(e) => handleCopy(e, cell.getValue())}
@@ -79,7 +71,7 @@ export const MRT_CopyButton = <TData extends MRT_RowData>({
79
71
  py: 0,
80
72
  textAlign: 'inherit',
81
73
  textTransform: 'inherit',
82
- ...(parseFromValuesOrFunc(buttonProps?.sx, theme) as any),
74
+ ...(parseFromValuesOrFunc(buttonProps?.sx, theme) as CSSObject),
83
75
  })}
84
76
  title={undefined}
85
77
  />
@@ -11,9 +11,7 @@ interface Person {
11
11
 
12
12
  const data: Person[] = [{ name: 'Alice' }];
13
13
 
14
- const columns = (): MRT_ColumnDef<Person>[] => [
15
- { accessorKey: 'name', header: 'Name' },
16
- ];
14
+ const columns = (): MRT_ColumnDef<Person>[] => [{ accessorKey: 'name', header: 'Name' }];
17
15
 
18
16
  describe('creating a row', () => {
19
17
  test('calls onCreatingRowSave when save is clicked', async () => {
@@ -41,9 +39,7 @@ describe('creating a row', () => {
41
39
 
42
40
  expect(container.querySelectorAll('tbody input').length).toBeGreaterThan(0);
43
41
 
44
- await user.click(
45
- container.querySelector('[aria-label="Save"]') as HTMLElement,
46
- );
42
+ await user.click(container.querySelector('[aria-label="Save"]') as HTMLElement);
47
43
 
48
44
  expect(onCreatingRowSave).toHaveBeenCalled();
49
45
  });