@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,16 +1,12 @@
1
- import { Box } from '@mui/material';
2
- import { IconButton } from '@mui/material';
3
- import { ListItemIcon } from '@mui/material';
4
- import { MenuItem, type MenuItemProps } from '@mui/material';
5
- import { type ReactNode } from 'react';
1
+ import { Box, IconButton, ListItemIcon, MenuItem, type MenuItemProps } from '@mui/material';
2
+ import { type MouseEventHandler, type ReactNode } from 'react';
6
3
 
7
4
  import { type MRT_RowData, type MRT_TableInstance } from '../../types';
8
5
 
9
- export interface MRT_ActionMenuItemProps<TData extends MRT_RowData>
10
- extends MenuItemProps {
6
+ export interface MRT_ActionMenuItemProps<TData extends MRT_RowData> extends MenuItemProps {
11
7
  icon: ReactNode;
12
8
  label: string;
13
- onOpenSubMenu?: MenuItemProps['onClick'] | MenuItemProps['onMouseEnter'];
9
+ onOpenSubMenu?: MouseEventHandler<HTMLElement>;
14
10
  table: MRT_TableInstance<TData>;
15
11
  }
16
12
 
@@ -20,7 +16,7 @@ export const MRT_ActionMenuItem = <TData extends MRT_RowData>({
20
16
  onOpenSubMenu,
21
17
  table,
22
18
  ...rest
23
- }: MRT_ActionMenuItemProps<TData>) => {
19
+ }: MRT_ActionMenuItemProps<TData>): JSX.Element => {
24
20
  const {
25
21
  options: {
26
22
  icons: { ArrowRightIcon },
@@ -49,12 +45,7 @@ export const MRT_ActionMenuItem = <TData extends MRT_RowData>({
49
45
  {label}
50
46
  </Box>
51
47
  {onOpenSubMenu && (
52
- <IconButton
53
- onClick={onOpenSubMenu as any}
54
- onMouseEnter={onOpenSubMenu as any}
55
- size="small"
56
- sx={{ p: 0 }}
57
- >
48
+ <IconButton onClick={onOpenSubMenu} onMouseEnter={onOpenSubMenu} size="small" sx={{ p: 0 }}>
58
49
  <ArrowRightIcon />
59
50
  </IconButton>
60
51
  )}
@@ -5,15 +5,14 @@ import { openEditingCell } from '../../utils/cell.utils';
5
5
  import { parseFromValuesOrFunc } from '../../utils/utils';
6
6
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
7
7
 
8
- export interface MRT_CellActionMenuProps<TData extends MRT_RowData>
9
- extends Partial<MenuProps> {
8
+ export interface MRT_CellActionMenuProps<TData extends MRT_RowData> extends Partial<MenuProps> {
10
9
  table: MRT_TableInstance<TData>;
11
10
  }
12
11
 
13
12
  export const MRT_CellActionMenu = <TData extends MRT_RowData>({
14
13
  table,
15
14
  ...rest
16
- }: MRT_CellActionMenuProps<TData>) => {
15
+ }: MRT_CellActionMenuProps<TData>): JSX.Element | false => {
17
16
  const {
18
17
  options: {
19
18
  editDisplayMode,
@@ -32,16 +31,15 @@ export const MRT_CellActionMenu = <TData extends MRT_RowData>({
32
31
  const { column } = cell;
33
32
  const { columnDef } = column;
34
33
 
35
- const handleClose = (event?: any) => {
36
- event?.stopPropagation();
34
+ const handleClose = (event?: { stopPropagation?: () => void }) => {
35
+ event?.stopPropagation?.();
37
36
  table.setActionCell(null);
38
37
  actionCellRef.current = null;
39
38
  };
40
39
 
41
40
  const internalMenuItems = [
42
41
  (parseFromValuesOrFunc(enableClickToCopy, cell) === 'context-menu' ||
43
- parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) ===
44
- 'context-menu') && (
42
+ parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) === 'context-menu') && (
45
43
  <MRT_ActionMenuItem
46
44
  icon={<ContentCopy />}
47
45
  key={'mrt-copy'}
@@ -78,8 +76,7 @@ export const MRT_CellActionMenu = <TData extends MRT_RowData>({
78
76
  };
79
77
 
80
78
  const menuItems =
81
- columnDef.renderCellActionMenuItems?.(renderActionProps) ??
82
- renderCellActionMenuItems?.(renderActionProps);
79
+ columnDef.renderCellActionMenuItems?.(renderActionProps) ?? renderCellActionMenuItems?.(renderActionProps);
83
80
 
84
81
  return (
85
82
  (!!menuItems?.length || !!internalMenuItems?.length) && (
@@ -1,17 +1,12 @@
1
1
  import { Menu, type MenuProps } from '@mui/material';
2
2
  import { type MouseEvent, useState } from 'react';
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 { getColumnFilterInfo } from '../../utils/column.utils';
10
6
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
11
7
  import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
12
8
 
13
- export interface MRT_ColumnActionMenuProps<TData extends MRT_RowData>
14
- extends Partial<MenuProps> {
9
+ export interface MRT_ColumnActionMenuProps<TData extends MRT_RowData> extends Partial<MenuProps> {
15
10
  anchorEl: HTMLElement | null;
16
11
  header: MRT_Header<TData>;
17
12
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
@@ -24,7 +19,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
24
19
  setAnchorEl,
25
20
  table,
26
21
  ...rest
27
- }: MRT_ColumnActionMenuProps<TData>) => {
22
+ }: MRT_ColumnActionMenuProps<TData>): JSX.Element => {
28
23
  const {
29
24
  getAllLeafColumns,
30
25
  options: {
@@ -60,12 +55,10 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
60
55
  } = table;
61
56
  const { column } = header;
62
57
  const { columnDef } = column;
63
- const { columnSizing, columnVisibility, density, showColumnFilters } =
64
- table.state;
58
+ const { columnSizing, columnVisibility, density, showColumnFilters } = table.state;
65
59
  const columnFilterValue = column.getFilterValue();
66
60
 
67
- const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
68
- useState<HTMLElement | null>(null);
61
+ const [filterMenuAnchorEl, setFilterMenuAnchorEl] = useState<HTMLElement | null>(null);
69
62
 
70
63
  const handleClearSort = () => {
71
64
  column.clearSorting();
@@ -100,7 +93,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
100
93
 
101
94
  const handleGroupByColumn = () => {
102
95
  column.toggleGrouping();
103
- setColumnOrder((old: any) => ['mrt-row-expand', ...old]);
96
+ setColumnOrder((old) => ['mrt-row-expand', ...old]);
104
97
  setAnchorEl(null);
105
98
  };
106
99
 
@@ -135,15 +128,13 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
135
128
 
136
129
  const isSelectFilter = !!columnDef.filterSelectOptions;
137
130
 
138
- const { allowedColumnFilterOptions, currentFilterOption } =
139
- getColumnFilterInfo({ header, table });
131
+ const { allowedColumnFilterOptions, currentFilterOption } = getColumnFilterInfo({ header, table });
140
132
 
141
133
  const showFilterModeSubMenu =
142
134
  enableColumnFilterModes &&
143
135
  columnDef.enableColumnFilterModes !== false &&
144
136
  !isSelectFilter &&
145
- (allowedColumnFilterOptions === undefined ||
146
- !!allowedColumnFilterOptions?.length);
137
+ (allowedColumnFilterOptions === undefined || !!allowedColumnFilterOptions?.length);
147
138
 
148
139
  const internalColumnMenuItems = [
149
140
  ...(enableSorting && column.getCanSort()
@@ -160,14 +151,9 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
160
151
  ),
161
152
  <MRT_ActionMenuItem
162
153
  disabled={column.getIsSorted() === 'asc'}
163
- icon={
164
- <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
165
- }
154
+ icon={<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />}
166
155
  key={1}
167
- label={localization.sortByColumnAsc?.replace(
168
- '{column}',
169
- String(columnDef.header),
170
- )}
156
+ label={localization.sortByColumnAsc?.replace('{column}', String(columnDef.header))}
171
157
  onClick={handleSortAsc}
172
158
  table={table}
173
159
  />,
@@ -176,10 +162,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
176
162
  divider={enableColumnFilters || enableGrouping || enableHiding}
177
163
  icon={<SortIcon />}
178
164
  key={2}
179
- label={localization.sortByColumnDesc?.replace(
180
- '{column}',
181
- String(columnDef.header),
182
- )}
165
+ label={localization.sortByColumnDesc?.replace('{column}', String(columnDef.header))}
183
166
  onClick={handleSortDesc}
184
167
  table={table}
185
168
  />,
@@ -190,8 +173,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
190
173
  <MRT_ActionMenuItem
191
174
  disabled={
192
175
  !columnFilterValue ||
193
- (Array.isArray(columnFilterValue) &&
194
- !columnFilterValue.filter((value) => value).length)
176
+ (Array.isArray(columnFilterValue) && !columnFilterValue.filter((value) => value).length)
195
177
  }
196
178
  icon={<FilterListOffIcon />}
197
179
  key={3}
@@ -205,18 +187,9 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
205
187
  divider={enableGrouping || enableHiding}
206
188
  icon={<FilterListIcon />}
207
189
  key={4}
208
- label={localization.filterByColumn?.replace(
209
- '{column}',
210
- String(columnDef.header),
211
- )}
212
- onClick={
213
- showColumnFilters
214
- ? handleOpenFilterModeMenu
215
- : handleFilterByColumn
216
- }
217
- onOpenSubMenu={
218
- showFilterModeSubMenu ? handleOpenFilterModeMenu : undefined
219
- }
190
+ label={localization.filterByColumn?.replace('{column}', String(columnDef.header))}
191
+ onClick={showColumnFilters ? handleOpenFilterModeMenu : handleFilterByColumn}
192
+ onOpenSubMenu={showFilterModeSubMenu ? handleOpenFilterModeMenu : undefined}
220
193
  table={table}
221
194
  />
222
195
  ),
@@ -238,9 +211,10 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
238
211
  divider={enableColumnPinning}
239
212
  icon={<DynamicFeedIcon />}
240
213
  key={6}
241
- label={localization[
242
- column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn'
243
- ]?.replace('{column}', String(columnDef.header))}
214
+ label={localization[column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn']?.replace(
215
+ '{column}',
216
+ String(columnDef.header),
217
+ )}
244
218
  onClick={handleGroupByColumn}
245
219
  table={table}
246
220
  />,
@@ -293,24 +267,15 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
293
267
  disabled={!column.getCanHide()}
294
268
  icon={<VisibilityOffIcon />}
295
269
  key={11}
296
- label={localization.hideColumn?.replace(
297
- '{column}',
298
- String(columnDef.header),
299
- )}
270
+ label={localization.hideColumn?.replace('{column}', String(columnDef.header))}
300
271
  onClick={handleHideColumn}
301
272
  table={table}
302
273
  />,
303
274
  <MRT_ActionMenuItem
304
- disabled={
305
- !Object.values(columnVisibility).filter((visible) => !visible)
306
- .length
307
- }
275
+ disabled={!Object.values(columnVisibility).filter((visible) => !visible).length}
308
276
  icon={<ViewColumnIcon />}
309
277
  key={12}
310
- label={localization.showAllColumns?.replace(
311
- '{column}',
312
- String(columnDef.header),
313
- )}
278
+ label={localization.showAllColumns?.replace('{column}', String(columnDef.header))}
314
279
  onClick={handleShowAllColumns}
315
280
  table={table}
316
281
  />,
@@ -1,5 +1,5 @@
1
1
  import { Menu, type MenuProps } from '@mui/material';
2
- import { useMemo } from 'react';
2
+ import { useState } from 'react';
3
3
 
4
4
  import {
5
5
  type MRT_FilterOption,
@@ -11,9 +11,7 @@ import {
11
11
  } from '../../types';
12
12
  import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
13
13
 
14
- export const mrtFilterOptions = (
15
- localization: MRT_Localization,
16
- ): MRT_InternalFilterOption[] => [
14
+ export const mrtFilterOptions = (localization: MRT_Localization): MRT_InternalFilterOption[] => [
17
15
  {
18
16
  divider: false,
19
17
  label: localization.filterFuzzy,
@@ -105,12 +103,12 @@ const emptyModes = ['empty', 'notEmpty'];
105
103
  const arrModes = ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'];
106
104
  const rangeVariants = ['range-slider', 'date-range', 'datetime-range', 'range'];
107
105
 
108
- export interface MRT_FilterOptionMenuProps<TData extends MRT_RowData>
109
- extends Partial<MenuProps> {
106
+ export interface MRT_FilterOptionMenuProps<TData extends MRT_RowData> extends Partial<MenuProps> {
110
107
  anchorEl: HTMLElement | null;
111
108
  header?: MRT_Header<TData>;
112
109
  onSelect?: () => void;
113
110
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
111
+ // oxlint-disable-next-line typescript/no-explicit-any
114
112
  setFilterValue?: (filterValue: any) => void;
115
113
  table: MRT_TableInstance<TData>;
116
114
  }
@@ -123,7 +121,7 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
123
121
  setFilterValue,
124
122
  table,
125
123
  ...rest
126
- }: MRT_FilterOptionMenuProps<TData>) => {
124
+ }: MRT_FilterOptionMenuProps<TData>): JSX.Element => {
127
125
  const {
128
126
  options: {
129
127
  columnFilterModeOptions,
@@ -141,27 +139,21 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
141
139
  const { columnDef } = column ?? {};
142
140
  const currentFilterValue = column?.getFilterValue();
143
141
 
144
- let allowedColumnFilterOptions =
145
- columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
142
+ let allowedColumnFilterOptions = columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
146
143
 
147
144
  if (rangeVariants.includes(columnDef?.filterVariant as string)) {
148
- allowedColumnFilterOptions = [
149
- ...rangeModes,
150
- ...(allowedColumnFilterOptions ?? []),
151
- ].filter((option) => rangeModes.includes(option));
145
+ allowedColumnFilterOptions = [...rangeModes, ...(allowedColumnFilterOptions ?? [])].filter((option) =>
146
+ rangeModes.includes(option),
147
+ );
152
148
  }
153
149
 
154
- const internalFilterOptions = useMemo(
155
- () =>
156
- mrtFilterOptions(localization).filter((filterOption) =>
157
- columnDef
158
- ? allowedColumnFilterOptions === undefined ||
159
- allowedColumnFilterOptions?.includes(filterOption.option)
160
- : (!globalFilterModeOptions ||
161
- globalFilterModeOptions.includes(filterOption.option)) &&
162
- ['contains', 'fuzzy', 'startsWith'].includes(filterOption.option),
163
- ),
164
- [],
150
+ const [internalFilterOptions] = useState(() =>
151
+ mrtFilterOptions(localization).filter((filterOption) =>
152
+ columnDef
153
+ ? allowedColumnFilterOptions === undefined || allowedColumnFilterOptions?.includes(filterOption.option)
154
+ : (!globalFilterModeOptions || globalFilterModeOptions.includes(filterOption.option)) &&
155
+ ['contains', 'fuzzy', 'startsWith'].includes(filterOption.option),
156
+ ),
165
157
  );
166
158
 
167
159
  const handleSelectFilterMode = (option: MRT_FilterOption) => {
@@ -171,7 +163,7 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
171
163
  setGlobalFilterFn(option);
172
164
  } else if (option !== prevFilterMode) {
173
165
  // column filter mode
174
- setColumnFilterFns((prev: { [key: string]: any }) => ({
166
+ setColumnFilterFns((prev) => ({
175
167
  ...prev,
176
168
  [header.id]: option,
177
169
  }));
@@ -179,37 +171,24 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
179
171
  // reset filter value and/or perform new filter render
180
172
  if (emptyModes.includes(option)) {
181
173
  // will now be empty/notEmpty filter mode
182
- if (
183
- currentFilterValue !== ' ' &&
184
- !emptyModes.includes(prevFilterMode)
185
- ) {
174
+ if (currentFilterValue !== ' ' && !emptyModes.includes(prevFilterMode)) {
186
175
  column.setFilterValue(' ');
187
176
  } else if (currentFilterValue) {
188
177
  column.setFilterValue(currentFilterValue); // perform new filter render
189
178
  }
190
- } else if (
191
- columnDef?.filterVariant === 'multi-select' ||
192
- arrModes.includes(option as string)
193
- ) {
179
+ } else if (columnDef?.filterVariant === 'multi-select' || arrModes.includes(option as string)) {
194
180
  // will now be array filter mode
195
- if (
196
- currentFilterValue instanceof String ||
197
- (currentFilterValue as Array<any>)?.length
198
- ) {
181
+ if (currentFilterValue instanceof String || (currentFilterValue as Array<unknown>)?.length) {
199
182
  column.setFilterValue([]);
200
183
  setFilterValue?.([]);
201
184
  } else if (currentFilterValue) {
202
185
  column.setFilterValue(currentFilterValue); // perform new filter render
203
186
  }
204
- } else if (
205
- columnDef?.filterVariant?.includes('range') ||
206
- rangeModes.includes(option as MRT_FilterOption)
207
- ) {
187
+ } else if (columnDef?.filterVariant?.includes('range') || rangeModes.includes(option as MRT_FilterOption)) {
208
188
  // will now be range filter mode
209
189
  if (
210
190
  !Array.isArray(currentFilterValue) ||
211
- (!(currentFilterValue as Array<any>)?.every((v) => v === '') &&
212
- !rangeModes.includes(prevFilterMode))
191
+ (!(currentFilterValue as Array<unknown>)?.every((v) => v === '') && !rangeModes.includes(prevFilterMode))
213
192
  ) {
214
193
  column.setFilterValue(['', '']);
215
194
  setFilterValue?.('');
@@ -221,10 +200,7 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
221
200
  if (Array.isArray(currentFilterValue)) {
222
201
  column.setFilterValue('');
223
202
  setFilterValue?.('');
224
- } else if (
225
- currentFilterValue === ' ' &&
226
- emptyModes.includes(prevFilterMode)
227
- ) {
203
+ } else if (currentFilterValue === ' ' && emptyModes.includes(prevFilterMode)) {
228
204
  column.setFilterValue(undefined);
229
205
  } else {
230
206
  column.setFilterValue(currentFilterValue); // perform new filter render
@@ -235,8 +211,7 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
235
211
  onSelect?.();
236
212
  };
237
213
 
238
- const filterOption =
239
- !!header && columnDef ? columnDef._filterFn : globalFilterFn;
214
+ const filterOption = !!header && columnDef ? columnDef._filterFn : globalFilterFn;
240
215
 
241
216
  return (
242
217
  <Menu
@@ -257,13 +232,13 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
257
232
  >
258
233
  {(header && column && columnDef
259
234
  ? (columnDef.renderColumnFilterModeMenuItems?.({
260
- column: column as any,
235
+ column,
261
236
  internalFilterOptions,
262
237
  onSelectFilterMode: handleSelectFilterMode,
263
238
  table,
264
239
  }) ??
265
240
  renderColumnFilterModeMenuItems?.({
266
- column: column as any,
241
+ column,
267
242
  internalFilterOptions,
268
243
  onSelectFilterMode: handleSelectFilterMode,
269
244
  table,
@@ -273,20 +248,18 @@ export const MRT_FilterOptionMenu = <TData extends MRT_RowData>({
273
248
  onSelectFilterMode: handleSelectFilterMode,
274
249
  table,
275
250
  })) ??
276
- internalFilterOptions.map(
277
- ({ divider, label, option, symbol }, index) => (
278
- <MRT_ActionMenuItem
279
- divider={divider}
280
- icon={symbol}
281
- key={index}
282
- label={label}
283
- onClick={() => handleSelectFilterMode(option as MRT_FilterOption)}
284
- selected={option === filterOption}
285
- table={table}
286
- value={option}
287
- />
288
- ),
289
- )}
251
+ internalFilterOptions.map(({ divider, label, option, symbol }, index) => (
252
+ <MRT_ActionMenuItem
253
+ divider={divider}
254
+ icon={symbol}
255
+ key={index}
256
+ label={label}
257
+ onClick={() => handleSelectFilterMode(option as MRT_FilterOption)}
258
+ selected={option === filterOption}
259
+ table={table}
260
+ value={option}
261
+ />
262
+ ))}
290
263
  </Menu>
291
264
  );
292
265
  };
@@ -1,16 +1,11 @@
1
1
  import { Menu, type MenuProps } from '@mui/material';
2
2
  import { type MouseEvent, type ReactNode, useMemo } 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_ActionMenuItem } from './MRT_ActionMenuItem';
11
7
 
12
- export interface MRT_RowActionMenuProps<TData extends MRT_RowData>
13
- extends Partial<MenuProps> {
8
+ export interface MRT_RowActionMenuProps<TData extends MRT_RowData> extends Partial<MenuProps> {
14
9
  anchorEl: HTMLElement | null;
15
10
  handleEdit: (event: MouseEvent) => void;
16
11
  row: MRT_Row<TData>;
@@ -27,7 +22,7 @@ export const MRT_RowActionMenu = <TData extends MRT_RowData>({
27
22
  staticRowIndex,
28
23
  table,
29
24
  ...rest
30
- }: MRT_RowActionMenuProps<TData>) => {
25
+ }: MRT_RowActionMenuProps<TData>): JSX.Element | null => {
31
26
  const {
32
27
  options: {
33
28
  editDisplayMode,
@@ -42,28 +37,44 @@ export const MRT_RowActionMenu = <TData extends MRT_RowData>({
42
37
 
43
38
  const menuItems = useMemo(() => {
44
39
  const items: ReactNode[] = [];
45
- const editItem = parseFromValuesOrFunc(enableEditing, row) &&
46
- ['modal', 'row'].includes(editDisplayMode!) && (
47
- <MRT_ActionMenuItem
48
- icon={<EditIcon />}
49
- key={'edit'}
50
- label={localization.edit}
51
- onClick={handleEdit}
52
- table={table}
53
- />
54
- );
55
- if (editItem) items.push(editItem);
40
+ const editItem = parseFromValuesOrFunc(enableEditing, row) && ['modal', 'row'].includes(editDisplayMode!) && (
41
+ <MRT_ActionMenuItem
42
+ icon={<EditIcon />}
43
+ key={'edit'}
44
+ label={localization.edit}
45
+ onClick={handleEdit}
46
+ table={table}
47
+ />
48
+ );
49
+ if (editItem) {
50
+ items.push(editItem);
51
+ }
56
52
  const rowActionMenuItems = renderRowActionMenuItems?.({
57
53
  closeMenu: () => setAnchorEl(null),
58
54
  row,
59
55
  staticRowIndex,
60
56
  table,
61
57
  });
62
- if (rowActionMenuItems?.length) items.push(...rowActionMenuItems);
58
+ if (rowActionMenuItems?.length) {
59
+ items.push(...rowActionMenuItems);
60
+ }
63
61
  return items;
64
- }, [renderRowActionMenuItems, row, staticRowIndex, table]);
62
+ }, [
63
+ EditIcon,
64
+ editDisplayMode,
65
+ enableEditing,
66
+ handleEdit,
67
+ localization.edit,
68
+ renderRowActionMenuItems,
69
+ row,
70
+ setAnchorEl,
71
+ staticRowIndex,
72
+ table,
73
+ ]);
65
74
 
66
- if (!menuItems.length) return null;
75
+ if (!menuItems.length) {
76
+ return null;
77
+ }
67
78
 
68
79
  return (
69
80
  <Menu