material-react-table 0.3.0 → 0.3.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/README.md +32 -162
- package/dist/MaterialReactTable.d.ts +52 -45
- package/dist/body/MRT_TableBodyRow.d.ts +16 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +7 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
- package/dist/inputs/MRT_EditCellTextField.d.ts +7 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +1732 -466
- 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 +1743 -477
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
- package/dist/menus/MRT_RowActionMenu.d.ts +10 -0
- package/dist/table/MRT_TableButtonCell.d.ts +3 -0
- package/dist/{footer → toolbar}/MRT_TablePagination.d.ts +0 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
- package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
- package/dist/toolbar/{MRT_Toolbar.d.ts → MRT_ToolbarTop.d.ts} +1 -1
- package/dist/useMaterialReactTable.d.ts +10 -2
- package/dist/utils/localization.d.ts +25 -14
- package/dist/utils/useMRTCalcs.d.ts +1 -1
- package/package.json +26 -21
- package/src/@types/faker.d.ts +4 -0
- package/src/@types/react-table-config.d.ts +131 -0
- package/src/MaterialReactTable.tsx +92 -101
- package/src/body/MRT_TableBody.tsx +17 -40
- package/src/body/MRT_TableBodyCell.tsx +36 -11
- package/src/body/MRT_TableBodyRow.tsx +35 -26
- package/src/body/MRT_TableDetailPanel.tsx +41 -15
- package/src/buttons/MRT_EditActionButtons.tsx +49 -0
- package/src/buttons/MRT_ExpandAllButton.tsx +15 -19
- package/src/buttons/MRT_ExpandButton.tsx +23 -21
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +14 -21
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -9
- package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +83 -0
- package/src/buttons/MRT_ToggleSearchButton.tsx +29 -0
- package/src/footer/MRT_TableFooter.tsx +4 -22
- package/src/footer/MRT_TableFooterCell.tsx +35 -10
- package/src/footer/MRT_TableFooterRow.tsx +24 -16
- package/src/head/MRT_TableHead.tsx +6 -23
- package/src/head/MRT_TableHeadCell.tsx +65 -28
- package/src/head/MRT_TableHeadRow.tsx +44 -17
- package/src/index.tsx +2 -5
- package/src/inputs/MRT_DensePaddingSwitch.tsx +23 -0
- package/src/inputs/MRT_EditCellTextField.tsx +64 -0
- package/src/inputs/MRT_FilterTextField.tsx +42 -15
- package/src/inputs/MRT_SearchTextField.tsx +40 -43
- package/src/inputs/MRT_SelectAllCheckbox.tsx +9 -6
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +69 -48
- package/src/menus/MRT_RowActionMenu.tsx +33 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +2 -2
- package/src/table/MRT_Table.tsx +13 -5
- package/src/table/MRT_TableButtonCell.tsx +9 -0
- package/src/table/MRT_TableContainer.tsx +32 -5
- package/src/table/MRT_TableSpacerCell.tsx +15 -1
- package/src/toolbar/MRT_TablePagination.tsx +34 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +41 -0
- package/src/toolbar/MRT_ToolbarButtons.tsx +29 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +59 -0
- package/src/useMaterialReactTable.tsx +40 -44
- package/src/utils/localization.ts +42 -20
- package/src/utils/useMRTCalcs.tsx +1 -3
- package/dist/utils/overrideWarnings.d.ts +0 -1
- package/src/footer/MRT_TablePagination.tsx +0 -42
- package/src/toolbar/MRT_Toolbar.tsx +0 -39
- package/src/utils/overrideWarnings.ts +0 -41
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
Context,
|
|
3
|
-
createContext,
|
|
4
|
-
PropsWithChildren,
|
|
5
|
-
useContext,
|
|
6
|
-
} from 'react';
|
|
1
|
+
import React, { Context, createContext, PropsWithChildren, useContext, useState } from 'react';
|
|
7
2
|
import {
|
|
3
|
+
PluginHook,
|
|
4
|
+
Row,
|
|
8
5
|
TableInstance,
|
|
9
6
|
useExpanded,
|
|
10
7
|
useFilters,
|
|
@@ -19,42 +16,30 @@ import {
|
|
|
19
16
|
} from 'react-table';
|
|
20
17
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
21
18
|
import { UseMRTCalcs, useMRTCalcs } from './utils/useMRTCalcs';
|
|
22
|
-
import { showoverrideWarnings } from './utils/overrideWarnings';
|
|
23
19
|
|
|
24
20
|
export interface UseMaterialReactTable<D extends {}>
|
|
25
21
|
extends MaterialReactTableProps<D>,
|
|
26
22
|
UseMRTCalcs {
|
|
23
|
+
currentEditingRow: Row<D> | null;
|
|
24
|
+
densePadding: boolean;
|
|
25
|
+
setCurrentEditingRow: (currentRowEditingId: Row<D> | null) => void;
|
|
26
|
+
setDensePadding: (densePadding: boolean) => void;
|
|
27
|
+
setShowFilters: (showFilters: boolean) => void;
|
|
28
|
+
setShowSearch: (showSearch: boolean) => void;
|
|
29
|
+
showFilters: boolean;
|
|
30
|
+
showSearch: boolean;
|
|
27
31
|
tableInstance: TableInstance<D>;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
const MaterialReactTableContext = (<D extends {}>() =>
|
|
31
|
-
createContext<UseMaterialReactTable<D>>(
|
|
32
|
-
|
|
33
|
-
)
|
|
35
|
+
createContext<UseMaterialReactTable<D>>({} as UseMaterialReactTable<D>) as Context<
|
|
36
|
+
UseMaterialReactTable<D>
|
|
37
|
+
>)();
|
|
34
38
|
|
|
35
|
-
export const MaterialReactTableProvider = <D extends {}>(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
defaultColumn,
|
|
40
|
-
getRowId,
|
|
41
|
-
getSubRows,
|
|
42
|
-
initialState,
|
|
43
|
-
stateReducer,
|
|
44
|
-
surpressoverrideWarnings,
|
|
45
|
-
...rest
|
|
46
|
-
}: PropsWithChildren<MaterialReactTableProps<D>>) => {
|
|
47
|
-
const tableInstance = useTable<D>(
|
|
48
|
-
{
|
|
49
|
-
columns,
|
|
50
|
-
data,
|
|
51
|
-
defaultColumn,
|
|
52
|
-
getRowId,
|
|
53
|
-
getSubRows,
|
|
54
|
-
initialState,
|
|
55
|
-
stateReducer,
|
|
56
|
-
},
|
|
57
|
-
useFlexLayout,
|
|
39
|
+
export const MaterialReactTableProvider = <D extends {}>(
|
|
40
|
+
props: PropsWithChildren<MaterialReactTableProps<D>>,
|
|
41
|
+
) => {
|
|
42
|
+
const hooks: PluginHook<D>[] = [
|
|
58
43
|
useResizeColumns,
|
|
59
44
|
useFilters,
|
|
60
45
|
useGlobalFilter,
|
|
@@ -63,30 +48,41 @@ export const MaterialReactTableProvider = <D extends {}>({
|
|
|
63
48
|
useExpanded,
|
|
64
49
|
usePagination,
|
|
65
50
|
useRowSelect,
|
|
66
|
-
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
if (props.enableColumnResizing) hooks.unshift(useFlexLayout);
|
|
54
|
+
|
|
55
|
+
const tableInstance = useTable<D>(props, ...hooks);
|
|
67
56
|
|
|
68
57
|
const mrtCalcs = useMRTCalcs({ tableInstance });
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
const [showSearch, setShowSearch] = useState(props.defaultShowSearchTextField ?? false);
|
|
60
|
+
const [showFilters, setShowFilters] = useState<boolean>(props.defaultShowFilters ?? false);
|
|
61
|
+
const [densePadding, setDensePadding] = useState<boolean>(props.defaultDensePadding ?? false);
|
|
62
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<Row | null>(null);
|
|
73
63
|
|
|
74
64
|
return (
|
|
75
65
|
<MaterialReactTableContext.Provider
|
|
76
66
|
value={{
|
|
77
|
-
//@ts-ignore
|
|
78
|
-
tableInstance,
|
|
79
67
|
...mrtCalcs,
|
|
80
|
-
...
|
|
68
|
+
...props,
|
|
69
|
+
currentEditingRow,
|
|
70
|
+
densePadding,
|
|
71
|
+
setCurrentEditingRow,
|
|
72
|
+
setDensePadding,
|
|
73
|
+
setShowFilters,
|
|
74
|
+
setShowSearch,
|
|
75
|
+
showFilters,
|
|
76
|
+
showSearch,
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
tableInstance,
|
|
81
79
|
}}
|
|
82
80
|
>
|
|
83
|
-
{children}
|
|
81
|
+
{props.children}
|
|
84
82
|
</MaterialReactTableContext.Provider>
|
|
85
83
|
);
|
|
86
84
|
};
|
|
87
85
|
|
|
88
|
-
export const useMaterialReactTable = <
|
|
89
|
-
D extends {},
|
|
90
|
-
>(): UseMaterialReactTable<D> =>
|
|
86
|
+
export const useMaterialReactTable = <D extends {}>(): UseMaterialReactTable<D> =>
|
|
91
87
|
//@ts-ignore
|
|
92
88
|
useContext<UseMaterialReactTable<D>>(MaterialReactTableContext);
|
|
@@ -1,33 +1,55 @@
|
|
|
1
1
|
export interface MRT_Localization {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
actionsHeadColumnTitle: string;
|
|
3
|
+
columnActionMenuButtonTitle: string;
|
|
4
|
+
columnActionMenuItemClearSort: string;
|
|
5
|
+
columnActionMenuItemGroupBy: string;
|
|
6
|
+
columnActionMenuItemHideColumn: string;
|
|
7
|
+
columnActionMenuItemSortAsc: string;
|
|
8
|
+
columnActionMenuItemSortDesc: string;
|
|
9
|
+
columnActionMenuItemUnGroupBy: string;
|
|
10
|
+
expandAllButtonTitle: string;
|
|
11
|
+
expandButtonTitle: string;
|
|
12
|
+
filterTextFieldClearButtonTitle: string;
|
|
13
|
+
filterTextFieldPlaceholder: string;
|
|
14
|
+
rowActionButtonCancel: string;
|
|
15
|
+
rowActionButtonSave: string;
|
|
16
|
+
rowActionMenuButtonTitle: string;
|
|
17
|
+
rowActionMenuItemEdit: string;
|
|
18
|
+
rowActionsColumnTitle: string;
|
|
19
|
+
searchTextFieldClearButtonTitle: string;
|
|
20
|
+
searchTextFieldPlaceholder: string;
|
|
21
|
+
selectAllCheckboxTitle: string;
|
|
22
|
+
selectCheckboxTitle: string;
|
|
23
|
+
showHideColumnsButtonTitle: string;
|
|
24
|
+
toggleDensePaddingSwitchTitle: string;
|
|
25
|
+
toggleFilterButtonTitle: string;
|
|
26
|
+
toggleSearchButtonTitle: string;
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
export const defaultLocalization: MRT_Localization = {
|
|
30
|
+
actionsHeadColumnTitle: 'Actions',
|
|
19
31
|
columnActionMenuButtonTitle: 'Column Actions',
|
|
20
|
-
columnActionMenuItemHideColumn: 'Hide column',
|
|
21
|
-
columnActionMenuItemSortAsc: 'Sort ascending',
|
|
22
32
|
columnActionMenuItemClearSort: 'Clear sorting',
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
columnActionMenuItemGroupBy: 'Group by {column}',
|
|
34
|
+
columnActionMenuItemHideColumn: 'Hide {column} column',
|
|
35
|
+
columnActionMenuItemSortAsc: 'Sort by {column} ascending',
|
|
36
|
+
columnActionMenuItemSortDesc: 'Sort by {column} descending',
|
|
37
|
+
columnActionMenuItemUnGroupBy: 'Ungroup by {column}',
|
|
26
38
|
expandAllButtonTitle: 'Expand all',
|
|
27
39
|
expandButtonTitle: 'Expand',
|
|
28
40
|
filterTextFieldClearButtonTitle: 'Clear filter',
|
|
29
|
-
filterTextFieldPlaceholder: 'Filter',
|
|
41
|
+
filterTextFieldPlaceholder: 'Filter by {column}',
|
|
42
|
+
rowActionButtonCancel: 'Cancel',
|
|
43
|
+
rowActionButtonSave: 'Save',
|
|
44
|
+
rowActionMenuButtonTitle: 'Row Actions',
|
|
45
|
+
rowActionMenuItemEdit: 'Edit',
|
|
46
|
+
selectCheckboxTitle: 'Select row',
|
|
47
|
+
rowActionsColumnTitle: 'Actions',
|
|
30
48
|
searchTextFieldClearButtonTitle: 'Clear search',
|
|
31
49
|
searchTextFieldPlaceholder: 'Search',
|
|
50
|
+
selectAllCheckboxTitle: 'Select all',
|
|
32
51
|
showHideColumnsButtonTitle: 'Show/Hide columns',
|
|
52
|
+
toggleDensePaddingSwitchTitle: 'Toggle dense padding',
|
|
53
|
+
toggleFilterButtonTitle: 'Toggle filters',
|
|
54
|
+
toggleSearchButtonTitle: 'Toggle search'
|
|
33
55
|
};
|
|
@@ -11,9 +11,7 @@ interface Props<D extends {}> {
|
|
|
11
11
|
tableInstance: TableInstance<D>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const useMRTCalcs = <D extends {}>({
|
|
15
|
-
tableInstance,
|
|
16
|
-
}: Props<D>): UseMRTCalcs => {
|
|
14
|
+
export const useMRTCalcs = <D extends {}>({ tableInstance }: Props<D>): UseMRTCalcs => {
|
|
17
15
|
const anyRowsCanExpand = useMemo(
|
|
18
16
|
() => tableInstance.rows.some((row) => row.canExpand),
|
|
19
17
|
[tableInstance.rows],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const showoverrideWarnings: (props: any) => void;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
-
import { TablePagination, TableRow } from '@mui/material';
|
|
3
|
-
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
-
|
|
5
|
-
interface Props {}
|
|
6
|
-
|
|
7
|
-
export const MRT_TablePagination: FC<Props> = () => {
|
|
8
|
-
const {
|
|
9
|
-
tableInstance,
|
|
10
|
-
tablePaginationProps,
|
|
11
|
-
overrideTablePaginationComponent,
|
|
12
|
-
} = useMaterialReactTable();
|
|
13
|
-
|
|
14
|
-
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
|
15
|
-
tableInstance.setPageSize(+event.target.value);
|
|
16
|
-
tableInstance.gotoPage(0);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
if (overrideTablePaginationComponent) {
|
|
20
|
-
return <>{overrideTablePaginationComponent(tableInstance)}</>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<TableRow>
|
|
25
|
-
<TablePagination
|
|
26
|
-
colSpan={tableInstance.visibleColumns.length + 10}
|
|
27
|
-
count={tableInstance.rows.length}
|
|
28
|
-
onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
|
|
29
|
-
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
30
|
-
page={tableInstance.state.pageIndex}
|
|
31
|
-
rowsPerPage={tableInstance.state.pageSize}
|
|
32
|
-
showFirstButton={
|
|
33
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
34
|
-
}
|
|
35
|
-
showLastButton={
|
|
36
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
37
|
-
}
|
|
38
|
-
{...tablePaginationProps}
|
|
39
|
-
/>
|
|
40
|
-
</TableRow>
|
|
41
|
-
);
|
|
42
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import { styled, Toolbar as MuiToolbar, Typography } from '@mui/material';
|
|
3
|
-
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
|
-
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
-
|
|
6
|
-
const Toolbar = styled(MuiToolbar)({
|
|
7
|
-
padding: '0.5rem',
|
|
8
|
-
display: 'flex',
|
|
9
|
-
justifyContent: 'space-between',
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
interface Props {}
|
|
13
|
-
|
|
14
|
-
export const MRT_Toolbar: FC<Props> = () => {
|
|
15
|
-
const {
|
|
16
|
-
overrideTableToolbarComponent,
|
|
17
|
-
enableSearch,
|
|
18
|
-
tableInstance,
|
|
19
|
-
tableTitleProps,
|
|
20
|
-
tableToolbarProps,
|
|
21
|
-
title,
|
|
22
|
-
} = useMaterialReactTable();
|
|
23
|
-
|
|
24
|
-
if (overrideTableToolbarComponent) {
|
|
25
|
-
return <>{overrideTableToolbarComponent(tableInstance)}</>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//if no features in the toolbar are enabled, don't render anything
|
|
29
|
-
if (!enableSearch && !title && !tableToolbarProps) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<Toolbar variant="dense" {...tableToolbarProps}>
|
|
35
|
-
{title ? <Typography {...tableTitleProps}>{title}</Typography> : <span />}
|
|
36
|
-
{enableSearch && <MRT_SearchTextField />}
|
|
37
|
-
</Toolbar>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export const showoverrideWarnings = (props: any) => {
|
|
2
|
-
if (props.overrideTableBodyCellComponent) {
|
|
3
|
-
showWarning('TableCell', 'props');
|
|
4
|
-
}
|
|
5
|
-
if (props.overrideTableBodyComponent) {
|
|
6
|
-
showWarning('TableBody', 'tableBodyProps');
|
|
7
|
-
}
|
|
8
|
-
if (props.overrideTableBodyRowComponent) {
|
|
9
|
-
showWarning('TableRow', 'props');
|
|
10
|
-
}
|
|
11
|
-
if (props.overrideTableDetailPanelComponent) {
|
|
12
|
-
showWarning('Detail Panel', 'tableDetailPanelProps');
|
|
13
|
-
}
|
|
14
|
-
if (props.overrideTableFooterComponent) {
|
|
15
|
-
showWarning('TableFooter', 'tableFooterProps');
|
|
16
|
-
}
|
|
17
|
-
if (props.overrideTableFooterCellComponent) {
|
|
18
|
-
showWarning('TableCell', 'props');
|
|
19
|
-
}
|
|
20
|
-
if (props.overrideTableFooterRowComponent) {
|
|
21
|
-
showWarning('TableRow', 'props');
|
|
22
|
-
}
|
|
23
|
-
if (props.overrideTableHeadComponent) {
|
|
24
|
-
showWarning('TableHead', 'tableHeadProps');
|
|
25
|
-
}
|
|
26
|
-
if (props.overrideTableHeadRowComponent) {
|
|
27
|
-
showWarning('TableRow', 'props');
|
|
28
|
-
}
|
|
29
|
-
if (props.overrideTablePaginationComponent) {
|
|
30
|
-
showWarning('', 'props');
|
|
31
|
-
}
|
|
32
|
-
if (props.overrideTableToolbarComponent) {
|
|
33
|
-
showWarning('TableBodyCell', 'props');
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const showWarning = (componentName: string, propsName: string) => {
|
|
38
|
-
console.warn(
|
|
39
|
-
`Caution.\nYou are overriding the built-in Mui ${componentName} Component in material-react-table.\n\nYou should only use this as a last resort!\n\nConsider customizing the Mui ${componentName} Component instead with ${propsName}.`,
|
|
40
|
-
);
|
|
41
|
-
};
|