material-react-table 0.3.0 → 0.3.1
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 +46 -44
- 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/head/MRT_TableHeadCell.d.ts +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
- package/dist/material-react-table.cjs.development.js +1459 -412
- 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 +1474 -427
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_RowActionMenu.d.ts +9 -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 +7 -1
- package/dist/utils/localization.d.ts +22 -14
- package/package.json +15 -13
- package/src/MaterialReactTable.tsx +117 -100
- package/src/body/MRT_TableBody.tsx +26 -27
- package/src/body/MRT_TableBodyCell.tsx +17 -6
- package/src/body/MRT_TableBodyRow.tsx +39 -23
- package/src/body/MRT_TableDetailPanel.tsx +38 -14
- package/src/buttons/MRT_EditActionButtons.tsx +51 -0
- package/src/buttons/MRT_ExpandAllButton.tsx +9 -4
- package/src/buttons/MRT_ExpandButton.tsx +12 -6
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +12 -12
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +1 -1
- package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
- package/src/footer/MRT_TableFooter.tsx +2 -17
- package/src/footer/MRT_TableFooterCell.tsx +18 -7
- package/src/footer/MRT_TableFooterRow.tsx +28 -14
- package/src/head/MRT_TableHead.tsx +6 -18
- package/src/head/MRT_TableHeadCell.tsx +37 -17
- package/src/head/MRT_TableHeadRow.tsx +42 -14
- package/src/index.tsx +2 -5
- package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
- package/src/inputs/MRT_FilterTextField.tsx +5 -0
- package/src/inputs/MRT_SearchTextField.tsx +4 -4
- package/src/inputs/MRT_SelectAllCheckbox.tsx +11 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +29 -24
- package/src/menus/MRT_RowActionMenu.tsx +52 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +2 -2
- package/src/table/MRT_Table.tsx +13 -4
- package/src/table/MRT_TableContainer.tsx +9 -5
- package/src/table/MRT_TableSpacerCell.tsx +17 -1
- package/src/toolbar/MRT_TablePagination.tsx +37 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +58 -0
- package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +81 -0
- package/src/useMaterialReactTable.tsx +36 -32
- package/src/utils/localization.ts +32 -16
- 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
|
@@ -3,8 +3,10 @@ import React, {
|
|
|
3
3
|
createContext,
|
|
4
4
|
PropsWithChildren,
|
|
5
5
|
useContext,
|
|
6
|
+
useState,
|
|
6
7
|
} from 'react';
|
|
7
8
|
import {
|
|
9
|
+
PluginHook,
|
|
8
10
|
TableInstance,
|
|
9
11
|
useExpanded,
|
|
10
12
|
useFilters,
|
|
@@ -19,11 +21,16 @@ import {
|
|
|
19
21
|
} from 'react-table';
|
|
20
22
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
21
23
|
import { UseMRTCalcs, useMRTCalcs } from './utils/useMRTCalcs';
|
|
22
|
-
import { showoverrideWarnings } from './utils/overrideWarnings';
|
|
23
24
|
|
|
24
25
|
export interface UseMaterialReactTable<D extends {}>
|
|
25
26
|
extends MaterialReactTableProps<D>,
|
|
26
27
|
UseMRTCalcs {
|
|
28
|
+
currentEditingRowId: string | null;
|
|
29
|
+
densePadding: boolean;
|
|
30
|
+
setCurrentEditingRowId: (currentRowEditingId: string | null) => void;
|
|
31
|
+
setDensePadding: (densePadding: boolean) => void;
|
|
32
|
+
setShowFilters: (showFilters: boolean) => void;
|
|
33
|
+
showFilters: boolean;
|
|
27
34
|
tableInstance: TableInstance<D>;
|
|
28
35
|
}
|
|
29
36
|
|
|
@@ -32,29 +39,10 @@ const MaterialReactTableContext = (<D extends {}>() =>
|
|
|
32
39
|
{} as UseMaterialReactTable<D>,
|
|
33
40
|
) as Context<UseMaterialReactTable<D>>)();
|
|
34
41
|
|
|
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,
|
|
42
|
+
export const MaterialReactTableProvider = <D extends {}>(
|
|
43
|
+
props: PropsWithChildren<MaterialReactTableProps<D>>,
|
|
44
|
+
) => {
|
|
45
|
+
const hooks: PluginHook<D>[] = [
|
|
58
46
|
useResizeColumns,
|
|
59
47
|
useFilters,
|
|
60
48
|
useGlobalFilter,
|
|
@@ -63,24 +51,40 @@ export const MaterialReactTableProvider = <D extends {}>({
|
|
|
63
51
|
useExpanded,
|
|
64
52
|
usePagination,
|
|
65
53
|
useRowSelect,
|
|
66
|
-
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
if (props.enableColumnResizing) hooks.unshift(useFlexLayout);
|
|
57
|
+
|
|
58
|
+
const tableInstance = useTable<D>(props, ...hooks);
|
|
67
59
|
|
|
68
60
|
const mrtCalcs = useMRTCalcs({ tableInstance });
|
|
69
61
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
const [showFilters, setShowFilters] = useState<boolean>(
|
|
63
|
+
props.defaultShowFilters ?? false,
|
|
64
|
+
);
|
|
65
|
+
const [densePadding, setDensePadding] = useState<boolean>(
|
|
66
|
+
props.defaultDensePadding ?? false,
|
|
67
|
+
);
|
|
68
|
+
const [currentEditingRowId, setCurrentEditingRowId] = useState<string | null>(
|
|
69
|
+
null,
|
|
70
|
+
);
|
|
73
71
|
|
|
74
72
|
return (
|
|
75
73
|
<MaterialReactTableContext.Provider
|
|
76
74
|
value={{
|
|
77
|
-
//@ts-ignore
|
|
78
|
-
tableInstance,
|
|
79
75
|
...mrtCalcs,
|
|
80
|
-
...
|
|
76
|
+
...props,
|
|
77
|
+
densePadding,
|
|
78
|
+
setDensePadding,
|
|
79
|
+
setShowFilters,
|
|
80
|
+
currentEditingRowId,
|
|
81
|
+
setCurrentEditingRowId,
|
|
82
|
+
showFilters,
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
tableInstance,
|
|
81
85
|
}}
|
|
82
86
|
>
|
|
83
|
-
{children}
|
|
87
|
+
{props.children}
|
|
84
88
|
</MaterialReactTableContext.Provider>
|
|
85
89
|
);
|
|
86
90
|
};
|
|
@@ -1,33 +1,49 @@
|
|
|
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
|
+
rowActionMenuButtonTitle: string;
|
|
15
|
+
rowActionsColumnTitle: string;
|
|
16
|
+
rowActionButtonSave: string;
|
|
17
|
+
rowActionButtonCancel: string;
|
|
18
|
+
rowActionMenuItemEdit: string;
|
|
19
|
+
searchTextFieldClearButtonTitle: string;
|
|
20
|
+
searchTextFieldPlaceholder: string;
|
|
21
|
+
showHideColumnsButtonTitle: string;
|
|
22
|
+
toggleDensePaddingSwitchTitle: string;
|
|
23
|
+
toggleFilterButtonTitle: string;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
export const defaultLocalization: MRT_Localization = {
|
|
27
|
+
actionsHeadColumnTitle: 'Actions',
|
|
19
28
|
columnActionMenuButtonTitle: 'Column Actions',
|
|
29
|
+
columnActionMenuItemClearSort: 'Clear sorting',
|
|
30
|
+
columnActionMenuItemGroupBy: 'Group by column',
|
|
20
31
|
columnActionMenuItemHideColumn: 'Hide column',
|
|
21
32
|
columnActionMenuItemSortAsc: 'Sort ascending',
|
|
22
|
-
columnActionMenuItemClearSort: 'Clear sorting',
|
|
23
33
|
columnActionMenuItemSortDesc: 'Sort descending',
|
|
24
|
-
columnActionMenuItemGroupBy: 'Group by column',
|
|
25
34
|
columnActionMenuItemUnGroupBy: 'Ungroup column',
|
|
26
35
|
expandAllButtonTitle: 'Expand all',
|
|
27
36
|
expandButtonTitle: 'Expand',
|
|
28
37
|
filterTextFieldClearButtonTitle: 'Clear filter',
|
|
29
38
|
filterTextFieldPlaceholder: 'Filter',
|
|
39
|
+
rowActionMenuButtonTitle: 'Row Actions',
|
|
40
|
+
rowActionsColumnTitle: 'Actions',
|
|
41
|
+
rowActionMenuItemEdit: 'Edit',
|
|
42
|
+
rowActionButtonSave: 'Save',
|
|
43
|
+
rowActionButtonCancel: 'Cancel',
|
|
30
44
|
searchTextFieldClearButtonTitle: 'Clear search',
|
|
31
45
|
searchTextFieldPlaceholder: 'Search',
|
|
32
46
|
showHideColumnsButtonTitle: 'Show/Hide columns',
|
|
47
|
+
toggleDensePaddingSwitchTitle: 'Toggle dense padding',
|
|
48
|
+
toggleFilterButtonTitle: 'Toggle filters',
|
|
33
49
|
};
|
|
@@ -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
|
-
};
|