material-react-table 0.5.7 → 0.6.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.
- package/dist/MaterialReactTable.d.ts +8 -2
- package/dist/body/MRT_TableBodyCell.d.ts +1 -1
- package/dist/body/MRT_TableBodyRow.d.ts +1 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
- package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
- package/dist/enums.d.ts +12 -0
- package/dist/filtersFNs.d.ts +20 -0
- package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
- package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/head/MRT_TableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHeadRow.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
- package/dist/localization.d.ts +44 -44
- package/dist/material-react-table.cjs.development.js +569 -360
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +570 -361
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -2
- package/dist/menus/MRT_FilterTypeMenu.d.ts +1 -1
- package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +3 -2
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -0
- package/dist/useMRT.d.ts +1 -1
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +5 -9
- package/src/body/MRT_TableBody.tsx +1 -1
- package/src/body/MRT_TableBodyCell.tsx +1 -1
- package/src/body/MRT_TableBodyRow.tsx +1 -1
- package/src/body/MRT_TableDetailPanel.tsx +1 -1
- package/src/buttons/MRT_EditActionButtons.tsx +5 -8
- package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
- package/src/buttons/MRT_ExpandButton.tsx +3 -3
- package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -55
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +4 -8
- package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
- package/src/enums.ts +12 -0
- package/src/filtersFNs.ts +42 -0
- package/src/footer/MRT_TableFooter.tsx +1 -1
- package/src/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/footer/MRT_TableFooterRow.tsx +1 -1
- package/src/head/MRT_TableHead.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +22 -18
- package/src/head/MRT_TableHeadCellActions.tsx +1 -1
- package/src/head/MRT_TableHeadRow.tsx +1 -1
- package/src/inputs/MRT_EditCellTextField.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +99 -21
- package/src/inputs/MRT_SearchTextField.tsx +3 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -5
- package/src/localization.ts +89 -88
- package/src/menus/MRT_ColumnActionMenu.tsx +109 -56
- package/src/menus/MRT_FilterTypeMenu.tsx +63 -26
- package/src/menus/MRT_RowActionMenu.tsx +4 -10
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +54 -33
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
- package/src/useMRT.tsx +36 -14
package/src/useMRT.tsx
CHANGED
|
@@ -21,7 +21,8 @@ import {
|
|
|
21
21
|
useSortBy,
|
|
22
22
|
useTable,
|
|
23
23
|
} from 'react-table';
|
|
24
|
-
import { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
|
|
24
|
+
import type { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
|
|
25
|
+
import { MRT_FILTER_TYPE } from './enums';
|
|
25
26
|
import { defaultFilterFNs } from './filtersFNs';
|
|
26
27
|
import { MRT_Icons } from './icons';
|
|
27
28
|
import { MRT_Localization } from './localization';
|
|
@@ -81,7 +82,9 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
81
82
|
props.initialState?.showSearch ?? false,
|
|
82
83
|
);
|
|
83
84
|
|
|
84
|
-
const filterTypes = useMemo<
|
|
85
|
+
const filterTypes = useMemo<{
|
|
86
|
+
[key in MRT_FILTER_TYPE]: any;
|
|
87
|
+
}>(
|
|
85
88
|
() => ({
|
|
86
89
|
...defaultFilterFNs,
|
|
87
90
|
...props.filterTypes,
|
|
@@ -89,25 +92,43 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
89
92
|
[props.filterTypes],
|
|
90
93
|
);
|
|
91
94
|
|
|
95
|
+
const getInitialFilterTypeState = () => {
|
|
96
|
+
let lowestLevelColumns: any[] = props.columns;
|
|
97
|
+
let currentCols: any[] = props.columns;
|
|
98
|
+
while (!!currentCols.length && currentCols.some((col) => col.columns)) {
|
|
99
|
+
const nextCols = currentCols
|
|
100
|
+
.filter((col) => !!col.columns)
|
|
101
|
+
.map((col) => col.columns)
|
|
102
|
+
.flat();
|
|
103
|
+
if (nextCols.every((col) => !col.columns)) {
|
|
104
|
+
lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
|
|
105
|
+
}
|
|
106
|
+
currentCols = nextCols;
|
|
107
|
+
}
|
|
108
|
+
lowestLevelColumns = lowestLevelColumns.filter((col) => !col.columns);
|
|
109
|
+
|
|
110
|
+
return Object.assign(
|
|
111
|
+
{},
|
|
112
|
+
...lowestLevelColumns.map((c) => ({
|
|
113
|
+
[c.accessor as string]:
|
|
114
|
+
c.filter ??
|
|
115
|
+
props?.initialState?.filters?.[c.accessor as any] ??
|
|
116
|
+
(!!c.filterSelectOptions ? 'equals' : 'fuzzy'),
|
|
117
|
+
})),
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
92
121
|
const [currentFilterTypes, setCurrentFilterTypes] = useState<{
|
|
93
122
|
[key: string]: MRT_FilterType;
|
|
94
|
-
}>(() =>
|
|
95
|
-
Object.assign(
|
|
96
|
-
{},
|
|
97
|
-
...props.columns
|
|
98
|
-
.map((c) => c.accessor?.toString() as string)
|
|
99
|
-
.map((accessor) => ({
|
|
100
|
-
[accessor]:
|
|
101
|
-
props?.initialState?.filters?.[accessor as any] ?? 'fuzzy',
|
|
102
|
-
})),
|
|
103
|
-
),
|
|
104
|
-
);
|
|
123
|
+
}>(() => getInitialFilterTypeState());
|
|
105
124
|
|
|
106
125
|
const columns = useMemo(
|
|
107
126
|
() =>
|
|
108
127
|
props.columns.map((column) => {
|
|
109
128
|
column.filter =
|
|
110
|
-
filterTypes[
|
|
129
|
+
filterTypes[
|
|
130
|
+
currentFilterTypes[column.accessor as string] as MRT_FILTER_TYPE
|
|
131
|
+
];
|
|
111
132
|
return column;
|
|
112
133
|
}),
|
|
113
134
|
[props.columns, filterTypes, currentFilterTypes],
|
|
@@ -119,6 +140,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
119
140
|
columns,
|
|
120
141
|
// @ts-ignore
|
|
121
142
|
filterTypes,
|
|
143
|
+
globalFilterValue: 'fuzzy',
|
|
122
144
|
useControlledState: (state) =>
|
|
123
145
|
useMemo(
|
|
124
146
|
() => ({
|