material-react-table 0.38.2 → 0.39.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 (54) hide show
  1. package/dist/cjs/MaterialReactTable.d.ts +26 -4
  2. package/dist/cjs/body/MRT_EditRowModal.d.ts +1 -0
  3. package/dist/cjs/body/MRT_TableBodyRow.d.ts +1 -0
  4. package/dist/cjs/buttons/MRT_ColumnPinningButtons.d.ts +1 -0
  5. package/dist/cjs/buttons/MRT_EditActionButtons.d.ts +1 -0
  6. package/dist/cjs/buttons/MRT_FullScreenToggleButton.d.ts +1 -0
  7. package/dist/cjs/buttons/MRT_ShowHideColumnsButton.d.ts +1 -0
  8. package/dist/cjs/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -0
  9. package/dist/cjs/buttons/MRT_ToggleFiltersButton.d.ts +1 -0
  10. package/dist/cjs/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -0
  11. package/dist/cjs/column.utils.d.ts +1 -0
  12. package/dist/cjs/index.js +79 -47
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/inputs/MRT_EditCellTextField.d.ts +1 -0
  15. package/dist/cjs/inputs/MRT_GlobalFilterTextField.d.ts +1 -0
  16. package/dist/cjs/menus/MRT_FilterOptionMenu.d.ts +3 -7
  17. package/dist/cjs/menus/MRT_ShowHideColumnsMenu.d.ts +1 -0
  18. package/dist/cjs/table/MRT_TableRoot.d.ts +1 -0
  19. package/dist/esm/MaterialReactTable.d.ts +26 -4
  20. package/dist/esm/body/MRT_EditRowModal.d.ts +1 -0
  21. package/dist/esm/body/MRT_TableBodyRow.d.ts +1 -0
  22. package/dist/esm/buttons/MRT_ColumnPinningButtons.d.ts +1 -0
  23. package/dist/esm/buttons/MRT_EditActionButtons.d.ts +1 -0
  24. package/dist/esm/buttons/MRT_FullScreenToggleButton.d.ts +1 -0
  25. package/dist/esm/buttons/MRT_ShowHideColumnsButton.d.ts +1 -0
  26. package/dist/esm/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -0
  27. package/dist/esm/buttons/MRT_ToggleFiltersButton.d.ts +1 -0
  28. package/dist/esm/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -0
  29. package/dist/esm/column.utils.d.ts +1 -0
  30. package/dist/esm/inputs/MRT_EditCellTextField.d.ts +1 -0
  31. package/dist/esm/inputs/MRT_GlobalFilterTextField.d.ts +1 -0
  32. package/dist/esm/material-react-table.esm.js +79 -47
  33. package/dist/esm/material-react-table.esm.js.map +1 -1
  34. package/dist/esm/menus/MRT_FilterOptionMenu.d.ts +3 -7
  35. package/dist/esm/menus/MRT_ShowHideColumnsMenu.d.ts +1 -0
  36. package/dist/esm/table/MRT_TableRoot.d.ts +1 -0
  37. package/dist/index.d.ts +28 -5
  38. package/package.json +2 -2
  39. package/src/MaterialReactTable.tsx +42 -7
  40. package/src/body/MRT_TableBody.tsx +1 -0
  41. package/src/body/MRT_TableBodyCellValue.tsx +10 -11
  42. package/src/body/MRT_TableBodyRow.tsx +14 -3
  43. package/src/buttons/MRT_ExpandAllButton.tsx +5 -3
  44. package/src/buttons/MRT_GrabHandleButton.tsx +5 -3
  45. package/src/column.utils.ts +1 -1
  46. package/src/footer/MRT_TableFooter.tsx +22 -2
  47. package/src/head/MRT_TableHeadCellFilterContainer.tsx +3 -2
  48. package/src/head/MRT_TableHeadRow.tsx +3 -1
  49. package/src/inputs/MRT_FilterTextField.tsx +5 -8
  50. package/src/inputs/MRT_GlobalFilterTextField.tsx +2 -2
  51. package/src/menus/MRT_ColumnActionMenu.tsx +3 -3
  52. package/src/menus/MRT_FilterOptionMenu.tsx +50 -33
  53. package/src/table/MRT_TablePaper.tsx +5 -3
  54. package/src/table/MRT_TableRoot.tsx +3 -4
@@ -1,16 +1,16 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Box, Menu, MenuItem } from '@mui/material';
3
- import type { MRT_FilterOption, MRT_Header, MRT_TableInstance } from '..';
3
+ import type {
4
+ MRT_FilterOption,
5
+ MRT_Header,
6
+ MRT_InternalFilterOption,
7
+ MRT_TableInstance,
8
+ } from '..';
4
9
  import { MRT_Localization } from '../localization';
5
10
 
6
- export const internalFilterOptions = (
11
+ export const mrtFilterOptions = (
7
12
  localization: MRT_Localization,
8
- ): {
9
- option: string;
10
- symbol: string;
11
- label: string;
12
- divider: boolean;
13
- }[] => [
13
+ ): MRT_InternalFilterOption[] => [
14
14
  {
15
15
  option: 'fuzzy',
16
16
  symbol: '≈',
@@ -118,31 +118,33 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
118
118
  enabledGlobalFilterOptions,
119
119
  columnFilterModeOptions,
120
120
  localization,
121
+ renderColumnFilterModeMenuItems,
122
+ renderGlobalFilterModeMenuItems,
121
123
  },
122
124
  setColumnFilterFns,
123
125
  setGlobalFilterFn,
124
126
  } = table;
125
- const { columnFilterFns, globalFilterFn, density } = getState();
127
+ const { globalFilterFn, density } = getState();
126
128
  const { column } = header ?? {};
127
129
  const { columnDef } = column ?? {};
128
130
 
129
131
  const allowedColumnFilterOptions =
130
132
  columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
131
133
 
132
- const filterOptions = useMemo(
134
+ const internalFilterOptions = useMemo(
133
135
  () =>
134
- internalFilterOptions(localization).filter((filterOption) =>
136
+ mrtFilterOptions(localization).filter((filterOption) =>
135
137
  columnDef
136
138
  ? allowedColumnFilterOptions === undefined ||
137
139
  allowedColumnFilterOptions?.includes(filterOption.option)
138
140
  : (!enabledGlobalFilterOptions ||
139
141
  enabledGlobalFilterOptions.includes(filterOption.option)) &&
140
- ['fuzzy', 'contains'].includes(filterOption.option),
142
+ ['fuzzy', 'contains', 'startsWith'].includes(filterOption.option),
141
143
  ),
142
144
  [],
143
145
  );
144
146
 
145
- const handleSelectFilterType = (option: MRT_FilterOption) => {
147
+ const handleSelectFilterMode = (option: MRT_FilterOption) => {
146
148
  if (header && column) {
147
149
  setColumnFilterFns((prev: { [key: string]: any }) => ({
148
150
  ...prev,
@@ -162,7 +164,8 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
162
164
  onSelect?.();
163
165
  };
164
166
 
165
- const filterOption = !!header ? columnFilterFns[header.id] : globalFilterFn;
167
+ const filterOption =
168
+ !!header && columnDef ? columnDef._filterFn : globalFilterFn;
166
169
 
167
170
  return (
168
171
  <Menu
@@ -174,25 +177,39 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
174
177
  dense: density === 'compact',
175
178
  }}
176
179
  >
177
- {filterOptions.map(({ option, label, divider, symbol }, index) => (
178
- <MenuItem
179
- divider={divider}
180
- key={index}
181
- onClick={() => handleSelectFilterType(option as MRT_FilterOption)}
182
- selected={option === filterOption}
183
- sx={{
184
- py: '6px',
185
- my: 0,
186
- alignItems: 'center',
187
- display: 'flex',
188
- gap: '2ch',
189
- }}
190
- value={option}
191
- >
192
- <Box sx={{ fontSize: '1.25rem', width: '2ch' }}>{symbol}</Box>
193
- {label}
194
- </MenuItem>
195
- ))}
180
+ {(header && column
181
+ ? renderColumnFilterModeMenuItems?.({
182
+ column: column as any,
183
+ internalFilterOptions,
184
+ onSelectFilterMode: handleSelectFilterMode,
185
+ table,
186
+ })
187
+ : renderGlobalFilterModeMenuItems?.({
188
+ internalFilterOptions,
189
+ onSelectFilterMode: handleSelectFilterMode,
190
+ table,
191
+ })) ??
192
+ internalFilterOptions.map(
193
+ ({ option, label, divider, symbol }, index) => (
194
+ <MenuItem
195
+ divider={divider}
196
+ key={index}
197
+ onClick={() => handleSelectFilterMode(option as MRT_FilterOption)}
198
+ selected={option === filterOption}
199
+ sx={{
200
+ alignItems: 'center',
201
+ display: 'flex',
202
+ gap: '2ch',
203
+ my: 0,
204
+ py: '6px',
205
+ }}
206
+ value={option}
207
+ >
208
+ <Box sx={{ fontSize: '1.25rem', width: '2ch' }}>{symbol}</Box>
209
+ {label}
210
+ </MenuItem>
211
+ ),
212
+ )}
196
213
  </Menu>
197
214
  );
198
215
  };
@@ -35,10 +35,12 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
35
35
  <Paper
36
36
  elevation={2}
37
37
  {...tablePaperProps}
38
- sx={{
38
+ sx={(theme) => ({
39
39
  transition: 'all 0.2s ease-in-out',
40
- ...tablePaperProps?.sx,
41
- }}
40
+ ...(tablePaperProps?.sx instanceof Function
41
+ ? tablePaperProps?.sx(theme)
42
+ : (tablePaperProps?.sx as any)),
43
+ })}
42
44
  style={{
43
45
  ...tablePaperProps?.style,
44
46
  height: isFullScreen ? '100vh' : undefined,
@@ -24,6 +24,7 @@ import {
24
24
  getDefaultColumnFilterFn,
25
25
  defaultDisplayColumnDefOptions,
26
26
  showExpandColumn,
27
+ getColumnId,
27
28
  } from '../column.utils';
28
29
  import type {
29
30
  MRT_Cell,
@@ -65,13 +66,11 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
65
66
  {},
66
67
  ...getAllLeafColumnDefs(props.columns as MRT_ColumnDef<TData>[]).map(
67
68
  (col) => ({
68
- [col.id?.toString() ?? col.accessorKey?.toString() ?? '']:
69
+ [getColumnId(col)]:
69
70
  col.filterFn instanceof Function
70
71
  ? col.filterFn.name ?? 'custom'
71
72
  : col.filterFn ??
72
- initialState?.columnFilterFns?.[
73
- col.id?.toString() ?? col.accessorKey?.toString() ?? ''
74
- ] ??
73
+ initialState?.columnFilterFns?.[getColumnId(col)] ??
75
74
  getDefaultColumnFilterFn(col),
76
75
  }),
77
76
  ),