material-react-table 2.0.0-alpha.0 → 2.0.0-alpha.2

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 (119) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/index.js +2480 -2392
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/MaterialReactTable.d.ts +1 -1
  5. package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -2
  6. package/dist/cjs/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
  7. package/dist/cjs/types/body/index.d.ts +1 -0
  8. package/dist/cjs/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
  9. package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +9 -0
  10. package/dist/cjs/types/buttons/index.d.ts +2 -1
  11. package/dist/cjs/types/column.utils.d.ts +7 -6
  12. package/dist/cjs/types/filterFns.d.ts +14 -14
  13. package/dist/cjs/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
  14. package/dist/cjs/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
  15. package/dist/cjs/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
  16. package/dist/cjs/types/icons.d.ts +1 -1
  17. package/dist/cjs/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
  18. package/dist/cjs/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
  19. package/dist/cjs/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
  20. package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
  21. package/dist/cjs/types/toolbar/MRT_TopToolbar.d.ts +1 -1
  22. package/dist/cjs/types/types.d.ts +203 -197
  23. package/dist/esm/material-react-table.esm.js +2442 -2358
  24. package/dist/esm/material-react-table.esm.js.map +1 -1
  25. package/dist/esm/types/MaterialReactTable.d.ts +1 -1
  26. package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -2
  27. package/dist/esm/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
  28. package/dist/esm/types/body/index.d.ts +1 -0
  29. package/dist/esm/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
  30. package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +9 -0
  31. package/dist/esm/types/buttons/index.d.ts +2 -1
  32. package/dist/esm/types/column.utils.d.ts +7 -6
  33. package/dist/esm/types/filterFns.d.ts +14 -14
  34. package/dist/esm/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
  35. package/dist/esm/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
  36. package/dist/esm/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
  37. package/dist/esm/types/icons.d.ts +1 -1
  38. package/dist/esm/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
  39. package/dist/esm/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
  40. package/dist/esm/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
  41. package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
  42. package/dist/esm/types/toolbar/MRT_TopToolbar.d.ts +1 -1
  43. package/dist/esm/types/types.d.ts +203 -197
  44. package/dist/index.d.ts +293 -272
  45. package/locales/en.esm.js +1 -0
  46. package/locales/en.esm.js.map +1 -1
  47. package/locales/en.js +1 -0
  48. package/locales/en.js.map +1 -1
  49. package/locales/fr.esm.js +1 -1
  50. package/locales/fr.esm.js.map +1 -1
  51. package/locales/fr.js +1 -1
  52. package/locales/fr.js.map +1 -1
  53. package/package.json +10 -9
  54. package/src/MaterialReactTable.tsx +2 -2
  55. package/src/body/MRT_TableBody.tsx +180 -76
  56. package/src/body/MRT_TableBodyCell.tsx +45 -43
  57. package/src/body/MRT_TableBodyCellValue.tsx +5 -5
  58. package/src/body/MRT_TableBodyRow.tsx +117 -29
  59. package/src/body/MRT_TableBodyRowGrabHandle.tsx +6 -5
  60. package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
  61. package/src/body/MRT_TableDetailPanel.tsx +16 -22
  62. package/src/body/index.ts +2 -1
  63. package/src/buttons/MRT_CopyButton.tsx +14 -20
  64. package/src/buttons/MRT_EditActionButtons.tsx +4 -4
  65. package/src/buttons/MRT_ExpandAllButton.tsx +7 -9
  66. package/src/buttons/MRT_ExpandButton.tsx +6 -7
  67. package/src/buttons/MRT_GrabHandleButton.tsx +12 -13
  68. package/src/buttons/MRT_RowPinButton.tsx +74 -0
  69. package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -1
  70. package/src/buttons/MRT_ToggleFullScreenButton.tsx +2 -2
  71. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +9 -10
  72. package/src/buttons/index.ts +2 -1
  73. package/src/column.utils.ts +33 -21
  74. package/src/filterFns.ts +29 -29
  75. package/src/footer/MRT_TableFooter.tsx +14 -8
  76. package/src/footer/MRT_TableFooterCell.tsx +8 -21
  77. package/src/footer/MRT_TableFooterRow.tsx +7 -8
  78. package/src/head/MRT_TableHead.tsx +12 -8
  79. package/src/head/MRT_TableHeadCell.tsx +18 -25
  80. package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +18 -23
  81. package/src/head/MRT_TableHeadCellFilterContainer.tsx +11 -4
  82. package/src/head/MRT_TableHeadCellFilterLabel.tsx +106 -61
  83. package/src/head/MRT_TableHeadCellGrabHandle.tsx +8 -15
  84. package/src/head/MRT_TableHeadCellResizeHandle.tsx +11 -11
  85. package/src/head/MRT_TableHeadCellSortLabel.tsx +8 -8
  86. package/src/head/MRT_TableHeadRow.tsx +7 -8
  87. package/src/hooks/useMRT_DisplayColumns.tsx +17 -4
  88. package/src/hooks/useMRT_Effects.ts +3 -3
  89. package/src/hooks/useMRT_TableInstance.ts +17 -10
  90. package/src/hooks/useMRT_TableOptions.ts +9 -5
  91. package/src/icons.ts +2 -2
  92. package/src/inputs/MRT_EditCellTextField.tsx +23 -31
  93. package/src/inputs/MRT_FilterCheckbox.tsx +17 -29
  94. package/src/inputs/MRT_FilterRangeFields.tsx +1 -1
  95. package/src/inputs/MRT_FilterRangeSlider.tsx +12 -29
  96. package/src/inputs/MRT_FilterTextField.tsx +83 -99
  97. package/src/inputs/MRT_GlobalFilterTextField.tsx +29 -29
  98. package/src/inputs/MRT_SelectCheckbox.tsx +35 -21
  99. package/src/locales/en.ts +1 -1
  100. package/src/locales/fr.ts +1 -1
  101. package/src/menus/MRT_ColumnActionMenu.tsx +14 -14
  102. package/src/menus/MRT_FilterOptionMenu.tsx +35 -35
  103. package/src/menus/MRT_RowActionMenu.tsx +17 -18
  104. package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -6
  105. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +5 -5
  106. package/src/modals/MRT_EditRowModal.tsx +12 -20
  107. package/src/sortingFns.ts +1 -1
  108. package/src/table/MRT_Table.tsx +14 -19
  109. package/src/table/MRT_TableContainer.tsx +14 -20
  110. package/src/table/MRT_TablePaper.tsx +16 -20
  111. package/src/toolbar/MRT_BottomToolbar.tsx +18 -24
  112. package/src/toolbar/MRT_LinearProgressBar.tsx +8 -7
  113. package/src/toolbar/MRT_TablePagination.tsx +23 -25
  114. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +11 -14
  115. package/src/toolbar/MRT_ToolbarDropZone.tsx +6 -6
  116. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -5
  117. package/src/toolbar/MRT_TopToolbar.tsx +14 -20
  118. package/src/types.ts +269 -252
  119. package/src/useMaterialReactTable.ts +1 -1
@@ -14,88 +14,88 @@ export const mrtFilterOptions = (
14
14
  localization: MRT_Localization,
15
15
  ): MRT_InternalFilterOption[] => [
16
16
  {
17
+ divider: false,
18
+ label: localization.filterFuzzy,
17
19
  option: 'fuzzy',
18
20
  symbol: '≈',
19
- label: localization.filterFuzzy,
20
- divider: false,
21
21
  },
22
22
  {
23
+ divider: false,
24
+ label: localization.filterContains,
23
25
  option: 'contains',
24
26
  symbol: '*',
25
- label: localization.filterContains,
26
- divider: false,
27
27
  },
28
28
  {
29
+ divider: false,
30
+ label: localization.filterStartsWith,
29
31
  option: 'startsWith',
30
32
  symbol: 'a',
31
- label: localization.filterStartsWith,
32
- divider: false,
33
33
  },
34
34
  {
35
+ divider: true,
36
+ label: localization.filterEndsWith,
35
37
  option: 'endsWith',
36
38
  symbol: 'z',
37
- label: localization.filterEndsWith,
38
- divider: true,
39
39
  },
40
40
  {
41
+ divider: false,
42
+ label: localization.filterEquals,
41
43
  option: 'equals',
42
44
  symbol: '=',
43
- label: localization.filterEquals,
44
- divider: false,
45
45
  },
46
46
  {
47
+ divider: true,
48
+ label: localization.filterNotEquals,
47
49
  option: 'notEquals',
48
50
  symbol: '≠',
49
- label: localization.filterNotEquals,
50
- divider: true,
51
51
  },
52
52
  {
53
+ divider: false,
54
+ label: localization.filterBetween,
53
55
  option: 'between',
54
56
  symbol: '⇿',
55
- label: localization.filterBetween,
56
- divider: false,
57
57
  },
58
58
  {
59
+ divider: true,
60
+ label: localization.filterBetweenInclusive,
59
61
  option: 'betweenInclusive',
60
62
  symbol: '⬌',
61
- label: localization.filterBetweenInclusive,
62
- divider: true,
63
63
  },
64
64
  {
65
+ divider: false,
66
+ label: localization.filterGreaterThan,
65
67
  option: 'greaterThan',
66
68
  symbol: '>',
67
- label: localization.filterGreaterThan,
68
- divider: false,
69
69
  },
70
70
  {
71
+ divider: false,
72
+ label: localization.filterGreaterThanOrEqualTo,
71
73
  option: 'greaterThanOrEqualTo',
72
74
  symbol: '≥',
73
- label: localization.filterGreaterThanOrEqualTo,
74
- divider: false,
75
75
  },
76
76
  {
77
+ divider: false,
78
+ label: localization.filterLessThan,
77
79
  option: 'lessThan',
78
80
  symbol: '<',
79
- label: localization.filterLessThan,
80
- divider: false,
81
81
  },
82
82
  {
83
+ divider: true,
84
+ label: localization.filterLessThanOrEqualTo,
83
85
  option: 'lessThanOrEqualTo',
84
86
  symbol: '≤',
85
- label: localization.filterLessThanOrEqualTo,
86
- divider: true,
87
87
  },
88
88
  {
89
+ divider: false,
90
+ label: localization.filterEmpty,
89
91
  option: 'empty',
90
92
  symbol: '∅',
91
- label: localization.filterEmpty,
92
- divider: false,
93
93
  },
94
94
  {
95
+ divider: false,
96
+ label: localization.filterNotEmpty,
95
97
  option: 'notEmpty',
96
98
  symbol: '!∅',
97
- label: localization.filterNotEmpty,
98
- divider: false,
99
99
  },
100
100
  ];
101
101
 
@@ -133,7 +133,7 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any>>({
133
133
  setColumnFilterFns,
134
134
  setGlobalFilterFn,
135
135
  } = table;
136
- const { globalFilterFn, density } = getState();
136
+ const { density, globalFilterFn } = getState();
137
137
  const { column } = header ?? {};
138
138
  const { columnDef } = column ?? {};
139
139
  const currentFilterValue = column?.getFilterValue();
@@ -156,7 +156,7 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any>>({
156
156
  allowedColumnFilterOptions?.includes(filterOption.option)
157
157
  : (!globalFilterModeOptions ||
158
158
  globalFilterModeOptions.includes(filterOption.option)) &&
159
- ['fuzzy', 'contains', 'startsWith'].includes(filterOption.option),
159
+ ['contains', 'fuzzy', 'startsWith'].includes(filterOption.option),
160
160
  ),
161
161
  [],
162
162
  );
@@ -232,13 +232,13 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any>>({
232
232
 
233
233
  return (
234
234
  <Menu
235
- anchorEl={anchorEl}
236
- anchorOrigin={{ vertical: 'center', horizontal: 'right' }}
237
- onClose={() => setAnchorEl(null)}
238
- open={!!anchorEl}
239
235
  MenuListProps={{
240
236
  dense: density === 'compact',
241
237
  }}
238
+ anchorEl={anchorEl}
239
+ anchorOrigin={{ horizontal: 'right', vertical: 'center' }}
240
+ onClose={() => setAnchorEl(null)}
241
+ open={!!anchorEl}
242
242
  >
243
243
  {(header && column && columnDef
244
244
  ? columnDef.renderColumnFilterModeMenuItems?.({
@@ -259,7 +259,7 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any>>({
259
259
  table,
260
260
  })) ??
261
261
  internalFilterOptions.map(
262
- ({ option, label, divider, symbol }, index) => (
262
+ ({ divider, label, option, symbol }, index) => (
263
263
  <MenuItem
264
264
  divider={divider}
265
265
  key={index}
@@ -7,6 +7,7 @@ import {
7
7
  commonListItemStyles,
8
8
  commonMenuItemStyles,
9
9
  } from './MRT_ColumnActionMenu';
10
+ import { parseFromValuesOrFunc } from '../column.utils';
10
11
  import { type MRT_Row, type MRT_TableInstance } from '../types';
11
12
 
12
13
  interface Props<TData extends Record<string, any>> {
@@ -27,8 +28,8 @@ export const MRT_RowActionMenu = <TData extends Record<string, any>>({
27
28
  const {
28
29
  getState,
29
30
  options: {
30
- icons: { EditIcon },
31
31
  enableEditing,
32
+ icons: { EditIcon },
32
33
  localization,
33
34
  renderRowActionMenuItems,
34
35
  },
@@ -37,30 +38,28 @@ export const MRT_RowActionMenu = <TData extends Record<string, any>>({
37
38
 
38
39
  return (
39
40
  <Menu
40
- anchorEl={anchorEl}
41
- open={!!anchorEl}
42
- onClick={(event) => event.stopPropagation()}
43
- onClose={() => setAnchorEl(null)}
44
41
  MenuListProps={{
45
42
  dense: density === 'compact',
46
43
  }}
44
+ anchorEl={anchorEl}
45
+ onClick={(event) => event.stopPropagation()}
46
+ onClose={() => setAnchorEl(null)}
47
+ open={!!anchorEl}
47
48
  >
48
- {enableEditing instanceof Function
49
- ? enableEditing(row)
50
- : enableEditing && (
51
- <MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
52
- <Box sx={commonListItemStyles}>
53
- <ListItemIcon>
54
- <EditIcon />
55
- </ListItemIcon>
56
- {localization.edit}
57
- </Box>
58
- </MenuItem>
59
- )}
49
+ {parseFromValuesOrFunc(enableEditing, row) && (
50
+ <MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
51
+ <Box sx={commonListItemStyles}>
52
+ <ListItemIcon>
53
+ <EditIcon />
54
+ </ListItemIcon>
55
+ {localization.edit}
56
+ </Box>
57
+ </MenuItem>
58
+ )}
60
59
  {renderRowActionMenuItems?.({
60
+ closeMenu: () => setAnchorEl(null),
61
61
  row,
62
62
  table,
63
- closeMenu: () => setAnchorEl(null),
64
63
  })}
65
64
  </Menu>
66
65
  );
@@ -29,15 +29,15 @@ export const MRT_ShowHideColumnsMenu = <TData extends Record<string, any>>({
29
29
  getLeftLeafColumns,
30
30
  getRightLeafColumns,
31
31
  getState,
32
- toggleAllColumnsVisible,
33
32
  options: {
34
33
  enableColumnOrdering,
35
- enableHiding,
36
34
  enableColumnPinning,
35
+ enableHiding,
37
36
  localization,
38
37
  },
38
+ toggleAllColumnsVisible,
39
39
  } = table;
40
- const { density, columnOrder, columnPinning } = getState();
40
+ const { columnOrder, columnPinning, density } = getState();
41
41
 
42
42
  const hideAllColumns = () => {
43
43
  getAllLeafColumns()
@@ -75,12 +75,12 @@ export const MRT_ShowHideColumnsMenu = <TData extends Record<string, any>>({
75
75
 
76
76
  return (
77
77
  <Menu
78
- anchorEl={anchorEl}
79
- open={!!anchorEl}
80
- onClose={() => setAnchorEl(null)}
81
78
  MenuListProps={{
82
79
  dense: density === 'compact',
83
80
  }}
81
+ anchorEl={anchorEl}
82
+ onClose={() => setAnchorEl(null)}
83
+ open={!!anchorEl}
84
84
  >
85
85
  <Box
86
86
  sx={{
@@ -28,17 +28,17 @@ export const MRT_ShowHideColumnsMenuItems = <
28
28
  TData extends Record<string, any>,
29
29
  >({
30
30
  allColumns,
31
+ column,
31
32
  hoveredColumn,
32
33
  setHoveredColumn,
33
- column,
34
34
  table,
35
35
  }: Props<TData>) => {
36
36
  const {
37
37
  getState,
38
38
  options: {
39
39
  enableColumnOrdering,
40
- enableHiding,
41
40
  enableColumnPinning,
41
+ enableHiding,
42
42
  localization,
43
43
  },
44
44
  setColumnOrder,
@@ -89,19 +89,19 @@ export const MRT_ShowHideColumnsMenuItems = <
89
89
  <>
90
90
  <MenuItem
91
91
  disableRipple
92
- ref={menuItemRef as any}
93
92
  onDragEnter={handleDragEnter}
93
+ ref={menuItemRef as any}
94
94
  sx={(theme) => ({
95
95
  alignItems: 'center',
96
96
  justifyContent: 'flex-start',
97
97
  my: 0,
98
98
  opacity: isDragging ? 0.5 : 1,
99
- outlineOffset: '-2px',
100
99
  outline: isDragging
101
100
  ? `2px dashed ${theme.palette.divider}`
102
101
  : hoveredColumn?.id === column.id
103
102
  ? `2px dashed ${theme.palette.primary.main}`
104
103
  : 'none',
104
+ outlineOffset: '-2px',
105
105
  pl: `${(column.depth + 0.5) * 2}rem`,
106
106
  py: '6px',
107
107
  })}
@@ -135,6 +135,7 @@ export const MRT_ShowHideColumnsMenuItems = <
135
135
  ))}
136
136
  {enableHiding ? (
137
137
  <FormControlLabel
138
+ checked={switchChecked}
138
139
  componentsProps={{
139
140
  typography: {
140
141
  sx: {
@@ -143,7 +144,6 @@ export const MRT_ShowHideColumnsMenuItems = <
143
144
  },
144
145
  },
145
146
  }}
146
- checked={switchChecked}
147
147
  control={
148
148
  <Tooltip
149
149
  arrow
@@ -4,6 +4,7 @@ import DialogContent from '@mui/material/DialogContent';
4
4
  import DialogTitle from '@mui/material/DialogTitle';
5
5
  import Stack from '@mui/material/Stack';
6
6
  import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
7
+ import { parseFromValuesOrFunc } from '../column.utils';
7
8
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
8
9
  import { type MRT_Row, type MRT_TableInstance } from '../types';
9
10
 
@@ -20,32 +21,23 @@ export const MRT_EditRowModal = <TData extends Record<string, any>>({
20
21
  getState,
21
22
  options: {
22
23
  localization,
23
- onEditingRowCancel,
24
- onCreatingRowCancel,
25
- renderEditRowModalContent,
26
- renderCreateRowModalContent,
27
24
  muiCreateRowModalProps,
28
25
  muiEditRowModalProps,
26
+ onCreatingRowCancel,
27
+ onEditingRowCancel,
28
+ renderCreateRowModalContent,
29
+ renderEditRowModalContent,
29
30
  },
30
- setEditingRow,
31
31
  setCreatingRow,
32
+ setEditingRow,
32
33
  } = table;
33
34
  const { creatingRow, editingRow } = getState();
34
35
  const row = (creatingRow ?? editingRow) as MRT_Row<TData>;
35
36
 
36
- const createModalProps =
37
- muiCreateRowModalProps instanceof Function
38
- ? muiCreateRowModalProps({ row, table })
39
- : muiCreateRowModalProps;
40
-
41
- const editModalProps =
42
- muiEditRowModalProps instanceof Function
43
- ? muiEditRowModalProps({ row, table })
44
- : muiEditRowModalProps;
45
-
46
37
  const dialogProps = {
47
- ...editModalProps,
48
- ...(creatingRow && createModalProps),
38
+ ...parseFromValuesOrFunc(muiEditRowModalProps, { row, table }),
39
+ ...(creatingRow &&
40
+ parseFromValuesOrFunc(muiCreateRowModalProps, { row, table })),
49
41
  };
50
42
 
51
43
  const internalEditComponents = row
@@ -79,18 +71,18 @@ export const MRT_EditRowModal = <TData extends Record<string, any>>({
79
71
  >
80
72
  {((creatingRow &&
81
73
  renderCreateRowModalContent?.({
74
+ internalEditComponents,
82
75
  row,
83
76
  table,
84
- internalEditComponents,
85
77
  })) ||
86
78
  renderEditRowModalContent?.({
79
+ internalEditComponents,
87
80
  row,
88
81
  table,
89
- internalEditComponents,
90
82
  })) ?? (
91
83
  <>
92
84
  <DialogTitle sx={{ textAlign: 'center' }}>
93
- {(creatingRow && localization.create) || localization.edit}
85
+ {localization.edit}
94
86
  </DialogTitle>
95
87
  <DialogContent>
96
88
  <form onSubmit={(e) => e.preventDefault()}>
package/src/sortingFns.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { compareItems, type RankingInfo } from '@tanstack/match-sorter-utils';
1
+ import { type RankingInfo, compareItems } from '@tanstack/match-sorter-utils';
2
2
  import { type Row, sortingFns } from '@tanstack/react-table';
3
3
  import { type MRT_Row } from './types';
4
4
 
@@ -1,15 +1,15 @@
1
1
  import { useCallback, useMemo } from 'react';
2
2
  import {
3
- defaultRangeExtractor,
4
- useVirtualizer,
5
3
  type Range,
6
4
  type Virtualizer,
5
+ defaultRangeExtractor,
6
+ useVirtualizer,
7
7
  } from '@tanstack/react-virtual';
8
8
  import Table from '@mui/material/Table';
9
- import { MRT_TableHead } from '../head/MRT_TableHead';
10
- import { Memo_MRT_TableBody, MRT_TableBody } from '../body/MRT_TableBody';
9
+ import { MRT_TableBody, Memo_MRT_TableBody } from '../body/MRT_TableBody';
10
+ import { parseCSSVarId, parseFromValuesOrFunc } from '../column.utils';
11
11
  import { MRT_TableFooter } from '../footer/MRT_TableFooter';
12
- import { parseCSSVarId } from '../column.utils';
12
+ import { MRT_TableHead } from '../head/MRT_TableHead';
13
13
  import { type MRT_TableInstance } from '../types';
14
14
 
15
15
  interface Props<TData extends Record<string, any>> {
@@ -26,9 +26,9 @@ export const MRT_Table = <TData extends Record<string, any>>({
26
26
  columnVirtualizerInstanceRef,
27
27
  columnVirtualizerOptions,
28
28
  columns,
29
+ enableColumnPinning,
29
30
  enableColumnResizing,
30
31
  enableColumnVirtualization,
31
- enableColumnPinning,
32
32
  enableStickyHeader,
33
33
  enableTableFooter,
34
34
  enableTableHead,
@@ -46,15 +46,12 @@ export const MRT_Table = <TData extends Record<string, any>>({
46
46
  isFullScreen,
47
47
  } = getState();
48
48
 
49
- const tableProps =
50
- muiTableProps instanceof Function
51
- ? muiTableProps({ table })
52
- : muiTableProps;
49
+ const tableProps = parseFromValuesOrFunc(muiTableProps, { table });
53
50
 
54
- const vProps =
55
- columnVirtualizerOptions instanceof Function
56
- ? columnVirtualizerOptions({ table })
57
- : columnVirtualizerOptions;
51
+ const columnVirtualizerProps = parseFromValuesOrFunc(
52
+ columnVirtualizerOptions,
53
+ { table },
54
+ );
58
55
 
59
56
  const columnSizeVars = useMemo(() => {
60
57
  const headers = getFlatHeaders();
@@ -115,7 +112,7 @@ export const MRT_Table = <TData extends Record<string, any>>({
115
112
  ],
116
113
  [leftPinnedIndexes, rightPinnedIndexes],
117
114
  ),
118
- ...vProps,
115
+ ...columnVirtualizerProps,
119
116
  })
120
117
  : undefined;
121
118
 
@@ -150,16 +147,14 @@ export const MRT_Table = <TData extends Record<string, any>>({
150
147
  <Table
151
148
  stickyHeader={enableStickyHeader || isFullScreen}
152
149
  {...tableProps}
150
+ style={{ ...columnSizeVars, ...tableProps?.style }}
153
151
  sx={(theme) => ({
154
152
  borderCollapse: 'separate',
155
153
  display: layoutMode === 'grid' ? 'grid' : 'table',
156
154
  tableLayout:
157
155
  layoutMode !== 'grid' && enableColumnResizing ? 'fixed' : undefined,
158
- ...(tableProps?.sx instanceof Function
159
- ? tableProps.sx(theme)
160
- : (tableProps?.sx as any)),
156
+ ...(parseFromValuesOrFunc(tableProps?.sx, theme) as any),
161
157
  })}
162
- style={{ ...columnSizeVars, ...tableProps?.style }}
163
158
  >
164
159
  {enableTableHead && <MRT_TableHead {...props} />}
165
160
  {memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? (
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useLayoutEffect, useState } from 'react';
2
2
  import TableContainer from '@mui/material/TableContainer';
3
3
  import { MRT_Table } from './MRT_Table';
4
+ import { parseFromValuesOrFunc } from '../column.utils';
4
5
  import { MRT_EditRowModal } from '../modals';
5
6
  import { type MRT_TableInstance } from '../types';
6
7
 
@@ -22,20 +23,15 @@ export const MRT_TableContainer = <TData extends Record<string, any>>({
22
23
  enableStickyHeader,
23
24
  muiTableContainerProps,
24
25
  },
25
- refs: { tableContainerRef, bottomToolbarRef, topToolbarRef },
26
+ refs: { bottomToolbarRef, tableContainerRef, topToolbarRef },
26
27
  } = table;
27
- const {
28
- isFullScreen,
29
- creatingRow,
30
- editingRow,
31
- } = getState();
28
+ const { creatingRow, editingRow, isFullScreen } = getState();
32
29
 
33
30
  const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
34
31
 
35
- const tableContainerProps =
36
- muiTableContainerProps instanceof Function
37
- ? muiTableContainerProps({ table })
38
- : muiTableContainerProps;
32
+ const tableContainerProps = parseFromValuesOrFunc(muiTableContainerProps, {
33
+ table,
34
+ });
39
35
 
40
36
  useIsomorphicLayoutEffect(() => {
41
37
  const topToolbarHeight =
@@ -66,22 +62,20 @@ export const MRT_TableContainer = <TData extends Record<string, any>>({
66
62
  }
67
63
  }
68
64
  }}
69
- sx={(theme) => ({
70
- maxWidth: '100%',
71
- maxHeight: enableStickyHeader
72
- ? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
73
- : undefined,
74
- overflow: 'auto',
75
- ...(tableContainerProps?.sx instanceof Function
76
- ? tableContainerProps.sx(theme)
77
- : (tableContainerProps?.sx as any)),
78
- })}
79
65
  style={{
80
66
  maxHeight: isFullScreen
81
67
  ? `calc(100vh - ${totalToolbarHeight}px)`
82
68
  : undefined,
83
69
  ...tableContainerProps?.style,
84
70
  }}
71
+ sx={(theme) => ({
72
+ maxHeight: enableStickyHeader
73
+ ? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
74
+ : undefined,
75
+ maxWidth: '100%',
76
+ overflow: 'auto',
77
+ ...(parseFromValuesOrFunc(tableContainerProps?.sx, theme) as any),
78
+ })}
85
79
  >
86
80
  <MRT_Table table={table} />
87
81
  {(createModalOpen || editModalOpen) && (
@@ -1,7 +1,8 @@
1
1
  import Paper from '@mui/material/Paper';
2
- import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
3
- import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
4
2
  import { MRT_TableContainer } from './MRT_TableContainer';
3
+ import { parseFromValuesOrFunc } from '../column.utils';
4
+ import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
5
+ import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
5
6
  import { type MRT_TableInstance } from '../types';
6
7
 
7
8
  interface Props<TData extends Record<string, any>> {
@@ -24,10 +25,7 @@ export const MRT_TablePaper = <TData extends Record<string, any>>({
24
25
  } = table;
25
26
  const { isFullScreen } = getState();
26
27
 
27
- const tablePaperProps =
28
- muiTablePaperProps instanceof Function
29
- ? muiTablePaperProps({ table })
30
- : muiTablePaperProps;
28
+ const tablePaperProps = parseFromValuesOrFunc(muiTablePaperProps, { table });
31
29
 
32
30
  return (
33
31
  <Paper
@@ -40,15 +38,7 @@ export const MRT_TablePaper = <TData extends Record<string, any>>({
40
38
  tablePaperProps.ref.current = ref;
41
39
  }
42
40
  }}
43
- sx={(theme) => ({
44
- overflow: 'hidden',
45
- transition: 'all 100ms ease-in-out',
46
- ...(tablePaperProps?.sx instanceof Function
47
- ? tablePaperProps?.sx(theme)
48
- : (tablePaperProps?.sx as any)),
49
- })}
50
41
  style={{
51
- ...tablePaperProps?.style,
52
42
  ...(isFullScreen
53
43
  ? {
54
44
  bottom: 0,
@@ -65,17 +55,23 @@ export const MRT_TablePaper = <TData extends Record<string, any>>({
65
55
  zIndex: 10,
66
56
  }
67
57
  : {}),
58
+ ...tablePaperProps?.style,
68
59
  }}
60
+ sx={(theme) => ({
61
+ overflow: 'hidden',
62
+ transition: 'all 100ms ease-in-out',
63
+ ...(parseFromValuesOrFunc(tablePaperProps?.sx, theme) as any),
64
+ })}
69
65
  >
70
66
  {enableTopToolbar &&
71
- (renderTopToolbar instanceof Function
72
- ? renderTopToolbar({ table })
73
- : renderTopToolbar ?? <MRT_TopToolbar table={table} />)}
67
+ (parseFromValuesOrFunc(renderTopToolbar, { table }) ?? (
68
+ <MRT_TopToolbar table={table} />
69
+ ))}
74
70
  <MRT_TableContainer table={table} />
75
71
  {enableBottomToolbar &&
76
- (renderBottomToolbar instanceof Function
77
- ? renderBottomToolbar({ table })
78
- : renderBottomToolbar ?? <MRT_BottomToolbar table={table} />)}
72
+ (parseFromValuesOrFunc(renderBottomToolbar, { table }) ?? (
73
+ <MRT_BottomToolbar table={table} />
74
+ ))}
79
75
  </Paper>
80
76
  );
81
77
  };
@@ -1,12 +1,13 @@
1
1
  import Box from '@mui/material/Box';
2
2
  import Toolbar from '@mui/material/Toolbar';
3
- import useMediaQuery from '@mui/material/useMediaQuery';
4
3
  import { alpha } from '@mui/material/styles';
4
+ import useMediaQuery from '@mui/material/useMediaQuery';
5
+ import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
5
6
  import { MRT_TablePagination } from './MRT_TablePagination';
6
7
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
7
8
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
8
- import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
9
9
  import { commonToolbarStyles } from './MRT_TopToolbar';
10
+ import { parseFromValuesOrFunc } from '../column.utils';
10
11
  import { type MRT_TableInstance } from '../types';
11
12
 
12
13
  interface Props<TData extends Record<string, any>> {
@@ -32,10 +33,7 @@ export const MRT_BottomToolbar = <TData extends Record<string, any>>({
32
33
 
33
34
  const isMobile = useMediaQuery('(max-width:720px)');
34
35
 
35
- const toolbarProps =
36
- muiBottomToolbarProps instanceof Function
37
- ? muiBottomToolbarProps({ table })
38
- : muiBottomToolbarProps;
36
+ const toolbarProps = parseFromValuesOrFunc(muiBottomToolbarProps, { table });
39
37
 
40
38
  const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
41
39
 
@@ -52,22 +50,18 @@ export const MRT_BottomToolbar = <TData extends Record<string, any>>({
52
50
  }
53
51
  }
54
52
  }}
55
- sx={(theme) =>
56
- ({
57
- ...commonToolbarStyles({ theme }),
58
- bottom: isFullScreen ? '0' : undefined,
59
- boxShadow: `0 1px 2px -1px ${alpha(
60
- theme.palette.common.black,
61
- 0.1,
62
- )} inset`,
63
- left: 0,
64
- position: isFullScreen ? 'fixed' : 'relative',
65
- right: 0,
66
- ...(toolbarProps?.sx instanceof Function
67
- ? toolbarProps.sx(theme)
68
- : (toolbarProps?.sx as any)),
69
- } as any)
70
- }
53
+ sx={(theme) => ({
54
+ ...commonToolbarStyles({ theme }),
55
+ bottom: isFullScreen ? '0' : undefined,
56
+ boxShadow: `0 1px 2px -1px ${alpha(
57
+ theme.palette.common.black,
58
+ 0.1,
59
+ )} inset`,
60
+ left: 0,
61
+ position: isFullScreen ? 'fixed' : 'relative',
62
+ right: 0,
63
+ ...(parseFromValuesOrFunc(toolbarProps?.sx, theme) as any),
64
+ })}
71
65
  >
72
66
  <MRT_LinearProgressBar isTopToolbar={false} table={table} />
73
67
  {positionToolbarAlertBanner === 'bottom' && (
@@ -104,8 +98,8 @@ export const MRT_BottomToolbar = <TData extends Record<string, any>>({
104
98
  }}
105
99
  >
106
100
  {enablePagination &&
107
- ['bottom', 'both'].includes(positionPagination ?? '') && (
108
- <MRT_TablePagination table={table} position="bottom" />
101
+ ['both', 'bottom'].includes(positionPagination ?? '') && (
102
+ <MRT_TablePagination position="bottom" table={table} />
109
103
  )}
110
104
  </Box>
111
105
  </Box>