material-react-table 0.5.3 → 0.5.6
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 -1
- package/dist/filtersFNs.d.ts +67 -0
- package/dist/icons.d.ts +3 -0
- package/dist/localization.d.ts +14 -1
- package/dist/material-react-table.cjs.development.js +447 -81
- 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 +448 -82
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_FilterTypeMenu.d.ts +10 -0
- package/dist/useMRT.d.ts +13 -9
- package/package.json +9 -5
- package/src/MaterialReactTable.tsx +23 -1
- package/src/body/MRT_TableBodyCell.tsx +12 -3
- package/src/buttons/MRT_EditActionButtons.tsx +3 -1
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +7 -3
- 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/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +91 -44
- package/src/{icons.tsx → icons.ts} +9 -0
- package/src/index.tsx +0 -2
- package/src/inputs/MRT_FilterTextField.tsx +121 -52
- package/src/inputs/MRT_SearchTextField.tsx +2 -1
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -7
- package/src/localization.ts +30 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +103 -39
- package/src/menus/MRT_FilterTypeMenu.tsx +109 -0
- package/src/menus/MRT_RowActionMenu.tsx +10 -3
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
- package/src/table/MRT_TableContainer.tsx +7 -1
- package/src/useMRT.tsx +67 -13
|
@@ -19,6 +19,7 @@ export const MRT_TableContainer: FC<Props> = () => {
|
|
|
19
19
|
hideToolbarTop,
|
|
20
20
|
isFetching,
|
|
21
21
|
isLoading,
|
|
22
|
+
muiLinearProgressProps,
|
|
22
23
|
muiTableContainerProps,
|
|
23
24
|
tableInstance,
|
|
24
25
|
} = useMRT();
|
|
@@ -47,6 +48,11 @@ export const MRT_TableContainer: FC<Props> = () => {
|
|
|
47
48
|
? muiTableContainerProps(tableInstance)
|
|
48
49
|
: muiTableContainerProps;
|
|
49
50
|
|
|
51
|
+
const linearProgressProps =
|
|
52
|
+
muiLinearProgressProps instanceof Function
|
|
53
|
+
? muiLinearProgressProps(tableInstance)
|
|
54
|
+
: muiLinearProgressProps;
|
|
55
|
+
|
|
50
56
|
return (
|
|
51
57
|
<TableContainer
|
|
52
58
|
component={Paper}
|
|
@@ -67,7 +73,7 @@ export const MRT_TableContainer: FC<Props> = () => {
|
|
|
67
73
|
>
|
|
68
74
|
{!hideToolbarTop && <MRT_ToolbarTop />}
|
|
69
75
|
<Collapse in={isFetching || isLoading} unmountOnExit>
|
|
70
|
-
<LinearProgress />
|
|
76
|
+
<LinearProgress {...linearProgressProps} />
|
|
71
77
|
</Collapse>
|
|
72
78
|
<Box
|
|
73
79
|
sx={{
|
package/src/useMRT.tsx
CHANGED
|
@@ -5,6 +5,8 @@ import React, {
|
|
|
5
5
|
useContext,
|
|
6
6
|
useMemo,
|
|
7
7
|
useState,
|
|
8
|
+
Dispatch,
|
|
9
|
+
SetStateAction,
|
|
8
10
|
} from 'react';
|
|
9
11
|
import {
|
|
10
12
|
PluginHook,
|
|
@@ -19,7 +21,8 @@ import {
|
|
|
19
21
|
useSortBy,
|
|
20
22
|
useTable,
|
|
21
23
|
} from 'react-table';
|
|
22
|
-
import { MRT_Row, MRT_TableInstance } from '.';
|
|
24
|
+
import { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
|
|
25
|
+
import { defaultFilterFNs } from './filtersFNs';
|
|
23
26
|
import { MRT_Icons } from './icons';
|
|
24
27
|
import { MRT_Localization } from './localization';
|
|
25
28
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
@@ -28,19 +31,25 @@ export type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
|
28
31
|
anyRowsCanExpand: boolean;
|
|
29
32
|
anyRowsExpanded: boolean;
|
|
30
33
|
icons: MRT_Icons;
|
|
34
|
+
idPrefix: string;
|
|
31
35
|
localization: MRT_Localization;
|
|
32
|
-
setCurrentEditingRow:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
|
|
37
|
+
setCurrentFilterTypes: Dispatch<
|
|
38
|
+
SetStateAction<{
|
|
39
|
+
[key: string]: MRT_FilterType;
|
|
40
|
+
}>
|
|
41
|
+
>;
|
|
42
|
+
setDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
43
|
+
setFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
44
|
+
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
45
|
+
setShowSearch: Dispatch<SetStateAction<boolean>>;
|
|
37
46
|
tableInstance: MRT_TableInstance<D>;
|
|
38
47
|
};
|
|
39
48
|
|
|
40
|
-
const MaterialReactTableContext = (<D extends {}>() =>
|
|
49
|
+
const MaterialReactTableContext = (<D extends {} = {}>() =>
|
|
41
50
|
createContext<UseMRT<D>>({} as UseMRT<D>) as Context<UseMRT<D>>)();
|
|
42
51
|
|
|
43
|
-
export const MaterialReactTableProvider = <D extends {}>(
|
|
52
|
+
export const MaterialReactTableProvider = <D extends {} = {}>(
|
|
44
53
|
props: PropsWithChildren<MaterialReactTableProps<D>>,
|
|
45
54
|
) => {
|
|
46
55
|
const hooks: PluginHook<D>[] = [
|
|
@@ -56,7 +65,7 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
56
65
|
if (props.enableColumnResizing)
|
|
57
66
|
hooks.unshift(useResizeColumns, useFlexLayout);
|
|
58
67
|
|
|
59
|
-
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
|
|
68
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row<D> | null>(
|
|
60
69
|
null,
|
|
61
70
|
);
|
|
62
71
|
const [densePadding, setDensePadding] = useState(
|
|
@@ -72,14 +81,50 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
72
81
|
props.initialState?.showSearch ?? false,
|
|
73
82
|
);
|
|
74
83
|
|
|
75
|
-
const
|
|
84
|
+
const filterTypes = useMemo<Partial<{ [key in MRT_FilterType]: any }>>(
|
|
85
|
+
() => ({
|
|
86
|
+
...defaultFilterFNs,
|
|
87
|
+
...props.filterTypes,
|
|
88
|
+
}),
|
|
89
|
+
[props.filterTypes],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const [currentFilterTypes, setCurrentFilterTypes] = useState<{
|
|
93
|
+
[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
|
+
);
|
|
105
|
+
|
|
106
|
+
const columns = useMemo(
|
|
107
|
+
() =>
|
|
108
|
+
props.columns.map((column) => {
|
|
109
|
+
column.filter =
|
|
110
|
+
filterTypes[currentFilterTypes[column.accessor as string]];
|
|
111
|
+
return column;
|
|
112
|
+
}),
|
|
113
|
+
[props.columns, filterTypes, currentFilterTypes],
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const tableInstance = useTable(
|
|
76
117
|
{
|
|
77
118
|
...props,
|
|
119
|
+
columns,
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
filterTypes,
|
|
78
122
|
useControlledState: (state) =>
|
|
79
123
|
useMemo(
|
|
80
124
|
() => ({
|
|
81
125
|
...state,
|
|
82
126
|
currentEditingRow,
|
|
127
|
+
currentFilterTypes,
|
|
83
128
|
densePadding,
|
|
84
129
|
fullScreen,
|
|
85
130
|
showFilters,
|
|
@@ -89,6 +134,7 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
89
134
|
}),
|
|
90
135
|
[
|
|
91
136
|
currentEditingRow,
|
|
137
|
+
currentFilterTypes,
|
|
92
138
|
densePadding,
|
|
93
139
|
fullScreen,
|
|
94
140
|
showFilters,
|
|
@@ -100,6 +146,10 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
100
146
|
...hooks,
|
|
101
147
|
) as MRT_TableInstance<D>;
|
|
102
148
|
|
|
149
|
+
const idPrefix = useMemo(
|
|
150
|
+
() => props.idPrefix ?? Math.random().toString(36).substring(2, 9),
|
|
151
|
+
[props.idPrefix],
|
|
152
|
+
);
|
|
103
153
|
const anyRowsCanExpand = useMemo(
|
|
104
154
|
() => tableInstance.rows.some((row) => row.canExpand),
|
|
105
155
|
[tableInstance.rows],
|
|
@@ -115,7 +165,10 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
115
165
|
...props,
|
|
116
166
|
anyRowsCanExpand,
|
|
117
167
|
anyRowsExpanded,
|
|
168
|
+
idPrefix,
|
|
169
|
+
//@ts-ignore
|
|
118
170
|
setCurrentEditingRow,
|
|
171
|
+
setCurrentFilterTypes,
|
|
119
172
|
setDensePadding,
|
|
120
173
|
setFullScreen,
|
|
121
174
|
setShowFilters,
|
|
@@ -129,6 +182,7 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
129
182
|
);
|
|
130
183
|
};
|
|
131
184
|
|
|
132
|
-
export const useMRT = <D extends {}>(): UseMRT<D> =>
|
|
133
|
-
|
|
134
|
-
|
|
185
|
+
export const useMRT = <D extends {} = {}>(): UseMRT<D> =>
|
|
186
|
+
useContext<UseMRT<D>>(
|
|
187
|
+
MaterialReactTableContext as unknown as Context<UseMRT<D>>,
|
|
188
|
+
);
|