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.
- package/dist/MaterialReactTable.d.ts +13 -5
- package/dist/filtersFNs.d.ts +6 -10
- package/dist/localization.d.ts +43 -46
- package/dist/material-react-table.cjs.development.js +404 -331
- 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 +405 -332
- package/dist/material-react-table.esm.js.map +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 +4 -0
- package/package.json +3 -3
- package/src/MaterialReactTable.tsx +59 -47
- package/src/buttons/MRT_EditActionButtons.tsx +4 -7
- package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
- package/src/buttons/MRT_ExpandButton.tsx +2 -2
- package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -52
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +2 -2
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +3 -7
- package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
- package/src/filtersFNs.ts +6 -16
- package/src/head/MRT_TableHeadCell.tsx +19 -6
- package/src/head/MRT_TableHeadCellActions.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +34 -9
- package/src/inputs/MRT_SearchTextField.tsx +3 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +4 -4
- package/src/localization.ts +87 -92
- package/src/menus/MRT_ColumnActionMenu.tsx +59 -14
- package/src/menus/MRT_FilterTypeMenu.tsx +10 -10
- package/src/menus/MRT_RowActionMenu.tsx +1 -1
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -35
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
- 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 {
|
|
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
|
|
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
|
-
|
|
104
|
+
return lowestLevelColumns.filter((col) => !col.columns);
|
|
105
|
+
}, [props.columns]);
|
|
109
106
|
|
|
110
|
-
|
|
107
|
+
const [currentFilterTypes, setCurrentFilterTypes] = useState<{
|
|
108
|
+
[key: string]: MRT_FilterType;
|
|
109
|
+
}>(() =>
|
|
110
|
+
Object.assign(
|
|
111
111
|
{},
|
|
112
|
-
...
|
|
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
|
|
126
|
-
() =>
|
|
127
|
-
|
|
128
|
-
column.
|
|
129
|
-
|
|
130
|
-
|
|
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.
|
|
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
|
-
|
|
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),
|