material-react-table 0.3.4 → 0.3.5
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 -3
- package/dist/body/MRT_TableBodyCell.d.ts +3 -0
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +4 -0
- package/dist/head/MRT_TableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellActions.d.ts +5 -0
- package/dist/material-react-table.cjs.development.js +416 -277
- 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 +419 -280
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +5 -0
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +5 -0
- package/dist/{useMaterialReactTable.d.ts → useMRT.d.ts} +6 -3
- package/dist/utils/localization.d.ts +6 -0
- package/package.json +14 -14
- package/src/@types/react-table-config.d.ts +56 -31
- package/src/MaterialReactTable.tsx +64 -18
- package/src/body/MRT_TableBody.tsx +2 -2
- package/src/body/MRT_TableBodyCell.tsx +16 -9
- package/src/body/MRT_TableBodyRow.tsx +22 -7
- package/src/body/MRT_TableDetailPanel.tsx +14 -5
- package/src/buttons/MRT_EditActionButtons.tsx +11 -4
- package/src/buttons/MRT_ExpandAllButton.tsx +6 -3
- package/src/buttons/MRT_ExpandButton.tsx +9 -3
- package/src/buttons/MRT_FullScreenToggleButton.tsx +23 -0
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +43 -5
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +7 -3
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -3
- package/src/buttons/MRT_ToggleSearchButton.tsx +7 -3
- package/src/footer/MRT_TableFooter.tsx +6 -3
- package/src/footer/MRT_TableFooterCell.tsx +5 -3
- package/src/footer/MRT_TableFooterRow.tsx +17 -6
- package/src/head/MRT_TableHead.tsx +9 -4
- package/src/head/MRT_TableHeadCell.tsx +11 -7
- package/src/head/MRT_TableHeadCellActions.tsx +18 -0
- package/src/head/MRT_TableHeadRow.tsx +19 -12
- package/src/inputs/MRT_DensePaddingSwitch.tsx +2 -2
- package/src/inputs/MRT_EditCellTextField.tsx +2 -2
- package/src/inputs/MRT_FilterTextField.tsx +6 -3
- package/src/inputs/MRT_SearchTextField.tsx +15 -7
- package/src/inputs/MRT_SelectAllCheckbox.tsx +3 -2
- package/src/inputs/MRT_SelectCheckbox.tsx +3 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +40 -13
- package/src/menus/MRT_RowActionMenu.tsx +21 -6
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +24 -15
- package/src/table/MRT_Table.tsx +3 -2
- package/src/table/MRT_TableContainer.tsx +30 -6
- package/src/table/MRT_TableSpacerCell.tsx +5 -3
- package/src/toolbar/MRT_TablePagination.tsx +9 -5
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +102 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +14 -8
- package/src/toolbar/{MRT_ToolbarButtons.tsx → MRT_ToolbarInternalButtons.tsx} +11 -4
- package/src/toolbar/MRT_ToolbarTop.tsx +19 -11
- package/src/{useMaterialReactTable.tsx → useMRT.tsx} +43 -19
- package/src/utils/localization.ts +14 -2
- package/dist/toolbar/MRT_ToolbarButtons.d.ts +0 -5
- package/dist/utils/useMRTCalcs.d.ts +0 -11
- package/src/utils/useMRTCalcs.tsx +0 -40
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
Context,
|
|
3
|
+
createContext,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import {
|
|
3
10
|
PluginHook,
|
|
4
11
|
Row,
|
|
@@ -15,15 +22,16 @@ import {
|
|
|
15
22
|
useTable,
|
|
16
23
|
} from 'react-table';
|
|
17
24
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
18
|
-
import { UseMRTCalcs, useMRTCalcs } from './utils/useMRTCalcs';
|
|
19
25
|
|
|
20
|
-
export interface
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
export interface UseMRT<D extends {} = {}> extends MaterialReactTableProps<D> {
|
|
27
|
+
anyRowsCanExpand: boolean;
|
|
28
|
+
anyRowsExpanded: boolean;
|
|
23
29
|
currentEditingRow: Row<D> | null;
|
|
24
30
|
densePadding: boolean;
|
|
31
|
+
fullScreen: boolean;
|
|
25
32
|
setCurrentEditingRow: (currentRowEditingId: Row<D> | null) => void;
|
|
26
33
|
setDensePadding: (densePadding: boolean) => void;
|
|
34
|
+
setFullScreen: (fullScreen: boolean) => void;
|
|
27
35
|
setShowFilters: (showFilters: boolean) => void;
|
|
28
36
|
setShowSearch: (showSearch: boolean) => void;
|
|
29
37
|
showFilters: boolean;
|
|
@@ -32,15 +40,12 @@ export interface UseMaterialReactTable<D extends {}>
|
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
const MaterialReactTableContext = (<D extends {}>() =>
|
|
35
|
-
createContext<
|
|
36
|
-
UseMaterialReactTable<D>
|
|
37
|
-
>)();
|
|
43
|
+
createContext<UseMRT<D>>({} as UseMRT<D>) as Context<UseMRT<D>>)();
|
|
38
44
|
|
|
39
45
|
export const MaterialReactTableProvider = <D extends {}>(
|
|
40
46
|
props: PropsWithChildren<MaterialReactTableProps<D>>,
|
|
41
47
|
) => {
|
|
42
48
|
const hooks: PluginHook<D>[] = [
|
|
43
|
-
useResizeColumns,
|
|
44
49
|
useFilters,
|
|
45
50
|
useGlobalFilter,
|
|
46
51
|
useGroupBy,
|
|
@@ -50,31 +55,50 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
50
55
|
useRowSelect,
|
|
51
56
|
];
|
|
52
57
|
|
|
53
|
-
if (props.enableColumnResizing)
|
|
58
|
+
if (props.enableColumnResizing)
|
|
59
|
+
hooks.unshift(useResizeColumns, useFlexLayout);
|
|
54
60
|
|
|
55
61
|
const tableInstance = useTable<D>(props, ...hooks);
|
|
56
62
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
63
|
+
const anyRowsCanExpand = useMemo(
|
|
64
|
+
() => tableInstance.rows.some((row) => row.canExpand),
|
|
65
|
+
[tableInstance.rows],
|
|
66
|
+
);
|
|
67
|
+
const anyRowsExpanded = useMemo(
|
|
68
|
+
() => tableInstance.rows.some((row) => row.isExpanded),
|
|
69
|
+
[tableInstance.rows],
|
|
70
|
+
);
|
|
62
71
|
const [currentEditingRow, setCurrentEditingRow] = useState<Row | null>(null);
|
|
72
|
+
const [densePadding, setDensePadding] = useState(
|
|
73
|
+
props.defaultDensePadding ?? false,
|
|
74
|
+
);
|
|
75
|
+
const [fullScreen, setFullScreen] = useState(
|
|
76
|
+
props.defaultFullScreen ?? false,
|
|
77
|
+
);
|
|
78
|
+
const [showFilters, setShowFilters] = useState(
|
|
79
|
+
props.defaultShowFilters ?? false,
|
|
80
|
+
);
|
|
81
|
+
const [showSearch, setShowSearch] = useState(
|
|
82
|
+
props.defaultShowSearchTextField ?? false,
|
|
83
|
+
);
|
|
63
84
|
|
|
64
85
|
return (
|
|
65
86
|
<MaterialReactTableContext.Provider
|
|
66
87
|
value={{
|
|
67
|
-
...mrtCalcs,
|
|
68
88
|
...props,
|
|
89
|
+
anyRowsCanExpand,
|
|
90
|
+
anyRowsExpanded,
|
|
69
91
|
currentEditingRow,
|
|
70
92
|
densePadding,
|
|
71
93
|
setCurrentEditingRow,
|
|
72
94
|
setDensePadding,
|
|
95
|
+
fullScreen,
|
|
96
|
+
setFullScreen,
|
|
73
97
|
setShowFilters,
|
|
74
98
|
setShowSearch,
|
|
75
99
|
showFilters,
|
|
76
100
|
showSearch,
|
|
77
|
-
|
|
101
|
+
//@ts-ignore
|
|
78
102
|
tableInstance,
|
|
79
103
|
}}
|
|
80
104
|
>
|
|
@@ -83,6 +107,6 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
83
107
|
);
|
|
84
108
|
};
|
|
85
109
|
|
|
86
|
-
export const
|
|
110
|
+
export const useMRT = <D extends {}>(): UseMRT<D> =>
|
|
87
111
|
//@ts-ignore
|
|
88
|
-
useContext<
|
|
112
|
+
useContext<UseMRT<D>>(MaterialReactTableContext);
|
|
@@ -7,6 +7,8 @@ export interface MRT_Localization {
|
|
|
7
7
|
columnActionMenuItemSortAsc: string;
|
|
8
8
|
columnActionMenuItemSortDesc: string;
|
|
9
9
|
columnActionMenuItemUnGroupBy: string;
|
|
10
|
+
columnShowHideMenuHideAll: string;
|
|
11
|
+
columnShowHideMenuShowAll: string;
|
|
10
12
|
expandAllButtonTitle: string;
|
|
11
13
|
expandButtonTitle: string;
|
|
12
14
|
filterTextFieldClearButtonTitle: string;
|
|
@@ -23,7 +25,11 @@ export interface MRT_Localization {
|
|
|
23
25
|
showHideColumnsButtonTitle: string;
|
|
24
26
|
toggleDensePaddingSwitchTitle: string;
|
|
25
27
|
toggleFilterButtonTitle: string;
|
|
28
|
+
toggleFullScreenButtonTitle: string;
|
|
26
29
|
toggleSearchButtonTitle: string;
|
|
30
|
+
toolbarAlertSelectionMessage: string;
|
|
31
|
+
toolbarAlertGroupedByMessage: string;
|
|
32
|
+
toolbarAlertGroupedThenByMessage: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export const defaultLocalization: MRT_Localization = {
|
|
@@ -35,6 +41,8 @@ export const defaultLocalization: MRT_Localization = {
|
|
|
35
41
|
columnActionMenuItemSortAsc: 'Sort by {column} ascending',
|
|
36
42
|
columnActionMenuItemSortDesc: 'Sort by {column} descending',
|
|
37
43
|
columnActionMenuItemUnGroupBy: 'Ungroup by {column}',
|
|
44
|
+
columnShowHideMenuHideAll: 'Hide all',
|
|
45
|
+
columnShowHideMenuShowAll: 'Show all',
|
|
38
46
|
expandAllButtonTitle: 'Expand all',
|
|
39
47
|
expandButtonTitle: 'Expand',
|
|
40
48
|
filterTextFieldClearButtonTitle: 'Clear filter',
|
|
@@ -43,13 +51,17 @@ export const defaultLocalization: MRT_Localization = {
|
|
|
43
51
|
rowActionButtonSave: 'Save',
|
|
44
52
|
rowActionMenuButtonTitle: 'Row Actions',
|
|
45
53
|
rowActionMenuItemEdit: 'Edit',
|
|
46
|
-
selectCheckboxTitle: 'Select row',
|
|
47
54
|
rowActionsColumnTitle: 'Actions',
|
|
48
55
|
searchTextFieldClearButtonTitle: 'Clear search',
|
|
49
56
|
searchTextFieldPlaceholder: 'Search',
|
|
50
57
|
selectAllCheckboxTitle: 'Select all',
|
|
58
|
+
selectCheckboxTitle: 'Select row',
|
|
51
59
|
showHideColumnsButtonTitle: 'Show/Hide columns',
|
|
52
60
|
toggleDensePaddingSwitchTitle: 'Toggle dense padding',
|
|
53
61
|
toggleFilterButtonTitle: 'Toggle filters',
|
|
54
|
-
|
|
62
|
+
toggleFullScreenButtonTitle: 'Toggle full screen',
|
|
63
|
+
toggleSearchButtonTitle: 'Toggle search',
|
|
64
|
+
toolbarAlertSelectionMessage: '{selectedCount} of {rowCount} row(s) selected',
|
|
65
|
+
toolbarAlertGroupedByMessage: 'Grouped by ',
|
|
66
|
+
toolbarAlertGroupedThenByMessage: ', then by ',
|
|
55
67
|
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TableInstance } from 'react-table';
|
|
2
|
-
export interface UseMRTCalcs {
|
|
3
|
-
anyRowsCanExpand: boolean;
|
|
4
|
-
anyRowsExpanded: boolean;
|
|
5
|
-
maxColumnDepth: number;
|
|
6
|
-
}
|
|
7
|
-
interface Props<D extends {}> {
|
|
8
|
-
tableInstance: TableInstance<D>;
|
|
9
|
-
}
|
|
10
|
-
export declare const useMRTCalcs: <D extends {}>({ tableInstance }: Props<D>) => UseMRTCalcs;
|
|
11
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { TableInstance } from 'react-table';
|
|
3
|
-
|
|
4
|
-
export interface UseMRTCalcs {
|
|
5
|
-
anyRowsCanExpand: boolean;
|
|
6
|
-
anyRowsExpanded: boolean;
|
|
7
|
-
maxColumnDepth: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface Props<D extends {}> {
|
|
11
|
-
tableInstance: TableInstance<D>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const useMRTCalcs = <D extends {}>({ tableInstance }: Props<D>): UseMRTCalcs => {
|
|
15
|
-
const anyRowsCanExpand = useMemo(
|
|
16
|
-
() => tableInstance.rows.some((row) => row.canExpand),
|
|
17
|
-
[tableInstance.rows],
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const anyRowsExpanded = useMemo(
|
|
21
|
-
() => tableInstance.rows.some((row) => row.isExpanded),
|
|
22
|
-
[tableInstance.rows],
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const maxColumnDepth = useMemo(() => {
|
|
26
|
-
let maxDepth = 1;
|
|
27
|
-
tableInstance.columns.forEach((column) => {
|
|
28
|
-
if (column.columns?.length) {
|
|
29
|
-
maxDepth = Math.max(maxDepth, column.columns.length);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return maxDepth - 1;
|
|
33
|
-
}, [tableInstance.columns]);
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
anyRowsCanExpand,
|
|
37
|
-
anyRowsExpanded,
|
|
38
|
-
maxColumnDepth,
|
|
39
|
-
};
|
|
40
|
-
};
|