material-react-table 0.6.10 → 0.7.0-alpha.1
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 +142 -82
- package/dist/body/MRT_TableBody.d.ts +3 -0
- package/dist/body/MRT_TableBodyCell.d.ts +2 -11
- package/dist/body/MRT_TableBodyRow.d.ts +3 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/buttons/MRT_CopyButton.d.ts +4 -2
- package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
- package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
- package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
- package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
- package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
- package/dist/footer/MRT_TableFooter.d.ts +3 -0
- package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
- package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
- package/dist/head/MRT_TableHead.d.ts +3 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -18
- package/dist/head/MRT_TableHeadRow.d.ts +2 -1
- package/dist/icons.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
- package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
- package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
- package/dist/localization.d.ts +7 -2
- package/dist/material-react-table.cjs.development.js +2142 -1729
- 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 +2143 -1730
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
- package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
- package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
- package/dist/table/MRT_Table.d.ts +3 -0
- package/dist/table/MRT_TableContainer.d.ts +2 -0
- package/dist/table/MRT_TablePaper.d.ts +7 -0
- package/dist/table/MRT_TableRoot.d.ts +3 -0
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
- package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
- package/dist/utils.d.ts +12 -2
- package/package.json +27 -28
- package/src/MaterialReactTable.tsx +298 -242
- package/src/body/MRT_TableBody.tsx +25 -21
- package/src/body/MRT_TableBodyCell.tsx +73 -58
- package/src/body/MRT_TableBodyRow.tsx +35 -74
- package/src/body/MRT_TableDetailPanel.tsx +16 -14
- package/src/buttons/MRT_CopyButton.tsx +14 -7
- package/src/buttons/MRT_EditActionButtons.tsx +13 -12
- package/src/buttons/MRT_ExpandAllButton.tsx +24 -9
- package/src/buttons/MRT_ExpandButton.tsx +21 -14
- package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +17 -9
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
- package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +26 -21
- package/src/buttons/MRT_ToggleSearchButton.tsx +18 -11
- package/src/footer/MRT_TableFooter.tsx +23 -7
- package/src/footer/MRT_TableFooterCell.tsx +32 -24
- package/src/footer/MRT_TableFooterRow.tsx +20 -38
- package/src/head/MRT_TableHead.tsx +23 -7
- package/src/head/MRT_TableHeadCell.tsx +201 -152
- package/src/head/MRT_TableHeadRow.tsx +15 -103
- package/src/icons.ts +3 -3
- package/src/inputs/MRT_EditCellTextField.tsx +23 -24
- package/src/inputs/MRT_FilterTextField.tsx +51 -30
- package/src/inputs/MRT_SearchTextField.tsx +38 -21
- package/src/inputs/MRT_SelectCheckbox.tsx +34 -24
- package/src/localization.ts +13 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
- package/src/menus/MRT_FilterTypeMenu.tsx +28 -22
- package/src/menus/MRT_RowActionMenu.tsx +16 -11
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +28 -17
- package/src/table/MRT_Table.tsx +24 -14
- package/src/table/MRT_TableContainer.tsx +109 -44
- package/src/table/MRT_TablePaper.tsx +61 -0
- package/src/table/MRT_TableRoot.tsx +236 -0
- package/src/toolbar/MRT_LinearProgressBar.tsx +9 -6
- package/src/toolbar/MRT_TablePagination.tsx +28 -18
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +31 -19
- package/src/toolbar/MRT_ToolbarBottom.tsx +31 -20
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +29 -16
- package/src/toolbar/MRT_ToolbarTop.tsx +34 -27
- package/src/utils.ts +37 -8
- package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
- package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
- package/dist/useMRT.d.ts +0 -28
- package/src/@types/faker.d.ts +0 -4
- package/src/@types/react-table-config.d.ts +0 -53
- package/src/head/MRT_TableHeadCellActions.tsx +0 -29
- package/src/table/MRT_TableSpacerCell.tsx +0 -20
- package/src/useMRT.tsx +0 -226
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
2
|
import { TablePagination } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
5
|
+
interface Props {
|
|
6
|
+
tableInstance: MRT_TableInstance;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
|
-
export const MRT_TablePagination: FC<Props> = () => {
|
|
8
|
-
const {
|
|
9
|
+
export const MRT_TablePagination: FC<Props> = ({ tableInstance }) => {
|
|
10
|
+
const {
|
|
11
|
+
getPrePaginationRowModel,
|
|
12
|
+
getState,
|
|
13
|
+
setPageIndex,
|
|
14
|
+
setPageSize,
|
|
15
|
+
options: { muiTablePaginationProps },
|
|
16
|
+
} = tableInstance;
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
pagination: { pageSize = 10, pageIndex = 0 },
|
|
20
|
+
} = getState();
|
|
9
21
|
|
|
10
22
|
const tablePaginationProps =
|
|
11
23
|
muiTablePaginationProps instanceof Function
|
|
@@ -13,25 +25,23 @@ export const MRT_TablePagination: FC<Props> = () => {
|
|
|
13
25
|
: muiTablePaginationProps;
|
|
14
26
|
|
|
15
27
|
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
|
16
|
-
|
|
17
|
-
tableInstance.gotoPage(0);
|
|
28
|
+
setPageSize(+event.target.value);
|
|
18
29
|
};
|
|
19
30
|
|
|
31
|
+
const showFirstLastPageButtons =
|
|
32
|
+
getPrePaginationRowModel().rows.length / pageSize > 2;
|
|
33
|
+
|
|
20
34
|
return (
|
|
21
35
|
<TablePagination
|
|
22
|
-
component=
|
|
23
|
-
count={
|
|
24
|
-
onPageChange={(_, newPage) =>
|
|
36
|
+
component="div"
|
|
37
|
+
count={getPrePaginationRowModel().rows.length}
|
|
38
|
+
onPageChange={(_: any, newPage: number) => setPageIndex(newPage)}
|
|
25
39
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
26
|
-
page={
|
|
27
|
-
rowsPerPage={
|
|
28
|
-
SelectProps={{
|
|
29
|
-
showFirstButton={
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
showLastButton={
|
|
33
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
34
|
-
}
|
|
40
|
+
page={pageIndex}
|
|
41
|
+
rowsPerPage={pageSize}
|
|
42
|
+
SelectProps={{ sx: { m: '0 1rem 0 1ch' } }}
|
|
43
|
+
showFirstButton={showFirstLastPageButtons}
|
|
44
|
+
showLastButton={showFirstLastPageButtons}
|
|
35
45
|
{...tablePaginationProps}
|
|
36
46
|
sx={{
|
|
37
47
|
m: '0 0.5rem',
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import React, { FC, Fragment } from 'react';
|
|
2
2
|
import { Alert, Box, Chip, Collapse, useMediaQuery } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
5
|
+
interface Props {
|
|
6
|
+
tableInstance: MRT_TableInstance;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
|
-
export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
9
|
+
export const MRT_ToolbarAlertBanner: FC<Props> = ({ tableInstance }) => {
|
|
8
10
|
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
getPrePaginationRowModel,
|
|
12
|
+
getSelectedRowModel,
|
|
13
|
+
getState,
|
|
14
|
+
toggleColumnGrouping,
|
|
15
|
+
options: {
|
|
16
|
+
localization,
|
|
17
|
+
muiTableToolbarAlertBannerProps,
|
|
18
|
+
positionToolbarActions,
|
|
19
|
+
positionToolbarAlertBanner,
|
|
20
|
+
renderToolbarCustomActions,
|
|
21
|
+
},
|
|
22
|
+
} = tableInstance;
|
|
23
|
+
|
|
24
|
+
const { grouping } = getState();
|
|
16
25
|
|
|
17
26
|
const isMobile = useMediaQuery('(max-width:720px)');
|
|
18
27
|
|
|
@@ -22,30 +31,33 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
|
22
31
|
: muiTableToolbarAlertBannerProps;
|
|
23
32
|
|
|
24
33
|
const selectMessage =
|
|
25
|
-
|
|
34
|
+
getSelectedRowModel().rows.length > 0
|
|
26
35
|
? localization.selectedCountOfRowCountRowsSelected
|
|
27
36
|
?.replace(
|
|
28
37
|
'{selectedCount}',
|
|
29
|
-
|
|
38
|
+
getSelectedRowModel().rows.length.toString(),
|
|
39
|
+
)
|
|
40
|
+
?.replace(
|
|
41
|
+
'{rowCount}',
|
|
42
|
+
getPrePaginationRowModel().rows.length.toString(),
|
|
30
43
|
)
|
|
31
|
-
?.replace('{rowCount}', tableInstance.flatRows.length.toString())
|
|
32
44
|
: null;
|
|
33
45
|
|
|
34
46
|
const groupedByMessage =
|
|
35
|
-
|
|
47
|
+
grouping.length > 0 ? (
|
|
36
48
|
<span>
|
|
37
49
|
{localization.groupedBy}{' '}
|
|
38
|
-
{
|
|
50
|
+
{grouping.map((columnId, index) => (
|
|
39
51
|
<Fragment key={`${index}-${columnId}`}>
|
|
40
52
|
{index > 0 ? localization.thenBy : ''}
|
|
41
53
|
<Chip
|
|
42
54
|
color="secondary"
|
|
43
55
|
label={
|
|
44
|
-
tableInstance
|
|
45
|
-
(
|
|
46
|
-
|
|
56
|
+
tableInstance
|
|
57
|
+
.getAllColumns()
|
|
58
|
+
.find((column) => column.id === columnId)?.header
|
|
47
59
|
}
|
|
48
|
-
onDelete={() =>
|
|
60
|
+
onDelete={() => toggleColumnGrouping(columnId)}
|
|
49
61
|
/>
|
|
50
62
|
</Fragment>
|
|
51
63
|
))}
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { Box, Toolbar } from '@mui/material';
|
|
3
|
-
import { useMRT } from '../useMRT';
|
|
2
|
+
import { alpha, Box, Toolbar } from '@mui/material';
|
|
4
3
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
5
4
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
6
5
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
7
6
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
8
7
|
import { commonToolbarStyles } from './MRT_ToolbarTop';
|
|
8
|
+
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
|
-
interface Props {
|
|
10
|
+
interface Props {
|
|
11
|
+
tableInstance: MRT_TableInstance;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
14
|
+
export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
13
15
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
getState,
|
|
17
|
+
options: {
|
|
18
|
+
hideToolbarInternalActions,
|
|
19
|
+
idPrefix,
|
|
20
|
+
enablePagination,
|
|
21
|
+
muiTableToolbarBottomProps,
|
|
22
|
+
positionPagination,
|
|
23
|
+
positionToolbarActions,
|
|
24
|
+
positionToolbarAlertBanner,
|
|
25
|
+
},
|
|
26
|
+
} = tableInstance;
|
|
27
|
+
|
|
28
|
+
const { isFullScreen } = getState();
|
|
22
29
|
|
|
23
30
|
const toolbarProps =
|
|
24
31
|
muiTableToolbarBottomProps instanceof Function
|
|
@@ -27,30 +34,34 @@ export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
|
27
34
|
|
|
28
35
|
return (
|
|
29
36
|
<Toolbar
|
|
37
|
+
id={`mrt-${idPrefix}-toolbar-bottom`}
|
|
30
38
|
variant="dense"
|
|
31
39
|
{...toolbarProps}
|
|
32
40
|
sx={(theme) =>
|
|
33
41
|
({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
...commonToolbarStyles({ theme }),
|
|
43
|
+
bottom: isFullScreen ? '0' : undefined,
|
|
44
|
+
position: isFullScreen ? 'fixed' : undefined,
|
|
45
|
+
boxShadow: `-3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
37
46
|
...toolbarProps?.sx,
|
|
38
47
|
} as any)
|
|
39
48
|
}
|
|
40
49
|
>
|
|
41
|
-
<MRT_LinearProgressBar />
|
|
50
|
+
<MRT_LinearProgressBar tableInstance={tableInstance} />
|
|
42
51
|
<Box
|
|
43
52
|
sx={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}
|
|
44
53
|
>
|
|
45
54
|
{!hideToolbarInternalActions && positionToolbarActions === 'bottom' ? (
|
|
46
|
-
<MRT_ToolbarInternalButtons />
|
|
55
|
+
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
47
56
|
) : (
|
|
48
57
|
<span />
|
|
49
58
|
)}
|
|
50
|
-
{positionToolbarAlertBanner === 'bottom' &&
|
|
51
|
-
|
|
59
|
+
{positionToolbarAlertBanner === 'bottom' && (
|
|
60
|
+
<MRT_ToolbarAlertBanner tableInstance={tableInstance} />
|
|
61
|
+
)}
|
|
62
|
+
{enablePagination &&
|
|
52
63
|
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
53
|
-
<MRT_TablePagination />
|
|
64
|
+
<MRT_TablePagination tableInstance={tableInstance} />
|
|
54
65
|
)}
|
|
55
66
|
</Box>
|
|
56
67
|
</Toolbar>
|
|
@@ -5,20 +5,23 @@ import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton'
|
|
|
5
5
|
import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingButton';
|
|
6
6
|
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
7
7
|
import { MRT_ToggleSearchButton } from '../buttons/MRT_ToggleSearchButton';
|
|
8
|
-
import {
|
|
8
|
+
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
|
-
interface Props {
|
|
10
|
+
interface Props {
|
|
11
|
+
tableInstance: MRT_TableInstance;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
export const MRT_ToolbarInternalButtons: FC<Props> = () => {
|
|
14
|
+
export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
13
15
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
options: {
|
|
17
|
+
enableColumnFilters,
|
|
18
|
+
enableHiding,
|
|
19
|
+
enableDensePaddingToggle,
|
|
20
|
+
enableGlobalFilter,
|
|
21
|
+
enableFullScreenToggle,
|
|
22
|
+
renderToolbarInternalActions,
|
|
23
|
+
},
|
|
24
|
+
} = tableInstance;
|
|
22
25
|
|
|
23
26
|
if (renderToolbarInternalActions) {
|
|
24
27
|
return (
|
|
@@ -43,11 +46,21 @@ export const MRT_ToolbarInternalButtons: FC<Props> = () => {
|
|
|
43
46
|
p: '0 0.5rem',
|
|
44
47
|
}}
|
|
45
48
|
>
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
|
|
49
|
+
{enableGlobalFilter && (
|
|
50
|
+
<MRT_ToggleSearchButton tableInstance={tableInstance} />
|
|
51
|
+
)}
|
|
52
|
+
{enableColumnFilters && (
|
|
53
|
+
<MRT_ToggleFiltersButton tableInstance={tableInstance} />
|
|
54
|
+
)}
|
|
55
|
+
{enableHiding && (
|
|
56
|
+
<MRT_ShowHideColumnsButton tableInstance={tableInstance} />
|
|
57
|
+
)}
|
|
58
|
+
{enableDensePaddingToggle && (
|
|
59
|
+
<MRT_ToggleDensePaddingButton tableInstance={tableInstance} />
|
|
60
|
+
)}
|
|
61
|
+
{enableFullScreenToggle && (
|
|
62
|
+
<MRT_FullScreenToggleButton tableInstance={tableInstance} />
|
|
63
|
+
)}
|
|
51
64
|
</Box>
|
|
52
65
|
);
|
|
53
66
|
};
|
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { alpha, Box, Theme, Toolbar } from '@mui/material';
|
|
3
3
|
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
|
-
import { useMRT } from '../useMRT';
|
|
5
4
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
6
5
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
7
6
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
8
7
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
9
8
|
import { MRT_TableInstance } from '..';
|
|
10
9
|
|
|
11
|
-
export const commonToolbarStyles = (
|
|
12
|
-
theme: Theme,
|
|
13
|
-
tableInstance: MRT_TableInstance,
|
|
14
|
-
) => ({
|
|
10
|
+
export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
15
11
|
backgroundColor: theme.palette.background.default,
|
|
16
12
|
backgroundImage: `linear-gradient(${alpha(
|
|
17
13
|
theme.palette.common.white,
|
|
18
14
|
0.05,
|
|
19
15
|
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
20
16
|
display: 'grid',
|
|
21
|
-
opacity: tableInstance.state.fullScreen ? 0.95 : 1,
|
|
22
17
|
p: '0 !important',
|
|
23
18
|
width: '100%',
|
|
24
19
|
zIndex: 1,
|
|
25
20
|
});
|
|
26
21
|
|
|
27
|
-
interface Props {
|
|
22
|
+
interface Props {
|
|
23
|
+
tableInstance: MRT_TableInstance;
|
|
24
|
+
}
|
|
28
25
|
|
|
29
|
-
export const MRT_ToolbarTop: FC<Props> = () => {
|
|
26
|
+
export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
30
27
|
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
getState,
|
|
29
|
+
options: {
|
|
30
|
+
enableGlobalFilter,
|
|
31
|
+
enablePagination,
|
|
32
|
+
hideToolbarInternalActions,
|
|
33
|
+
idPrefix,
|
|
34
|
+
muiTableToolbarTopProps,
|
|
35
|
+
positionPagination,
|
|
36
|
+
positionToolbarActions,
|
|
37
|
+
positionToolbarAlertBanner,
|
|
38
|
+
renderToolbarCustomActions,
|
|
39
|
+
},
|
|
40
|
+
} = tableInstance;
|
|
41
|
+
|
|
42
|
+
const { isFullScreen } = getState();
|
|
41
43
|
|
|
42
44
|
const toolbarProps =
|
|
43
45
|
muiTableToolbarTopProps instanceof Function
|
|
@@ -46,18 +48,21 @@ export const MRT_ToolbarTop: FC<Props> = () => {
|
|
|
46
48
|
|
|
47
49
|
return (
|
|
48
50
|
<Toolbar
|
|
51
|
+
id={`mrt-${idPrefix}-toolbar-top`}
|
|
49
52
|
variant="dense"
|
|
50
53
|
{...toolbarProps}
|
|
51
54
|
sx={(theme) =>
|
|
52
55
|
({
|
|
53
|
-
position:
|
|
54
|
-
top:
|
|
55
|
-
...commonToolbarStyles(theme
|
|
56
|
+
position: isFullScreen ? 'sticky' : undefined,
|
|
57
|
+
top: isFullScreen ? '0' : undefined,
|
|
58
|
+
...commonToolbarStyles({ theme }),
|
|
56
59
|
...toolbarProps?.sx,
|
|
57
60
|
} as any)
|
|
58
61
|
}
|
|
59
62
|
>
|
|
60
|
-
{positionToolbarAlertBanner === 'top' &&
|
|
63
|
+
{positionToolbarAlertBanner === 'top' && (
|
|
64
|
+
<MRT_ToolbarAlertBanner tableInstance={tableInstance} />
|
|
65
|
+
)}
|
|
61
66
|
<Box
|
|
62
67
|
sx={{
|
|
63
68
|
p: '0.5rem',
|
|
@@ -74,19 +79,21 @@ export const MRT_ToolbarTop: FC<Props> = () => {
|
|
|
74
79
|
zIndex: 3,
|
|
75
80
|
}}
|
|
76
81
|
>
|
|
77
|
-
{
|
|
82
|
+
{enableGlobalFilter && (
|
|
83
|
+
<MRT_SearchTextField tableInstance={tableInstance} />
|
|
84
|
+
)}
|
|
78
85
|
{!hideToolbarInternalActions && positionToolbarActions === 'top' && (
|
|
79
|
-
<MRT_ToolbarInternalButtons />
|
|
86
|
+
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
80
87
|
)}
|
|
81
88
|
</Box>
|
|
82
89
|
</Box>
|
|
83
90
|
<div>
|
|
84
|
-
{
|
|
91
|
+
{enablePagination &&
|
|
85
92
|
['top', 'both'].includes(positionPagination ?? '') && (
|
|
86
|
-
<MRT_TablePagination />
|
|
93
|
+
<MRT_TablePagination tableInstance={tableInstance} />
|
|
87
94
|
)}
|
|
88
95
|
</div>
|
|
89
|
-
<MRT_LinearProgressBar />
|
|
96
|
+
<MRT_LinearProgressBar tableInstance={tableInstance} />
|
|
90
97
|
</Toolbar>
|
|
91
98
|
);
|
|
92
99
|
};
|
package/src/utils.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
+
import { MRT_ColumnInterface, MRT_FilterType } from '.';
|
|
3
|
+
import { MRT_FILTER_TYPE } from './enums';
|
|
2
4
|
|
|
3
|
-
export const
|
|
4
|
-
columns: MRT_ColumnInterface[]
|
|
5
|
-
) => {
|
|
6
|
-
let lowestLevelColumns: MRT_ColumnInterface[]
|
|
7
|
-
|
|
8
|
-
let currentCols: MRT_ColumnInterface[] | MRT_ColumnInstance[] | undefined =
|
|
9
|
-
columns;
|
|
5
|
+
export const getAllLeafColumnDefs = (
|
|
6
|
+
columns: MRT_ColumnInterface[],
|
|
7
|
+
): MRT_ColumnInterface[] => {
|
|
8
|
+
let lowestLevelColumns: MRT_ColumnInterface[] = columns;
|
|
9
|
+
let currentCols: MRT_ColumnInterface[] | undefined = columns;
|
|
10
10
|
while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
|
|
11
11
|
const nextCols: MRT_ColumnInterface[] = currentCols
|
|
12
12
|
.filter((col) => !!col.columns)
|
|
@@ -19,3 +19,32 @@ export const findLowestLevelCols = (
|
|
|
19
19
|
}
|
|
20
20
|
return lowestLevelColumns.filter((col) => !col.columns);
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
export const createGroup = <D extends Record<string, any> = {}>(
|
|
24
|
+
table: Table<D>,
|
|
25
|
+
column: MRT_ColumnInterface<D>,
|
|
26
|
+
currentFilterTypes: { [key: string]: MRT_FilterType },
|
|
27
|
+
): ColumnDef<D> =>
|
|
28
|
+
table.createGroup({
|
|
29
|
+
...column,
|
|
30
|
+
columns: column?.columns?.map?.((col) =>
|
|
31
|
+
col.columns
|
|
32
|
+
? createGroup<D>(table, col, currentFilterTypes)
|
|
33
|
+
: createDataColumn(table, col, currentFilterTypes),
|
|
34
|
+
),
|
|
35
|
+
} as any);
|
|
36
|
+
|
|
37
|
+
export const createDataColumn = <D extends Record<string, any> = {}>(
|
|
38
|
+
table: Table<D>,
|
|
39
|
+
column: MRT_ColumnInterface<D>,
|
|
40
|
+
currentFilterTypes: { [key: string]: MRT_FilterType },
|
|
41
|
+
): ColumnDef<D> => // @ts-ignore
|
|
42
|
+
table.createDataColumn(column.id, {
|
|
43
|
+
filterType: currentFilterTypes[column.id] || MRT_FILTER_TYPE.BEST_MATCH,
|
|
44
|
+
...column,
|
|
45
|
+
}) as any;
|
|
46
|
+
|
|
47
|
+
export const createDisplayColumn = <D extends Record<string, any> = {}>(
|
|
48
|
+
table: Table<D>,
|
|
49
|
+
column: Omit<MRT_ColumnInterface<D>, 'header'> & { header?: string },
|
|
50
|
+
): ColumnDef<D> => table.createDisplayColumn(column);
|
package/dist/useMRT.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React, { Dispatch, PropsWithChildren, SetStateAction } from 'react';
|
|
2
|
-
import type { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
|
|
3
|
-
import { MRT_FILTER_TYPE } from './enums';
|
|
4
|
-
import { MRT_Icons } from './icons';
|
|
5
|
-
import { MRT_Localization } from './localization';
|
|
6
|
-
import { MaterialReactTableProps } from './MaterialReactTable';
|
|
7
|
-
export declare type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
8
|
-
anyRowsCanExpand: boolean;
|
|
9
|
-
anyRowsExpanded: boolean;
|
|
10
|
-
icons: MRT_Icons;
|
|
11
|
-
idPrefix: string;
|
|
12
|
-
filterTypes: {
|
|
13
|
-
[key in MRT_FILTER_TYPE]: any;
|
|
14
|
-
};
|
|
15
|
-
localization: MRT_Localization;
|
|
16
|
-
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
|
|
17
|
-
setCurrentFilterTypes: Dispatch<SetStateAction<{
|
|
18
|
-
[key: string]: MRT_FilterType;
|
|
19
|
-
}>>;
|
|
20
|
-
setCurrentGlobalFilterType: Dispatch<SetStateAction<MRT_FILTER_TYPE>>;
|
|
21
|
-
setDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
22
|
-
setFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
23
|
-
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
24
|
-
setShowSearch: Dispatch<SetStateAction<boolean>>;
|
|
25
|
-
tableInstance: MRT_TableInstance<D>;
|
|
26
|
-
};
|
|
27
|
-
export declare const MaterialReactTableProvider: <D extends {} = {}>(props: React.PropsWithChildren<MaterialReactTableProps<D>>) => JSX.Element;
|
|
28
|
-
export declare const useMRT: <D extends {} = {}>() => UseMRT<D>;
|
package/src/@types/faker.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
UseGroupByHooks,
|
|
3
|
-
UseRowSelectHooks,
|
|
4
|
-
UseSortByHooks,
|
|
5
|
-
} from 'react-table';
|
|
6
|
-
import {
|
|
7
|
-
MRT_Cell,
|
|
8
|
-
MRT_ColumnInstance,
|
|
9
|
-
MRT_ColumnInterface,
|
|
10
|
-
MRT_Row,
|
|
11
|
-
MRT_TableInstance,
|
|
12
|
-
MRT_TableOptions,
|
|
13
|
-
MRT_TableState,
|
|
14
|
-
} from '..';
|
|
15
|
-
|
|
16
|
-
declare module 'react-table' {
|
|
17
|
-
export interface TableOptions<D extends Record<string, unknown>>
|
|
18
|
-
extends MRT_TableOptions<D> {}
|
|
19
|
-
|
|
20
|
-
export interface Hooks<
|
|
21
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
22
|
-
> extends UseExpandedHooks<D>,
|
|
23
|
-
UseGroupByHooks<D>,
|
|
24
|
-
UseRowSelectHooks<D>,
|
|
25
|
-
UseSortByHooks<D> {}
|
|
26
|
-
|
|
27
|
-
export interface TableInstance<
|
|
28
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
29
|
-
> extends MRT_TableInstance<D> {
|
|
30
|
-
rows: MRT_Row<D>[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface TableState<
|
|
34
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
35
|
-
> extends MRT_TableState<D> {}
|
|
36
|
-
|
|
37
|
-
export interface ColumnInterface<
|
|
38
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
39
|
-
> extends MRT_ColumnInterface<D> {}
|
|
40
|
-
|
|
41
|
-
export interface ColumnInstance<
|
|
42
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
43
|
-
> extends MRT_ColumnInstance<D> {}
|
|
44
|
-
|
|
45
|
-
export interface Cell<
|
|
46
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
47
|
-
V = any,
|
|
48
|
-
> extends MRT_Cell<D> {}
|
|
49
|
-
|
|
50
|
-
export interface Row<
|
|
51
|
-
D extends Record<string, unknown> = Record<string, unknown>,
|
|
52
|
-
> extends MRT_Row<D> {}
|
|
53
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import { TableCell } from '@mui/material';
|
|
3
|
-
import { useMRT } from '../useMRT';
|
|
4
|
-
import { commonTableHeadCellStyles } from './MRT_TableHeadCell';
|
|
5
|
-
|
|
6
|
-
interface Props {}
|
|
7
|
-
|
|
8
|
-
export const MRT_TableHeadCellActions: FC<Props> = () => {
|
|
9
|
-
const {
|
|
10
|
-
localization,
|
|
11
|
-
tableInstance: {
|
|
12
|
-
state: { densePadding },
|
|
13
|
-
},
|
|
14
|
-
} = useMRT();
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<TableCell
|
|
18
|
-
style={{ textAlign: 'center' }}
|
|
19
|
-
sx={{
|
|
20
|
-
...commonTableHeadCellStyles(densePadding),
|
|
21
|
-
textAlign: 'center',
|
|
22
|
-
maxWidth: '4rem',
|
|
23
|
-
width: '4rem',
|
|
24
|
-
}}
|
|
25
|
-
>
|
|
26
|
-
{localization.actions}
|
|
27
|
-
</TableCell>
|
|
28
|
-
);
|
|
29
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React, { CSSProperties, FC } from 'react';
|
|
2
|
-
import { TableCell } from '@mui/material';
|
|
3
|
-
import { useMRT } from '../useMRT';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
width?: CSSProperties['width'];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
|
|
10
|
-
const { muiTableBodyCellProps } = useMRT();
|
|
11
|
-
|
|
12
|
-
const tableCellProps =
|
|
13
|
-
muiTableBodyCellProps instanceof Function
|
|
14
|
-
? muiTableBodyCellProps()
|
|
15
|
-
: muiTableBodyCellProps;
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<TableCell {...tableCellProps} sx={{ width, ...tableCellProps?.sx }} />
|
|
19
|
-
);
|
|
20
|
-
};
|