material-react-table 0.6.9 → 0.6.10
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 -4
- package/dist/enums.d.ts +2 -1
- package/dist/filtersFNs.d.ts +13 -5
- package/dist/localization.d.ts +3 -1
- package/dist/material-react-table.cjs.development.js +280 -213
- 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 +281 -214
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_FilterTypeMenu.d.ts +1 -1
- package/dist/useMRT.d.ts +1 -0
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +15 -6
- package/src/body/MRT_TableBodyCell.tsx +8 -2
- package/src/body/MRT_TableBodyRow.tsx +15 -6
- package/src/buttons/MRT_CopyButton.tsx +24 -6
- package/src/buttons/MRT_ExpandAllButton.tsx +13 -20
- package/src/buttons/MRT_ExpandButton.tsx +20 -33
- package/src/enums.ts +2 -1
- package/src/filtersFNs.ts +17 -3
- package/src/head/MRT_TableHeadCell.tsx +1 -0
- package/src/head/MRT_TableHeadRow.tsx +28 -17
- package/src/inputs/MRT_FilterTextField.tsx +1 -8
- package/src/inputs/MRT_SearchTextField.tsx +27 -3
- package/src/localization.ts +7 -3
- package/src/menus/MRT_FilterTypeMenu.tsx +44 -18
- package/src/useMRT.tsx +12 -1
|
@@ -4,11 +4,12 @@ import { useMRT } from '../useMRT';
|
|
|
4
4
|
import type { MRT_FilterType, MRT_HeaderGroup } from '..';
|
|
5
5
|
import { MRT_FILTER_TYPE } from '../enums';
|
|
6
6
|
import {
|
|
7
|
+
bestMatch,
|
|
8
|
+
bestMatchFirst,
|
|
7
9
|
contains,
|
|
8
10
|
empty,
|
|
9
11
|
endsWith,
|
|
10
12
|
equals,
|
|
11
|
-
fuzzy,
|
|
12
13
|
greaterThan,
|
|
13
14
|
lessThan,
|
|
14
15
|
notEmpty,
|
|
@@ -24,7 +25,7 @@ const commonMenuItemStyles = {
|
|
|
24
25
|
|
|
25
26
|
interface Props {
|
|
26
27
|
anchorEl: HTMLElement | null;
|
|
27
|
-
column
|
|
28
|
+
column?: MRT_HeaderGroup;
|
|
28
29
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
29
30
|
onSelect?: () => void;
|
|
30
31
|
}
|
|
@@ -35,7 +36,13 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
35
36
|
onSelect,
|
|
36
37
|
setAnchorEl,
|
|
37
38
|
}) => {
|
|
38
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
enabledGlobalFilterTypes,
|
|
41
|
+
localization,
|
|
42
|
+
setCurrentFilterTypes,
|
|
43
|
+
setCurrentGlobalFilterType,
|
|
44
|
+
tableInstance,
|
|
45
|
+
} = useMRT();
|
|
39
46
|
|
|
40
47
|
const filterTypes: {
|
|
41
48
|
type: MRT_FILTER_TYPE;
|
|
@@ -46,15 +53,21 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
46
53
|
() =>
|
|
47
54
|
[
|
|
48
55
|
{
|
|
49
|
-
type: MRT_FILTER_TYPE.
|
|
50
|
-
label: localization.
|
|
56
|
+
type: MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
57
|
+
label: localization.filterBestMatchFirst,
|
|
51
58
|
divider: false,
|
|
52
|
-
fn:
|
|
59
|
+
fn: bestMatchFirst,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: MRT_FILTER_TYPE.BEST_MATCH,
|
|
63
|
+
label: localization.filterBestMatch,
|
|
64
|
+
divider: !!column,
|
|
65
|
+
fn: bestMatch,
|
|
53
66
|
},
|
|
54
67
|
{
|
|
55
68
|
type: MRT_FILTER_TYPE.CONTAINS,
|
|
56
69
|
label: localization.filterContains,
|
|
57
|
-
divider:
|
|
70
|
+
divider: false,
|
|
58
71
|
fn: contains,
|
|
59
72
|
},
|
|
60
73
|
{
|
|
@@ -105,26 +118,39 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
105
118
|
divider: false,
|
|
106
119
|
fn: notEmpty,
|
|
107
120
|
},
|
|
108
|
-
].filter(
|
|
109
|
-
|
|
110
|
-
!column.
|
|
121
|
+
].filter((filterType) =>
|
|
122
|
+
column
|
|
123
|
+
? !column.enabledFilterTypes ||
|
|
124
|
+
column.enabledFilterTypes.includes(filterType.type)
|
|
125
|
+
: (!enabledGlobalFilterTypes ||
|
|
126
|
+
enabledGlobalFilterTypes.includes(filterType.type)) &&
|
|
127
|
+
[
|
|
128
|
+
MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
129
|
+
MRT_FILTER_TYPE.BEST_MATCH,
|
|
130
|
+
].includes(filterType.type),
|
|
111
131
|
),
|
|
112
132
|
[],
|
|
113
133
|
);
|
|
114
134
|
|
|
115
135
|
const handleSelectFilterType = (value: MRT_FILTER_TYPE) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
if (column) {
|
|
137
|
+
setCurrentFilterTypes((prev: { [key: string]: MRT_FilterType }) => ({
|
|
138
|
+
...prev,
|
|
139
|
+
[column.id]: value,
|
|
140
|
+
}));
|
|
141
|
+
if ([MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(value)) {
|
|
142
|
+
column.setFilter(' ');
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
setCurrentGlobalFilterType(value);
|
|
123
146
|
}
|
|
147
|
+
setAnchorEl(null);
|
|
124
148
|
onSelect?.();
|
|
125
149
|
};
|
|
126
150
|
|
|
127
|
-
const filterType =
|
|
151
|
+
const filterType = column
|
|
152
|
+
? tableInstance.state.currentFilterTypes[column.id]
|
|
153
|
+
: tableInstance.state.currentGlobalFilterType;
|
|
128
154
|
|
|
129
155
|
return (
|
|
130
156
|
<Menu
|
package/src/useMRT.tsx
CHANGED
|
@@ -47,6 +47,7 @@ export type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
|
47
47
|
[key: string]: MRT_FilterType;
|
|
48
48
|
}>
|
|
49
49
|
>;
|
|
50
|
+
setCurrentGlobalFilterType: Dispatch<SetStateAction<MRT_FILTER_TYPE>>;
|
|
50
51
|
setDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
51
52
|
setFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
52
53
|
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
@@ -98,11 +99,17 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
98
99
|
[c.accessor as string]:
|
|
99
100
|
c.filter ??
|
|
100
101
|
props?.initialState?.filters?.[c.accessor as any] ??
|
|
101
|
-
(!!c.filterSelectOptions
|
|
102
|
+
(!!c.filterSelectOptions?.length
|
|
103
|
+
? MRT_FILTER_TYPE.EQUALS
|
|
104
|
+
: MRT_FILTER_TYPE.BEST_MATCH),
|
|
102
105
|
})),
|
|
103
106
|
),
|
|
104
107
|
);
|
|
105
108
|
|
|
109
|
+
const [currentGlobalFilterType, setCurrentGlobalFilterType] = useState<
|
|
110
|
+
MRT_FilterType | string | undefined
|
|
111
|
+
>(props.globalFilter);
|
|
112
|
+
|
|
106
113
|
const applyFiltersToColumns = useCallback(
|
|
107
114
|
(cols: MRT_ColumnInterface[]) =>
|
|
108
115
|
cols.map((column) => {
|
|
@@ -146,12 +153,14 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
146
153
|
// @ts-ignore
|
|
147
154
|
columns,
|
|
148
155
|
data,
|
|
156
|
+
globalFilter: currentGlobalFilterType,
|
|
149
157
|
useControlledState: (state) =>
|
|
150
158
|
useMemo(
|
|
151
159
|
() => ({
|
|
152
160
|
...state,
|
|
153
161
|
currentEditingRow,
|
|
154
162
|
currentFilterTypes,
|
|
163
|
+
currentGlobalFilterType,
|
|
155
164
|
densePadding,
|
|
156
165
|
fullScreen,
|
|
157
166
|
showFilters,
|
|
@@ -162,6 +171,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
162
171
|
[
|
|
163
172
|
currentEditingRow,
|
|
164
173
|
currentFilterTypes,
|
|
174
|
+
currentGlobalFilterType,
|
|
165
175
|
densePadding,
|
|
166
176
|
fullScreen,
|
|
167
177
|
showFilters,
|
|
@@ -196,6 +206,7 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
|
196
206
|
//@ts-ignore
|
|
197
207
|
setCurrentEditingRow,
|
|
198
208
|
setCurrentFilterTypes,
|
|
209
|
+
setCurrentGlobalFilterType,
|
|
199
210
|
setDensePadding,
|
|
200
211
|
setFullScreen,
|
|
201
212
|
setShowFilters,
|