material-react-table 0.2.0 → 0.3.3
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 +55 -50
- 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/head/MRT_TableHeadCell.d.ts +4 -1
- package/dist/index.d.ts +2 -0
- package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
- package/dist/inputs/MRT_EditCellTextfield.d.ts +7 -0
- package/dist/material-react-table.cjs.development.js +1659 -440
- 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 +1669 -450
- 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 +10 -5
- package/dist/utils/localization.d.ts +23 -12
- package/package.json +20 -17
- package/src/@types/faker.d.ts +4 -0
- package/src/@types/react-table-config.d.ts +153 -0
- package/src/MaterialReactTable.tsx +125 -97
- package/src/body/MRT_TableBody.tsx +18 -40
- package/src/body/MRT_TableBodyCell.tsx +53 -9
- package/src/body/MRT_TableBodyRow.tsx +49 -21
- package/src/body/MRT_TableDetailPanel.tsx +50 -15
- package/src/buttons/MRT_EditActionButtons.tsx +55 -0
- package/src/buttons/MRT_ExpandAllButton.tsx +22 -15
- package/src/buttons/MRT_ExpandButton.tsx +30 -18
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +12 -12
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +3 -1
- package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
- package/src/footer/MRT_TableFooter.tsx +4 -19
- package/src/footer/MRT_TableFooterCell.tsx +36 -9
- package/src/footer/MRT_TableFooterRow.tsx +31 -13
- package/src/head/MRT_TableHead.tsx +8 -20
- package/src/head/MRT_TableHeadCell.tsx +73 -30
- package/src/head/MRT_TableHeadRow.tsx +46 -19
- package/src/index.tsx +2 -0
- package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
- package/src/inputs/MRT_EditCellTextfield.tsx +57 -0
- package/src/inputs/MRT_FilterTextField.tsx +4 -0
- package/src/inputs/MRT_SearchTextField.tsx +17 -8
- package/src/inputs/MRT_SelectAllCheckbox.tsx +16 -5
- package/src/inputs/MRT_SelectCheckbox.tsx +12 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +37 -12
- 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 +37 -5
- package/src/table/MRT_TableSpacerCell.tsx +17 -1
- package/src/toolbar/MRT_TablePagination.tsx +37 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +43 -0
- package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +68 -0
- package/src/useMaterialReactTable.tsx +39 -23
- package/src/utils/localization.ts +36 -14
- package/dist/utils/overrideWarnings.d.ts +0 -1
- package/src/footer/MRT_TablePagination.tsx +0 -39
- package/src/toolbar/MRT_Toolbar.tsx +0 -39
- package/src/utils/overrideWarnings.ts +0 -41
|
@@ -5,6 +5,7 @@ import { ColumnInstance } from 'react-table';
|
|
|
5
5
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
6
6
|
import SortIcon from '@mui/icons-material/Sort';
|
|
7
7
|
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
8
|
+
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
8
9
|
|
|
9
10
|
const MenuItem = styled(MuiMenuItem)({
|
|
10
11
|
display: 'flex',
|
|
@@ -22,8 +23,12 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
22
23
|
column,
|
|
23
24
|
setAnchorEl,
|
|
24
25
|
}) => {
|
|
25
|
-
const {
|
|
26
|
-
|
|
26
|
+
const {
|
|
27
|
+
disableColumnHiding,
|
|
28
|
+
enableColumnGrouping,
|
|
29
|
+
disableSortBy,
|
|
30
|
+
localization,
|
|
31
|
+
} = useMaterialReactTable();
|
|
27
32
|
|
|
28
33
|
const handleClearSort = () => {
|
|
29
34
|
column.clearSortBy();
|
|
@@ -45,38 +50,58 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
45
50
|
setAnchorEl(null);
|
|
46
51
|
};
|
|
47
52
|
|
|
53
|
+
const handleGroupByColumn = () => {
|
|
54
|
+
column.toggleGroupBy();
|
|
55
|
+
setAnchorEl(null);
|
|
56
|
+
};
|
|
57
|
+
|
|
48
58
|
return (
|
|
49
59
|
<Menu
|
|
50
60
|
anchorEl={anchorEl}
|
|
51
61
|
open={!!anchorEl}
|
|
52
62
|
onClose={() => setAnchorEl(null)}
|
|
53
63
|
>
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
<MenuItem
|
|
64
|
+
{!disableSortBy &&
|
|
65
|
+
column.canSort && [
|
|
66
|
+
<MenuItem
|
|
67
|
+
key={1}
|
|
68
|
+
disabled={!column.isSorted}
|
|
69
|
+
onClick={handleClearSort}
|
|
70
|
+
>
|
|
57
71
|
<ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
|
|
58
|
-
</MenuItem
|
|
72
|
+
</MenuItem>,
|
|
59
73
|
<MenuItem
|
|
74
|
+
key={2}
|
|
60
75
|
disabled={column.isSorted && !column.isSortedDesc}
|
|
61
76
|
onClick={handleSortAsc}
|
|
62
77
|
>
|
|
63
78
|
<SortIcon /> {localization?.columnActionMenuItemSortAsc}
|
|
64
|
-
</MenuItem
|
|
79
|
+
</MenuItem>,
|
|
65
80
|
<MenuItem
|
|
81
|
+
key={3}
|
|
66
82
|
disabled={column.isSorted && column.isSortedDesc}
|
|
67
83
|
onClick={handleSortDesc}
|
|
68
84
|
>
|
|
69
85
|
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
|
|
70
86
|
{localization?.columnActionMenuItemSortDesc}
|
|
71
|
-
</MenuItem
|
|
72
|
-
<Divider
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{enableColumnHiding && (
|
|
87
|
+
</MenuItem>,
|
|
88
|
+
<Divider key={4} />,
|
|
89
|
+
]}
|
|
90
|
+
{!disableColumnHiding && (
|
|
76
91
|
<MenuItem onClick={handleHideColumn}>
|
|
77
92
|
<VisibilityOffIcon /> {localization?.columnActionMenuItemHideColumn}
|
|
78
93
|
</MenuItem>
|
|
79
94
|
)}
|
|
95
|
+
{enableColumnGrouping && column.canGroupBy && (
|
|
96
|
+
<MenuItem disabled={column.isGrouped} onClick={handleGroupByColumn}>
|
|
97
|
+
<DynamicFeedIcon /> {localization?.columnActionMenuItemGroupBy}
|
|
98
|
+
</MenuItem>
|
|
99
|
+
)}
|
|
100
|
+
{enableColumnGrouping && column.canGroupBy && (
|
|
101
|
+
<MenuItem disabled={!column.isGrouped} onClick={handleGroupByColumn}>
|
|
102
|
+
<DynamicFeedIcon /> {localization?.columnActionMenuItemUnGroupBy}
|
|
103
|
+
</MenuItem>
|
|
104
|
+
)}
|
|
80
105
|
</Menu>
|
|
81
106
|
);
|
|
82
107
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import { Row } from 'react-table';
|
|
5
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
6
|
+
|
|
7
|
+
const MenuItem = styled(MuiMenuItem)({
|
|
8
|
+
display: 'flex',
|
|
9
|
+
gap: '0.75rem',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
anchorEl: HTMLElement | null;
|
|
14
|
+
row: Row;
|
|
15
|
+
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const MRT_RowActionMenu: FC<Props> = ({
|
|
19
|
+
anchorEl,
|
|
20
|
+
row,
|
|
21
|
+
setAnchorEl,
|
|
22
|
+
}) => {
|
|
23
|
+
const {
|
|
24
|
+
enableRowEditing,
|
|
25
|
+
localization,
|
|
26
|
+
renderRowActionMenuItems,
|
|
27
|
+
setCurrentEditingRow,
|
|
28
|
+
tableInstance,
|
|
29
|
+
} = useMaterialReactTable();
|
|
30
|
+
|
|
31
|
+
const handleEdit = () => {
|
|
32
|
+
setCurrentEditingRow({ ...row });
|
|
33
|
+
setAnchorEl(null);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Menu
|
|
38
|
+
anchorEl={anchorEl}
|
|
39
|
+
open={!!anchorEl}
|
|
40
|
+
onClose={() => setAnchorEl(null)}
|
|
41
|
+
>
|
|
42
|
+
{enableRowEditing && (
|
|
43
|
+
<MenuItem onClick={handleEdit}>
|
|
44
|
+
<EditIcon /> {localization?.rowActionMenuItemEdit}
|
|
45
|
+
</MenuItem>
|
|
46
|
+
)}
|
|
47
|
+
{renderRowActionMenuItems?.(row, tableInstance, () =>
|
|
48
|
+
setAnchorEl(null),
|
|
49
|
+
) ?? null}
|
|
50
|
+
</Menu>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -17,10 +17,10 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
|
|
|
17
17
|
<MenuItem style={{ paddingLeft: `${column.depth + 1}rem` }}>
|
|
18
18
|
{isMaxDepth ? (
|
|
19
19
|
<FormControlLabel
|
|
20
|
-
onChange={() => isMaxDepth && column.toggleHidden()}
|
|
21
|
-
label={column.Header as string}
|
|
22
20
|
checked={column.isVisible}
|
|
23
21
|
control={<Switch />}
|
|
22
|
+
label={column.Header as string}
|
|
23
|
+
onChange={() => isMaxDepth && column.toggleHidden()}
|
|
24
24
|
/>
|
|
25
25
|
) : (
|
|
26
26
|
<Typography>{column.Header}</Typography>
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -8,14 +8,23 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
|
8
8
|
interface Props {}
|
|
9
9
|
|
|
10
10
|
export const MRT_Table: FC<Props> = () => {
|
|
11
|
-
const { tableInstance,
|
|
11
|
+
const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } =
|
|
12
12
|
useMaterialReactTable();
|
|
13
13
|
|
|
14
|
+
const tableProps = {
|
|
15
|
+
...muiTableProps,
|
|
16
|
+
...tableInstance.getTableProps(),
|
|
17
|
+
style: {
|
|
18
|
+
...tableInstance.getTableProps().style,
|
|
19
|
+
...(muiTableProps?.style ?? {}),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
14
23
|
return (
|
|
15
|
-
<Table {...tableProps}
|
|
16
|
-
{
|
|
24
|
+
<Table {...tableProps}>
|
|
25
|
+
{!hideTableHead && <MRT_TableHead />}
|
|
17
26
|
<MRT_TableBody />
|
|
18
|
-
{
|
|
27
|
+
{!hideTableFooter && <MRT_TableFooter />}
|
|
19
28
|
</Table>
|
|
20
29
|
);
|
|
21
30
|
};
|
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
alpha,
|
|
4
|
+
CircularProgress,
|
|
5
|
+
LinearProgress,
|
|
6
|
+
Paper,
|
|
7
|
+
styled,
|
|
8
|
+
TableContainer,
|
|
9
|
+
} from '@mui/material';
|
|
3
10
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
11
|
import { MRT_Table } from './MRT_Table';
|
|
5
|
-
import {
|
|
12
|
+
import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
|
|
13
|
+
import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
|
|
14
|
+
|
|
15
|
+
const CircularProgressWrapper = styled('div')(({ theme }) => ({
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
backgroundColor: alpha(theme.palette.background.paper, 0.5),
|
|
18
|
+
display: 'grid',
|
|
19
|
+
height: '100%',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
margin: 'auto',
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
width: 'calc(100% - 2rem)',
|
|
24
|
+
}));
|
|
6
25
|
|
|
7
26
|
interface Props {}
|
|
8
27
|
|
|
9
28
|
export const MRT_TableContainer: FC<Props> = () => {
|
|
10
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
muiTableContainerProps,
|
|
31
|
+
hideToolbarTop,
|
|
32
|
+
hideToolbarBottom,
|
|
33
|
+
isLoading,
|
|
34
|
+
isFetching,
|
|
35
|
+
} = useMaterialReactTable();
|
|
11
36
|
|
|
12
37
|
return (
|
|
13
|
-
<TableContainer component={Paper} {...
|
|
14
|
-
{
|
|
38
|
+
<TableContainer component={Paper} {...muiTableContainerProps}>
|
|
39
|
+
{!hideToolbarTop && <MRT_ToolbarTop />}
|
|
40
|
+
{isFetching && <LinearProgress />}
|
|
41
|
+
{isLoading && (
|
|
42
|
+
<CircularProgressWrapper>
|
|
43
|
+
<CircularProgress aria-busy="true" aria-label="Loading data" />
|
|
44
|
+
</CircularProgressWrapper>
|
|
45
|
+
)}
|
|
15
46
|
<MRT_Table />
|
|
47
|
+
{!hideToolbarBottom && <MRT_ToolbarBottom />}
|
|
16
48
|
</TableContainer>
|
|
17
49
|
);
|
|
18
50
|
};
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import React, { CSSProperties, FC } from 'react';
|
|
2
2
|
import { TableCell } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
5
6
|
width?: CSSProperties['width'];
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
|
|
9
|
-
|
|
10
|
+
const { muiTableBodyCellProps } = useMaterialReactTable();
|
|
11
|
+
|
|
12
|
+
const mTableBodyCellrops =
|
|
13
|
+
muiTableBodyCellProps instanceof Function
|
|
14
|
+
? muiTableBodyCellProps()
|
|
15
|
+
: muiTableBodyCellProps;
|
|
16
|
+
|
|
17
|
+
const tableCellProps = {
|
|
18
|
+
...mTableBodyCellrops,
|
|
19
|
+
style: {
|
|
20
|
+
width,
|
|
21
|
+
...(mTableBodyCellrops?.style ?? {}),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return <TableCell {...tableCellProps} />;
|
|
10
26
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
+
import { TablePagination } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
|
|
5
|
+
interface Props {}
|
|
6
|
+
|
|
7
|
+
export const MRT_TablePagination: FC<Props> = () => {
|
|
8
|
+
const { tableInstance, muiTablePaginationProps } = useMaterialReactTable();
|
|
9
|
+
|
|
10
|
+
const tablePaginationProps =
|
|
11
|
+
muiTablePaginationProps instanceof Function
|
|
12
|
+
? muiTablePaginationProps(tableInstance)
|
|
13
|
+
: muiTablePaginationProps;
|
|
14
|
+
|
|
15
|
+
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
|
16
|
+
tableInstance.setPageSize(+event.target.value);
|
|
17
|
+
tableInstance.gotoPage(0);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<TablePagination
|
|
22
|
+
component={'div'}
|
|
23
|
+
count={tableInstance.rows.length}
|
|
24
|
+
onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
|
|
25
|
+
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
26
|
+
page={tableInstance.state.pageIndex}
|
|
27
|
+
rowsPerPage={tableInstance.state.pageSize}
|
|
28
|
+
showFirstButton={
|
|
29
|
+
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
30
|
+
}
|
|
31
|
+
showLastButton={
|
|
32
|
+
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
33
|
+
}
|
|
34
|
+
{...tablePaginationProps}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { styled, Toolbar as MuiToolbar } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
5
|
+
import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
|
|
6
|
+
|
|
7
|
+
const Toolbar = styled(MuiToolbar)({
|
|
8
|
+
padding: 0,
|
|
9
|
+
display: 'flex',
|
|
10
|
+
justifyContent: 'space-between',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
interface Props {}
|
|
14
|
+
|
|
15
|
+
export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
16
|
+
const {
|
|
17
|
+
hideToolbarActions,
|
|
18
|
+
manualPagination,
|
|
19
|
+
muiTableToolbarBottomProps,
|
|
20
|
+
positionPagination,
|
|
21
|
+
positionToolbarActions,
|
|
22
|
+
tableInstance,
|
|
23
|
+
} = useMaterialReactTable();
|
|
24
|
+
|
|
25
|
+
const toolbarProps =
|
|
26
|
+
muiTableToolbarBottomProps instanceof Function
|
|
27
|
+
? muiTableToolbarBottomProps(tableInstance)
|
|
28
|
+
: muiTableToolbarBottomProps;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Toolbar variant="dense" {...toolbarProps}>
|
|
32
|
+
{!hideToolbarActions && positionToolbarActions === 'bottom' ? (
|
|
33
|
+
<MRT_ToolbarButtons />
|
|
34
|
+
) : (
|
|
35
|
+
<span />
|
|
36
|
+
)}
|
|
37
|
+
{!manualPagination &&
|
|
38
|
+
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
39
|
+
<MRT_TablePagination />
|
|
40
|
+
)}
|
|
41
|
+
</Toolbar>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { styled } from '@mui/material';
|
|
3
|
+
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
4
|
+
import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
|
|
5
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
|
+
import { MRT_DensePaddingSwitch } from '../inputs/MRT_DensePaddingSwitch';
|
|
7
|
+
|
|
8
|
+
const ToolbarButtonsContainer = styled('div')({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
gap: '0.5rem',
|
|
11
|
+
alignItems: 'center',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
interface Props {}
|
|
15
|
+
|
|
16
|
+
export const MRT_ToolbarButtons: FC<Props> = () => {
|
|
17
|
+
const { disableFilters, disableColumnHiding, disableDensePaddingToggle } =
|
|
18
|
+
useMaterialReactTable();
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<ToolbarButtonsContainer>
|
|
22
|
+
{!disableFilters && <MRT_ToggleFiltersButton />}
|
|
23
|
+
{!disableColumnHiding && <MRT_ShowHideColumnsButton />}
|
|
24
|
+
{!disableDensePaddingToggle && <MRT_DensePaddingSwitch />}
|
|
25
|
+
</ToolbarButtonsContainer>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
|
|
6
|
+
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
7
|
+
|
|
8
|
+
const Toolbar = styled(MuiToolbar)({
|
|
9
|
+
display: 'grid',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const ToolbarTopRow = styled('div')({
|
|
13
|
+
padding: '0.5rem',
|
|
14
|
+
display: 'flex',
|
|
15
|
+
justifyContent: 'space-between',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const ToolbarActionsContainer = styled('div')({
|
|
19
|
+
display: 'flex',
|
|
20
|
+
gap: '0.5rem',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
interface Props {}
|
|
24
|
+
|
|
25
|
+
export const MRT_ToolbarTop: FC<Props> = () => {
|
|
26
|
+
const {
|
|
27
|
+
disableGlobalFilter,
|
|
28
|
+
hideToolbarActions,
|
|
29
|
+
manualPagination,
|
|
30
|
+
muiTableTitleProps,
|
|
31
|
+
muiTableToolbarTopProps,
|
|
32
|
+
positionPagination,
|
|
33
|
+
positionToolbarActions,
|
|
34
|
+
tableInstance,
|
|
35
|
+
title,
|
|
36
|
+
} = useMaterialReactTable();
|
|
37
|
+
|
|
38
|
+
const toolbarProps =
|
|
39
|
+
muiTableToolbarTopProps instanceof Function
|
|
40
|
+
? muiTableToolbarTopProps(tableInstance)
|
|
41
|
+
: muiTableToolbarTopProps;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Toolbar variant="dense" {...toolbarProps}>
|
|
45
|
+
<ToolbarTopRow>
|
|
46
|
+
{title ? (
|
|
47
|
+
<Typography variant="h5" {...muiTableTitleProps}>
|
|
48
|
+
{title}
|
|
49
|
+
</Typography>
|
|
50
|
+
) : (
|
|
51
|
+
<span />
|
|
52
|
+
)}
|
|
53
|
+
<ToolbarActionsContainer>
|
|
54
|
+
{!disableGlobalFilter && <MRT_SearchTextField />}
|
|
55
|
+
{!hideToolbarActions && positionToolbarActions === 'top' && (
|
|
56
|
+
<MRT_ToolbarButtons />
|
|
57
|
+
)}
|
|
58
|
+
</ToolbarActionsContainer>
|
|
59
|
+
</ToolbarTopRow>
|
|
60
|
+
<div>
|
|
61
|
+
{!manualPagination &&
|
|
62
|
+
['top', 'both'].includes(positionPagination ?? '') && (
|
|
63
|
+
<MRT_TablePagination />
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
</Toolbar>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -3,26 +3,35 @@ import React, {
|
|
|
3
3
|
createContext,
|
|
4
4
|
PropsWithChildren,
|
|
5
5
|
useContext,
|
|
6
|
+
useState,
|
|
6
7
|
} from 'react';
|
|
7
8
|
import {
|
|
9
|
+
PluginHook,
|
|
10
|
+
Row,
|
|
8
11
|
TableInstance,
|
|
9
12
|
useExpanded,
|
|
10
13
|
useFilters,
|
|
11
14
|
useFlexLayout,
|
|
12
15
|
useGlobalFilter,
|
|
16
|
+
useGroupBy,
|
|
13
17
|
usePagination,
|
|
14
18
|
useResizeColumns,
|
|
15
19
|
useRowSelect,
|
|
16
20
|
useSortBy,
|
|
17
21
|
useTable,
|
|
18
22
|
} from 'react-table';
|
|
19
|
-
import { MaterialReactTableProps } from '
|
|
23
|
+
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
20
24
|
import { UseMRTCalcs, useMRTCalcs } from './utils/useMRTCalcs';
|
|
21
|
-
import { showOverrideWarnings } from './utils/overrideWarnings';
|
|
22
25
|
|
|
23
|
-
interface UseMaterialReactTable<D extends {}>
|
|
26
|
+
export interface UseMaterialReactTable<D extends {}>
|
|
24
27
|
extends MaterialReactTableProps<D>,
|
|
25
28
|
UseMRTCalcs {
|
|
29
|
+
currentEditingRow: Row<D> | null;
|
|
30
|
+
densePadding: boolean;
|
|
31
|
+
setCurrentEditingRow: (currentRowEditingId: Row<D> | null) => void;
|
|
32
|
+
setDensePadding: (densePadding: boolean) => void;
|
|
33
|
+
setShowFilters: (showFilters: boolean) => void;
|
|
34
|
+
showFilters: boolean;
|
|
26
35
|
tableInstance: TableInstance<D>;
|
|
27
36
|
}
|
|
28
37
|
|
|
@@ -31,43 +40,50 @@ const MaterialReactTableContext = (<D extends {}>() =>
|
|
|
31
40
|
{} as UseMaterialReactTable<D>,
|
|
32
41
|
) as Context<UseMaterialReactTable<D>>)();
|
|
33
42
|
|
|
34
|
-
export const MaterialReactTableProvider = <D extends {}>(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
surpressOverrideWarnings,
|
|
39
|
-
...rest
|
|
40
|
-
}: PropsWithChildren<MaterialReactTableProps<D>>) => {
|
|
41
|
-
const tableInstance = useTable(
|
|
42
|
-
{ columns, data },
|
|
43
|
-
useFlexLayout,
|
|
43
|
+
export const MaterialReactTableProvider = <D extends {}>(
|
|
44
|
+
props: PropsWithChildren<MaterialReactTableProps<D>>,
|
|
45
|
+
) => {
|
|
46
|
+
const hooks: PluginHook<D>[] = [
|
|
44
47
|
useResizeColumns,
|
|
45
48
|
useFilters,
|
|
46
49
|
useGlobalFilter,
|
|
50
|
+
useGroupBy,
|
|
47
51
|
useSortBy,
|
|
48
52
|
useExpanded,
|
|
49
53
|
usePagination,
|
|
50
54
|
useRowSelect,
|
|
51
|
-
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
if (props.enableColumnResizing) hooks.unshift(useFlexLayout);
|
|
58
|
+
|
|
59
|
+
const tableInstance = useTable<D>(props, ...hooks);
|
|
52
60
|
|
|
53
61
|
const mrtCalcs = useMRTCalcs({ tableInstance });
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
const [showFilters, setShowFilters] = useState<boolean>(
|
|
64
|
+
props.defaultShowFilters ?? false,
|
|
65
|
+
);
|
|
66
|
+
const [densePadding, setDensePadding] = useState<boolean>(
|
|
67
|
+
props.defaultDensePadding ?? false,
|
|
68
|
+
);
|
|
69
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<Row | null>(null);
|
|
58
70
|
|
|
59
71
|
return (
|
|
60
72
|
<MaterialReactTableContext.Provider
|
|
61
|
-
//@ts-ignore
|
|
62
73
|
value={{
|
|
63
|
-
columns,
|
|
64
|
-
data,
|
|
65
|
-
tableInstance,
|
|
66
74
|
...mrtCalcs,
|
|
67
|
-
...
|
|
75
|
+
...props,
|
|
76
|
+
densePadding,
|
|
77
|
+
setDensePadding,
|
|
78
|
+
setShowFilters,
|
|
79
|
+
currentEditingRow,
|
|
80
|
+
setCurrentEditingRow,
|
|
81
|
+
showFilters,
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
tableInstance,
|
|
68
84
|
}}
|
|
69
85
|
>
|
|
70
|
-
{children}
|
|
86
|
+
{props.children}
|
|
71
87
|
</MaterialReactTableContext.Provider>
|
|
72
88
|
);
|
|
73
89
|
};
|
|
@@ -1,29 +1,51 @@
|
|
|
1
1
|
export interface MRT_Localization {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
showHideColumnsButtonTitle: string;
|
|
23
|
+
toggleDensePaddingSwitchTitle: string;
|
|
24
|
+
toggleFilterButtonTitle: string;
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
export const defaultLocalization: MRT_Localization = {
|
|
28
|
+
actionsHeadColumnTitle: 'Actions',
|
|
17
29
|
columnActionMenuButtonTitle: 'Column Actions',
|
|
30
|
+
columnActionMenuItemClearSort: 'Clear sorting',
|
|
31
|
+
columnActionMenuItemGroupBy: 'Group by column',
|
|
18
32
|
columnActionMenuItemHideColumn: 'Hide column',
|
|
19
33
|
columnActionMenuItemSortAsc: 'Sort ascending',
|
|
20
|
-
columnActionMenuItemClearSort: 'Clear sorting',
|
|
21
34
|
columnActionMenuItemSortDesc: 'Sort descending',
|
|
35
|
+
columnActionMenuItemUnGroupBy: 'Ungroup column',
|
|
22
36
|
expandAllButtonTitle: 'Expand all',
|
|
23
37
|
expandButtonTitle: 'Expand',
|
|
24
38
|
filterTextFieldClearButtonTitle: 'Clear filter',
|
|
25
39
|
filterTextFieldPlaceholder: 'Filter',
|
|
40
|
+
rowActionButtonCancel: 'Cancel',
|
|
41
|
+
rowActionButtonSave: 'Save',
|
|
42
|
+
rowActionMenuButtonTitle: 'Row Actions',
|
|
43
|
+
rowActionMenuItemEdit: 'Edit',
|
|
44
|
+
rowActionsColumnTitle: 'Actions',
|
|
26
45
|
searchTextFieldClearButtonTitle: 'Clear search',
|
|
27
46
|
searchTextFieldPlaceholder: 'Search',
|
|
28
|
-
|
|
47
|
+
selectAllCheckboxTitle: 'Select all',
|
|
48
|
+
showHideColumnsButtonTitle: 'Show/Hide columns',
|
|
49
|
+
toggleDensePaddingSwitchTitle: 'Toggle dense padding',
|
|
50
|
+
toggleFilterButtonTitle: 'Toggle filters',
|
|
29
51
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const showOverrideWarnings: (props: any) => void;
|
|
@@ -1,39 +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 { tableInstance, tablePaginationProps, OverrideTablePaginationComponent } =
|
|
9
|
-
useMaterialReactTable();
|
|
10
|
-
|
|
11
|
-
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
|
12
|
-
tableInstance.setPageSize(+event.target.value);
|
|
13
|
-
tableInstance.gotoPage(0);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
if (OverrideTablePaginationComponent) {
|
|
17
|
-
return <>{OverrideTablePaginationComponent(tableInstance)}</>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<TableRow>
|
|
22
|
-
<TablePagination
|
|
23
|
-
colSpan={tableInstance.visibleColumns.length + 10}
|
|
24
|
-
count={tableInstance.rows.length}
|
|
25
|
-
onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
|
|
26
|
-
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
27
|
-
page={tableInstance.state.pageIndex}
|
|
28
|
-
rowsPerPage={tableInstance.state.pageSize}
|
|
29
|
-
showFirstButton={
|
|
30
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
31
|
-
}
|
|
32
|
-
showLastButton={
|
|
33
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
34
|
-
}
|
|
35
|
-
{...tablePaginationProps}
|
|
36
|
-
/>
|
|
37
|
-
</TableRow>
|
|
38
|
-
);
|
|
39
|
-
};
|