material-react-table 0.6.7 → 0.6.8
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 +4 -0
- package/dist/material-react-table.cjs.development.js +34 -27
- 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 +34 -27
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +8 -0
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +19 -1
- package/src/head/MRT_TableHeadCell.tsx +5 -3
- package/src/head/MRT_TableHeadRow.tsx +2 -1
- package/src/inputs/MRT_EditCellTextField.tsx +0 -6
- package/src/inputs/MRT_FilterTextField.tsx +0 -4
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -1
- package/src/menus/MRT_ColumnActionMenu.tsx +6 -1
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +12 -1
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +1 -1
- package/src/table/MRT_TableSpacerCell.tsx +1 -8
- package/src/utils.ts +8 -4
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MRT_ColumnInterface } from '.';
|
|
2
|
-
export declare const findLowestLevelCols: (columns: MRT_ColumnInterface[]) => MRT_ColumnInterface<{}>[];
|
|
1
|
+
import { MRT_ColumnInstance, MRT_ColumnInterface } from '.';
|
|
2
|
+
export declare const findLowestLevelCols: (columns: MRT_ColumnInterface[] | MRT_ColumnInstance[]) => MRT_ColumnInterface<{}>[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.6.
|
|
2
|
+
"version": "0.6.8",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material-UI implementation of react-table, inspired by material-table and the mui DataGrid, written from the ground up in TypeScript.",
|
|
@@ -135,6 +135,8 @@ export type MRT_ColumnInterface<D extends {} = {}> = ColumnInterface<D> &
|
|
|
135
135
|
accessor?: string;
|
|
136
136
|
columns?: MRT_ColumnInterface<D>[];
|
|
137
137
|
disableClickToCopy?: boolean;
|
|
138
|
+
disableColumnActions?: boolean;
|
|
139
|
+
disableColumnHiding?: boolean;
|
|
138
140
|
disableEditing?: boolean;
|
|
139
141
|
disableFilters?: boolean;
|
|
140
142
|
filter?: MRT_FilterType | string | FilterType<D>;
|
|
@@ -152,6 +154,9 @@ export type MRT_ColumnInterface<D extends {} = {}> = ColumnInterface<D> &
|
|
|
152
154
|
muiTableHeadCellFilterTextFieldProps?:
|
|
153
155
|
| TextFieldProps
|
|
154
156
|
| ((column: Column<D>) => TextFieldProps);
|
|
157
|
+
muiTableHeadCellColumnActionsButtonProps?:
|
|
158
|
+
| IconButtonProps
|
|
159
|
+
| ((column: Column<D>) => IconButtonProps);
|
|
155
160
|
muiTableHeadCellProps?:
|
|
156
161
|
| TableCellProps
|
|
157
162
|
| ((column: Column<D>) => TableCellProps);
|
|
@@ -277,6 +282,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
277
282
|
muiTableFooterCellProps?:
|
|
278
283
|
| TableCellProps
|
|
279
284
|
| ((column: Column<D>) => TableCellProps);
|
|
285
|
+
muiTableHeadCellColumnActionsButtonProps?:
|
|
286
|
+
| IconButtonProps
|
|
287
|
+
| ((column: Column<D>) => IconButtonProps);
|
|
280
288
|
muiTableFooterProps?:
|
|
281
289
|
| TableFooterProps
|
|
282
290
|
| ((tableInstance: MRT_TableInstance<D>) => TableFooterProps);
|
|
@@ -10,8 +10,9 @@ interface Props {
|
|
|
10
10
|
|
|
11
11
|
export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
12
12
|
const {
|
|
13
|
-
localization,
|
|
14
13
|
icons: { MoreVertIcon },
|
|
14
|
+
localization,
|
|
15
|
+
muiTableHeadCellColumnActionsButtonProps,
|
|
15
16
|
} = useMRT();
|
|
16
17
|
|
|
17
18
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
@@ -22,6 +23,21 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
|
22
23
|
setAnchorEl(event.currentTarget);
|
|
23
24
|
};
|
|
24
25
|
|
|
26
|
+
const mTableHeadCellColumnActionsButtonProps =
|
|
27
|
+
muiTableHeadCellColumnActionsButtonProps instanceof Function
|
|
28
|
+
? muiTableHeadCellColumnActionsButtonProps(column)
|
|
29
|
+
: muiTableHeadCellColumnActionsButtonProps;
|
|
30
|
+
|
|
31
|
+
const mcTableHeadCellColumnActionsButtonProps =
|
|
32
|
+
column.muiTableHeadCellColumnActionsButtonProps instanceof Function
|
|
33
|
+
? column.muiTableHeadCellColumnActionsButtonProps(column)
|
|
34
|
+
: column.muiTableHeadCellColumnActionsButtonProps;
|
|
35
|
+
|
|
36
|
+
const iconButtonProps = {
|
|
37
|
+
...mTableHeadCellColumnActionsButtonProps,
|
|
38
|
+
...mcTableHeadCellColumnActionsButtonProps,
|
|
39
|
+
};
|
|
40
|
+
|
|
25
41
|
return (
|
|
26
42
|
<>
|
|
27
43
|
<Tooltip
|
|
@@ -35,6 +51,7 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
|
35
51
|
aria-label={localization.columnActions}
|
|
36
52
|
onClick={handleClick}
|
|
37
53
|
size="small"
|
|
54
|
+
{...iconButtonProps}
|
|
38
55
|
sx={{
|
|
39
56
|
height: '2rem',
|
|
40
57
|
mr: '2px',
|
|
@@ -45,6 +62,7 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
|
45
62
|
'&:hover': {
|
|
46
63
|
opacity: 1,
|
|
47
64
|
},
|
|
65
|
+
...iconButtonProps.sx,
|
|
48
66
|
}}
|
|
49
67
|
>
|
|
50
68
|
<MoreVertIcon />
|
|
@@ -178,9 +178,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
178
178
|
)}
|
|
179
179
|
</Box>
|
|
180
180
|
<Box sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}>
|
|
181
|
-
{!disableColumnActions &&
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
{!disableColumnActions &&
|
|
182
|
+
!column.disableColumnActions &&
|
|
183
|
+
!isParentHeader && (
|
|
184
|
+
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
185
|
+
)}
|
|
184
186
|
{enableColumnResizing && !isParentHeader && (
|
|
185
187
|
<Divider
|
|
186
188
|
flexItem
|
|
@@ -19,6 +19,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
|
19
19
|
const {
|
|
20
20
|
anyRowsCanExpand,
|
|
21
21
|
disableExpandAll,
|
|
22
|
+
disableSelectAll,
|
|
22
23
|
enableRowActions,
|
|
23
24
|
enableRowEditing,
|
|
24
25
|
enableRowNumbers,
|
|
@@ -81,7 +82,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
|
81
82
|
)
|
|
82
83
|
) : null}
|
|
83
84
|
{enableSelection ? (
|
|
84
|
-
!isParentHeader ? (
|
|
85
|
+
!isParentHeader && !disableSelectAll ? (
|
|
85
86
|
<MRT_SelectCheckbox selectAll />
|
|
86
87
|
) : (
|
|
87
88
|
<MRT_TableSpacerCell width="1rem" />
|
|
@@ -39,12 +39,6 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
|
39
39
|
const textFieldProps = {
|
|
40
40
|
...mTableBodyCellEditTextFieldProps,
|
|
41
41
|
...mcTableBodyCellEditTextFieldProps,
|
|
42
|
-
style: {
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
...muiTableBodyCellEditTextFieldProps?.style,
|
|
45
|
-
//@ts-ignore
|
|
46
|
-
...cell.column.muiTableBodyCellEditTextFieldProps?.style,
|
|
47
|
-
},
|
|
48
42
|
};
|
|
49
43
|
|
|
50
44
|
if (!cell.column.disableEditing && cell.column.Edit) {
|
|
@@ -43,10 +43,6 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
43
43
|
const textFieldProps = {
|
|
44
44
|
...mTableHeadCellFilterTextFieldProps,
|
|
45
45
|
...mcTableHeadCellFilterTextFieldProps,
|
|
46
|
-
style: {
|
|
47
|
-
...mTableHeadCellFilterTextFieldProps?.style,
|
|
48
|
-
...mcTableHeadCellFilterTextFieldProps?.style,
|
|
49
|
-
},
|
|
50
46
|
} as TextFieldProps;
|
|
51
47
|
|
|
52
48
|
const [filterValue, setFilterValue] = useState('');
|
|
@@ -29,7 +29,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
|
29
29
|
|
|
30
30
|
return (
|
|
31
31
|
<TableCell
|
|
32
|
-
sx={
|
|
32
|
+
sx={{
|
|
33
|
+
...commonTableBodyButtonCellStyles(tableInstance.state.densePadding),
|
|
34
|
+
maxWidth: '2rem',
|
|
35
|
+
width: '2rem',
|
|
36
|
+
}}
|
|
33
37
|
>
|
|
34
38
|
<Tooltip
|
|
35
39
|
arrow
|
|
@@ -246,7 +246,12 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
246
246
|
</MenuItem>,
|
|
247
247
|
]}
|
|
248
248
|
{!disableColumnHiding && [
|
|
249
|
-
<MenuItem
|
|
249
|
+
<MenuItem
|
|
250
|
+
disabled={column.disableColumnHiding}
|
|
251
|
+
key={0}
|
|
252
|
+
onClick={handleHideColumn}
|
|
253
|
+
sx={commonMenuItemStyles}
|
|
254
|
+
>
|
|
250
255
|
<Box sx={commonListItemStyles}>
|
|
251
256
|
<ListItemIcon>
|
|
252
257
|
<VisibilityOffIcon />
|
|
@@ -3,6 +3,7 @@ import { Button, Menu, Divider, Box } from '@mui/material';
|
|
|
3
3
|
import type { MRT_ColumnInstance } from '..';
|
|
4
4
|
import { useMRT } from '../useMRT';
|
|
5
5
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
6
|
+
import { findLowestLevelCols } from '../utils';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
anchorEl: HTMLElement | null;
|
|
@@ -17,6 +18,16 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
17
18
|
}) => {
|
|
18
19
|
const { localization, tableInstance } = useMRT();
|
|
19
20
|
|
|
21
|
+
const hideAllColumns = () => {
|
|
22
|
+
(
|
|
23
|
+
findLowestLevelCols(
|
|
24
|
+
tableInstance.columns as MRT_ColumnInstance[],
|
|
25
|
+
) as MRT_ColumnInstance[]
|
|
26
|
+
)
|
|
27
|
+
.filter((col: MRT_ColumnInstance) => !col.disableColumnHiding)
|
|
28
|
+
.forEach((col: MRT_ColumnInstance) => col.toggleHidden(true));
|
|
29
|
+
};
|
|
30
|
+
|
|
20
31
|
return (
|
|
21
32
|
<Menu
|
|
22
33
|
anchorEl={anchorEl}
|
|
@@ -40,7 +51,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
40
51
|
!tableInstance.getToggleHideAllColumnsProps().checked &&
|
|
41
52
|
!tableInstance.getToggleHideAllColumnsProps().indeterminate
|
|
42
53
|
}
|
|
43
|
-
onClick={
|
|
54
|
+
onClick={hideAllColumns}
|
|
44
55
|
>
|
|
45
56
|
{localization.hideAll}
|
|
46
57
|
</Button>
|
|
@@ -43,7 +43,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
43
43
|
componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
|
|
44
44
|
checked={switchChecked}
|
|
45
45
|
control={<Switch />}
|
|
46
|
-
disabled={isSubMenu && switchChecked}
|
|
46
|
+
disabled={(isSubMenu && switchChecked) || column.disableColumnHiding}
|
|
47
47
|
label={column.Header as string}
|
|
48
48
|
onChange={() => handleToggleColumnHidden(column)}
|
|
49
49
|
/>
|
|
@@ -9,18 +9,11 @@ interface Props {
|
|
|
9
9
|
export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
|
|
10
10
|
const { muiTableBodyCellProps } = useMRT();
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const tableCellProps =
|
|
13
13
|
muiTableBodyCellProps instanceof Function
|
|
14
14
|
? muiTableBodyCellProps()
|
|
15
15
|
: muiTableBodyCellProps;
|
|
16
16
|
|
|
17
|
-
const tableCellProps = {
|
|
18
|
-
...mTableBodyCellrops,
|
|
19
|
-
style: {
|
|
20
|
-
...mTableBodyCellrops?.style,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
17
|
return (
|
|
25
18
|
<TableCell {...tableCellProps} sx={{ width, ...tableCellProps?.sx }} />
|
|
26
19
|
);
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { MRT_ColumnInterface } from '.';
|
|
1
|
+
import { MRT_ColumnInstance, MRT_ColumnInterface } from '.';
|
|
2
2
|
|
|
3
|
-
export const findLowestLevelCols = (
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const findLowestLevelCols = (
|
|
4
|
+
columns: MRT_ColumnInterface[] | MRT_ColumnInstance[],
|
|
5
|
+
) => {
|
|
6
|
+
let lowestLevelColumns: MRT_ColumnInterface[] | MRT_ColumnInstance[] =
|
|
7
|
+
columns;
|
|
8
|
+
let currentCols: MRT_ColumnInterface[] | MRT_ColumnInstance[] | undefined =
|
|
9
|
+
columns;
|
|
6
10
|
while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
|
|
7
11
|
const nextCols: MRT_ColumnInterface[] = currentCols
|
|
8
12
|
.filter((col) => !!col.columns)
|