material-react-table 0.3.3 → 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/dist/MaterialReactTable.d.ts +8 -5
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
- package/dist/inputs/{MRT_EditCellTextfield.d.ts → MRT_EditCellTextField.d.ts} +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +250 -160
- 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 +253 -163
- 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 +1 -0
- package/dist/table/MRT_TableButtonCell.d.ts +3 -0
- package/dist/useMaterialReactTable.d.ts +2 -0
- package/dist/utils/localization.d.ts +2 -0
- package/dist/utils/useMRTCalcs.d.ts +1 -1
- package/package.json +8 -6
- package/src/@types/react-table-config.d.ts +33 -55
- package/src/MaterialReactTable.tsx +22 -54
- package/src/body/MRT_TableBody.tsx +1 -2
- package/src/body/MRT_TableBodyCell.tsx +7 -14
- package/src/body/MRT_TableBodyRow.tsx +7 -24
- package/src/body/MRT_TableDetailPanel.tsx +3 -12
- package/src/buttons/MRT_EditActionButtons.tsx +4 -10
- package/src/buttons/MRT_ExpandAllButton.tsx +7 -18
- package/src/buttons/MRT_ExpandButton.tsx +8 -15
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +2 -9
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -8
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +42 -24
- package/src/buttons/MRT_ToggleSearchButton.tsx +29 -0
- package/src/footer/MRT_TableFooter.tsx +1 -4
- package/src/footer/MRT_TableFooterCell.tsx +2 -4
- package/src/footer/MRT_TableFooterRow.tsx +4 -10
- package/src/head/MRT_TableHead.tsx +2 -7
- package/src/head/MRT_TableHeadCell.tsx +15 -15
- package/src/head/MRT_TableHeadRow.tsx +2 -4
- package/src/inputs/MRT_DensePaddingSwitch.tsx +4 -2
- package/src/inputs/{MRT_EditCellTextfield.tsx → MRT_EditCellTextField.tsx} +21 -14
- package/src/inputs/MRT_FilterTextField.tsx +39 -16
- package/src/inputs/MRT_SearchTextField.tsx +40 -43
- package/src/inputs/MRT_SelectAllCheckbox.tsx +8 -13
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -13
- package/src/menus/MRT_ColumnActionMenu.tsx +51 -35
- package/src/menus/MRT_RowActionMenu.tsx +6 -25
- package/src/table/MRT_Table.tsx +1 -2
- package/src/table/MRT_TableButtonCell.tsx +9 -0
- package/src/table/MRT_TableContainer.tsx +2 -7
- package/src/table/MRT_TableSpacerCell.tsx +1 -3
- package/src/toolbar/MRT_TablePagination.tsx +3 -6
- package/src/toolbar/MRT_ToolbarBottom.tsx +4 -6
- package/src/toolbar/MRT_ToolbarButtons.tsx +3 -1
- package/src/toolbar/MRT_ToolbarTop.tsx +8 -17
- package/src/useMaterialReactTable.tsx +14 -21
- package/src/utils/localization.ts +10 -6
- package/src/utils/useMRTCalcs.tsx +1 -3
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Checkbox
|
|
2
|
+
import { Checkbox } from '@mui/material';
|
|
3
3
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
-
|
|
5
|
-
const TableCell = styled(MuiTableCell, {
|
|
6
|
-
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
7
|
-
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
8
|
-
padding: densePadding ? '0' : '0.6rem',
|
|
9
|
-
transition: 'all 0.2s ease-in-out',
|
|
10
|
-
}));
|
|
4
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
11
5
|
|
|
12
6
|
export const MRT_SelectAllCheckbox = () => {
|
|
13
|
-
const { tableInstance, disableSelectAll, densePadding, localization } =
|
|
14
|
-
useMaterialReactTable();
|
|
7
|
+
const { tableInstance, disableSelectAll, densePadding, localization } = useMaterialReactTable();
|
|
15
8
|
|
|
16
9
|
return (
|
|
17
|
-
<
|
|
10
|
+
<MRT_TableButtonCell densePadding={densePadding} variant="head">
|
|
18
11
|
{!disableSelectAll ? (
|
|
19
12
|
<Checkbox
|
|
20
|
-
|
|
13
|
+
inputProps={{
|
|
14
|
+
'aria-label': localization?.selectAllCheckboxTitle ?? '',
|
|
15
|
+
}}
|
|
21
16
|
{...tableInstance.getToggleAllPageRowsSelectedProps()}
|
|
22
17
|
/>
|
|
23
18
|
) : null}
|
|
24
|
-
</
|
|
19
|
+
</MRT_TableButtonCell>
|
|
25
20
|
);
|
|
26
21
|
};
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
-
import { Checkbox
|
|
2
|
+
import { Checkbox } from '@mui/material';
|
|
3
3
|
import { Row } from 'react-table';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
-
|
|
6
|
-
const TableCell = styled(MuiTableCell, {
|
|
7
|
-
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
8
|
-
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
9
|
-
padding: densePadding ? '0' : '0.6rem',
|
|
10
|
-
transition: 'all 0.2s ease-in-out',
|
|
11
|
-
}));
|
|
5
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
12
6
|
|
|
13
7
|
interface Props {
|
|
14
8
|
row: Row;
|
|
15
9
|
}
|
|
16
10
|
|
|
17
11
|
export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
|
|
18
|
-
const { tableInstance, onRowSelectChange, densePadding } =
|
|
19
|
-
useMaterialReactTable();
|
|
12
|
+
const { tableInstance, onRowSelectChange, densePadding, localization } = useMaterialReactTable();
|
|
20
13
|
|
|
21
14
|
const onSelectChange = (event: ChangeEvent) => {
|
|
22
15
|
row.getToggleRowSelectedProps()?.onChange?.(event);
|
|
@@ -24,11 +17,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
|
|
|
24
17
|
};
|
|
25
18
|
|
|
26
19
|
return (
|
|
27
|
-
<
|
|
20
|
+
<MRT_TableButtonCell densePadding={densePadding}>
|
|
28
21
|
<Checkbox
|
|
29
|
-
{
|
|
22
|
+
inputProps={{
|
|
23
|
+
'aria-label': localization?.selectCheckboxTitle,
|
|
24
|
+
}}
|
|
30
25
|
onChange={onSelectChange}
|
|
26
|
+
{...row.getToggleRowSelectedProps()}
|
|
31
27
|
/>
|
|
32
|
-
</
|
|
28
|
+
</MRT_TableButtonCell>
|
|
33
29
|
);
|
|
34
30
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
3
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
-
import {
|
|
4
|
+
import { HeaderGroup } 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
8
|
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
9
|
+
import FilterIcon from '@mui/icons-material/FilterList';
|
|
9
10
|
|
|
10
11
|
const MenuItem = styled(MuiMenuItem)({
|
|
11
12
|
display: 'flex',
|
|
@@ -14,20 +15,18 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
14
15
|
|
|
15
16
|
interface Props {
|
|
16
17
|
anchorEl: HTMLElement | null;
|
|
17
|
-
column:
|
|
18
|
+
column: HeaderGroup;
|
|
18
19
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
22
|
-
anchorEl,
|
|
23
|
-
column,
|
|
24
|
-
setAnchorEl,
|
|
25
|
-
}) => {
|
|
22
|
+
export const MRT_ColumnActionMenu: FC<Props> = ({ anchorEl, column, setAnchorEl }) => {
|
|
26
23
|
const {
|
|
27
24
|
disableColumnHiding,
|
|
28
25
|
enableColumnGrouping,
|
|
29
26
|
disableSortBy,
|
|
30
27
|
localization,
|
|
28
|
+
disableFilters,
|
|
29
|
+
setShowFilters,
|
|
31
30
|
} = useMaterialReactTable();
|
|
32
31
|
|
|
33
32
|
const handleClearSort = () => {
|
|
@@ -55,19 +54,26 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
55
54
|
setAnchorEl(null);
|
|
56
55
|
};
|
|
57
56
|
|
|
57
|
+
const handleFilterByColumn = () => {
|
|
58
|
+
setShowFilters(true);
|
|
59
|
+
setTimeout(
|
|
60
|
+
() =>
|
|
61
|
+
document
|
|
62
|
+
.getElementById(
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
column.muiTableHeadCellFilterTextFieldProps?.id ?? `filter-${column.id}-column`,
|
|
65
|
+
)
|
|
66
|
+
?.focus(),
|
|
67
|
+
200,
|
|
68
|
+
);
|
|
69
|
+
setAnchorEl(null);
|
|
70
|
+
};
|
|
71
|
+
|
|
58
72
|
return (
|
|
59
|
-
<Menu
|
|
60
|
-
anchorEl={anchorEl}
|
|
61
|
-
open={!!anchorEl}
|
|
62
|
-
onClose={() => setAnchorEl(null)}
|
|
63
|
-
>
|
|
73
|
+
<Menu anchorEl={anchorEl} open={!!anchorEl} onClose={() => setAnchorEl(null)}>
|
|
64
74
|
{!disableSortBy &&
|
|
65
75
|
column.canSort && [
|
|
66
|
-
<MenuItem
|
|
67
|
-
key={1}
|
|
68
|
-
disabled={!column.isSorted}
|
|
69
|
-
onClick={handleClearSort}
|
|
70
|
-
>
|
|
76
|
+
<MenuItem key={1} disabled={!column.isSorted} onClick={handleClearSort}>
|
|
71
77
|
<ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
|
|
72
78
|
</MenuItem>,
|
|
73
79
|
<MenuItem
|
|
@@ -75,7 +81,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
75
81
|
disabled={column.isSorted && !column.isSortedDesc}
|
|
76
82
|
onClick={handleSortAsc}
|
|
77
83
|
>
|
|
78
|
-
<SortIcon />
|
|
84
|
+
<SortIcon />{' '}
|
|
85
|
+
{localization?.columnActionMenuItemSortAsc?.replace('{column}', String(column.Header))}
|
|
79
86
|
</MenuItem>,
|
|
80
87
|
<MenuItem
|
|
81
88
|
key={3}
|
|
@@ -83,25 +90,34 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
83
90
|
onClick={handleSortDesc}
|
|
84
91
|
>
|
|
85
92
|
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
|
|
86
|
-
{localization?.columnActionMenuItemSortDesc}
|
|
93
|
+
{localization?.columnActionMenuItemSortDesc?.replace('{column}', String(column.Header))}
|
|
94
|
+
</MenuItem>,
|
|
95
|
+
]}
|
|
96
|
+
{!disableFilters &&
|
|
97
|
+
column.canFilter && [
|
|
98
|
+
<Divider key={0} />,
|
|
99
|
+
<MenuItem key={1} onClick={handleFilterByColumn}>
|
|
100
|
+
<FilterIcon />{' '}
|
|
101
|
+
{localization?.filterTextFieldPlaceholder?.replace('{column}', String(column.Header))}
|
|
102
|
+
</MenuItem>,
|
|
103
|
+
]}
|
|
104
|
+
{enableColumnGrouping &&
|
|
105
|
+
column.canGroupBy && [
|
|
106
|
+
<Divider key={1} />,
|
|
107
|
+
<MenuItem key={2} onClick={handleGroupByColumn}>
|
|
108
|
+
<DynamicFeedIcon />{' '}
|
|
109
|
+
{localization?.[
|
|
110
|
+
column.isGrouped ? 'columnActionMenuItemUnGroupBy' : 'columnActionMenuItemGroupBy'
|
|
111
|
+
]?.replace('{column}', String(column.Header))}
|
|
87
112
|
</MenuItem>,
|
|
88
|
-
<Divider key={4} />,
|
|
89
113
|
]}
|
|
90
|
-
{!disableColumnHiding &&
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
)}
|
|
114
|
+
{!disableColumnHiding && [
|
|
115
|
+
<Divider key={0} />,
|
|
116
|
+
<MenuItem key={1} onClick={handleHideColumn}>
|
|
117
|
+
<VisibilityOffIcon />{' '}
|
|
118
|
+
{localization?.columnActionMenuItemHideColumn?.replace('{column}', String(column.Header))}
|
|
119
|
+
</MenuItem>,
|
|
120
|
+
]}
|
|
105
121
|
</Menu>
|
|
106
122
|
);
|
|
107
123
|
};
|
|
@@ -13,40 +13,21 @@ interface Props {
|
|
|
13
13
|
anchorEl: HTMLElement | null;
|
|
14
14
|
row: Row;
|
|
15
15
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
16
|
+
handleEdit: () => void;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export const MRT_RowActionMenu: FC<Props> = ({
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
};
|
|
19
|
+
export const MRT_RowActionMenu: FC<Props> = ({ anchorEl, row, handleEdit, setAnchorEl }) => {
|
|
20
|
+
const { enableRowEditing, localization, renderRowActionMenuItems, tableInstance } =
|
|
21
|
+
useMaterialReactTable();
|
|
35
22
|
|
|
36
23
|
return (
|
|
37
|
-
<Menu
|
|
38
|
-
anchorEl={anchorEl}
|
|
39
|
-
open={!!anchorEl}
|
|
40
|
-
onClose={() => setAnchorEl(null)}
|
|
41
|
-
>
|
|
24
|
+
<Menu anchorEl={anchorEl} open={!!anchorEl} onClose={() => setAnchorEl(null)}>
|
|
42
25
|
{enableRowEditing && (
|
|
43
26
|
<MenuItem onClick={handleEdit}>
|
|
44
27
|
<EditIcon /> {localization?.rowActionMenuItemEdit}
|
|
45
28
|
</MenuItem>
|
|
46
29
|
)}
|
|
47
|
-
{renderRowActionMenuItems?.(row, tableInstance, () =>
|
|
48
|
-
setAnchorEl(null),
|
|
49
|
-
) ?? null}
|
|
30
|
+
{renderRowActionMenuItems?.(row, tableInstance, () => setAnchorEl(null)) ?? null}
|
|
50
31
|
</Menu>
|
|
51
32
|
);
|
|
52
33
|
};
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -8,8 +8,7 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
|
8
8
|
interface Props {}
|
|
9
9
|
|
|
10
10
|
export const MRT_Table: FC<Props> = () => {
|
|
11
|
-
const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } =
|
|
12
|
-
useMaterialReactTable();
|
|
11
|
+
const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } = useMaterialReactTable();
|
|
13
12
|
|
|
14
13
|
const tableProps = {
|
|
15
14
|
...muiTableProps,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { styled, TableCell as MuiTableCell } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export const MRT_TableButtonCell = styled(MuiTableCell, {
|
|
4
|
+
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
5
|
+
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
6
|
+
padding: densePadding ? '1px' : '0.6rem',
|
|
7
|
+
textAlign: 'center',
|
|
8
|
+
transition: 'all 0.2s ease-in-out',
|
|
9
|
+
}));
|
|
@@ -26,13 +26,8 @@ const CircularProgressWrapper = styled('div')(({ theme }) => ({
|
|
|
26
26
|
interface Props {}
|
|
27
27
|
|
|
28
28
|
export const MRT_TableContainer: FC<Props> = () => {
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
hideToolbarTop,
|
|
32
|
-
hideToolbarBottom,
|
|
33
|
-
isLoading,
|
|
34
|
-
isFetching,
|
|
35
|
-
} = useMaterialReactTable();
|
|
29
|
+
const { muiTableContainerProps, hideToolbarTop, hideToolbarBottom, isLoading, isFetching } =
|
|
30
|
+
useMaterialReactTable();
|
|
36
31
|
|
|
37
32
|
return (
|
|
38
33
|
<TableContainer component={Paper} {...muiTableContainerProps}>
|
|
@@ -10,9 +10,7 @@ export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
|
|
|
10
10
|
const { muiTableBodyCellProps } = useMaterialReactTable();
|
|
11
11
|
|
|
12
12
|
const mTableBodyCellrops =
|
|
13
|
-
muiTableBodyCellProps instanceof Function
|
|
14
|
-
? muiTableBodyCellProps()
|
|
15
|
-
: muiTableBodyCellProps;
|
|
13
|
+
muiTableBodyCellProps instanceof Function ? muiTableBodyCellProps() : muiTableBodyCellProps;
|
|
16
14
|
|
|
17
15
|
const tableCellProps = {
|
|
18
16
|
...mTableBodyCellrops,
|
|
@@ -25,12 +25,9 @@ export const MRT_TablePagination: FC<Props> = () => {
|
|
|
25
25
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
26
26
|
page={tableInstance.state.pageIndex}
|
|
27
27
|
rowsPerPage={tableInstance.state.pageSize}
|
|
28
|
-
showFirstButton={
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
showLastButton={
|
|
32
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
33
|
-
}
|
|
28
|
+
showFirstButton={tableInstance.rows.length / tableInstance.state.pageSize > 2}
|
|
29
|
+
showLastButton={tableInstance.rows.length / tableInstance.state.pageSize > 2}
|
|
30
|
+
style={{ padding: 0 }}
|
|
34
31
|
{...tablePaginationProps}
|
|
35
32
|
/>
|
|
36
33
|
);
|
|
@@ -5,7 +5,6 @@ import { MRT_TablePagination } from './MRT_TablePagination';
|
|
|
5
5
|
import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
|
|
6
6
|
|
|
7
7
|
const Toolbar = styled(MuiToolbar)({
|
|
8
|
-
padding: 0,
|
|
9
8
|
display: 'flex',
|
|
10
9
|
justifyContent: 'space-between',
|
|
11
10
|
});
|
|
@@ -28,16 +27,15 @@ export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
|
28
27
|
: muiTableToolbarBottomProps;
|
|
29
28
|
|
|
30
29
|
return (
|
|
31
|
-
<Toolbar variant="dense" {...toolbarProps}>
|
|
30
|
+
<Toolbar style={{ padding: 0 }} variant="dense" {...toolbarProps}>
|
|
32
31
|
{!hideToolbarActions && positionToolbarActions === 'bottom' ? (
|
|
33
32
|
<MRT_ToolbarButtons />
|
|
34
33
|
) : (
|
|
35
34
|
<span />
|
|
36
35
|
)}
|
|
37
|
-
{!manualPagination &&
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)}
|
|
36
|
+
{!manualPagination && ['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
37
|
+
<MRT_TablePagination />
|
|
38
|
+
)}
|
|
41
39
|
</Toolbar>
|
|
42
40
|
);
|
|
43
41
|
};
|
|
@@ -4,6 +4,7 @@ import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
|
4
4
|
import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
|
|
5
5
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
6
|
import { MRT_DensePaddingSwitch } from '../inputs/MRT_DensePaddingSwitch';
|
|
7
|
+
import { MRT_ToggleSearchButton } from '../buttons/MRT_ToggleSearchButton';
|
|
7
8
|
|
|
8
9
|
const ToolbarButtonsContainer = styled('div')({
|
|
9
10
|
display: 'flex',
|
|
@@ -14,11 +15,12 @@ const ToolbarButtonsContainer = styled('div')({
|
|
|
14
15
|
interface Props {}
|
|
15
16
|
|
|
16
17
|
export const MRT_ToolbarButtons: FC<Props> = () => {
|
|
17
|
-
const { disableFilters, disableColumnHiding, disableDensePaddingToggle } =
|
|
18
|
+
const { disableFilters, disableColumnHiding, disableDensePaddingToggle, disableGlobalFilter } =
|
|
18
19
|
useMaterialReactTable();
|
|
19
20
|
|
|
20
21
|
return (
|
|
21
22
|
<ToolbarButtonsContainer>
|
|
23
|
+
{!disableGlobalFilter && <MRT_ToggleSearchButton />}
|
|
22
24
|
{!disableFilters && <MRT_ToggleFiltersButton />}
|
|
23
25
|
{!disableColumnHiding && <MRT_ShowHideColumnsButton />}
|
|
24
26
|
{!disableDensePaddingToggle && <MRT_DensePaddingSwitch />}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { styled, Toolbar as MuiToolbar
|
|
2
|
+
import { styled, Toolbar as MuiToolbar } from '@mui/material';
|
|
3
3
|
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
|
|
@@ -7,6 +7,7 @@ import { MRT_TablePagination } from './MRT_TablePagination';
|
|
|
7
7
|
|
|
8
8
|
const Toolbar = styled(MuiToolbar)({
|
|
9
9
|
display: 'grid',
|
|
10
|
+
padding: '0.5rem !important',
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
const ToolbarTopRow = styled('div')({
|
|
@@ -27,12 +28,11 @@ export const MRT_ToolbarTop: FC<Props> = () => {
|
|
|
27
28
|
disableGlobalFilter,
|
|
28
29
|
hideToolbarActions,
|
|
29
30
|
manualPagination,
|
|
30
|
-
muiTableTitleProps,
|
|
31
31
|
muiTableToolbarTopProps,
|
|
32
32
|
positionPagination,
|
|
33
33
|
positionToolbarActions,
|
|
34
|
+
renderToolbarActions,
|
|
34
35
|
tableInstance,
|
|
35
|
-
title,
|
|
36
36
|
} = useMaterialReactTable();
|
|
37
37
|
|
|
38
38
|
const toolbarProps =
|
|
@@ -43,25 +43,16 @@ export const MRT_ToolbarTop: FC<Props> = () => {
|
|
|
43
43
|
return (
|
|
44
44
|
<Toolbar variant="dense" {...toolbarProps}>
|
|
45
45
|
<ToolbarTopRow>
|
|
46
|
-
{
|
|
47
|
-
<Typography variant="h5" {...muiTableTitleProps}>
|
|
48
|
-
{title}
|
|
49
|
-
</Typography>
|
|
50
|
-
) : (
|
|
51
|
-
<span />
|
|
52
|
-
)}
|
|
46
|
+
{renderToolbarActions?.(tableInstance) ?? <span />}
|
|
53
47
|
<ToolbarActionsContainer>
|
|
54
48
|
{!disableGlobalFilter && <MRT_SearchTextField />}
|
|
55
|
-
{!hideToolbarActions && positionToolbarActions === 'top' &&
|
|
56
|
-
<MRT_ToolbarButtons />
|
|
57
|
-
)}
|
|
49
|
+
{!hideToolbarActions && positionToolbarActions === 'top' && <MRT_ToolbarButtons />}
|
|
58
50
|
</ToolbarActionsContainer>
|
|
59
51
|
</ToolbarTopRow>
|
|
60
52
|
<div>
|
|
61
|
-
{!manualPagination &&
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)}
|
|
53
|
+
{!manualPagination && ['top', 'both'].includes(positionPagination ?? '') && (
|
|
54
|
+
<MRT_TablePagination />
|
|
55
|
+
)}
|
|
65
56
|
</div>
|
|
66
57
|
</Toolbar>
|
|
67
58
|
);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
Context,
|
|
3
|
-
createContext,
|
|
4
|
-
PropsWithChildren,
|
|
5
|
-
useContext,
|
|
6
|
-
useState,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, { Context, createContext, PropsWithChildren, useContext, useState } from 'react';
|
|
8
2
|
import {
|
|
9
3
|
PluginHook,
|
|
10
4
|
Row,
|
|
@@ -31,14 +25,16 @@ export interface UseMaterialReactTable<D extends {}>
|
|
|
31
25
|
setCurrentEditingRow: (currentRowEditingId: Row<D> | null) => void;
|
|
32
26
|
setDensePadding: (densePadding: boolean) => void;
|
|
33
27
|
setShowFilters: (showFilters: boolean) => void;
|
|
28
|
+
setShowSearch: (showSearch: boolean) => void;
|
|
34
29
|
showFilters: boolean;
|
|
30
|
+
showSearch: boolean;
|
|
35
31
|
tableInstance: TableInstance<D>;
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
const MaterialReactTableContext = (<D extends {}>() =>
|
|
39
|
-
createContext<UseMaterialReactTable<D>>(
|
|
40
|
-
|
|
41
|
-
)
|
|
35
|
+
createContext<UseMaterialReactTable<D>>({} as UseMaterialReactTable<D>) as Context<
|
|
36
|
+
UseMaterialReactTable<D>
|
|
37
|
+
>)();
|
|
42
38
|
|
|
43
39
|
export const MaterialReactTableProvider = <D extends {}>(
|
|
44
40
|
props: PropsWithChildren<MaterialReactTableProps<D>>,
|
|
@@ -60,12 +56,9 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
60
56
|
|
|
61
57
|
const mrtCalcs = useMRTCalcs({ tableInstance });
|
|
62
58
|
|
|
63
|
-
const [
|
|
64
|
-
|
|
65
|
-
);
|
|
66
|
-
const [densePadding, setDensePadding] = useState<boolean>(
|
|
67
|
-
props.defaultDensePadding ?? false,
|
|
68
|
-
);
|
|
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);
|
|
69
62
|
const [currentEditingRow, setCurrentEditingRow] = useState<Row | null>(null);
|
|
70
63
|
|
|
71
64
|
return (
|
|
@@ -73,12 +66,14 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
73
66
|
value={{
|
|
74
67
|
...mrtCalcs,
|
|
75
68
|
...props,
|
|
69
|
+
currentEditingRow,
|
|
76
70
|
densePadding,
|
|
71
|
+
setCurrentEditingRow,
|
|
77
72
|
setDensePadding,
|
|
78
73
|
setShowFilters,
|
|
79
|
-
|
|
80
|
-
setCurrentEditingRow,
|
|
74
|
+
setShowSearch,
|
|
81
75
|
showFilters,
|
|
76
|
+
showSearch,
|
|
82
77
|
// @ts-ignore
|
|
83
78
|
tableInstance,
|
|
84
79
|
}}
|
|
@@ -88,8 +83,6 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
88
83
|
);
|
|
89
84
|
};
|
|
90
85
|
|
|
91
|
-
export const useMaterialReactTable = <
|
|
92
|
-
D extends {},
|
|
93
|
-
>(): UseMaterialReactTable<D> =>
|
|
86
|
+
export const useMaterialReactTable = <D extends {}>(): UseMaterialReactTable<D> =>
|
|
94
87
|
//@ts-ignore
|
|
95
88
|
useContext<UseMaterialReactTable<D>>(MaterialReactTableContext);
|
|
@@ -19,28 +19,31 @@ export interface MRT_Localization {
|
|
|
19
19
|
searchTextFieldClearButtonTitle: string;
|
|
20
20
|
searchTextFieldPlaceholder: string;
|
|
21
21
|
selectAllCheckboxTitle: string;
|
|
22
|
+
selectCheckboxTitle: string;
|
|
22
23
|
showHideColumnsButtonTitle: string;
|
|
23
24
|
toggleDensePaddingSwitchTitle: string;
|
|
24
25
|
toggleFilterButtonTitle: string;
|
|
26
|
+
toggleSearchButtonTitle: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export const defaultLocalization: MRT_Localization = {
|
|
28
30
|
actionsHeadColumnTitle: 'Actions',
|
|
29
31
|
columnActionMenuButtonTitle: 'Column Actions',
|
|
30
32
|
columnActionMenuItemClearSort: 'Clear sorting',
|
|
31
|
-
columnActionMenuItemGroupBy: 'Group by column',
|
|
32
|
-
columnActionMenuItemHideColumn: 'Hide column',
|
|
33
|
-
columnActionMenuItemSortAsc: 'Sort ascending',
|
|
34
|
-
columnActionMenuItemSortDesc: 'Sort descending',
|
|
35
|
-
columnActionMenuItemUnGroupBy: 'Ungroup column',
|
|
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}',
|
|
36
38
|
expandAllButtonTitle: 'Expand all',
|
|
37
39
|
expandButtonTitle: 'Expand',
|
|
38
40
|
filterTextFieldClearButtonTitle: 'Clear filter',
|
|
39
|
-
filterTextFieldPlaceholder: 'Filter',
|
|
41
|
+
filterTextFieldPlaceholder: 'Filter by {column}',
|
|
40
42
|
rowActionButtonCancel: 'Cancel',
|
|
41
43
|
rowActionButtonSave: 'Save',
|
|
42
44
|
rowActionMenuButtonTitle: 'Row Actions',
|
|
43
45
|
rowActionMenuItemEdit: 'Edit',
|
|
46
|
+
selectCheckboxTitle: 'Select row',
|
|
44
47
|
rowActionsColumnTitle: 'Actions',
|
|
45
48
|
searchTextFieldClearButtonTitle: 'Clear search',
|
|
46
49
|
searchTextFieldPlaceholder: 'Search',
|
|
@@ -48,4 +51,5 @@ export const defaultLocalization: MRT_Localization = {
|
|
|
48
51
|
showHideColumnsButtonTitle: 'Show/Hide columns',
|
|
49
52
|
toggleDensePaddingSwitchTitle: 'Toggle dense padding',
|
|
50
53
|
toggleFilterButtonTitle: 'Toggle filters',
|
|
54
|
+
toggleSearchButtonTitle: 'Toggle search'
|
|
51
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],
|