material-react-table 0.4.6 → 0.4.9
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 +3 -2
- package/dist/MaterialReactTable.d.ts +68 -23
- package/dist/body/MRT_TableBodyCell.d.ts +2 -2
- package/dist/body/MRT_TableBodyRow.d.ts +2 -2
- package/dist/body/MRT_TableDetailPanel.d.ts +2 -2
- package/dist/buttons/MRT_EditActionButtons.d.ts +2 -2
- package/dist/buttons/MRT_ExpandButton.d.ts +2 -2
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +2 -2
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -2
- package/dist/footer/MRT_TableFooterCell.d.ts +2 -2
- package/dist/footer/MRT_TableFooterRow.d.ts +2 -2
- package/dist/head/MRT_TableHeadCell.d.ts +2 -2
- package/dist/head/MRT_TableHeadRow.d.ts +2 -2
- package/dist/inputs/MRT_EditCellTextField.d.ts +2 -2
- package/dist/inputs/MRT_FilterTextField.d.ts +2 -2
- package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -2
- package/dist/material-react-table.cjs.development.js +42 -26
- 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 +43 -27
- 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 +2 -2
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -2
- package/dist/useMRT.d.ts +4 -4
- package/package.json +1 -1
- package/src/@types/react-table-config.d.ts +18 -121
- package/src/MaterialReactTable.tsx +183 -23
- package/src/body/MRT_TableBody.tsx +2 -1
- package/src/body/MRT_TableBodyCell.tsx +2 -2
- package/src/body/MRT_TableBodyRow.tsx +6 -4
- package/src/body/MRT_TableDetailPanel.tsx +9 -16
- package/src/buttons/MRT_EditActionButtons.tsx +2 -2
- package/src/buttons/MRT_ExpandButton.tsx +2 -2
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +2 -1
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +3 -3
- package/src/footer/MRT_TableFooter.tsx +2 -1
- package/src/footer/MRT_TableFooterCell.tsx +2 -2
- package/src/footer/MRT_TableFooterRow.tsx +3 -3
- package/src/head/MRT_TableHead.tsx +2 -1
- package/src/head/MRT_TableHeadCell.tsx +2 -2
- package/src/head/MRT_TableHeadRow.tsx +3 -3
- package/src/index.tsx +2 -0
- package/src/inputs/MRT_EditCellTextField.tsx +2 -2
- package/src/inputs/MRT_FilterTextField.tsx +3 -2
- package/src/inputs/MRT_SelectCheckbox.tsx +3 -3
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
- package/src/menus/MRT_RowActionMenu.tsx +2 -2
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +3 -2
- package/src/table/MRT_TableContainer.tsx +19 -1
- package/src/useMRT.tsx +18 -15
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
TableCell as MuiTableCell,
|
|
6
6
|
TableRow,
|
|
7
7
|
} from '@mui/material';
|
|
8
|
-
import { Row } from 'react-table';
|
|
9
8
|
import { useMRT } from '../useMRT';
|
|
9
|
+
import { MRT_Row } from '..';
|
|
10
10
|
|
|
11
11
|
const TableCell = styled(MuiTableCell, {
|
|
12
12
|
shouldForwardProp: (prop) => prop !== 'isExpanded',
|
|
@@ -18,16 +18,16 @@ const TableCell = styled(MuiTableCell, {
|
|
|
18
18
|
}));
|
|
19
19
|
|
|
20
20
|
interface Props {
|
|
21
|
-
row:
|
|
21
|
+
row: MRT_Row;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export const MRT_TableDetailPanel: FC<Props> = ({ row }) => {
|
|
25
25
|
const {
|
|
26
|
-
tableInstance,
|
|
27
|
-
renderDetailPanel,
|
|
28
|
-
muiTableDetailPanelProps,
|
|
29
26
|
muiTableBodyRowProps,
|
|
27
|
+
muiTableDetailPanelProps,
|
|
30
28
|
onDetailPanelClick,
|
|
29
|
+
renderDetailPanel,
|
|
30
|
+
tableInstance,
|
|
31
31
|
} = useMRT();
|
|
32
32
|
|
|
33
33
|
const mTableBodyRowProps =
|
|
@@ -37,27 +37,20 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row }) => {
|
|
|
37
37
|
|
|
38
38
|
const tableRowProps = {
|
|
39
39
|
...mTableBodyRowProps,
|
|
40
|
-
...row.
|
|
40
|
+
...row.getRowProps(),
|
|
41
41
|
style: {
|
|
42
|
-
...row.
|
|
42
|
+
...row.getRowProps().style,
|
|
43
43
|
...(mTableBodyRowProps?.style ?? {}),
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const
|
|
47
|
+
const tableCellProps =
|
|
48
48
|
muiTableDetailPanelProps instanceof Function
|
|
49
49
|
? muiTableDetailPanelProps(row)
|
|
50
50
|
: muiTableDetailPanelProps;
|
|
51
51
|
|
|
52
|
-
const tableCellProps = {
|
|
53
|
-
...mTableDetailPanelProps,
|
|
54
|
-
style: {
|
|
55
|
-
...(mTableDetailPanelProps?.style ?? {}),
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
52
|
return (
|
|
60
|
-
<TableRow
|
|
53
|
+
<TableRow {...tableRowProps}>
|
|
61
54
|
<TableCell
|
|
62
55
|
colSpan={tableInstance.visibleColumns.length + 10}
|
|
63
56
|
isExpanded={row.isExpanded}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { IconButton, styled, Tooltip } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
|
-
import {
|
|
4
|
+
import { MRT_Row } from '..';
|
|
5
5
|
|
|
6
6
|
const EditActionButtonWrappers = styled('div')({
|
|
7
7
|
display: 'flex',
|
|
@@ -9,7 +9,7 @@ const EditActionButtonWrappers = styled('div')({
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
|
-
row:
|
|
12
|
+
row: MRT_Row;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export const MRT_EditActionButtons: FC<Props> = ({ row }) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { IconButton, styled } from '@mui/material';
|
|
3
|
-
import { Row } from 'react-table';
|
|
4
3
|
import { useMRT } from '../useMRT';
|
|
5
4
|
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
5
|
+
import { MRT_Row } from '..';
|
|
6
6
|
|
|
7
7
|
const TableCell = styled(MRT_TableButtonCell, {
|
|
8
8
|
shouldForwardProp: (prop) => prop !== 'depth',
|
|
@@ -12,7 +12,7 @@ const TableCell = styled(MRT_TableButtonCell, {
|
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
15
|
-
row:
|
|
15
|
+
row: MRT_Row;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const MRT_ExpandButton: FC<Props> = ({ row }) => {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '@mui/material';
|
|
11
11
|
import { useMRT } from '../useMRT';
|
|
12
12
|
import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
|
|
13
|
+
import { MRT_ColumnInstance } from '..';
|
|
13
14
|
|
|
14
15
|
const MenuButtons = styled('div')({
|
|
15
16
|
display: 'flex',
|
|
@@ -67,7 +68,7 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
|
|
|
67
68
|
</Button>
|
|
68
69
|
</MenuButtons>
|
|
69
70
|
<Divider />
|
|
70
|
-
{tableInstance.columns.map((column, index) => (
|
|
71
|
+
{tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
|
|
71
72
|
<MRT_ShowHideColumnsMenu
|
|
72
73
|
key={`${index}-${column.id}`}
|
|
73
74
|
column={column}
|
|
@@ -2,7 +2,7 @@ import React, { FC, MouseEvent, useState } from 'react';
|
|
|
2
2
|
import { IconButton as MuiIconButton, styled, Tooltip } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
4
|
import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
|
|
5
|
-
import {
|
|
5
|
+
import { MRT_HeaderGroup } from '..';
|
|
6
6
|
|
|
7
7
|
const IconButton = styled(MuiIconButton)({
|
|
8
8
|
opacity: 0.5,
|
|
@@ -16,7 +16,7 @@ const IconButton = styled(MuiIconButton)({
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
interface Props {
|
|
19
|
-
column:
|
|
19
|
+
column: MRT_HeaderGroup;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
2
|
import { IconButton as MuiIconButton, styled, Tooltip } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
|
-
import { Row } from 'react-table';
|
|
5
4
|
import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
|
|
6
5
|
import { MRT_EditActionButtons } from './MRT_EditActionButtons';
|
|
7
6
|
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
7
|
+
import { MRT_Row } from '..';
|
|
8
8
|
|
|
9
9
|
const IconButton = styled(MuiIconButton)({
|
|
10
10
|
opacity: 0.5,
|
|
@@ -18,7 +18,7 @@ const IconButton = styled(MuiIconButton)({
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
interface Props {
|
|
21
|
-
row:
|
|
21
|
+
row: MRT_Row;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
|
|
@@ -26,7 +26,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
|
|
|
26
26
|
currentEditingRow,
|
|
27
27
|
densePadding,
|
|
28
28
|
enableRowEditing,
|
|
29
|
-
icons: {EditIcon, MoreHorizIcon},
|
|
29
|
+
icons: { EditIcon, MoreHorizIcon },
|
|
30
30
|
localization,
|
|
31
31
|
renderRowActionMenuItems,
|
|
32
32
|
renderRowActions,
|
|
@@ -2,6 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { TableFooter } from '@mui/material';
|
|
3
3
|
import { MRT_TableFooterRow } from './MRT_TableFooterRow';
|
|
4
4
|
import { useMRT } from '../useMRT';
|
|
5
|
+
import { MRT_HeaderGroup } from '..';
|
|
5
6
|
|
|
6
7
|
interface Props {}
|
|
7
8
|
|
|
@@ -10,7 +11,7 @@ export const MRT_TableFooter: FC<Props> = () => {
|
|
|
10
11
|
|
|
11
12
|
return (
|
|
12
13
|
<TableFooter {...muiTableFooterProps}>
|
|
13
|
-
{tableInstance.footerGroups.map((footerGroup) => (
|
|
14
|
+
{tableInstance.footerGroups.map((footerGroup: MRT_HeaderGroup) => (
|
|
14
15
|
<MRT_TableFooterRow
|
|
15
16
|
key={footerGroup.getFooterGroupProps().key}
|
|
16
17
|
footerGroup={footerGroup}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { styled, TableCell as MuiTableCell } from '@mui/material';
|
|
3
|
-
import { HeaderGroup } from 'react-table';
|
|
4
3
|
import { useMRT } from '../useMRT';
|
|
4
|
+
import { MRT_HeaderGroup } from '..';
|
|
5
5
|
|
|
6
6
|
const TableCell = styled(MuiTableCell, {
|
|
7
7
|
shouldForwardProp: (prop) =>
|
|
@@ -16,7 +16,7 @@ const TableCell = styled(MuiTableCell, {
|
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
interface Props {
|
|
19
|
-
column:
|
|
19
|
+
column: MRT_HeaderGroup;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { TableRow } from '@mui/material';
|
|
3
|
-
import { HeaderGroup } from 'react-table';
|
|
4
3
|
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
|
|
5
4
|
import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
|
|
6
5
|
import { useMRT } from '../useMRT';
|
|
6
|
+
import { MRT_HeaderGroup } from '..';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
footerGroup:
|
|
9
|
+
footerGroup: MRT_HeaderGroup;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
|
|
@@ -53,7 +53,7 @@ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
|
|
|
53
53
|
/>
|
|
54
54
|
)}
|
|
55
55
|
{enableSelection && <MRT_TableSpacerCell width="1rem" />}
|
|
56
|
-
{footerGroup.headers.map((column) => (
|
|
56
|
+
{footerGroup.headers.map((column: MRT_HeaderGroup) => (
|
|
57
57
|
<MRT_TableFooterCell
|
|
58
58
|
key={column.getFooterProps().key}
|
|
59
59
|
column={column}
|
|
@@ -2,6 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { TableHead } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadRow } from './MRT_TableHeadRow';
|
|
4
4
|
import { useMRT } from '../useMRT';
|
|
5
|
+
import { MRT_HeaderGroup } from '..';
|
|
5
6
|
|
|
6
7
|
interface Props {}
|
|
7
8
|
|
|
@@ -15,7 +16,7 @@ export const MRT_TableHead: FC<Props> = () => {
|
|
|
15
16
|
|
|
16
17
|
return (
|
|
17
18
|
<TableHead {...tableHeadProps}>
|
|
18
|
-
{tableInstance.headerGroups.map((headerGroup) => (
|
|
19
|
+
{tableInstance.headerGroups.map((headerGroup: MRT_HeaderGroup) => (
|
|
19
20
|
<MRT_TableHeadRow
|
|
20
21
|
key={headerGroup.getHeaderGroupProps().key}
|
|
21
22
|
headerGroup={headerGroup}
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
Collapse,
|
|
8
8
|
Tooltip,
|
|
9
9
|
} from '@mui/material';
|
|
10
|
-
import { HeaderGroup } from 'react-table';
|
|
11
10
|
import { useMRT } from '../useMRT';
|
|
12
11
|
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
13
12
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
13
|
+
import { MRT_HeaderGroup } from '..';
|
|
14
14
|
|
|
15
15
|
export const MRT_StyledTableHeadCell = styled(MuiTableCell, {
|
|
16
16
|
shouldForwardProp: (prop) =>
|
|
@@ -52,7 +52,7 @@ const Divider = styled(MuiDivider)({
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
interface Props {
|
|
55
|
-
column:
|
|
55
|
+
column: MRT_HeaderGroup;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { TableRow } from '@mui/material';
|
|
3
|
-
import { HeaderGroup } from 'react-table';
|
|
4
3
|
import {
|
|
5
4
|
MRT_StyledTableHeadCell,
|
|
6
5
|
MRT_TableHeadCell,
|
|
@@ -10,9 +9,10 @@ import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
|
|
10
9
|
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
11
10
|
import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
|
|
12
11
|
import { MRT_TableHeadCellActions } from './MRT_TableHeadCellActions';
|
|
12
|
+
import { MRT_HeaderGroup } from '..';
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
15
|
-
headerGroup:
|
|
15
|
+
headerGroup: MRT_HeaderGroup;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
@@ -81,7 +81,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
|
81
81
|
<MRT_TableSpacerCell width="1rem" />
|
|
82
82
|
)
|
|
83
83
|
) : null}
|
|
84
|
-
{headerGroup.headers.map((column:
|
|
84
|
+
{headerGroup.headers.map((column: MRT_HeaderGroup) => (
|
|
85
85
|
<MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
|
|
86
86
|
))}
|
|
87
87
|
{(enableRowActions || enableRowEditing) &&
|
package/src/index.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
2
|
import { TextField } from '@mui/material';
|
|
3
|
-
import { Cell } from 'react-table';
|
|
4
3
|
import { useMRT } from '../useMRT';
|
|
4
|
+
import { MRT_Cell } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
|
-
cell:
|
|
7
|
+
cell: MRT_Cell;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
2
|
import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { useAsyncDebounce } from 'react-table';
|
|
4
4
|
import { useMRT } from '../useMRT';
|
|
5
|
+
import { MRT_HeaderGroup } from '..';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
|
-
column:
|
|
8
|
+
column: MRT_HeaderGroup;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
2
|
import { Checkbox, Tooltip } from '@mui/material';
|
|
3
|
-
import { Row } from 'react-table';
|
|
4
3
|
import { useMRT } from '../useMRT';
|
|
5
4
|
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
5
|
+
import { MRT_Row } from '..';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
|
-
row?:
|
|
8
|
+
row?: MRT_Row;
|
|
9
9
|
selectAll?: boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -20,8 +20,8 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
|
20
20
|
|
|
21
21
|
const onSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
22
22
|
if (selectAll) {
|
|
23
|
+
tableInstance?.getToggleAllRowsSelectedProps?.()?.onChange?.(event);
|
|
23
24
|
onSelectAllChange?.(event, tableInstance.selectedFlatRows);
|
|
24
|
-
tableInstance.toggleAllRowsSelected(event.target.checked);
|
|
25
25
|
} else if (row) {
|
|
26
26
|
row?.getToggleRowSelectedProps()?.onChange?.(event);
|
|
27
27
|
onRowSelectChange?.(event, row, tableInstance.selectedFlatRows);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
|
-
import {
|
|
4
|
+
import { MRT_HeaderGroup } from '..';
|
|
5
5
|
|
|
6
6
|
const MenuItem = styled(MuiMenuItem)({
|
|
7
7
|
display: 'flex',
|
|
@@ -10,7 +10,7 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
anchorEl: HTMLElement | null;
|
|
13
|
-
column:
|
|
13
|
+
column: MRT_HeaderGroup;
|
|
14
14
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
|
-
import {
|
|
4
|
+
import { MRT_Row } from '..';
|
|
5
5
|
|
|
6
6
|
const MenuItem = styled(MuiMenuItem)({
|
|
7
7
|
display: 'flex',
|
|
@@ -10,7 +10,7 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
anchorEl: HTMLElement | null;
|
|
13
|
-
row:
|
|
13
|
+
row: MRT_Row;
|
|
14
14
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
15
15
|
handleEdit: () => void;
|
|
16
16
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
3
|
import { ColumnInstance } from 'react-table';
|
|
4
|
+
import { MRT_ColumnInstance } from '..';
|
|
4
5
|
|
|
5
6
|
interface Props {
|
|
6
|
-
column:
|
|
7
|
+
column: MRT_ColumnInstance;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
|
|
@@ -35,7 +36,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
|
|
|
35
36
|
onChange={() => handleToggleColumnHidden(column)}
|
|
36
37
|
/>
|
|
37
38
|
</MenuItem>
|
|
38
|
-
{column.columns?.map((c, i) => (
|
|
39
|
+
{column.columns?.map((c: MRT_ColumnInstance, i) => (
|
|
39
40
|
<MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
|
|
40
41
|
))}
|
|
41
42
|
</>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { FC, useEffect, useRef } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
CircularProgress,
|
|
4
4
|
LinearProgress,
|
|
@@ -50,6 +50,24 @@ export const MRT_TableContainer: FC<Props> = () => {
|
|
|
50
50
|
muiTableContainerProps,
|
|
51
51
|
tableInstance,
|
|
52
52
|
} = useMRT();
|
|
53
|
+
const originalBodyOverflowStyle = useRef<string | undefined>();
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (typeof window !== 'undefined') {
|
|
57
|
+
originalBodyOverflowStyle.current = document?.body?.style?.overflow;
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (typeof window !== 'undefined') {
|
|
63
|
+
if (fullScreen) {
|
|
64
|
+
document.body.style.overflow = 'hidden';
|
|
65
|
+
} else {
|
|
66
|
+
document.body.style.overflow =
|
|
67
|
+
originalBodyOverflowStyle.current ?? 'auto';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, [fullScreen]);
|
|
53
71
|
|
|
54
72
|
const tableContainerProps =
|
|
55
73
|
muiTableContainerProps instanceof Function
|
package/src/useMRT.tsx
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
Context,
|
|
3
|
-
createContext,
|
|
4
3
|
PropsWithChildren,
|
|
4
|
+
createContext,
|
|
5
5
|
useContext,
|
|
6
6
|
useMemo,
|
|
7
7
|
useState,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import {
|
|
10
10
|
PluginHook,
|
|
11
|
-
Row,
|
|
12
|
-
TableInstance,
|
|
13
11
|
useExpanded,
|
|
14
12
|
useFilters,
|
|
15
13
|
useFlexLayout,
|
|
@@ -21,6 +19,7 @@ import {
|
|
|
21
19
|
useSortBy,
|
|
22
20
|
useTable,
|
|
23
21
|
} from 'react-table';
|
|
22
|
+
import { MRT_Row, MRT_TableInstance } from '.';
|
|
24
23
|
import { MRT_Icons } from './icons';
|
|
25
24
|
import { MRT_Localization } from './localization';
|
|
26
25
|
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
@@ -28,19 +27,19 @@ import { MaterialReactTableProps } from './MaterialReactTable';
|
|
|
28
27
|
export type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
29
28
|
anyRowsCanExpand: boolean;
|
|
30
29
|
anyRowsExpanded: boolean;
|
|
31
|
-
currentEditingRow:
|
|
30
|
+
currentEditingRow: MRT_Row<D> | null;
|
|
32
31
|
densePadding: boolean;
|
|
33
32
|
fullScreen: boolean;
|
|
34
33
|
icons: MRT_Icons;
|
|
35
34
|
localization: MRT_Localization;
|
|
36
|
-
setCurrentEditingRow: (currentRowEditingId:
|
|
35
|
+
setCurrentEditingRow: (currentRowEditingId: MRT_Row<D> | null) => void;
|
|
37
36
|
setDensePadding: (densePadding: boolean) => void;
|
|
38
37
|
setFullScreen: (fullScreen: boolean) => void;
|
|
39
38
|
setShowFilters: (showFilters: boolean) => void;
|
|
40
39
|
setShowSearch: (showSearch: boolean) => void;
|
|
41
40
|
showFilters: boolean;
|
|
42
41
|
showSearch: boolean;
|
|
43
|
-
tableInstance:
|
|
42
|
+
tableInstance: MRT_TableInstance<D>;
|
|
44
43
|
};
|
|
45
44
|
|
|
46
45
|
const MaterialReactTableContext = (<D extends {}>() =>
|
|
@@ -62,28 +61,32 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
62
61
|
if (props.enableColumnResizing)
|
|
63
62
|
hooks.unshift(useResizeColumns, useFlexLayout);
|
|
64
63
|
|
|
65
|
-
const tableInstance = useTable<D>(props, ...hooks)
|
|
64
|
+
const tableInstance = useTable<D>(props, ...hooks) as MRT_TableInstance<D>;
|
|
66
65
|
|
|
67
66
|
const anyRowsCanExpand = useMemo(
|
|
68
|
-
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
() => tableInstance.rows.some((row: MRT_Row) => row.canExpand),
|
|
69
69
|
[tableInstance.rows],
|
|
70
70
|
);
|
|
71
71
|
const anyRowsExpanded = useMemo(
|
|
72
|
-
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
() => tableInstance.rows.some((row: MRT_Row) => row.isExpanded),
|
|
73
74
|
[tableInstance.rows],
|
|
74
75
|
);
|
|
75
|
-
const [currentEditingRow, setCurrentEditingRow] = useState<
|
|
76
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
|
|
77
|
+
null,
|
|
78
|
+
);
|
|
76
79
|
const [densePadding, setDensePadding] = useState(
|
|
77
|
-
props.
|
|
80
|
+
props.initialState?.densePadding ?? false,
|
|
78
81
|
);
|
|
79
82
|
const [fullScreen, setFullScreen] = useState(
|
|
80
|
-
props.
|
|
83
|
+
props.initialState?.fullScreen ?? false,
|
|
81
84
|
);
|
|
82
85
|
const [showFilters, setShowFilters] = useState(
|
|
83
|
-
props.
|
|
86
|
+
props.initialState?.showFilters ?? false,
|
|
84
87
|
);
|
|
85
88
|
const [showSearch, setShowSearch] = useState(
|
|
86
|
-
props.
|
|
89
|
+
props.initialState?.showSearchTextField ?? false,
|
|
87
90
|
);
|
|
88
91
|
|
|
89
92
|
return (
|
|
@@ -112,5 +115,5 @@ export const MaterialReactTableProvider = <D extends {}>(
|
|
|
112
115
|
};
|
|
113
116
|
|
|
114
117
|
export const useMRT = <D extends {}>(): UseMRT<D> =>
|
|
115
|
-
|
|
118
|
+
// @ts-ignore
|
|
116
119
|
useContext<UseMRT<D>>(MaterialReactTableContext);
|