material-react-table 0.32.0 → 0.33.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 (34) hide show
  1. package/dist/cjs/MaterialReactTable.d.ts +21 -22
  2. package/dist/cjs/aggregationFns.d.ts +11 -0
  3. package/dist/cjs/column.utils.d.ts +77 -2
  4. package/dist/cjs/{filtersFns.d.ts → filterFns.d.ts} +0 -0
  5. package/dist/cjs/index.d.ts +4 -0
  6. package/dist/cjs/index.min.js +4 -5
  7. package/dist/cjs/index.min.js.map +1 -1
  8. package/dist/{esm/toolbar/MRT_ToolbarBottom.d.ts → cjs/toolbar/MRT_BottomToolbar.d.ts} +1 -1
  9. package/dist/{esm/toolbar/MRT_ToolbarTop.d.ts → cjs/toolbar/MRT_TopToolbar.d.ts} +1 -1
  10. package/dist/esm/MaterialReactTable.d.ts +21 -22
  11. package/dist/esm/aggregationFns.d.ts +11 -0
  12. package/dist/esm/column.utils.d.ts +77 -2
  13. package/dist/esm/{filtersFns.d.ts → filterFns.d.ts} +0 -0
  14. package/dist/esm/index.d.ts +4 -0
  15. package/dist/esm/material-react-table.esm.min.js +4 -5
  16. package/dist/esm/material-react-table.esm.min.js.map +1 -1
  17. package/dist/{cjs/toolbar/MRT_ToolbarBottom.d.ts → esm/toolbar/MRT_BottomToolbar.d.ts} +1 -1
  18. package/dist/{cjs/toolbar/MRT_ToolbarTop.d.ts → esm/toolbar/MRT_TopToolbar.d.ts} +1 -1
  19. package/dist/index.d.ts +103 -104
  20. package/package.json +17 -17
  21. package/src/MaterialReactTable.tsx +39 -28
  22. package/src/aggregationFns.ts +3 -0
  23. package/src/body/MRT_TableBody.tsx +1 -1
  24. package/src/column.utils.ts +16 -8
  25. package/src/{filtersFns.ts → filterFns.ts} +0 -0
  26. package/src/head/MRT_TableHeadCellFilterContainer.tsx +2 -2
  27. package/src/head/MRT_TableHeadCellFilterLabel.tsx +2 -2
  28. package/src/index.tsx +6 -0
  29. package/src/inputs/MRT_FilterTextField.tsx +4 -4
  30. package/src/menus/MRT_FilterOptionMenu.tsx +6 -8
  31. package/src/table/MRT_TablePaper.tsx +5 -5
  32. package/src/table/MRT_TableRoot.tsx +20 -21
  33. package/src/toolbar/{MRT_ToolbarBottom.tsx → MRT_BottomToolbar.tsx} +10 -10
  34. package/src/toolbar/{MRT_ToolbarTop.tsx → MRT_TopToolbar.tsx} +8 -8
@@ -7,7 +7,7 @@ import {
7
7
  MRT_DisplayColumnIds,
8
8
  MRT_FilterOption,
9
9
  } from '.';
10
- import { MRT_FilterFns } from './filtersFns';
10
+ import { MRT_FilterFns } from './filterFns';
11
11
  import { MRT_SortingFns } from './sortingFns';
12
12
 
13
13
  export const defaultDisplayColumnDefOptions = {
@@ -50,7 +50,10 @@ export const getAllLeafColumnDefs = <TData extends Record<string, any> = {}>(
50
50
 
51
51
  export const prepareColumns = <TData extends Record<string, any> = {}>(
52
52
  columnDefs: MRT_ColumnDef<TData>[],
53
- currentFilterFns: { [key: string]: MRT_FilterOption },
53
+ columnFilterFns: { [key: string]: MRT_FilterOption },
54
+ filterFns: typeof MRT_FilterFns & MaterialReactTableProps<TData>['filterFns'],
55
+ sortingFns: typeof MRT_SortingFns &
56
+ MaterialReactTableProps<TData>['sortingFns'],
54
57
  ): MRT_DefinedColumnDef<TData>[] =>
55
58
  columnDefs.map((columnDef) => {
56
59
  if (!columnDef.id) columnDef.id = getColumnId(columnDef);
@@ -62,18 +65,23 @@ export const prepareColumns = <TData extends Record<string, any> = {}>(
62
65
  if (!columnDef.columnDefType) columnDef.columnDefType = 'data';
63
66
  if (!!columnDef.columns?.length) {
64
67
  columnDef.columnDefType = 'group';
65
- columnDef.columns = prepareColumns(columnDef.columns, currentFilterFns);
68
+ columnDef.columns = prepareColumns(
69
+ columnDef.columns,
70
+ columnFilterFns,
71
+ filterFns,
72
+ sortingFns,
73
+ );
66
74
  } else if (columnDef.columnDefType === 'data') {
67
- if (Object.keys(MRT_FilterFns).includes(currentFilterFns[columnDef.id])) {
75
+ if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
68
76
  columnDef.filterFn =
69
77
  // @ts-ignore
70
- MRT_FilterFns[currentFilterFns[columnDef.id]] ?? MRT_FilterFns.fuzzy;
78
+ filterFns[columnFilterFns[columnDef.id]] ?? filterFns.fuzzy;
71
79
  //@ts-ignore
72
- columnDef._filterFn = currentFilterFns[columnDef.id];
80
+ columnDef._filterFn = columnFilterFns[columnDef.id];
73
81
  }
74
- if (Object.keys(MRT_SortingFns).includes(columnDef.sortingFn as string)) {
82
+ if (Object.keys(sortingFns).includes(columnDef.sortingFn as string)) {
75
83
  // @ts-ignore
76
- columnDef.sortingFn = MRT_SortingFns[columnDef.sortingFn];
84
+ columnDef.sortingFn = sortingFns[columnDef.sortingFn];
77
85
  }
78
86
  } else if (columnDef.columnDefType === 'display') {
79
87
  columnDef = {
File without changes
@@ -14,13 +14,13 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
14
14
  table,
15
15
  }) => {
16
16
  const { getState } = table;
17
- const { currentFilterFns, showColumnFilters } = getState();
17
+ const { columnFilterFns, showColumnFilters } = getState();
18
18
  const { column } = header;
19
19
 
20
20
  return (
21
21
  <Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
22
22
  {['between', 'betweenInclusive', 'inNumberRange'].includes(
23
- currentFilterFns[column.id],
23
+ columnFilterFns[column.id],
24
24
  ) ? (
25
25
  <MRT_FilterRangeFields header={header} table={table} />
26
26
  ) : (
@@ -15,7 +15,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
15
15
  localization,
16
16
  },
17
17
  } = table;
18
- const { currentFilterFns } = getState();
18
+ const { columnFilterFns } = getState();
19
19
  const { column } = header;
20
20
  const { columnDef } = column;
21
21
 
@@ -24,7 +24,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
24
24
  'betweenInclusive',
25
25
  'inNumberRange',
26
26
  ].includes(columnDef._filterFn);
27
- const currentFilterOption = currentFilterFns?.[header.id];
27
+ const currentFilterOption = columnFilterFns?.[header.id];
28
28
  const filterTooltip = localization.filteringByColumn
29
29
  .replace('{column}', String(columnDef.header))
30
30
  .replace(
package/src/index.tsx CHANGED
@@ -1,3 +1,9 @@
1
1
  import MaterialReactTable from './MaterialReactTable';
2
2
  export default MaterialReactTable;
3
3
  export * from './MaterialReactTable';
4
+
5
+ import type { MRT_Icons } from './icons';
6
+ export type { MRT_Icons };
7
+
8
+ import type { MRT_Localization } from './localization';
9
+ export type { MRT_Localization };
@@ -42,11 +42,11 @@ export const MRT_FilterTextField: FC<Props> = ({
42
42
  muiTableHeadCellFilterTextFieldProps,
43
43
  tableId,
44
44
  },
45
- setCurrentFilterFns,
45
+ setColumnFilterFns,
46
46
  } = table;
47
47
  const { column } = header;
48
48
  const { columnDef } = column;
49
- const { currentFilterFns } = getState();
49
+ const { columnFilterFns } = getState();
50
50
 
51
51
  const mTableHeadCellFilterTextFieldProps =
52
52
  muiTableHeadCellFilterTextFieldProps instanceof Function
@@ -79,7 +79,7 @@ export const MRT_FilterTextField: FC<Props> = ({
79
79
  columnDef.filterVariant === 'text' ||
80
80
  (!isSelectFilter && !isMultiSelectFilter);
81
81
 
82
- const currentFilterOption = currentFilterFns?.[header.id];
82
+ const currentFilterOption = columnFilterFns?.[header.id];
83
83
  const filterId = `mrt-${tableId}-${header.id}-filter-text-field${
84
84
  rangeFilterIndex ?? ''
85
85
  }`;
@@ -166,7 +166,7 @@ export const MRT_FilterTextField: FC<Props> = ({
166
166
  const handleClearEmptyFilterChip = () => {
167
167
  setFilterValue('');
168
168
  column.setFilterValue(undefined);
169
- setCurrentFilterFns((prev) => ({
169
+ setColumnFilterFns((prev) => ({
170
170
  ...prev,
171
171
  [header.id]: 'fuzzy',
172
172
  }));
@@ -119,10 +119,10 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
119
119
  columnFilterModeOptions,
120
120
  localization,
121
121
  },
122
- setCurrentFilterFns,
123
- setCurrentGlobalFilterFn,
122
+ setColumnFilterFns,
123
+ setGlobalFilterFn,
124
124
  } = table;
125
- const { currentFilterFns, currentGlobalFilterFn, density } = getState();
125
+ const { columnFilterFns, globalFilterFn, density } = getState();
126
126
  const { column } = header ?? {};
127
127
  const { columnDef } = column ?? {};
128
128
 
@@ -144,7 +144,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
144
144
 
145
145
  const handleSelectFilterType = (option: MRT_FilterOption) => {
146
146
  if (header && column) {
147
- setCurrentFilterFns((prev: { [key: string]: any }) => ({
147
+ setColumnFilterFns((prev: { [key: string]: any }) => ({
148
148
  ...prev,
149
149
  [header.id]: option,
150
150
  }));
@@ -156,15 +156,13 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
156
156
  column.setFilterValue('');
157
157
  }
158
158
  } else {
159
- setCurrentGlobalFilterFn(option);
159
+ setGlobalFilterFn(option);
160
160
  }
161
161
  setAnchorEl(null);
162
162
  onSelect?.();
163
163
  };
164
164
 
165
- const filterOption = !!header
166
- ? currentFilterFns[header.id]
167
- : currentGlobalFilterFn;
165
+ const filterOption = !!header ? columnFilterFns[header.id] : globalFilterFn;
168
166
 
169
167
  return (
170
168
  <Menu
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useEffect } from 'react';
2
2
  import { Paper } from '@mui/material';
3
- import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
4
- import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
3
+ import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
4
+ import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
5
5
  import { MRT_TableContainer } from './MRT_TableContainer';
6
6
  import type { MRT_TableInstance } from '..';
7
7
 
@@ -12,7 +12,7 @@ interface Props {
12
12
  export const MRT_TablePaper: FC<Props> = ({ table }) => {
13
13
  const {
14
14
  getState,
15
- options: { enableToolbarBottom, enableToolbarTop, muiTablePaperProps },
15
+ options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps },
16
16
  } = table;
17
17
  const { isFullScreen } = getState();
18
18
 
@@ -49,9 +49,9 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
49
49
  width: isFullScreen ? '100vw' : undefined,
50
50
  }}
51
51
  >
52
- {enableToolbarTop && <MRT_ToolbarTop table={table} />}
52
+ {enableTopToolbar && <MRT_TopToolbar table={table} />}
53
53
  <MRT_TableContainer table={table} />
54
- {enableToolbarBottom && <MRT_ToolbarBottom table={table} />}
54
+ {enableBottomToolbar && <MRT_BottomToolbar table={table} />}
55
55
  </Paper>
56
56
  );
57
57
  };
@@ -23,7 +23,6 @@ import {
23
23
  getDefaultColumnFilterFn,
24
24
  defaultDisplayColumnDefOptions,
25
25
  } from '../column.utils';
26
- import { MRT_FilterFns } from '../filtersFns';
27
26
  import type {
28
27
  MRT_Cell,
29
28
  MRT_Column,
@@ -86,7 +85,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
86
85
  const [showGlobalFilter, setShowGlobalFilter] = useState(
87
86
  initialState?.showGlobalFilter ?? false,
88
87
  );
89
- const [currentFilterFns, setCurrentFilterFns] = useState<{
88
+ const [columnFilterFns, setColumnFilterFns] = useState<{
90
89
  [key: string]: MRT_FilterOption;
91
90
  }>(() =>
92
91
  Object.assign(
@@ -97,7 +96,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
97
96
  col.filterFn instanceof Function
98
97
  ? col.filterFn.name ?? 'custom'
99
98
  : col.filterFn ??
100
- initialState?.currentFilterFns?.[
99
+ initialState?.columnFilterFns?.[
101
100
  col.id?.toString() ?? col.accessorKey?.toString() ?? ''
102
101
  ] ??
103
102
  getDefaultColumnFilterFn(col),
@@ -105,12 +104,11 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
105
104
  ),
106
105
  ),
107
106
  );
108
- const [currentGlobalFilterFn, setCurrentGlobalFilterFn] =
109
- useState<MRT_FilterOption>(
110
- props.globalFilterFn instanceof String
111
- ? (props.globalFilterFn as MRT_FilterOption)
112
- : 'fuzzy',
113
- );
107
+ const [globalFilterFn, setGlobalFilterFn] = useState<MRT_FilterOption>(
108
+ props.globalFilterFn instanceof String
109
+ ? (props.globalFilterFn as MRT_FilterOption)
110
+ : 'fuzzy',
111
+ );
114
112
 
115
113
  const displayColumns = useMemo(
116
114
  () =>
@@ -200,15 +198,20 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
200
198
 
201
199
  const columnDefs = useMemo(
202
200
  () =>
203
- prepareColumns([...displayColumns, ...props.columns], currentFilterFns),
204
- [currentFilterFns, displayColumns, props.columns],
201
+ prepareColumns(
202
+ [...displayColumns, ...props.columns],
203
+ columnFilterFns,
204
+ props.filterFns as any,
205
+ props.sortingFns as any,
206
+ ),
207
+ [columnFilterFns, displayColumns, props.columns],
205
208
  );
206
209
 
207
210
  const data: TData[] = useMemo(
208
211
  () =>
209
212
  (props.state?.isLoading || props.state?.showSkeletons) &&
210
213
  !props.data.length
211
- ? [...Array(10).fill(null)].map(() =>
214
+ ? [...Array(5).fill(null)].map(() =>
212
215
  Object.assign(
213
216
  {},
214
217
  ...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
@@ -238,10 +241,9 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
238
241
  //@ts-ignore
239
242
  columns: columnDefs,
240
243
  data,
241
-
242
244
  globalFilterFn:
243
245
  //@ts-ignore
244
- MRT_FilterFns[currentGlobalFilterFn] ?? MRT_FilterFns.fuzzy,
246
+ props.filterFns[globalFilterFn] ?? props.filterFns.fuzzy,
245
247
  initialState,
246
248
  state: {
247
249
  columnOrder,
@@ -249,8 +251,8 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
249
251
  currentDraggingRow,
250
252
  currentEditingCell,
251
253
  currentEditingRow,
252
- currentFilterFns,
253
- currentGlobalFilterFn,
254
+ columnFilterFns,
255
+ globalFilterFn,
254
256
  currentHoveredColumn,
255
257
  currentHoveredRow,
256
258
  density,
@@ -270,9 +272,8 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
270
272
  props.onCurrentEditingCellChange ?? setCurrentEditingCell,
271
273
  setCurrentEditingRow:
272
274
  props.onCurrentEditingRowChange ?? setCurrentEditingRow,
273
- setCurrentFilterFns: props.onCurrentFilterFnsChange ?? setCurrentFilterFns,
274
- setCurrentGlobalFilterFn:
275
- props.onCurrentGlobalFilterFnChange ?? setCurrentGlobalFilterFn,
275
+ setColumnFilterFns: props.onCurrentFilterFnsChange ?? setColumnFilterFns,
276
+ setGlobalFilterFn: props.onCurrentGlobalFilterFnChange ?? setGlobalFilterFn,
276
277
  setCurrentHoveredColumn:
277
278
  props.onCurrentHoveredColumnChange ?? setCurrentHoveredColumn,
278
279
  setCurrentHoveredRow:
@@ -284,8 +285,6 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
284
285
  setShowGlobalFilter: props.onShowGlobalFilterChange ?? setShowGlobalFilter,
285
286
  } as MRT_TableInstance;
286
287
 
287
- useEffect(() => props?.onTableInstanceChange?.(table as any), [table]);
288
-
289
288
  return (
290
289
  <>
291
290
  <Dialog
@@ -3,7 +3,7 @@ import { alpha, Box, Toolbar, useMediaQuery } from '@mui/material';
3
3
  import { MRT_TablePagination } from './MRT_TablePagination';
4
4
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
5
5
  import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
6
- import { commonToolbarStyles } from './MRT_ToolbarTop';
6
+ import { commonToolbarStyles } from './MRT_TopToolbar';
7
7
  import { MRT_TableInstance } from '..';
8
8
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
9
9
 
@@ -11,16 +11,16 @@ interface Props {
11
11
  table: MRT_TableInstance;
12
12
  }
13
13
 
14
- export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
14
+ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
15
15
  const {
16
16
  getState,
17
17
  options: {
18
18
  enablePagination,
19
- muiTableToolbarBottomProps,
19
+ muiTableBottomToolbarProps,
20
20
  positionPagination,
21
21
  positionToolbarAlertBanner,
22
22
  positionToolbarDropZone,
23
- renderToolbarBottomCustomActions,
23
+ renderBottomToolbarCustomActions,
24
24
  tableId,
25
25
  },
26
26
  } = table;
@@ -29,11 +29,11 @@ export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
29
29
  const isMobile = useMediaQuery('(max-width:720px)');
30
30
 
31
31
  const toolbarProps =
32
- muiTableToolbarBottomProps instanceof Function
33
- ? muiTableToolbarBottomProps({ table })
34
- : muiTableToolbarBottomProps;
32
+ muiTableBottomToolbarProps instanceof Function
33
+ ? muiTableBottomToolbarProps({ table })
34
+ : muiTableBottomToolbarProps;
35
35
 
36
- const stackAlertBanner = isMobile || !!renderToolbarBottomCustomActions;
36
+ const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
37
37
 
38
38
  return (
39
39
  <Toolbar
@@ -68,9 +68,9 @@ export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
68
68
  width: '100%',
69
69
  }}
70
70
  >
71
- {renderToolbarBottomCustomActions ? (
71
+ {renderBottomToolbarCustomActions ? (
72
72
  <Box sx={{ p: '0.5rem' }}>
73
- {renderToolbarBottomCustomActions({ table })}
73
+ {renderBottomToolbarCustomActions({ table })}
74
74
  </Box>
75
75
  ) : (
76
76
  <span />
@@ -24,19 +24,19 @@ interface Props {
24
24
  table: MRT_TableInstance;
25
25
  }
26
26
 
27
- export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
27
+ export const MRT_TopToolbar: FC<Props> = ({ table }) => {
28
28
  const {
29
29
  getState,
30
30
  options: {
31
31
  enableGlobalFilter,
32
32
  enablePagination,
33
33
  enableToolbarInternalActions,
34
- muiTableToolbarTopProps,
34
+ muiTableTopToolbarProps,
35
35
  positionGlobalFilter,
36
36
  positionPagination,
37
37
  positionToolbarAlertBanner,
38
38
  positionToolbarDropZone,
39
- renderToolbarTopCustomActions,
39
+ renderTopToolbarCustomActions,
40
40
  tableId,
41
41
  },
42
42
  } = table;
@@ -46,12 +46,12 @@ export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
46
46
  const isMobile = useMediaQuery('(max-width:720px)');
47
47
 
48
48
  const toolbarProps =
49
- muiTableToolbarTopProps instanceof Function
50
- ? muiTableToolbarTopProps({ table })
51
- : muiTableToolbarTopProps;
49
+ muiTableTopToolbarProps instanceof Function
50
+ ? muiTableTopToolbarProps({ table })
51
+ : muiTableTopToolbarProps;
52
52
 
53
53
  const stackAlertBanner =
54
- isMobile || !!renderToolbarTopCustomActions || showGlobalFilter;
54
+ isMobile || !!renderTopToolbarCustomActions || showGlobalFilter;
55
55
 
56
56
  return (
57
57
  <Toolbar
@@ -95,7 +95,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
95
95
  <MRT_GlobalFilterTextField table={table} />
96
96
  )}
97
97
 
98
- {renderToolbarTopCustomActions?.({ table }) ?? <span />}
98
+ {renderTopToolbarCustomActions?.({ table }) ?? <span />}
99
99
  {enableToolbarInternalActions ? (
100
100
  <MRT_ToolbarInternalButtons table={table} />
101
101
  ) : (