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
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import { TableCell } from '@mui/material';
|
|
1
|
+
import React, { FC, MouseEvent } from 'react';
|
|
2
|
+
import { styled, TableCell as MuiTableCell } from '@mui/material';
|
|
3
3
|
import { Cell } from 'react-table';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
+
import { MRT_EditCellTextfield } from '../inputs/MRT_EditCellTextfield';
|
|
6
|
+
|
|
7
|
+
const TableCell = styled(MuiTableCell, {
|
|
8
|
+
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
9
|
+
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
10
|
+
padding: densePadding ? '0.5rem' : '1rem',
|
|
11
|
+
transition: 'all 0.2s ease-in-out',
|
|
12
|
+
}));
|
|
5
13
|
|
|
6
14
|
interface Props {
|
|
7
15
|
cell: Cell;
|
|
@@ -9,17 +17,53 @@ interface Props {
|
|
|
9
17
|
|
|
10
18
|
export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
|
|
11
19
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
onCellClick,
|
|
21
|
+
muiTableBodyCellProps,
|
|
22
|
+
densePadding,
|
|
23
|
+
currentEditingRow,
|
|
14
24
|
} = useMaterialReactTable();
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
const mTableCellBodyProps =
|
|
27
|
+
muiTableBodyCellProps instanceof Function
|
|
28
|
+
? muiTableBodyCellProps(cell)
|
|
29
|
+
: muiTableBodyCellProps;
|
|
30
|
+
|
|
31
|
+
const mcTableCellBodyProps =
|
|
32
|
+
cell.column.muiTableBodyCellProps instanceof Function
|
|
33
|
+
? cell.column.muiTableBodyCellProps(cell)
|
|
34
|
+
: cell.column.muiTableBodyCellProps;
|
|
35
|
+
|
|
36
|
+
const tableCellProps = {
|
|
37
|
+
...mTableCellBodyProps,
|
|
38
|
+
...mcTableCellBodyProps,
|
|
39
|
+
...cell.getCellProps(),
|
|
40
|
+
style: {
|
|
41
|
+
...cell.getCellProps().style,
|
|
42
|
+
...(mTableCellBodyProps?.style ?? {}),
|
|
43
|
+
...(mcTableCellBodyProps?.style ?? {}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
19
46
|
|
|
20
47
|
return (
|
|
21
|
-
<TableCell
|
|
22
|
-
{
|
|
48
|
+
<TableCell
|
|
49
|
+
densePadding={densePadding}
|
|
50
|
+
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
51
|
+
onCellClick?.(event, cell)
|
|
52
|
+
}
|
|
53
|
+
{...tableCellProps}
|
|
54
|
+
>
|
|
55
|
+
{currentEditingRow?.id === cell.row.id ? (
|
|
56
|
+
<MRT_EditCellTextfield cell={cell} />
|
|
57
|
+
) : cell.isPlaceholder ? null : cell.isAggregated ? (
|
|
58
|
+
cell.render('Aggregated')
|
|
59
|
+
) : cell.isGrouped ? (
|
|
60
|
+
<span>
|
|
61
|
+
{cell.render('Cell')} ({cell.row.subRows.length})
|
|
62
|
+
</span>
|
|
63
|
+
) : (
|
|
64
|
+
cell.render('Cell')
|
|
65
|
+
)}
|
|
66
|
+
{}
|
|
23
67
|
</TableCell>
|
|
24
68
|
);
|
|
25
69
|
};
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import React, { FC, MouseEvent } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
alpha,
|
|
4
|
+
styled,
|
|
5
|
+
TableCell,
|
|
6
|
+
TableRow as MuiTableRow,
|
|
7
|
+
} from '@mui/material';
|
|
3
8
|
import { Row } from 'react-table';
|
|
4
9
|
import { MRT_TableBodyCell } from './MRT_TableBodyCell';
|
|
5
10
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
11
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
|
7
12
|
import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
|
|
8
13
|
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
|
9
|
-
import {
|
|
14
|
+
import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
|
|
15
|
+
|
|
16
|
+
export const TableRow = styled(MuiTableRow, {
|
|
17
|
+
shouldForwardProp: (prop) => prop !== 'isSelected',
|
|
18
|
+
})<{ isSelected?: boolean }>(({ isSelected, theme }) => ({
|
|
19
|
+
backgroundColor: isSelected
|
|
20
|
+
? alpha(theme.palette.primary.light, 0.1)
|
|
21
|
+
: 'transparent',
|
|
22
|
+
}));
|
|
10
23
|
|
|
11
24
|
interface Props {
|
|
12
25
|
row: Row;
|
|
@@ -14,41 +27,56 @@ interface Props {
|
|
|
14
27
|
|
|
15
28
|
export const MRT_TableBodyRow: FC<Props> = ({ row }) => {
|
|
16
29
|
const {
|
|
17
|
-
OverrideTableBodyRowComponent,
|
|
18
30
|
anyRowsCanExpand,
|
|
31
|
+
enableRowActions,
|
|
19
32
|
enableSelection,
|
|
20
|
-
|
|
21
|
-
enableColumnHiding,
|
|
33
|
+
muiTableBodyRowProps,
|
|
22
34
|
onRowClick,
|
|
35
|
+
positionActionsColumn,
|
|
23
36
|
renderDetailPanel,
|
|
24
|
-
tableInstance,
|
|
25
37
|
} = useMaterialReactTable();
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
const mTableBodyRowProps =
|
|
40
|
+
muiTableBodyRowProps instanceof Function
|
|
41
|
+
? muiTableBodyRowProps(row)
|
|
42
|
+
: muiTableBodyRowProps;
|
|
43
|
+
|
|
44
|
+
const tableRowProps = {
|
|
45
|
+
...mTableBodyRowProps,
|
|
46
|
+
...row.getRowProps(),
|
|
47
|
+
style: {
|
|
48
|
+
...row.getRowProps().style,
|
|
49
|
+
...(mTableBodyRowProps?.style ?? {}),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
30
52
|
|
|
31
53
|
return (
|
|
32
54
|
<>
|
|
33
55
|
<TableRow
|
|
56
|
+
isSelected={row.isSelected}
|
|
57
|
+
hover
|
|
34
58
|
onClick={(event: MouseEvent<HTMLTableRowElement>) =>
|
|
35
59
|
onRowClick?.(event, row)
|
|
36
60
|
}
|
|
37
|
-
{...
|
|
61
|
+
{...tableRowProps}
|
|
38
62
|
>
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
{enableRowActions && positionActionsColumn === 'first' && (
|
|
64
|
+
<TableCell>
|
|
65
|
+
<MRT_ToggleRowActionMenuButton row={row} />
|
|
66
|
+
</TableCell>
|
|
67
|
+
)}
|
|
68
|
+
{(anyRowsCanExpand || renderDetailPanel) && (
|
|
69
|
+
<MRT_ExpandButton row={row} />
|
|
70
|
+
)}
|
|
47
71
|
{enableSelection && <MRT_SelectCheckbox row={row} />}
|
|
48
|
-
{row.cells.map((cell
|
|
49
|
-
<MRT_TableBodyCell key={
|
|
72
|
+
{row.cells.map((cell) => (
|
|
73
|
+
<MRT_TableBodyCell key={cell.getCellProps().key} cell={cell} />
|
|
50
74
|
))}
|
|
51
|
-
{
|
|
75
|
+
{enableRowActions && positionActionsColumn === 'last' && (
|
|
76
|
+
<TableCell>
|
|
77
|
+
<MRT_ToggleRowActionMenuButton row={row} />
|
|
78
|
+
</TableCell>
|
|
79
|
+
)}
|
|
52
80
|
</TableRow>
|
|
53
81
|
{renderDetailPanel && <MRT_TableDetailPanel row={row} />}
|
|
54
82
|
</>
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { FC, MouseEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Collapse,
|
|
4
|
+
styled,
|
|
5
|
+
TableCell as MuiTableCell,
|
|
6
|
+
TableRow,
|
|
7
|
+
} from '@mui/material';
|
|
3
8
|
import { Row } from 'react-table';
|
|
4
9
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
10
|
|
|
11
|
+
const TableCell = styled(MuiTableCell, {
|
|
12
|
+
shouldForwardProp: (prop) => prop !== 'isExpanded',
|
|
13
|
+
})<{ isExpanded?: boolean }>(({ isExpanded }) => ({
|
|
14
|
+
borderBottom: !isExpanded ? 'none' : undefined,
|
|
15
|
+
paddingBottom: isExpanded ? '1rem' : 0,
|
|
16
|
+
paddingTop: isExpanded ? '1rem' : 0,
|
|
17
|
+
transition: 'all 0.2s ease-in-out',
|
|
18
|
+
}));
|
|
19
|
+
|
|
6
20
|
interface Props {
|
|
7
21
|
row: Row;
|
|
8
22
|
}
|
|
@@ -11,25 +25,46 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row }) => {
|
|
|
11
25
|
const {
|
|
12
26
|
tableInstance,
|
|
13
27
|
renderDetailPanel,
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
muiTableDetailPanelProps,
|
|
29
|
+
muiTableBodyRowProps,
|
|
30
|
+
onDetailPanelClick,
|
|
16
31
|
} = useMaterialReactTable();
|
|
17
32
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
const mTableBodyRowProps =
|
|
34
|
+
muiTableBodyRowProps instanceof Function
|
|
35
|
+
? muiTableBodyRowProps(row)
|
|
36
|
+
: muiTableBodyRowProps;
|
|
37
|
+
|
|
38
|
+
const tableRowProps = {
|
|
39
|
+
...mTableBodyRowProps,
|
|
40
|
+
...row.getToggleRowExpandedProps(),
|
|
41
|
+
style: {
|
|
42
|
+
...row.getToggleRowExpandedProps().style,
|
|
43
|
+
...(mTableBodyRowProps?.style ?? {}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const mTableDetailPanelProps =
|
|
48
|
+
muiTableDetailPanelProps instanceof Function
|
|
49
|
+
? muiTableDetailPanelProps(row)
|
|
50
|
+
: muiTableDetailPanelProps;
|
|
51
|
+
|
|
52
|
+
const tableCellProps = {
|
|
53
|
+
...mTableDetailPanelProps,
|
|
54
|
+
style: {
|
|
55
|
+
...(mTableDetailPanelProps?.style ?? {}),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
21
58
|
|
|
22
59
|
return (
|
|
23
|
-
<TableRow {...
|
|
60
|
+
<TableRow hover {...tableRowProps}>
|
|
24
61
|
<TableCell
|
|
25
62
|
colSpan={tableInstance.visibleColumns.length + 10}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}}
|
|
32
|
-
{...tableDetailPanelProps}
|
|
63
|
+
isExpanded={row.isExpanded}
|
|
64
|
+
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
65
|
+
onDetailPanelClick?.(event, row)
|
|
66
|
+
}
|
|
67
|
+
{...tableCellProps}
|
|
33
68
|
>
|
|
34
69
|
<Collapse in={row.isExpanded}>{renderDetailPanel?.(row)}</Collapse>
|
|
35
70
|
</TableCell>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { IconButton, styled, Tooltip } from '@mui/material';
|
|
3
|
+
import SaveIcon from '@mui/icons-material/Save';
|
|
4
|
+
import CancelIcon from '@mui/icons-material/Cancel';
|
|
5
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
|
+
import { Row } from 'react-table';
|
|
7
|
+
|
|
8
|
+
const EditActionButtonWrappers = styled('div')({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
gap: '0.75rem',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
row: Row;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const MRT_EditActionButtons: FC<Props> = ({ row }) => {
|
|
18
|
+
const {
|
|
19
|
+
localization,
|
|
20
|
+
setCurrentEditingRow,
|
|
21
|
+
onRowEditSubmit,
|
|
22
|
+
currentEditingRow,
|
|
23
|
+
} = useMaterialReactTable();
|
|
24
|
+
|
|
25
|
+
const handleCancel = () => {
|
|
26
|
+
setCurrentEditingRow(null);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handleSave = async () => {
|
|
30
|
+
await onRowEditSubmit?.(currentEditingRow ?? row);
|
|
31
|
+
setCurrentEditingRow(null);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<EditActionButtonWrappers>
|
|
36
|
+
<Tooltip arrow title={localization?.rowActionButtonCancel ?? ''}>
|
|
37
|
+
<IconButton
|
|
38
|
+
aria-label={localization?.rowActionButtonCancel}
|
|
39
|
+
onClick={handleCancel}
|
|
40
|
+
>
|
|
41
|
+
<CancelIcon />
|
|
42
|
+
</IconButton>
|
|
43
|
+
</Tooltip>
|
|
44
|
+
<Tooltip arrow title={localization?.rowActionButtonSave ?? ''}>
|
|
45
|
+
<IconButton
|
|
46
|
+
aria-label={localization?.rowActionButtonSave}
|
|
47
|
+
color="info"
|
|
48
|
+
onClick={handleSave}
|
|
49
|
+
>
|
|
50
|
+
<SaveIcon />
|
|
51
|
+
</IconButton>
|
|
52
|
+
</Tooltip>
|
|
53
|
+
</EditActionButtonWrappers>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { IconButton, TableCell } from '@mui/material';
|
|
3
|
-
import
|
|
2
|
+
import { IconButton, styled, TableCell } from '@mui/material';
|
|
3
|
+
import MuiArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
|
|
6
|
+
const ArrowRightIcon = styled(MuiArrowRightIcon, {
|
|
7
|
+
shouldForwardProp: (prop) => prop !== 'rotation',
|
|
8
|
+
})<{ rotation?: number }>(({ rotation }) => ({
|
|
9
|
+
transform: `rotate(${rotation}deg)`,
|
|
10
|
+
transition: 'transform 0.2s',
|
|
11
|
+
}));
|
|
12
|
+
|
|
6
13
|
interface Props {}
|
|
7
14
|
|
|
8
15
|
export const MRT_ExpandAllButton: FC<Props> = () => {
|
|
9
|
-
const {
|
|
10
|
-
|
|
16
|
+
const {
|
|
17
|
+
tableInstance,
|
|
18
|
+
localization,
|
|
19
|
+
anyRowsExpanded,
|
|
20
|
+
densePadding,
|
|
21
|
+
renderDetailPanel,
|
|
22
|
+
} = useMaterialReactTable();
|
|
11
23
|
|
|
12
24
|
return (
|
|
13
25
|
<TableCell
|
|
14
26
|
size="small"
|
|
15
27
|
{...tableInstance.getToggleAllRowsExpandedProps()}
|
|
16
28
|
style={{
|
|
17
|
-
padding: '0.5rem',
|
|
18
|
-
|
|
19
|
-
width: `${tableInstance.expandedDepth + 2}rem`,
|
|
29
|
+
padding: densePadding ? '0' : '0.5rem 0.5rem',
|
|
30
|
+
transition: 'all 0.2s ease-in-out',
|
|
31
|
+
width: `${renderDetailPanel ? 2 : tableInstance.expandedDepth + 2}rem`,
|
|
20
32
|
}}
|
|
21
33
|
>
|
|
22
34
|
<IconButton
|
|
@@ -25,14 +37,9 @@ export const MRT_ExpandAllButton: FC<Props> = () => {
|
|
|
25
37
|
>
|
|
26
38
|
<ArrowRightIcon
|
|
27
39
|
fontSize="small"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
: anyRowsExpanded
|
|
32
|
-
? 'rotate(-90deg)'
|
|
33
|
-
: 'rotate(0)',
|
|
34
|
-
transition: 'transform 0.2s',
|
|
35
|
-
}}
|
|
40
|
+
rotation={
|
|
41
|
+
tableInstance.isAllRowsExpanded ? -180 : anyRowsExpanded ? -90 : 0
|
|
42
|
+
}
|
|
36
43
|
/>
|
|
37
44
|
</IconButton>
|
|
38
45
|
</TableCell>
|
|
@@ -1,37 +1,49 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { IconButton, TableCell } from '@mui/material';
|
|
2
|
+
import { IconButton, styled, TableCell as MuiTableCell } from '@mui/material';
|
|
3
3
|
import { Row } from 'react-table';
|
|
4
|
-
import
|
|
4
|
+
import MuiExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
5
5
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
6
|
|
|
7
|
+
const TableCell = styled(MuiTableCell, {
|
|
8
|
+
shouldForwardProp: (prop) => prop !== 'densePadding' && prop !== 'depth',
|
|
9
|
+
})<{ densePadding?: boolean; depth: number }>(({ densePadding, depth }) => ({
|
|
10
|
+
padding: densePadding ? '0' : '0.6rem',
|
|
11
|
+
paddingLeft: `${depth + 0.5}rem`,
|
|
12
|
+
transition: 'all 0.2s ease-in-out',
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const ExpandMoreIcon = styled(MuiExpandMoreIcon, {
|
|
16
|
+
shouldForwardProp: (prop) => prop !== 'rotation',
|
|
17
|
+
})<{ rotation?: number }>(({ rotation }) => ({
|
|
18
|
+
transform: `rotate(${rotation}deg)`,
|
|
19
|
+
transition: 'transform 0.2s',
|
|
20
|
+
}));
|
|
21
|
+
|
|
7
22
|
interface Props {
|
|
8
23
|
row: Row;
|
|
9
24
|
}
|
|
10
25
|
|
|
11
26
|
export const MRT_ExpandButton: FC<Props> = ({ row }) => {
|
|
12
|
-
const { localization,
|
|
27
|
+
const { localization, densePadding, renderDetailPanel } =
|
|
28
|
+
useMaterialReactTable();
|
|
13
29
|
|
|
14
30
|
return (
|
|
15
|
-
<TableCell
|
|
16
|
-
size="small"
|
|
17
|
-
{...row.getToggleRowExpandedProps()}
|
|
18
|
-
style={{
|
|
19
|
-
padding: '0.5rem',
|
|
20
|
-
paddingRight: '0',
|
|
21
|
-
paddingLeft: `${row.depth + 0.5}rem`,
|
|
22
|
-
width: `${tableInstance.expandedDepth - row.depth + 2}rem`,
|
|
23
|
-
}}
|
|
24
|
-
>
|
|
31
|
+
<TableCell size="small" densePadding={densePadding} depth={row.depth}>
|
|
25
32
|
<IconButton
|
|
26
33
|
aria-label={localization?.expandButtonTitle}
|
|
34
|
+
disabled={!row.canExpand && !renderDetailPanel}
|
|
27
35
|
title={localization?.expandButtonTitle}
|
|
36
|
+
{...row.getToggleRowExpandedProps()}
|
|
28
37
|
>
|
|
29
38
|
<ExpandMoreIcon
|
|
30
|
-
fontSize=
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
fontSize={row.canExpand || renderDetailPanel ? 'medium' : 'small'}
|
|
40
|
+
rotation={
|
|
41
|
+
!row.canExpand && !renderDetailPanel
|
|
42
|
+
? -90
|
|
43
|
+
: row.isExpanded
|
|
44
|
+
? -180
|
|
45
|
+
: 0
|
|
46
|
+
}
|
|
35
47
|
/>
|
|
36
48
|
</IconButton>
|
|
37
49
|
</TableCell>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
|
-
import { IconButton, Menu,
|
|
2
|
+
import { IconButton, Menu, Tooltip } from '@mui/material';
|
|
3
3
|
import ViewColumnIcon from '@mui/icons-material/ViewColumn';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
|
|
@@ -16,16 +16,16 @@ export const MRT_ShowHideColumnsButton: FC<Props> = () => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</
|
|
19
|
+
<>
|
|
20
|
+
<Tooltip arrow title={localization?.showHideColumnsButtonTitle ?? ''}>
|
|
21
|
+
<IconButton
|
|
22
|
+
aria-label={localization?.showHideColumnsButtonTitle}
|
|
23
|
+
onClick={handleClick}
|
|
24
|
+
size="small"
|
|
25
|
+
>
|
|
26
|
+
<ViewColumnIcon />
|
|
27
|
+
</IconButton>
|
|
28
|
+
</Tooltip>
|
|
29
29
|
<Menu
|
|
30
30
|
anchorEl={anchorEl}
|
|
31
31
|
open={!!anchorEl}
|
|
@@ -38,6 +38,6 @@ export const MRT_ShowHideColumnsButton: FC<Props> = () => {
|
|
|
38
38
|
/>
|
|
39
39
|
))}
|
|
40
40
|
</Menu>
|
|
41
|
-
|
|
41
|
+
</>
|
|
42
42
|
);
|
|
43
43
|
};
|
|
@@ -6,9 +6,11 @@ import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
|
|
|
6
6
|
import { HeaderGroup } from 'react-table';
|
|
7
7
|
|
|
8
8
|
const IconButton = styled(MuiIconButton)({
|
|
9
|
-
opacity: 0.
|
|
9
|
+
opacity: 0.5,
|
|
10
10
|
transition: 'opacity 0.2s',
|
|
11
11
|
marginRight: '2px',
|
|
12
|
+
height: '2rem',
|
|
13
|
+
width: '2rem',
|
|
12
14
|
'&:hover': {
|
|
13
15
|
opacity: 1,
|
|
14
16
|
},
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import FilterListIcon from '@mui/icons-material/FilterList';
|
|
5
|
+
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
|
6
|
+
|
|
7
|
+
type Props = {};
|
|
8
|
+
|
|
9
|
+
export const MRT_ToggleFiltersButton: FC<Props> = () => {
|
|
10
|
+
const { localization, setShowFilters, showFilters } = useMaterialReactTable();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Tooltip arrow title={localization?.toggleFilterButtonTitle ?? ''}>
|
|
14
|
+
<IconButton
|
|
15
|
+
aria-label={localization?.toggleFilterButtonTitle}
|
|
16
|
+
onClick={() => setShowFilters(!showFilters)}
|
|
17
|
+
size="small"
|
|
18
|
+
>
|
|
19
|
+
{showFilters ? <FilterListOffIcon /> : <FilterListIcon />}
|
|
20
|
+
</IconButton>
|
|
21
|
+
</Tooltip>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
|
+
import { IconButton as MuiIconButton, styled } from '@mui/material';
|
|
3
|
+
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
4
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
+
import { Row } from 'react-table';
|
|
6
|
+
import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
|
|
7
|
+
import { MRT_EditActionButtons } from './MRT_EditActionButtons';
|
|
8
|
+
|
|
9
|
+
const IconButton = styled(MuiIconButton)({
|
|
10
|
+
opacity: 0.5,
|
|
11
|
+
transition: 'opacity 0.2s',
|
|
12
|
+
marginRight: '2px',
|
|
13
|
+
height: '2rem',
|
|
14
|
+
width: '2rem',
|
|
15
|
+
'&:hover': {
|
|
16
|
+
opacity: 1,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
row: Row;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
|
|
25
|
+
const {
|
|
26
|
+
localization,
|
|
27
|
+
currentEditingRow,
|
|
28
|
+
renderRowActions,
|
|
29
|
+
tableInstance,
|
|
30
|
+
} = useMaterialReactTable();
|
|
31
|
+
|
|
32
|
+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
33
|
+
|
|
34
|
+
const handleOpenRowActionMenu = (event: MouseEvent<HTMLElement>) => {
|
|
35
|
+
event.stopPropagation();
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
setAnchorEl(event.currentTarget);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (renderRowActions) {
|
|
41
|
+
return <>{renderRowActions(row, tableInstance)}</>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (row.id === currentEditingRow?.id) {
|
|
45
|
+
return <MRT_EditActionButtons row={row} />;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<IconButton
|
|
51
|
+
aria-label={localization?.rowActionMenuButtonTitle}
|
|
52
|
+
title={localization?.rowActionMenuButtonTitle}
|
|
53
|
+
onClick={handleOpenRowActionMenu}
|
|
54
|
+
size="small"
|
|
55
|
+
>
|
|
56
|
+
<MoreHorizIcon />
|
|
57
|
+
</IconButton>
|
|
58
|
+
<MRT_RowActionMenu
|
|
59
|
+
anchorEl={anchorEl}
|
|
60
|
+
row={row}
|
|
61
|
+
setAnchorEl={setAnchorEl}
|
|
62
|
+
/>
|
|
63
|
+
</>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -2,35 +2,20 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { TableFooter } from '@mui/material';
|
|
3
3
|
import { MRT_TableFooterRow } from './MRT_TableFooterRow';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
-
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
6
5
|
|
|
7
6
|
interface Props {}
|
|
8
7
|
|
|
9
8
|
export const MRT_TableFooter: FC<Props> = () => {
|
|
10
|
-
const {
|
|
11
|
-
OverrideTableFooterComponent,
|
|
12
|
-
enablePagination,
|
|
13
|
-
positionPagination,
|
|
14
|
-
tableFooterProps,
|
|
15
|
-
tableInstance,
|
|
16
|
-
} = useMaterialReactTable();
|
|
17
|
-
|
|
18
|
-
if (OverrideTableFooterComponent) {
|
|
19
|
-
return <>{OverrideTableFooterComponent(tableInstance)}</>;
|
|
20
|
-
}
|
|
9
|
+
const { muiTableFooterProps, tableInstance } = useMaterialReactTable();
|
|
21
10
|
|
|
22
11
|
return (
|
|
23
|
-
<TableFooter {...
|
|
24
|
-
{tableInstance.footerGroups.map((footerGroup
|
|
12
|
+
<TableFooter {...muiTableFooterProps}>
|
|
13
|
+
{tableInstance.footerGroups.map((footerGroup) => (
|
|
25
14
|
<MRT_TableFooterRow
|
|
26
|
-
key={
|
|
15
|
+
key={footerGroup.getFooterGroupProps().key}
|
|
27
16
|
footerGroup={footerGroup}
|
|
28
17
|
/>
|
|
29
18
|
))}
|
|
30
|
-
{enablePagination &&
|
|
31
|
-
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
32
|
-
<MRT_TablePagination />
|
|
33
|
-
)}
|
|
34
19
|
</TableFooter>
|
|
35
20
|
);
|
|
36
21
|
};
|