material-react-table 0.6.10 → 0.7.0-alpha.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.
Files changed (104) hide show
  1. package/README.md +27 -17
  2. package/dist/MaterialReactTable.d.ts +306 -109
  3. package/dist/body/MRT_TableBody.d.ts +3 -0
  4. package/dist/body/MRT_TableBodyCell.d.ts +2 -11
  5. package/dist/body/MRT_TableBodyRow.d.ts +3 -1
  6. package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
  7. package/dist/buttons/MRT_CopyButton.d.ts +4 -2
  8. package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
  9. package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
  10. package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
  11. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
  12. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
  13. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
  14. package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
  15. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
  16. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
  17. package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
  18. package/dist/footer/MRT_TableFooter.d.ts +3 -0
  19. package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
  20. package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
  21. package/dist/head/MRT_TableHead.d.ts +3 -0
  22. package/dist/head/MRT_TableHeadCell.d.ts +4 -18
  23. package/dist/head/MRT_TableHeadRow.d.ts +2 -1
  24. package/dist/icons.d.ts +1 -1
  25. package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
  26. package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
  27. package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
  28. package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
  29. package/dist/localization.d.ts +7 -2
  30. package/dist/material-react-table.cjs.development.js +2209 -2483
  31. package/dist/material-react-table.cjs.development.js.map +1 -1
  32. package/dist/material-react-table.cjs.production.min.js +1 -1
  33. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  34. package/dist/material-react-table.esm.js +2210 -2484
  35. package/dist/material-react-table.esm.js.map +1 -1
  36. package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
  37. package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
  38. package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
  39. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
  40. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
  41. package/dist/table/MRT_Table.d.ts +3 -0
  42. package/dist/table/MRT_TableContainer.d.ts +2 -0
  43. package/dist/table/MRT_TablePaper.d.ts +7 -0
  44. package/dist/table/MRT_TableRoot.d.ts +3 -0
  45. package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
  46. package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
  47. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
  48. package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
  49. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
  50. package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
  51. package/dist/utils.d.ts +12 -2
  52. package/package.json +28 -29
  53. package/src/MaterialReactTable.tsx +594 -300
  54. package/src/body/MRT_TableBody.tsx +26 -22
  55. package/src/body/MRT_TableBodyCell.tsx +75 -60
  56. package/src/body/MRT_TableBodyRow.tsx +37 -76
  57. package/src/body/MRT_TableDetailPanel.tsx +21 -17
  58. package/src/buttons/MRT_CopyButton.tsx +16 -9
  59. package/src/buttons/MRT_EditActionButtons.tsx +16 -13
  60. package/src/buttons/MRT_ExpandAllButton.tsx +24 -9
  61. package/src/buttons/MRT_ExpandButton.tsx +22 -15
  62. package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
  63. package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
  64. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +22 -11
  65. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
  66. package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
  67. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +27 -22
  68. package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
  69. package/src/footer/MRT_TableFooter.tsx +24 -8
  70. package/src/footer/MRT_TableFooterCell.tsx +34 -26
  71. package/src/footer/MRT_TableFooterRow.tsx +21 -39
  72. package/src/head/MRT_TableHead.tsx +24 -8
  73. package/src/head/MRT_TableHeadCell.tsx +184 -142
  74. package/src/head/MRT_TableHeadRow.tsx +16 -104
  75. package/src/icons.ts +3 -3
  76. package/src/inputs/MRT_EditCellTextField.tsx +23 -24
  77. package/src/inputs/MRT_FilterTextField.tsx +53 -32
  78. package/src/inputs/MRT_SearchTextField.tsx +46 -24
  79. package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
  80. package/src/localization.ts +13 -2
  81. package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
  82. package/src/menus/MRT_FilterTypeMenu.tsx +28 -22
  83. package/src/menus/MRT_RowActionMenu.tsx +21 -14
  84. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
  85. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +27 -17
  86. package/src/table/MRT_Table.tsx +25 -15
  87. package/src/table/MRT_TableContainer.tsx +106 -45
  88. package/src/table/MRT_TablePaper.tsx +65 -0
  89. package/src/table/MRT_TableRoot.tsx +236 -0
  90. package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
  91. package/src/toolbar/MRT_TablePagination.tsx +33 -19
  92. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +33 -20
  93. package/src/toolbar/MRT_ToolbarBottom.tsx +32 -21
  94. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +34 -20
  95. package/src/toolbar/MRT_ToolbarTop.tsx +36 -29
  96. package/src/utils.ts +37 -8
  97. package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
  98. package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
  99. package/dist/useMRT.d.ts +0 -28
  100. package/src/@types/faker.d.ts +0 -4
  101. package/src/@types/react-table-config.d.ts +0 -53
  102. package/src/head/MRT_TableHeadCellActions.tsx +0 -29
  103. package/src/table/MRT_TableSpacerCell.tsx +0 -20
  104. package/src/useMRT.tsx +0 -226
@@ -1,37 +1,51 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { TablePagination } from '@mui/material';
3
- import { useMRT } from '../useMRT';
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 { tableInstance, muiTablePaginationProps } = useMRT();
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
12
- ? muiTablePaginationProps(tableInstance)
24
+ ? muiTablePaginationProps({ tableInstance })
13
25
  : muiTablePaginationProps;
14
26
 
15
27
  const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
16
- tableInstance.setPageSize(+event.target.value);
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={'div'}
23
- count={tableInstance.rows.length}
24
- onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
36
+ SelectProps={{
37
+ sx: { m: '0 1rem 0 1ch' },
38
+ MenuProps: { MenuListProps: { disablePadding: true } },
39
+ }}
40
+ component="div"
41
+ count={getPrePaginationRowModel().rows.length}
42
+ onPageChange={(_: any, newPage: number) => setPageIndex(newPage)}
25
43
  onRowsPerPageChange={handleChangeRowsPerPage}
26
- page={tableInstance.state.pageIndex}
27
- rowsPerPage={tableInstance.state.pageSize}
28
- SelectProps={{ style: { margin: '0 1rem 0 1ch' } }}
29
- showFirstButton={
30
- tableInstance.rows.length / tableInstance.state.pageSize > 2
31
- }
32
- showLastButton={
33
- tableInstance.rows.length / tableInstance.state.pageSize > 2
34
- }
44
+ page={pageIndex}
45
+ rowsPerPage={pageSize}
46
+ rowsPerPageOptions={[5, 10, 15, 20, 25, 30, 50, 100]}
47
+ showFirstButton={showFirstLastPageButtons}
48
+ showLastButton={showFirstLastPageButtons}
35
49
  {...tablePaginationProps}
36
50
  sx={{
37
51
  m: '0 0.5rem',
@@ -1,51 +1,63 @@
1
1
  import React, { FC, Fragment } from 'react';
2
2
  import { Alert, Box, Chip, Collapse, useMediaQuery } from '@mui/material';
3
- import { useMRT } from '../useMRT';
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
- muiTableToolbarAlertBannerProps,
10
- tableInstance,
11
- positionToolbarAlertBanner,
12
- positionToolbarActions,
13
- localization,
14
- renderToolbarCustomActions,
15
- } = useMRT();
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
 
19
28
  const alertProps =
20
29
  muiTableToolbarAlertBannerProps instanceof Function
21
- ? muiTableToolbarAlertBannerProps(tableInstance)
30
+ ? muiTableToolbarAlertBannerProps({ tableInstance })
22
31
  : muiTableToolbarAlertBannerProps;
23
32
 
24
33
  const selectMessage =
25
- tableInstance.selectedFlatRows.length > 0
34
+ getSelectedRowModel().rows.length > 0
26
35
  ? localization.selectedCountOfRowCountRowsSelected
27
36
  ?.replace(
28
37
  '{selectedCount}',
29
- tableInstance.selectedFlatRows.length.toString(),
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
- tableInstance.state.groupBy.length > 0 ? (
47
+ grouping.length > 0 ? (
36
48
  <span>
37
49
  {localization.groupedBy}{' '}
38
- {tableInstance.state.groupBy.map((columnId, index) => (
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.allColumns.find(
45
- (column) => column.id === columnId,
46
- )?.Header
56
+ tableInstance
57
+ .getAllColumns()
58
+ .find((column) => column.id === columnId)?.header
47
59
  }
48
- onDelete={() => tableInstance.toggleGroupBy(columnId, false)}
60
+ onDelete={() => toggleColumnGrouping(columnId)}
49
61
  />
50
62
  </Fragment>
51
63
  ))}
@@ -84,6 +96,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
84
96
  >
85
97
  <Box sx={{ p: '0.5rem 1rem' }}>
86
98
  {selectMessage}
99
+ <br />
87
100
  {groupedByMessage}
88
101
  </Box>
89
102
  </Alert>
@@ -1,56 +1,67 @@
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
- hideToolbarInternalActions,
15
- manualPagination,
16
- muiTableToolbarBottomProps,
17
- positionPagination,
18
- positionToolbarActions,
19
- positionToolbarAlertBanner,
20
- tableInstance,
21
- } = useMRT();
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
25
- ? muiTableToolbarBottomProps(tableInstance)
32
+ ? muiTableToolbarBottomProps({ tableInstance })
26
33
  : muiTableToolbarBottomProps;
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
- bottom: tableInstance.state.fullScreen ? '0' : undefined,
35
- position: tableInstance.state.fullScreen ? 'fixed' : undefined,
36
- ...commonToolbarStyles(theme, tableInstance),
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' && <MRT_ToolbarAlertBanner />}
51
- {!manualPagination &&
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,30 +5,34 @@ 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 { useMRT } from '../useMRT';
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
- disableFilters,
15
- disableColumnHiding,
16
- disableDensePaddingToggle,
17
- disableGlobalFilter,
18
- disableFullScreenToggle,
19
- renderToolbarInternalActions,
20
- tableInstance,
21
- } = useMRT();
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 (
25
28
  <>
26
- {renderToolbarInternalActions(tableInstance, {
27
- MRT_ToggleSearchButton,
28
- MRT_ToggleFiltersButton,
29
+ {renderToolbarInternalActions({
30
+ MRT_FullScreenToggleButton,
29
31
  MRT_ShowHideColumnsButton,
30
32
  MRT_ToggleDensePaddingButton,
31
- MRT_FullScreenToggleButton,
33
+ MRT_ToggleFiltersButton,
34
+ MRT_ToggleSearchButton,
35
+ tableInstance,
32
36
  })}
33
37
  </>
34
38
  );
@@ -43,11 +47,21 @@ export const MRT_ToolbarInternalButtons: FC<Props> = () => {
43
47
  p: '0 0.5rem',
44
48
  }}
45
49
  >
46
- {!disableGlobalFilter && <MRT_ToggleSearchButton />}
47
- {!disableFilters && <MRT_ToggleFiltersButton />}
48
- {!disableColumnHiding && <MRT_ShowHideColumnsButton />}
49
- {!disableDensePaddingToggle && <MRT_ToggleDensePaddingButton />}
50
- {!disableFullScreenToggle && <MRT_FullScreenToggleButton />}
50
+ {enableGlobalFilter && (
51
+ <MRT_ToggleSearchButton tableInstance={tableInstance} />
52
+ )}
53
+ {enableColumnFilters && (
54
+ <MRT_ToggleFiltersButton tableInstance={tableInstance} />
55
+ )}
56
+ {enableHiding && (
57
+ <MRT_ShowHideColumnsButton tableInstance={tableInstance} />
58
+ )}
59
+ {enableDensePaddingToggle && (
60
+ <MRT_ToggleDensePaddingButton tableInstance={tableInstance} />
61
+ )}
62
+ {enableFullScreenToggle && (
63
+ <MRT_FullScreenToggleButton tableInstance={tableInstance} />
64
+ )}
51
65
  </Box>
52
66
  );
53
67
  };
@@ -1,63 +1,68 @@
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
- disableGlobalFilter,
32
- hideToolbarInternalActions,
33
- manualPagination,
34
- muiTableToolbarTopProps,
35
- positionPagination,
36
- positionToolbarActions,
37
- positionToolbarAlertBanner,
38
- renderToolbarCustomActions,
39
- tableInstance,
40
- } = useMRT();
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
44
- ? muiTableToolbarTopProps(tableInstance)
46
+ ? muiTableToolbarTopProps({ tableInstance })
45
47
  : muiTableToolbarTopProps;
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: tableInstance.state.fullScreen ? 'sticky' : undefined,
54
- top: tableInstance.state.fullScreen ? '0' : undefined,
55
- ...commonToolbarStyles(theme, tableInstance),
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' && <MRT_ToolbarAlertBanner />}
63
+ {positionToolbarAlertBanner === 'top' && (
64
+ <MRT_ToolbarAlertBanner tableInstance={tableInstance} />
65
+ )}
61
66
  <Box
62
67
  sx={{
63
68
  p: '0.5rem',
@@ -65,7 +70,7 @@ export const MRT_ToolbarTop: FC<Props> = () => {
65
70
  justifyContent: 'space-between',
66
71
  }}
67
72
  >
68
- {renderToolbarCustomActions?.(tableInstance) ?? <span />}
73
+ {renderToolbarCustomActions?.({ tableInstance }) ?? <span />}
69
74
  <Box
70
75
  sx={{
71
76
  display: 'flex',
@@ -74,19 +79,21 @@ export const MRT_ToolbarTop: FC<Props> = () => {
74
79
  zIndex: 3,
75
80
  }}
76
81
  >
77
- {!disableGlobalFilter && <MRT_SearchTextField />}
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
- {!manualPagination &&
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 { MRT_ColumnInstance, MRT_ColumnInterface } from '.';
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 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;
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);
@@ -1,5 +0,0 @@
1
- import { FC } from 'react';
2
- interface Props {
3
- }
4
- export declare const MRT_TableHeadCellActions: FC<Props>;
5
- export {};
@@ -1,6 +0,0 @@
1
- import { CSSProperties, FC } from 'react';
2
- interface Props {
3
- width?: CSSProperties['width'];
4
- }
5
- export declare const MRT_TableSpacerCell: FC<Props>;
6
- export {};
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>;
@@ -1,4 +0,0 @@
1
- declare module '@faker-js/faker' {
2
- import faker from 'faker';
3
- export default faker;
4
- }
@@ -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
- };