material-react-table 0.6.8 → 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.
Files changed (107) hide show
  1. package/dist/MaterialReactTable.d.ts +147 -82
  2. package/dist/body/MRT_TableBody.d.ts +3 -0
  3. package/dist/body/MRT_TableBodyCell.d.ts +2 -11
  4. package/dist/body/MRT_TableBodyRow.d.ts +3 -1
  5. package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
  6. package/dist/buttons/MRT_CopyButton.d.ts +4 -2
  7. package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
  8. package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
  9. package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
  10. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
  11. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
  12. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
  13. package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
  14. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
  15. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
  16. package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
  17. package/dist/enums.d.ts +2 -1
  18. package/dist/filtersFNs.d.ts +13 -5
  19. package/dist/footer/MRT_TableFooter.d.ts +3 -0
  20. package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
  21. package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
  22. package/dist/head/MRT_TableHead.d.ts +3 -0
  23. package/dist/head/MRT_TableHeadCell.d.ts +4 -18
  24. package/dist/head/MRT_TableHeadRow.d.ts +2 -1
  25. package/dist/icons.d.ts +1 -1
  26. package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
  27. package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
  28. package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
  29. package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
  30. package/dist/localization.d.ts +9 -2
  31. package/dist/material-react-table.cjs.development.js +2183 -1686
  32. package/dist/material-react-table.cjs.development.js.map +1 -1
  33. package/dist/material-react-table.cjs.production.min.js +1 -1
  34. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  35. package/dist/material-react-table.esm.js +2191 -1694
  36. package/dist/material-react-table.esm.js.map +1 -1
  37. package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
  38. package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
  39. package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
  40. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
  41. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
  42. package/dist/table/MRT_Table.d.ts +3 -0
  43. package/dist/table/MRT_TableContainer.d.ts +2 -0
  44. package/dist/table/MRT_TablePaper.d.ts +7 -0
  45. package/dist/table/MRT_TableRoot.d.ts +3 -0
  46. package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
  47. package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
  48. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
  49. package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
  50. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
  51. package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
  52. package/dist/utils.d.ts +12 -2
  53. package/package.json +27 -28
  54. package/src/MaterialReactTable.tsx +314 -241
  55. package/src/body/MRT_TableBody.tsx +25 -21
  56. package/src/body/MRT_TableBodyCell.tsx +74 -53
  57. package/src/body/MRT_TableBodyRow.tsx +35 -51
  58. package/src/body/MRT_TableDetailPanel.tsx +16 -14
  59. package/src/buttons/MRT_CopyButton.tsx +36 -11
  60. package/src/buttons/MRT_EditActionButtons.tsx +13 -12
  61. package/src/buttons/MRT_ExpandAllButton.tsx +36 -28
  62. package/src/buttons/MRT_ExpandButton.tsx +34 -40
  63. package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
  64. package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
  65. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +17 -9
  66. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
  67. package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
  68. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +26 -21
  69. package/src/buttons/MRT_ToggleSearchButton.tsx +18 -11
  70. package/src/enums.ts +2 -1
  71. package/src/filtersFNs.ts +17 -3
  72. package/src/footer/MRT_TableFooter.tsx +23 -7
  73. package/src/footer/MRT_TableFooterCell.tsx +32 -24
  74. package/src/footer/MRT_TableFooterRow.tsx +20 -38
  75. package/src/head/MRT_TableHead.tsx +23 -7
  76. package/src/head/MRT_TableHeadCell.tsx +201 -151
  77. package/src/head/MRT_TableHeadRow.tsx +15 -81
  78. package/src/icons.ts +3 -3
  79. package/src/inputs/MRT_EditCellTextField.tsx +23 -24
  80. package/src/inputs/MRT_FilterTextField.tsx +51 -37
  81. package/src/inputs/MRT_SearchTextField.tsx +63 -22
  82. package/src/inputs/MRT_SelectCheckbox.tsx +75 -42
  83. package/src/localization.ts +19 -4
  84. package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
  85. package/src/menus/MRT_FilterTypeMenu.tsx +55 -23
  86. package/src/menus/MRT_RowActionMenu.tsx +16 -11
  87. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
  88. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +28 -17
  89. package/src/table/MRT_Table.tsx +24 -14
  90. package/src/table/MRT_TableContainer.tsx +109 -44
  91. package/src/table/MRT_TablePaper.tsx +61 -0
  92. package/src/table/MRT_TableRoot.tsx +236 -0
  93. package/src/toolbar/MRT_LinearProgressBar.tsx +9 -6
  94. package/src/toolbar/MRT_TablePagination.tsx +28 -18
  95. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +31 -19
  96. package/src/toolbar/MRT_ToolbarBottom.tsx +31 -20
  97. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +29 -16
  98. package/src/toolbar/MRT_ToolbarTop.tsx +34 -27
  99. package/src/utils.ts +37 -8
  100. package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
  101. package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
  102. package/dist/useMRT.d.ts +0 -27
  103. package/src/@types/faker.d.ts +0 -4
  104. package/src/@types/react-table-config.d.ts +0 -53
  105. package/src/head/MRT_TableHeadCellActions.tsx +0 -29
  106. package/src/table/MRT_TableSpacerCell.tsx +0 -20
  107. package/src/useMRT.tsx +0 -215
@@ -1,11 +1,23 @@
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
@@ -13,25 +25,23 @@ export const MRT_TablePagination: FC<Props> = () => {
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
+ component="div"
37
+ count={getPrePaginationRowModel().rows.length}
38
+ onPageChange={(_: any, newPage: number) => setPageIndex(newPage)}
25
39
  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
- }
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 { 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
 
@@ -22,30 +31,33 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
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
  ))}
@@ -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
- 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
@@ -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
- 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,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 { 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 (
@@ -43,11 +46,21 @@ export const MRT_ToolbarInternalButtons: FC<Props> = () => {
43
46
  p: '0 0.5rem',
44
47
  }}
45
48
  >
46
- {!disableGlobalFilter && <MRT_ToggleSearchButton />}
47
- {!disableFilters && <MRT_ToggleFiltersButton />}
48
- {!disableColumnHiding && <MRT_ShowHideColumnsButton />}
49
- {!disableDensePaddingToggle && <MRT_ToggleDensePaddingButton />}
50
- {!disableFullScreenToggle && <MRT_FullScreenToggleButton />}
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
- 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
@@ -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: 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',
@@ -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,27 +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
- setDensePadding: Dispatch<SetStateAction<boolean>>;
21
- setFullScreen: Dispatch<SetStateAction<boolean>>;
22
- setShowFilters: Dispatch<SetStateAction<boolean>>;
23
- setShowSearch: Dispatch<SetStateAction<boolean>>;
24
- tableInstance: MRT_TableInstance<D>;
25
- };
26
- export declare const MaterialReactTableProvider: <D extends {} = {}>(props: React.PropsWithChildren<MaterialReactTableProps<D>>) => JSX.Element;
27
- 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
- };