material-react-table 0.4.7 → 0.5.0
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 +66 -21
- package/dist/body/MRT_TableBodyCell.d.ts +12 -5
- package/dist/body/MRT_TableBodyRow.d.ts +3 -18
- 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 +10 -6
- 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 +412 -485
- 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 +416 -489
- 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 +3 -3
- package/src/@types/react-table-config.d.ts +18 -121
- package/src/MaterialReactTable.tsx +181 -21
- package/src/body/MRT_TableBody.tsx +8 -8
- package/src/body/MRT_TableBodyCell.tsx +22 -13
- package/src/body/MRT_TableBodyRow.tsx +20 -17
- package/src/body/MRT_TableDetailPanel.tsx +12 -29
- package/src/buttons/MRT_EditActionButtons.tsx +5 -10
- package/src/buttons/MRT_ExpandAllButton.tsx +5 -5
- package/src/buttons/MRT_ExpandButton.tsx +12 -12
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +11 -10
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +13 -14
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +11 -10
- package/src/footer/MRT_TableFooter.tsx +2 -1
- package/src/footer/MRT_TableFooterCell.tsx +12 -19
- package/src/footer/MRT_TableFooterRow.tsx +4 -4
- package/src/head/MRT_TableHead.tsx +2 -1
- package/src/head/MRT_TableHeadCell.tsx +49 -56
- package/src/head/MRT_TableHeadCellActions.tsx +5 -4
- package/src/head/MRT_TableHeadRow.tsx +8 -7
- 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_SearchTextField.tsx +2 -11
- package/src/inputs/MRT_SelectCheckbox.tsx +6 -6
- package/src/menus/MRT_ColumnActionMenu.tsx +19 -8
- package/src/menus/MRT_RowActionMenu.tsx +4 -9
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +4 -3
- package/src/table/MRT_Table.tsx +1 -1
- package/src/table/MRT_TableContainer.tsx +19 -44
- package/src/table/MRT_TableSpacerCell.tsx +4 -3
- package/src/toolbar/MRT_TablePagination.tsx +6 -1
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +19 -29
- package/src/toolbar/MRT_ToolbarBottom.tsx +23 -20
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +13 -12
- package/src/toolbar/MRT_ToolbarTop.tsx +38 -35
- package/src/useMRT.tsx +18 -15
- package/dist/table/MRT_TableButtonCell.d.ts +0 -3
- package/src/table/MRT_TableButtonCell.tsx +0 -9
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { alpha,
|
|
2
|
+
import { alpha, Toolbar } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
4
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
5
5
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
6
6
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
7
7
|
|
|
8
|
-
const Toolbar = styled(MuiToolbar, {
|
|
9
|
-
shouldForwardProp: (prop) => prop !== 'fullScreen',
|
|
10
|
-
})<{ fullScreen?: boolean }>(({ fullScreen, theme }) => ({
|
|
11
|
-
backgroundColor: theme.palette.background.default,
|
|
12
|
-
backgroundImage: `linear-gradient(${alpha(
|
|
13
|
-
theme.palette.common.white,
|
|
14
|
-
0.05,
|
|
15
|
-
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
16
|
-
bottom: fullScreen ? '0' : undefined,
|
|
17
|
-
display: 'flex',
|
|
18
|
-
justifyContent: 'space-between',
|
|
19
|
-
overflowY: 'hidden',
|
|
20
|
-
padding: '0 0.5rem !important',
|
|
21
|
-
position: fullScreen ? 'fixed' : undefined,
|
|
22
|
-
width: 'calc(100% - 1rem)',
|
|
23
|
-
zIndex: 1,
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
8
|
interface Props {}
|
|
27
9
|
|
|
28
10
|
export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
@@ -43,7 +25,28 @@ export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
|
43
25
|
: muiTableToolbarBottomProps;
|
|
44
26
|
|
|
45
27
|
return (
|
|
46
|
-
<Toolbar
|
|
28
|
+
<Toolbar
|
|
29
|
+
variant="dense"
|
|
30
|
+
{...toolbarProps}
|
|
31
|
+
sx={(theme) =>
|
|
32
|
+
({
|
|
33
|
+
backgroundColor: theme.palette.background.default,
|
|
34
|
+
backgroundImage: `linear-gradient(${alpha(
|
|
35
|
+
theme.palette.common.white,
|
|
36
|
+
0.05,
|
|
37
|
+
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
38
|
+
bottom: fullScreen ? '0' : undefined,
|
|
39
|
+
display: 'flex',
|
|
40
|
+
justifyContent: 'space-between',
|
|
41
|
+
overflowY: 'hidden',
|
|
42
|
+
p: '0 0.5rem !important',
|
|
43
|
+
position: fullScreen ? 'fixed' : undefined,
|
|
44
|
+
width: 'calc(100% - 1rem)',
|
|
45
|
+
zIndex: 1,
|
|
46
|
+
...toolbarProps?.sx,
|
|
47
|
+
} as any)
|
|
48
|
+
}
|
|
49
|
+
>
|
|
47
50
|
{!hideToolbarInternalActions && positionToolbarActions === 'bottom' ? (
|
|
48
51
|
<MRT_ToolbarInternalButtons />
|
|
49
52
|
) : (
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { MRT_FullScreenToggleButton } from '../buttons/MRT_FullScreenToggleButton';
|
|
4
4
|
import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
|
|
5
|
-
import { useMRT } from '../useMRT';
|
|
6
5
|
import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingButton';
|
|
6
|
+
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
7
7
|
import { MRT_ToggleSearchButton } from '../buttons/MRT_ToggleSearchButton';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const ToolbarButtonsContainer = styled('div')({
|
|
11
|
-
display: 'flex',
|
|
12
|
-
gap: '0.5rem',
|
|
13
|
-
alignItems: 'center',
|
|
14
|
-
});
|
|
8
|
+
import { useMRT } from '../useMRT';
|
|
15
9
|
|
|
16
10
|
interface Props {}
|
|
17
11
|
|
|
@@ -41,12 +35,19 @@ export const MRT_ToolbarInternalButtons: FC<Props> = () => {
|
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
return (
|
|
44
|
-
<
|
|
38
|
+
<Box
|
|
39
|
+
sx={{
|
|
40
|
+
display: 'flex',
|
|
41
|
+
gap: '0.5rem',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
p: '0 0.5rem',
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
45
46
|
{!disableGlobalFilter && <MRT_ToggleSearchButton />}
|
|
46
47
|
{!disableFilters && <MRT_ToggleFiltersButton />}
|
|
47
48
|
{!disableColumnHiding && <MRT_ShowHideColumnsButton />}
|
|
48
49
|
{!disableDensePaddingToggle && <MRT_ToggleDensePaddingButton />}
|
|
49
50
|
{!disableFullScreenToggle && <MRT_FullScreenToggleButton />}
|
|
50
|
-
</
|
|
51
|
+
</Box>
|
|
51
52
|
);
|
|
52
53
|
};
|
|
@@ -1,40 +1,11 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { alpha,
|
|
2
|
+
import { alpha, Box, Toolbar } from '@mui/material';
|
|
3
3
|
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
4
|
import { useMRT } from '../useMRT';
|
|
5
5
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
6
6
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
7
7
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
8
8
|
|
|
9
|
-
const Toolbar = styled(MuiToolbar, {
|
|
10
|
-
shouldForwardProp: (prop) => prop !== 'fullScreen',
|
|
11
|
-
})<{ fullScreen?: boolean }>(({ fullScreen, theme }) => ({
|
|
12
|
-
backgroundColor: theme.palette.background.default,
|
|
13
|
-
backgroundImage: `linear-gradient(${alpha(
|
|
14
|
-
theme.palette.common.white,
|
|
15
|
-
0.05,
|
|
16
|
-
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
17
|
-
display: 'grid',
|
|
18
|
-
padding: '0 0.5rem !important',
|
|
19
|
-
position: fullScreen ? 'sticky' : undefined,
|
|
20
|
-
top: fullScreen ? '0' : undefined,
|
|
21
|
-
width: 'calc(100% - 1rem)',
|
|
22
|
-
zIndex: 1,
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const ToolbarTopRow = styled('div')({
|
|
26
|
-
padding: '0.5rem',
|
|
27
|
-
display: 'flex',
|
|
28
|
-
justifyContent: 'space-between',
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const ToolbarActionsContainer = styled('div')({
|
|
32
|
-
display: 'flex',
|
|
33
|
-
gap: '0.5rem',
|
|
34
|
-
position: 'relative',
|
|
35
|
-
zIndex: 3,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
9
|
interface Props {}
|
|
39
10
|
|
|
40
11
|
export const MRT_ToolbarTop: FC<Props> = () => {
|
|
@@ -57,17 +28,49 @@ export const MRT_ToolbarTop: FC<Props> = () => {
|
|
|
57
28
|
: muiTableToolbarTopProps;
|
|
58
29
|
|
|
59
30
|
return (
|
|
60
|
-
<Toolbar
|
|
31
|
+
<Toolbar
|
|
32
|
+
variant="dense"
|
|
33
|
+
{...toolbarProps}
|
|
34
|
+
sx={(theme) =>
|
|
35
|
+
({
|
|
36
|
+
backgroundColor: theme.palette.background.default,
|
|
37
|
+
backgroundImage: `linear-gradient(${alpha(
|
|
38
|
+
theme.palette.common.white,
|
|
39
|
+
0.05,
|
|
40
|
+
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
41
|
+
display: 'grid',
|
|
42
|
+
p: '0 !important',
|
|
43
|
+
position: fullScreen ? 'sticky' : undefined,
|
|
44
|
+
top: fullScreen ? '0' : undefined,
|
|
45
|
+
width: '100%',
|
|
46
|
+
zIndex: 1,
|
|
47
|
+
...toolbarProps?.sx,
|
|
48
|
+
} as any)
|
|
49
|
+
}
|
|
50
|
+
>
|
|
61
51
|
{positionToolbarAlertBanner === 'top' && <MRT_ToolbarAlertBanner />}
|
|
62
|
-
<
|
|
52
|
+
<Box
|
|
53
|
+
sx={{
|
|
54
|
+
p: '0.5rem',
|
|
55
|
+
display: 'flex',
|
|
56
|
+
justifyContent: 'space-between',
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
63
59
|
{renderToolbarCustomActions?.(tableInstance) ?? <span />}
|
|
64
|
-
<
|
|
60
|
+
<Box
|
|
61
|
+
sx={{
|
|
62
|
+
display: 'flex',
|
|
63
|
+
gap: '0.5rem',
|
|
64
|
+
position: 'relative',
|
|
65
|
+
zIndex: 3,
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
65
68
|
{!disableGlobalFilter && <MRT_SearchTextField />}
|
|
66
69
|
{!hideToolbarInternalActions && positionToolbarActions === 'top' && (
|
|
67
70
|
<MRT_ToolbarInternalButtons />
|
|
68
71
|
)}
|
|
69
|
-
</
|
|
70
|
-
</
|
|
72
|
+
</Box>
|
|
73
|
+
</Box>
|
|
71
74
|
<div>
|
|
72
75
|
{!manualPagination &&
|
|
73
76
|
['top', 'both'].includes(positionPagination ?? '') && (
|
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);
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}));
|