material-react-table 0.5.3 → 0.5.4
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 +5 -0
- package/dist/filtersFNs.d.ts +67 -0
- package/dist/localization.d.ts +10 -1
- package/dist/material-react-table.cjs.development.js +367 -69
- 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 +368 -70
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_FilterMenu.d.ts +10 -0
- package/dist/useMRT.d.ts +13 -9
- package/package.json +6 -2
- package/src/MaterialReactTable.tsx +15 -1
- package/src/buttons/MRT_EditActionButtons.tsx +3 -1
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
- package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -1
- package/src/buttons/MRT_ToggleSearchButton.tsx +5 -2
- package/src/filtersFNs.ts +112 -0
- package/src/head/MRT_TableHeadCell.tsx +45 -44
- package/src/index.tsx +0 -2
- package/src/inputs/MRT_FilterTextField.tsx +117 -52
- package/src/inputs/MRT_SearchTextField.tsx +2 -1
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -7
- package/src/localization.ts +20 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +125 -85
- package/src/menus/MRT_FilterMenu.tsx +109 -0
- package/src/useMRT.tsx +67 -13
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { MRT_HeaderGroup } from '..';
|
|
3
|
+
interface Props {
|
|
4
|
+
anchorEl: HTMLElement | null;
|
|
5
|
+
column: MRT_HeaderGroup;
|
|
6
|
+
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
7
|
+
onSelect?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const MRT_FilterMenu: FC<Props>;
|
|
10
|
+
export {};
|
package/dist/useMRT.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { MRT_Row, MRT_TableInstance } from '.';
|
|
1
|
+
import React, { PropsWithChildren, Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
|
|
3
3
|
import { MRT_Icons } from './icons';
|
|
4
4
|
import { MRT_Localization } from './localization';
|
|
5
5
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
@@ -7,13 +7,17 @@ export declare type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
|
7
7
|
anyRowsCanExpand: boolean;
|
|
8
8
|
anyRowsExpanded: boolean;
|
|
9
9
|
icons: MRT_Icons;
|
|
10
|
+
idPrefix: string;
|
|
10
11
|
localization: MRT_Localization;
|
|
11
|
-
setCurrentEditingRow:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
|
|
13
|
+
setCurrentFilterTypes: Dispatch<SetStateAction<{
|
|
14
|
+
[key: string]: MRT_FilterType;
|
|
15
|
+
}>>;
|
|
16
|
+
setDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
17
|
+
setFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
18
|
+
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
19
|
+
setShowSearch: Dispatch<SetStateAction<boolean>>;
|
|
16
20
|
tableInstance: MRT_TableInstance<D>;
|
|
17
21
|
};
|
|
18
|
-
export declare const MaterialReactTableProvider: <D extends {}>(props: React.PropsWithChildren<MaterialReactTableProps<D>>) => JSX.Element;
|
|
19
|
-
export declare const useMRT: <D extends {}>() => UseMRT<D>;
|
|
22
|
+
export declare const MaterialReactTableProvider: <D extends {} = {}>(props: React.PropsWithChildren<MaterialReactTableProps<D>>) => JSX.Element;
|
|
23
|
+
export declare const useMRT: <D extends {} = {}>() => UseMRT<D>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.5.
|
|
2
|
+
"version": "0.5.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material-UI implementation of react-table, inspired by material-table and the mui DataGrid, written from the ground up in TypeScript.",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@storybook/react": "^6.4.19",
|
|
76
76
|
"@types/faker": "^6.6.8",
|
|
77
77
|
"@types/react": "^17.0.39",
|
|
78
|
-
"@types/react-dom": "^17.0.
|
|
78
|
+
"@types/react-dom": "^17.0.13",
|
|
79
79
|
"@types/react-table": "^7.7.9",
|
|
80
80
|
"babel-loader": "^8.2.3",
|
|
81
81
|
"husky": "^7.0.4",
|
|
@@ -93,9 +93,13 @@
|
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@emotion/react": ">=11",
|
|
96
|
+
"@emotion/styled": ">=11",
|
|
96
97
|
"@mui/icons-material": ">=5",
|
|
97
98
|
"@mui/material": ">=5",
|
|
98
99
|
"react": ">=16.8",
|
|
99
100
|
"react-table": ">=7"
|
|
101
|
+
},
|
|
102
|
+
"dependencies": {
|
|
103
|
+
"match-sorter": "^6.3.1"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
@@ -181,6 +181,16 @@ export type MRT_Cell<D extends {} = {}, _V = any> = Cell<D> &
|
|
|
181
181
|
UseGroupByCellProps<D> &
|
|
182
182
|
UseRowStateCellProps<D> & {};
|
|
183
183
|
|
|
184
|
+
export type MRT_FilterType =
|
|
185
|
+
| 'contains'
|
|
186
|
+
| 'empty'
|
|
187
|
+
| 'endsWith'
|
|
188
|
+
| 'equals'
|
|
189
|
+
| 'fuzzy'
|
|
190
|
+
| 'notEmpty'
|
|
191
|
+
| 'notEquals'
|
|
192
|
+
| 'startsWith';
|
|
193
|
+
|
|
184
194
|
export type MRT_TableState<D extends {} = {}> = TableState<D> &
|
|
185
195
|
UseColumnOrderState<D> &
|
|
186
196
|
UseExpandedState<D> &
|
|
@@ -193,6 +203,7 @@ export type MRT_TableState<D extends {} = {}> = TableState<D> &
|
|
|
193
203
|
UseRowStateState<D> &
|
|
194
204
|
UseSortByState<D> & {
|
|
195
205
|
currentEditingRow: MRT_Row<D> | null;
|
|
206
|
+
currentFilterTypes: { [key: string]: MRT_FilterType };
|
|
196
207
|
densePadding: boolean;
|
|
197
208
|
fullScreen: boolean;
|
|
198
209
|
showFilters: boolean;
|
|
@@ -229,6 +240,7 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
229
240
|
hideToolbarInternalActions?: boolean;
|
|
230
241
|
hideToolbarTop?: boolean;
|
|
231
242
|
icons?: Partial<MRT_Icons>;
|
|
243
|
+
idPrefix?: string;
|
|
232
244
|
isFetching?: boolean;
|
|
233
245
|
isLoading?: boolean;
|
|
234
246
|
localization?: Partial<MRT_Localization>;
|
|
@@ -275,7 +287,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
275
287
|
| ((
|
|
276
288
|
tableInstance: MRT_TableInstance<D>,
|
|
277
289
|
) => Partial<TablePaginationProps>);
|
|
278
|
-
muiTableProps?:
|
|
290
|
+
muiTableProps?:
|
|
291
|
+
| TableProps
|
|
292
|
+
| ((tableInstance: MRT_TableInstance<D>) => TableProps);
|
|
279
293
|
muiTableToolbarAlertBannerProps?:
|
|
280
294
|
| AlertProps
|
|
281
295
|
| ((tableInstance: MRT_TableInstance<D>) => AlertProps);
|
|
@@ -13,7 +13,9 @@ export const MRT_EditActionButtons: FC<Props> = ({ row }) => {
|
|
|
13
13
|
localization,
|
|
14
14
|
onRowEditSubmit,
|
|
15
15
|
setCurrentEditingRow,
|
|
16
|
-
tableInstance: {
|
|
16
|
+
tableInstance: {
|
|
17
|
+
state: { currentEditingRow },
|
|
18
|
+
},
|
|
17
19
|
} = useMRT();
|
|
18
20
|
|
|
19
21
|
const handleCancel = () => {
|
|
@@ -35,11 +35,12 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
|
35
35
|
onClick={handleClick}
|
|
36
36
|
size="small"
|
|
37
37
|
sx={{
|
|
38
|
+
height: '2rem',
|
|
39
|
+
mr: '2px',
|
|
40
|
+
mt: '-0.2rem',
|
|
38
41
|
opacity: 0.5,
|
|
39
42
|
transition: 'opacity 0.2s',
|
|
40
|
-
|
|
41
|
-
height: '1.6rem',
|
|
42
|
-
width: '1.6rem',
|
|
43
|
+
width: '2rem',
|
|
43
44
|
'&:hover': {
|
|
44
45
|
opacity: 1,
|
|
45
46
|
},
|
|
@@ -9,7 +9,9 @@ export const MRT_ToggleFiltersButton: FC<Props> = ({ ...rest }) => {
|
|
|
9
9
|
icons: { FilterListIcon, FilterListOffIcon },
|
|
10
10
|
localization,
|
|
11
11
|
setShowFilters,
|
|
12
|
-
tableInstance: {
|
|
12
|
+
tableInstance: {
|
|
13
|
+
state: { showFilters },
|
|
14
|
+
},
|
|
13
15
|
} = useMRT();
|
|
14
16
|
|
|
15
17
|
return (
|
|
@@ -7,10 +7,13 @@ interface Props extends IconButtonProps {}
|
|
|
7
7
|
export const MRT_ToggleSearchButton: FC<Props> = ({ ...rest }) => {
|
|
8
8
|
const {
|
|
9
9
|
icons: { SearchIcon, SearchOffIcon },
|
|
10
|
+
idPrefix,
|
|
10
11
|
localization,
|
|
11
12
|
muiSearchTextFieldProps,
|
|
12
13
|
setShowSearch,
|
|
13
|
-
tableInstance: {
|
|
14
|
+
tableInstance: {
|
|
15
|
+
state: { showSearch },
|
|
16
|
+
},
|
|
14
17
|
} = useMRT();
|
|
15
18
|
|
|
16
19
|
const handleToggleSearch = () => {
|
|
@@ -19,7 +22,7 @@ export const MRT_ToggleSearchButton: FC<Props> = ({ ...rest }) => {
|
|
|
19
22
|
() =>
|
|
20
23
|
document
|
|
21
24
|
.getElementById(
|
|
22
|
-
muiSearchTextFieldProps?.id ?? `
|
|
25
|
+
muiSearchTextFieldProps?.id ?? `mrt-${idPrefix}-search-text-field`,
|
|
23
26
|
)
|
|
24
27
|
?.focus(),
|
|
25
28
|
200,
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { matchSorter } from 'match-sorter';
|
|
2
|
+
import { MRT_Row } from '.';
|
|
3
|
+
|
|
4
|
+
export const fuzzyFilterFN = (
|
|
5
|
+
rows: MRT_Row[],
|
|
6
|
+
id: string,
|
|
7
|
+
filterValue: string | number,
|
|
8
|
+
) =>
|
|
9
|
+
matchSorter(rows, filterValue.toString().trim(), {
|
|
10
|
+
keys: [`values.${id}`],
|
|
11
|
+
sorter: (rankedItems) => rankedItems,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
fuzzyFilterFN.autoRemove = (val: any) => !val;
|
|
15
|
+
|
|
16
|
+
export const containsFilterFN = (
|
|
17
|
+
rows: MRT_Row[],
|
|
18
|
+
id: string,
|
|
19
|
+
filterValue: string | number,
|
|
20
|
+
) =>
|
|
21
|
+
rows.filter((row) =>
|
|
22
|
+
row.values[id]
|
|
23
|
+
.toString()
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
.trim()
|
|
26
|
+
.includes(filterValue.toString().toLowerCase().trim()),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
containsFilterFN.autoRemove = (val: any) => !val;
|
|
30
|
+
|
|
31
|
+
export const startsWithFilterFN = (
|
|
32
|
+
rows: MRT_Row[],
|
|
33
|
+
id: string,
|
|
34
|
+
filterValue: string | number,
|
|
35
|
+
) =>
|
|
36
|
+
rows.filter((row) =>
|
|
37
|
+
row.values[id]
|
|
38
|
+
.toString()
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.trim()
|
|
41
|
+
.startsWith(filterValue.toString().toLowerCase().trim()),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
startsWithFilterFN.autoRemove = (val: any) => !val;
|
|
45
|
+
|
|
46
|
+
export const endsWithFilterFN = (
|
|
47
|
+
rows: MRT_Row[],
|
|
48
|
+
id: string,
|
|
49
|
+
filterValue: string | number,
|
|
50
|
+
) =>
|
|
51
|
+
rows.filter((row) =>
|
|
52
|
+
row.values[id]
|
|
53
|
+
.toString()
|
|
54
|
+
.toLowerCase()
|
|
55
|
+
.trim()
|
|
56
|
+
.endsWith(filterValue.toString().toLowerCase().trim()),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
endsWithFilterFN.autoRemove = (val: any) => !val;
|
|
60
|
+
|
|
61
|
+
export const equalsFilterFN = (
|
|
62
|
+
rows: MRT_Row[],
|
|
63
|
+
id: string,
|
|
64
|
+
filterValue: string | number,
|
|
65
|
+
) =>
|
|
66
|
+
rows.filter(
|
|
67
|
+
(row) =>
|
|
68
|
+
row.values[id].toString().toLowerCase().trim() ===
|
|
69
|
+
filterValue.toString().toLowerCase().trim(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
equalsFilterFN.autoRemove = (val: any) => !val;
|
|
73
|
+
|
|
74
|
+
export const notEqualsFilterFN = (
|
|
75
|
+
rows: MRT_Row[],
|
|
76
|
+
id: string,
|
|
77
|
+
filterValue: string | number,
|
|
78
|
+
) =>
|
|
79
|
+
rows.filter(
|
|
80
|
+
(row) =>
|
|
81
|
+
row.values[id].toString().toLowerCase().trim() !==
|
|
82
|
+
filterValue.toString().toLowerCase().trim(),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
notEqualsFilterFN.autoRemove = (val: any) => !val;
|
|
86
|
+
|
|
87
|
+
export const emptyFilterFN = (
|
|
88
|
+
rows: MRT_Row[],
|
|
89
|
+
id: string,
|
|
90
|
+
_filterValue: string | number,
|
|
91
|
+
) => rows.filter((row) => !row.values[id].toString().toLowerCase().trim());
|
|
92
|
+
|
|
93
|
+
emptyFilterFN.autoRemove = (val: any) => !val;
|
|
94
|
+
|
|
95
|
+
export const notEmptyFilterFN = (
|
|
96
|
+
rows: MRT_Row[],
|
|
97
|
+
id: string,
|
|
98
|
+
_filterValue: string | number,
|
|
99
|
+
) => rows.filter((row) => !!row.values[id].toString().toLowerCase().trim());
|
|
100
|
+
|
|
101
|
+
notEmptyFilterFN.autoRemove = (val: any) => !val;
|
|
102
|
+
|
|
103
|
+
export const defaultFilterFNs = {
|
|
104
|
+
contains: containsFilterFN,
|
|
105
|
+
empty: emptyFilterFN,
|
|
106
|
+
endsWith: endsWithFilterFN,
|
|
107
|
+
equals: equalsFilterFN,
|
|
108
|
+
fuzzy: fuzzyFilterFN,
|
|
109
|
+
notEmpty: notEmptyFilterFN,
|
|
110
|
+
notEquals: notEqualsFilterFN,
|
|
111
|
+
startsWith: startsWithFilterFN,
|
|
112
|
+
};
|
|
@@ -73,6 +73,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
73
73
|
column.Header as string,
|
|
74
74
|
);
|
|
75
75
|
|
|
76
|
+
const columnHeader = column.render('Header') as string;
|
|
77
|
+
|
|
76
78
|
return (
|
|
77
79
|
<TableCell
|
|
78
80
|
align={isParentHeader ? 'center' : 'left'}
|
|
@@ -86,59 +88,58 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
86
88
|
}}
|
|
87
89
|
>
|
|
88
90
|
<Box
|
|
89
|
-
sx={{
|
|
91
|
+
sx={{
|
|
92
|
+
alignItems: 'flex-start',
|
|
93
|
+
display: 'flex',
|
|
94
|
+
justifyContent: isParentHeader ? 'center' : 'space-between',
|
|
95
|
+
width: '100%',
|
|
96
|
+
}}
|
|
90
97
|
>
|
|
91
98
|
<Box
|
|
99
|
+
{...column.getSortByToggleProps()}
|
|
92
100
|
sx={{
|
|
93
|
-
alignItems: '
|
|
101
|
+
alignItems: 'center',
|
|
94
102
|
display: 'flex',
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
flexWrap: 'nowrap',
|
|
104
|
+
whiteSpace: columnHeader.length < 15 ? 'nowrap' : 'normal',
|
|
97
105
|
}}
|
|
106
|
+
title={undefined}
|
|
98
107
|
>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<Tooltip arrow title={sortTooltip}>
|
|
107
|
-
<TableSortLabel
|
|
108
|
-
aria-label={sortTooltip}
|
|
109
|
-
active={column.isSorted}
|
|
110
|
-
direction={column.isSortedDesc ? 'desc' : 'asc'}
|
|
111
|
-
/>
|
|
112
|
-
</Tooltip>
|
|
113
|
-
)}
|
|
114
|
-
</Box>
|
|
115
|
-
<Box
|
|
116
|
-
sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}
|
|
117
|
-
>
|
|
118
|
-
{!disableColumnActions && !isParentHeader && (
|
|
119
|
-
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
120
|
-
)}
|
|
121
|
-
{enableColumnResizing && !isParentHeader && (
|
|
122
|
-
<Divider
|
|
123
|
-
flexItem
|
|
124
|
-
orientation="vertical"
|
|
125
|
-
onDoubleClick={() => tableInstance.resetResizing()}
|
|
126
|
-
{...column.getResizerProps()}
|
|
127
|
-
sx={{
|
|
128
|
-
borderRightWidth: '2px',
|
|
129
|
-
borderRadius: '2px',
|
|
130
|
-
maxHeight: '2rem',
|
|
131
|
-
}}
|
|
108
|
+
{column.render('Header')}
|
|
109
|
+
{!isParentHeader && column.canSort && (
|
|
110
|
+
<Tooltip arrow title={sortTooltip}>
|
|
111
|
+
<TableSortLabel
|
|
112
|
+
aria-label={sortTooltip}
|
|
113
|
+
active={column.isSorted}
|
|
114
|
+
direction={column.isSortedDesc ? 'desc' : 'asc'}
|
|
132
115
|
/>
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
</Tooltip>
|
|
117
|
+
)}
|
|
118
|
+
</Box>
|
|
119
|
+
<Box sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}>
|
|
120
|
+
{!disableColumnActions && !isParentHeader && (
|
|
121
|
+
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
122
|
+
)}
|
|
123
|
+
{enableColumnResizing && !isParentHeader && (
|
|
124
|
+
<Divider
|
|
125
|
+
flexItem
|
|
126
|
+
orientation="vertical"
|
|
127
|
+
onDoubleClick={() => tableInstance.resetResizing()}
|
|
128
|
+
{...column.getResizerProps()}
|
|
129
|
+
sx={{
|
|
130
|
+
borderRightWidth: '2px',
|
|
131
|
+
borderRadius: '2px',
|
|
132
|
+
maxHeight: '2rem',
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
135
136
|
</Box>
|
|
136
|
-
{!disableFilters && column.canFilter && (
|
|
137
|
-
<Collapse in={tableInstance.state.showFilters}>
|
|
138
|
-
<MRT_FilterTextField column={column} />
|
|
139
|
-
</Collapse>
|
|
140
|
-
)}
|
|
141
137
|
</Box>
|
|
138
|
+
{!disableFilters && column.canFilter && (
|
|
139
|
+
<Collapse in={tableInstance.state.showFilters}>
|
|
140
|
+
<MRT_FilterTextField column={column} />
|
|
141
|
+
</Collapse>
|
|
142
|
+
)}
|
|
142
143
|
</TableCell>
|
|
143
144
|
);
|
|
144
145
|
};
|
package/src/index.tsx
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { ChangeEvent, FC, MouseEvent, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Chip,
|
|
4
|
+
IconButton,
|
|
5
|
+
InputAdornment,
|
|
6
|
+
TextField,
|
|
7
|
+
TextFieldProps,
|
|
8
|
+
Tooltip,
|
|
9
|
+
} from '@mui/material';
|
|
3
10
|
import { useAsyncDebounce } from 'react-table';
|
|
4
11
|
import { useMRT } from '../useMRT';
|
|
5
12
|
import { MRT_HeaderGroup } from '..';
|
|
13
|
+
import { MRT_FilterMenu } from '../menus/MRT_FilterMenu';
|
|
6
14
|
|
|
7
15
|
interface Props {
|
|
8
16
|
column: MRT_HeaderGroup;
|
|
@@ -11,79 +19,136 @@ interface Props {
|
|
|
11
19
|
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
12
20
|
const {
|
|
13
21
|
icons: { FilterListIcon, CloseIcon },
|
|
22
|
+
idPrefix,
|
|
14
23
|
localization,
|
|
24
|
+
muiTableHeadCellFilterTextFieldProps,
|
|
25
|
+
setCurrentFilterTypes,
|
|
26
|
+
tableInstance,
|
|
15
27
|
} = useMRT();
|
|
16
28
|
|
|
29
|
+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
30
|
+
|
|
31
|
+
const mTableHeadCellFilterTextFieldProps =
|
|
32
|
+
muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
33
|
+
? muiTableHeadCellFilterTextFieldProps(column)
|
|
34
|
+
: muiTableHeadCellFilterTextFieldProps;
|
|
35
|
+
|
|
36
|
+
const mcTableHeadCellFilterTextFieldProps =
|
|
37
|
+
column.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
38
|
+
? column.muiTableHeadCellFilterTextFieldProps(column)
|
|
39
|
+
: column.muiTableHeadCellFilterTextFieldProps;
|
|
40
|
+
|
|
41
|
+
const textFieldProps = {
|
|
42
|
+
...mTableHeadCellFilterTextFieldProps,
|
|
43
|
+
...mcTableHeadCellFilterTextFieldProps,
|
|
44
|
+
style: {
|
|
45
|
+
...mTableHeadCellFilterTextFieldProps?.style,
|
|
46
|
+
...mcTableHeadCellFilterTextFieldProps?.style,
|
|
47
|
+
},
|
|
48
|
+
} as TextFieldProps;
|
|
49
|
+
|
|
17
50
|
const [filterValue, setFilterValue] = useState('');
|
|
18
51
|
|
|
19
52
|
const handleChange = useAsyncDebounce((value) => {
|
|
20
53
|
column.setFilter(value ?? undefined);
|
|
21
54
|
}, 150);
|
|
22
55
|
|
|
56
|
+
const handleFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
57
|
+
setAnchorEl(event.currentTarget);
|
|
58
|
+
};
|
|
59
|
+
|
|
23
60
|
const handleClear = () => {
|
|
24
61
|
setFilterValue('');
|
|
25
62
|
column.setFilter(undefined);
|
|
26
63
|
};
|
|
27
64
|
|
|
65
|
+
const handleClearFilterChip = () => {
|
|
66
|
+
setFilterValue('');
|
|
67
|
+
column.setFilter(undefined);
|
|
68
|
+
setCurrentFilterTypes((prev) => ({ ...prev, [column.id]: 'fuzzy' }));
|
|
69
|
+
};
|
|
70
|
+
|
|
28
71
|
if (column.Filter) {
|
|
29
72
|
return <>{column.Filter?.({ column })}</>;
|
|
30
73
|
}
|
|
31
74
|
|
|
75
|
+
const filterType = tableInstance.state.currentFilterTypes[column.id];
|
|
76
|
+
const showFilterChip = ['empty', 'notEmpty'].includes(filterType);
|
|
77
|
+
const filterPlaceholder = localization.filterTextFieldPlaceholder?.replace(
|
|
78
|
+
'{column}',
|
|
79
|
+
String(column.Header),
|
|
80
|
+
);
|
|
81
|
+
|
|
32
82
|
return (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
startAdornment: (
|
|
55
|
-
<Tooltip
|
|
56
|
-
arrow
|
|
57
|
-
title={localization.filterTextFieldPlaceholder?.replace(
|
|
58
|
-
'{column}',
|
|
59
|
-
String(column.Header),
|
|
60
|
-
)}
|
|
61
|
-
>
|
|
83
|
+
<>
|
|
84
|
+
<TextField
|
|
85
|
+
fullWidth
|
|
86
|
+
id={`mrt-${idPrefix}-${column.id}-filter-text-field`}
|
|
87
|
+
inputProps={{
|
|
88
|
+
sx: {
|
|
89
|
+
textOverflow: 'ellipsis',
|
|
90
|
+
},
|
|
91
|
+
title: filterPlaceholder,
|
|
92
|
+
}}
|
|
93
|
+
margin="none"
|
|
94
|
+
placeholder={showFilterChip ? '' : filterPlaceholder}
|
|
95
|
+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
96
|
+
setFilterValue(e.target.value);
|
|
97
|
+
handleChange(e.target.value);
|
|
98
|
+
}}
|
|
99
|
+
onClick={(e) => e.stopPropagation()}
|
|
100
|
+
value={filterValue ?? ''}
|
|
101
|
+
variant="standard"
|
|
102
|
+
InputProps={{
|
|
103
|
+
startAdornment: (
|
|
62
104
|
<InputAdornment position="start">
|
|
63
|
-
<
|
|
64
|
-
</InputAdornment>
|
|
65
|
-
</Tooltip>
|
|
66
|
-
),
|
|
67
|
-
endAdornment: (
|
|
68
|
-
<InputAdornment position="end">
|
|
69
|
-
<Tooltip
|
|
70
|
-
arrow
|
|
71
|
-
title={localization.filterTextFieldClearButtonTitle ?? ''}
|
|
72
|
-
>
|
|
73
|
-
<span>
|
|
105
|
+
<Tooltip arrow title="Change Filter Mode">
|
|
74
106
|
<IconButton
|
|
75
|
-
|
|
76
|
-
disabled={filterValue?.length === 0}
|
|
77
|
-
onClick={handleClear}
|
|
107
|
+
onClick={handleFilterMenuOpen}
|
|
78
108
|
size="small"
|
|
109
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
79
110
|
>
|
|
80
|
-
<
|
|
111
|
+
<FilterListIcon />
|
|
81
112
|
</IconButton>
|
|
82
|
-
</
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
</Tooltip>
|
|
114
|
+
{showFilterChip && (
|
|
115
|
+
<Chip onDelete={handleClearFilterChip} label={filterType} />
|
|
116
|
+
)}
|
|
117
|
+
</InputAdornment>
|
|
118
|
+
),
|
|
119
|
+
endAdornment: !showFilterChip && (
|
|
120
|
+
<InputAdornment position="end">
|
|
121
|
+
<Tooltip
|
|
122
|
+
arrow
|
|
123
|
+
placement="right"
|
|
124
|
+
title={localization.filterTextFieldClearButtonTitle ?? ''}
|
|
125
|
+
>
|
|
126
|
+
<span>
|
|
127
|
+
<IconButton
|
|
128
|
+
aria-label={localization.filterTextFieldClearButtonTitle}
|
|
129
|
+
disabled={filterValue?.length === 0}
|
|
130
|
+
onClick={handleClear}
|
|
131
|
+
size="small"
|
|
132
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
133
|
+
>
|
|
134
|
+
<CloseIcon fontSize="small" />
|
|
135
|
+
</IconButton>
|
|
136
|
+
</span>
|
|
137
|
+
</Tooltip>
|
|
138
|
+
</InputAdornment>
|
|
139
|
+
),
|
|
140
|
+
}}
|
|
141
|
+
{...textFieldProps}
|
|
142
|
+
sx={{
|
|
143
|
+
minWidth: '6rem',
|
|
144
|
+
...textFieldProps?.sx,
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
<MRT_FilterMenu
|
|
148
|
+
anchorEl={anchorEl}
|
|
149
|
+
column={column}
|
|
150
|
+
setAnchorEl={setAnchorEl}
|
|
151
|
+
/>
|
|
152
|
+
</>
|
|
88
153
|
);
|
|
89
154
|
};
|
|
@@ -8,6 +8,7 @@ interface Props {}
|
|
|
8
8
|
export const MRT_SearchTextField: FC<Props> = () => {
|
|
9
9
|
const {
|
|
10
10
|
icons: { SearchIcon, CloseIcon },
|
|
11
|
+
idPrefix,
|
|
11
12
|
localization,
|
|
12
13
|
muiSearchTextFieldProps,
|
|
13
14
|
onGlobalFilterChange,
|
|
@@ -32,7 +33,7 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
32
33
|
return (
|
|
33
34
|
<Collapse in={tableInstance.state.showSearch} orientation="horizontal">
|
|
34
35
|
<TextField
|
|
35
|
-
id=
|
|
36
|
+
id={`mrt-${idPrefix}-search-text-field`}
|
|
36
37
|
placeholder={localization.searchTextFieldPlaceholder}
|
|
37
38
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
38
39
|
setSearchValue(event.target.value);
|
|
@@ -10,12 +10,8 @@ interface Props {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
onRowSelectChange,
|
|
16
|
-
onSelectAllChange,
|
|
17
|
-
tableInstance,
|
|
18
|
-
} = useMRT();
|
|
13
|
+
const { localization, onRowSelectChange, onSelectAllChange, tableInstance } =
|
|
14
|
+
useMRT();
|
|
19
15
|
|
|
20
16
|
const onSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
21
17
|
if (selectAll) {
|
|
@@ -32,7 +28,9 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
|
32
28
|
: row?.getToggleRowSelectedProps();
|
|
33
29
|
|
|
34
30
|
return (
|
|
35
|
-
<TableCell
|
|
31
|
+
<TableCell
|
|
32
|
+
sx={commonTableBodyButtonCellStyles(tableInstance.state.densePadding)}
|
|
33
|
+
>
|
|
36
34
|
<Tooltip
|
|
37
35
|
arrow
|
|
38
36
|
enterDelay={1000}
|