material-react-table 0.5.9 → 0.6.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 (38) hide show
  1. package/dist/MaterialReactTable.d.ts +13 -5
  2. package/dist/filtersFNs.d.ts +6 -10
  3. package/dist/localization.d.ts +43 -46
  4. package/dist/material-react-table.cjs.development.js +404 -331
  5. package/dist/material-react-table.cjs.development.js.map +1 -1
  6. package/dist/material-react-table.cjs.production.min.js +1 -1
  7. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  8. package/dist/material-react-table.esm.js +405 -332
  9. package/dist/material-react-table.esm.js.map +1 -1
  10. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +3 -2
  11. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -0
  12. package/dist/useMRT.d.ts +4 -0
  13. package/package.json +3 -3
  14. package/src/MaterialReactTable.tsx +59 -47
  15. package/src/buttons/MRT_EditActionButtons.tsx +4 -7
  16. package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
  17. package/src/buttons/MRT_ExpandButton.tsx +2 -2
  18. package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
  19. package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -52
  20. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +2 -2
  21. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
  22. package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
  23. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +3 -7
  24. package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
  25. package/src/filtersFNs.ts +6 -16
  26. package/src/head/MRT_TableHeadCell.tsx +19 -6
  27. package/src/head/MRT_TableHeadCellActions.tsx +1 -1
  28. package/src/inputs/MRT_FilterTextField.tsx +34 -9
  29. package/src/inputs/MRT_SearchTextField.tsx +3 -3
  30. package/src/inputs/MRT_SelectCheckbox.tsx +4 -4
  31. package/src/localization.ts +87 -92
  32. package/src/menus/MRT_ColumnActionMenu.tsx +59 -14
  33. package/src/menus/MRT_FilterTypeMenu.tsx +10 -10
  34. package/src/menus/MRT_RowActionMenu.tsx +1 -1
  35. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -35
  36. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
  37. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
  38. package/src/useMRT.tsx +38 -34
package/src/useMRT.tsx CHANGED
@@ -7,6 +7,7 @@ import React, {
7
7
  useState,
8
8
  Dispatch,
9
9
  SetStateAction,
10
+ useCallback,
10
11
  } from 'react';
11
12
  import {
12
13
  PluginHook,
@@ -21,9 +22,13 @@ import {
21
22
  useSortBy,
22
23
  useTable,
23
24
  } from 'react-table';
24
- import type { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
25
+ import type {
26
+ MRT_ColumnInterface,
27
+ MRT_FilterType,
28
+ MRT_Row,
29
+ MRT_TableInstance,
30
+ } from '.';
25
31
  import { MRT_FILTER_TYPE } from './enums';
26
- import { defaultFilterFNs } from './filtersFNs';
27
32
  import { MRT_Icons } from './icons';
28
33
  import { MRT_Localization } from './localization';
29
34
  import { MaterialReactTableProps } from './MaterialReactTable';
@@ -33,6 +38,7 @@ export type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
33
38
  anyRowsExpanded: boolean;
34
39
  icons: MRT_Icons;
35
40
  idPrefix: string;
41
+ filterTypes: { [key in MRT_FILTER_TYPE]: any };
36
42
  localization: MRT_Localization;
37
43
  setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
38
44
  setCurrentFilterTypes: Dispatch<
@@ -82,17 +88,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
82
88
  props.initialState?.showSearch ?? false,
83
89
  );
84
90
 
85
- const filterTypes = useMemo<{
86
- [key in MRT_FILTER_TYPE]: any;
87
- }>(
88
- () => ({
89
- ...defaultFilterFNs,
90
- ...props.filterTypes,
91
- }),
92
- [props.filterTypes],
93
- );
94
-
95
- const getInitialFilterTypeState = () => {
91
+ const findLowestLevelCols = useCallback(() => {
96
92
  let lowestLevelColumns: any[] = props.columns;
97
93
  let currentCols: any[] = props.columns;
98
94
  while (!!currentCols.length && currentCols.some((col) => col.columns)) {
@@ -105,42 +101,50 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
105
101
  }
106
102
  currentCols = nextCols;
107
103
  }
108
- lowestLevelColumns = lowestLevelColumns.filter((col) => !col.columns);
104
+ return lowestLevelColumns.filter((col) => !col.columns);
105
+ }, [props.columns]);
109
106
 
110
- return Object.assign(
107
+ const [currentFilterTypes, setCurrentFilterTypes] = useState<{
108
+ [key: string]: MRT_FilterType;
109
+ }>(() =>
110
+ Object.assign(
111
111
  {},
112
- ...lowestLevelColumns.map((c) => ({
112
+ ...findLowestLevelCols().map((c) => ({
113
113
  [c.accessor as string]:
114
114
  c.filter ??
115
115
  props?.initialState?.filters?.[c.accessor as any] ??
116
116
  (!!c.filterSelectOptions ? 'equals' : 'fuzzy'),
117
117
  })),
118
- );
119
- };
120
-
121
- const [currentFilterTypes, setCurrentFilterTypes] = useState<{
122
- [key: string]: MRT_FilterType;
123
- }>(() => getInitialFilterTypeState());
118
+ ),
119
+ );
124
120
 
125
- const columns = useMemo(
126
- () =>
127
- props.columns.map((column) => {
128
- column.filter =
129
- filterTypes[
130
- currentFilterTypes[column.accessor as string] as MRT_FILTER_TYPE
131
- ];
121
+ const applyFiltersToColumns = useCallback(
122
+ (cols: MRT_ColumnInterface[]) =>
123
+ cols.map((column) => {
124
+ if (column.columns) {
125
+ applyFiltersToColumns(column.columns);
126
+ } else {
127
+ column.filter =
128
+ props?.filterTypes?.[
129
+ currentFilterTypes[column.accessor as string] as MRT_FILTER_TYPE
130
+ ];
131
+ }
132
132
  return column;
133
133
  }),
134
- [props.columns, filterTypes, currentFilterTypes],
134
+ [currentFilterTypes, props.filterTypes],
135
+ );
136
+
137
+ const columns = useMemo(
138
+ () => applyFiltersToColumns(props.columns),
139
+ [props.columns, applyFiltersToColumns],
135
140
  );
136
141
 
137
142
  const tableInstance = useTable(
143
+ // @ts-ignore
138
144
  {
139
145
  ...props,
140
- columns,
141
146
  // @ts-ignore
142
- filterTypes,
143
- globalFilterValue: 'fuzzy',
147
+ columns,
144
148
  useControlledState: (state) =>
145
149
  useMemo(
146
150
  () => ({
@@ -166,7 +170,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
166
170
  ),
167
171
  },
168
172
  ...hooks,
169
- ) as MRT_TableInstance<D>;
173
+ ) as unknown as MRT_TableInstance<D>;
170
174
 
171
175
  const idPrefix = useMemo(
172
176
  () => props.idPrefix ?? Math.random().toString(36).substring(2, 9),