material-react-table 0.6.9 → 0.7.0-alpha.2

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 +308 -107
  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 +2258 -2470
  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 +2260 -2472
  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 +598 -295
  55. package/src/body/MRT_TableBody.tsx +26 -22
  56. package/src/body/MRT_TableBodyCell.tsx +76 -55
  57. package/src/body/MRT_TableBodyRow.tsx +37 -67
  58. package/src/body/MRT_TableDetailPanel.tsx +21 -17
  59. package/src/buttons/MRT_CopyButton.tsx +36 -11
  60. package/src/buttons/MRT_EditActionButtons.tsx +16 -13
  61. package/src/buttons/MRT_ExpandAllButton.tsx +36 -28
  62. package/src/buttons/MRT_ExpandButton.tsx +35 -41
  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 +22 -11
  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 +27 -22
  69. package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
  70. package/src/enums.ts +2 -1
  71. package/src/filtersFNs.ts +17 -3
  72. package/src/footer/MRT_TableFooter.tsx +24 -8
  73. package/src/footer/MRT_TableFooterCell.tsx +34 -26
  74. package/src/footer/MRT_TableFooterRow.tsx +21 -39
  75. package/src/head/MRT_TableHead.tsx +24 -8
  76. package/src/head/MRT_TableHeadCell.tsx +185 -142
  77. package/src/head/MRT_TableHeadRow.tsx +16 -93
  78. package/src/icons.ts +3 -3
  79. package/src/inputs/MRT_EditCellTextField.tsx +23 -24
  80. package/src/inputs/MRT_FilterTextField.tsx +53 -39
  81. package/src/inputs/MRT_SearchTextField.tsx +71 -25
  82. package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
  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 +21 -14
  87. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
  88. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +27 -17
  89. package/src/table/MRT_Table.tsx +25 -15
  90. package/src/table/MRT_TableContainer.tsx +106 -45
  91. package/src/table/MRT_TablePaper.tsx +65 -0
  92. package/src/table/MRT_TableRoot.tsx +236 -0
  93. package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
  94. package/src/toolbar/MRT_TablePagination.tsx +30 -19
  95. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +33 -20
  96. package/src/toolbar/MRT_ToolbarBottom.tsx +32 -21
  97. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +34 -20
  98. package/src/toolbar/MRT_ToolbarTop.tsx +36 -29
  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,59 +1,53 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { IconButton, TableCell } from '@mui/material';
3
- import { useMRT } from '../useMRT';
4
- import type { MRT_Row } from '..';
5
- import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
2
+ import { IconButton } from '@mui/material';
3
+ import type { MRT_Row, MRT_TableInstance } from '..';
6
4
 
7
5
  interface Props {
8
6
  row: MRT_Row;
7
+ tableInstance: MRT_TableInstance;
9
8
  }
10
9
 
11
- export const MRT_ExpandButton: FC<Props> = ({ row }) => {
10
+ export const MRT_ExpandButton: FC<Props> = ({ row, tableInstance }) => {
12
11
  const {
13
- icons: { ExpandMoreIcon },
14
- localization,
15
- onRowExpandChange,
16
- renderDetailPanel,
17
- tableInstance: {
18
- state: { densePadding },
12
+ getState,
13
+ options: {
14
+ icons: { ExpandMoreIcon },
15
+ localization,
16
+ onRowExpandChange,
17
+ renderDetailPanel,
19
18
  },
20
- } = useMRT();
19
+ } = tableInstance;
20
+
21
+ const { isDensePadding } = getState();
21
22
 
22
23
  const handleToggleExpand = (event: MouseEvent<HTMLButtonElement>) => {
23
- // @ts-ignore
24
- row.getToggleRowExpandedProps()?.onClick(event);
25
- onRowExpandChange?.(event, row);
24
+ row.toggleExpanded();
25
+ onRowExpandChange?.({ event, row, tableInstance });
26
26
  };
27
27
 
28
28
  return (
29
- <TableCell
30
- size="small"
29
+ <IconButton
30
+ aria-label={localization.expand}
31
+ disabled={!row.getCanExpand() && !renderDetailPanel}
32
+ title={localization.expand}
33
+ onClick={handleToggleExpand}
31
34
  sx={{
32
- ...commonTableBodyButtonCellStyles(densePadding),
33
- pl: `${row.depth + 0.5}rem`,
34
- textAlign: 'left',
35
+ height: isDensePadding ? '1.75rem' : '2.25rem',
36
+ width: isDensePadding ? '1.75rem' : '2.25rem',
35
37
  }}
36
38
  >
37
- <IconButton
38
- aria-label={localization.expand}
39
- disabled={!row.canExpand && !renderDetailPanel}
40
- title={localization.expand}
41
- {...row.getToggleRowExpandedProps()}
42
- onClick={handleToggleExpand}
43
- >
44
- <ExpandMoreIcon
45
- style={{
46
- transform: `rotate(${
47
- !row.canExpand && !renderDetailPanel
48
- ? -90
49
- : row.isExpanded
50
- ? -180
51
- : 0
52
- }deg)`,
53
- transition: 'transform 0.2s',
54
- }}
55
- />
56
- </IconButton>
57
- </TableCell>
39
+ <ExpandMoreIcon
40
+ style={{
41
+ transform: `rotate(${
42
+ !row.getCanExpand() && !renderDetailPanel
43
+ ? -90
44
+ : row.getIsExpanded()
45
+ ? -180
46
+ : 0
47
+ }deg)`,
48
+ transition: 'transform 0.2s',
49
+ }}
50
+ />
51
+ </IconButton>
58
52
  );
59
53
  };
@@ -1,28 +1,35 @@
1
1
  import React, { FC } from 'react';
2
2
  import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
3
- import { useMRT } from '../useMRT';
3
+ import { MRT_TableInstance } from '..';
4
4
 
5
- interface Props extends IconButtonProps {}
5
+ interface Props extends IconButtonProps {
6
+ tableInstance: MRT_TableInstance;
7
+ }
6
8
 
7
- export const MRT_FullScreenToggleButton: FC<Props> = ({ ...rest }) => {
9
+ export const MRT_FullScreenToggleButton: FC<Props> = ({
10
+ tableInstance,
11
+ ...rest
12
+ }) => {
8
13
  const {
9
- icons: { FullscreenExitIcon, FullscreenIcon },
10
- localization,
11
- setFullScreen,
12
- tableInstance: {
13
- state: { fullScreen },
14
+ getState,
15
+ options: {
16
+ icons: { FullscreenExitIcon, FullscreenIcon },
17
+ localization,
18
+ setIsFullScreen,
14
19
  },
15
- } = useMRT();
20
+ } = tableInstance;
21
+
22
+ const { isFullScreen } = getState();
16
23
 
17
24
  return (
18
25
  <Tooltip arrow title={localization.toggleFullScreen}>
19
26
  <IconButton
20
27
  aria-label={localization.showHideFilters}
21
- onClick={() => setFullScreen(!fullScreen)}
28
+ onClick={() => setIsFullScreen(!isFullScreen)}
22
29
  size="small"
23
30
  {...rest}
24
31
  >
25
- {fullScreen ? <FullscreenExitIcon /> : <FullscreenIcon />}
32
+ {isFullScreen ? <FullscreenExitIcon /> : <FullscreenIcon />}
26
33
  </IconButton>
27
34
  </Tooltip>
28
35
  );
@@ -1,15 +1,22 @@
1
1
  import React, { FC, MouseEvent, useState } from 'react';
2
2
  import { IconButton, Tooltip, IconButtonProps } from '@mui/material';
3
- import { useMRT } from '../useMRT';
4
3
  import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
4
+ import { MRT_TableInstance } from '..';
5
5
 
6
- interface Props extends IconButtonProps {}
6
+ interface Props extends IconButtonProps {
7
+ tableInstance: MRT_TableInstance;
8
+ }
7
9
 
8
- export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
10
+ export const MRT_ShowHideColumnsButton: FC<Props> = ({
11
+ tableInstance,
12
+ ...rest
13
+ }) => {
9
14
  const {
10
- icons: { ViewColumnIcon },
11
- localization,
12
- } = useMRT();
15
+ options: {
16
+ icons: { ViewColumnIcon },
17
+ localization,
18
+ },
19
+ } = tableInstance;
13
20
 
14
21
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
15
22
 
@@ -29,7 +36,11 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
29
36
  <ViewColumnIcon />
30
37
  </IconButton>
31
38
  </Tooltip>
32
- <MRT_ShowHideColumnsMenu anchorEl={anchorEl} setAnchorEl={setAnchorEl} />
39
+ <MRT_ShowHideColumnsMenu
40
+ anchorEl={anchorEl}
41
+ setAnchorEl={setAnchorEl}
42
+ tableInstance={tableInstance}
43
+ />
33
44
  </>
34
45
  );
35
46
  };
@@ -1,19 +1,26 @@
1
1
  import React, { FC, MouseEvent, useState } from 'react';
2
2
  import { IconButton, Tooltip } from '@mui/material';
3
- import { useMRT } from '../useMRT';
4
3
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
5
- import type { MRT_HeaderGroup } from '..';
4
+ import type { MRT_Header, MRT_TableInstance } from '..';
6
5
 
7
6
  interface Props {
8
- column: MRT_HeaderGroup;
7
+ header: MRT_Header;
8
+ tableInstance: MRT_TableInstance;
9
9
  }
10
10
 
11
- export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
11
+ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
12
+ header,
13
+ tableInstance,
14
+ }) => {
12
15
  const {
13
- icons: { MoreVertIcon },
14
- localization,
15
- muiTableHeadCellColumnActionsButtonProps,
16
- } = useMRT();
16
+ options: {
17
+ icons: { MoreVertIcon },
18
+ localization,
19
+ muiTableHeadCellColumnActionsButtonProps,
20
+ },
21
+ } = tableInstance;
22
+
23
+ const { column } = header;
17
24
 
18
25
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
19
26
 
@@ -25,12 +32,15 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
25
32
 
26
33
  const mTableHeadCellColumnActionsButtonProps =
27
34
  muiTableHeadCellColumnActionsButtonProps instanceof Function
28
- ? muiTableHeadCellColumnActionsButtonProps(column)
35
+ ? muiTableHeadCellColumnActionsButtonProps({ column, tableInstance })
29
36
  : muiTableHeadCellColumnActionsButtonProps;
30
37
 
31
38
  const mcTableHeadCellColumnActionsButtonProps =
32
39
  column.muiTableHeadCellColumnActionsButtonProps instanceof Function
33
- ? column.muiTableHeadCellColumnActionsButtonProps(column)
40
+ ? column.muiTableHeadCellColumnActionsButtonProps({
41
+ column,
42
+ tableInstance,
43
+ })
34
44
  : column.muiTableHeadCellColumnActionsButtonProps;
35
45
 
36
46
  const iconButtonProps = {
@@ -70,8 +80,9 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
70
80
  </Tooltip>
71
81
  <MRT_ColumnActionMenu
72
82
  anchorEl={anchorEl}
73
- column={column}
83
+ header={header}
74
84
  setAnchorEl={setAnchorEl}
85
+ tableInstance={tableInstance}
75
86
  />
76
87
  </>
77
88
  );
@@ -1,28 +1,35 @@
1
1
  import React, { FC } from 'react';
2
2
  import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
3
- import { useMRT } from '../useMRT';
3
+ import { MRT_TableInstance } from '..';
4
4
 
5
- interface Props extends IconButtonProps {}
5
+ interface Props extends IconButtonProps {
6
+ tableInstance: MRT_TableInstance;
7
+ }
6
8
 
7
- export const MRT_ToggleDensePaddingButton: FC<Props> = ({ ...rest }) => {
9
+ export const MRT_ToggleDensePaddingButton: FC<Props> = ({
10
+ tableInstance,
11
+ ...rest
12
+ }) => {
8
13
  const {
9
- setDensePadding,
10
- localization,
11
- icons: { DensityMediumIcon, DensitySmallIcon },
12
- tableInstance: {
13
- state: { densePadding },
14
+ getState,
15
+ options: {
16
+ icons: { DensityMediumIcon, DensitySmallIcon },
17
+ localization,
18
+ setIsDensePadding,
14
19
  },
15
- } = useMRT();
20
+ } = tableInstance;
21
+
22
+ const { isDensePadding } = getState();
16
23
 
17
24
  return (
18
25
  <Tooltip arrow title={localization.toggleDensePadding}>
19
26
  <IconButton
20
27
  aria-label={localization.toggleDensePadding}
21
- onClick={() => setDensePadding(!densePadding)}
28
+ onClick={() => setIsDensePadding(!isDensePadding)}
22
29
  size="small"
23
30
  {...rest}
24
31
  >
25
- {densePadding ? <DensitySmallIcon /> : <DensityMediumIcon />}
32
+ {isDensePadding ? <DensitySmallIcon /> : <DensityMediumIcon />}
26
33
  </IconButton>
27
34
  </Tooltip>
28
35
  );
@@ -1,18 +1,25 @@
1
1
  import React, { FC } from 'react';
2
2
  import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
3
- import { useMRT } from '../useMRT';
3
+ import { MRT_TableInstance } from '..';
4
4
 
5
- interface Props extends IconButtonProps {}
5
+ interface Props extends IconButtonProps {
6
+ tableInstance: MRT_TableInstance;
7
+ }
6
8
 
7
- export const MRT_ToggleFiltersButton: FC<Props> = ({ ...rest }) => {
9
+ export const MRT_ToggleFiltersButton: FC<Props> = ({
10
+ tableInstance,
11
+ ...rest
12
+ }) => {
8
13
  const {
9
- icons: { FilterListIcon, FilterListOffIcon },
10
- localization,
11
- setShowFilters,
12
- tableInstance: {
13
- state: { showFilters },
14
+ getState,
15
+ options: {
16
+ icons: { FilterListIcon, FilterListOffIcon },
17
+ localization,
18
+ setShowFilters,
14
19
  },
15
- } = useMRT();
20
+ } = tableInstance;
21
+
22
+ const { showFilters } = getState();
16
23
 
17
24
  return (
18
25
  <Tooltip arrow title={localization.showHideFilters}>
@@ -1,16 +1,14 @@
1
1
  import React, { FC, MouseEvent, useState } from 'react';
2
- import { IconButton, TableCell, Tooltip } from '@mui/material';
3
- import { useMRT } from '../useMRT';
2
+ import { IconButton, Tooltip } from '@mui/material';
4
3
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
5
4
  import { MRT_EditActionButtons } from './MRT_EditActionButtons';
6
- import type { MRT_Row } from '..';
7
- import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
5
+ import type { MRT_Row, MRT_TableInstance } from '..';
8
6
 
9
7
  const commonIconButtonStyles = {
8
+ height: '2rem',
9
+ ml: '10px',
10
10
  opacity: 0.5,
11
11
  transition: 'opacity 0.2s',
12
- marginRight: '2px',
13
- height: '2rem',
14
12
  width: '2rem',
15
13
  '&:hover': {
16
14
  opacity: 1,
@@ -19,18 +17,26 @@ const commonIconButtonStyles = {
19
17
 
20
18
  interface Props {
21
19
  row: MRT_Row;
20
+ tableInstance: MRT_TableInstance;
22
21
  }
23
22
 
24
- export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
23
+ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
24
+ row,
25
+ tableInstance,
26
+ }) => {
25
27
  const {
26
- enableRowEditing,
27
- icons: { EditIcon, MoreHorizIcon },
28
- localization,
29
- renderRowActionMenuItems,
30
- renderRowActions,
31
- setCurrentEditingRow,
32
- tableInstance,
33
- } = useMRT();
28
+ getState,
29
+ options: {
30
+ enableRowEditing,
31
+ icons: { EditIcon, MoreHorizIcon },
32
+ localization,
33
+ renderRowActionMenuItems,
34
+ renderRowActions,
35
+ setCurrentEditingRow,
36
+ },
37
+ } = tableInstance;
38
+
39
+ const { currentEditingRow } = getState();
34
40
 
35
41
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
36
42
 
@@ -46,13 +52,11 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
46
52
  };
47
53
 
48
54
  return (
49
- <TableCell
50
- sx={commonTableBodyButtonCellStyles(tableInstance.state.densePadding)}
51
- >
55
+ <>
52
56
  {renderRowActions ? (
53
- <>{renderRowActions(row, tableInstance)}</>
54
- ) : row.id === tableInstance.state.currentEditingRow?.id ? (
55
- <MRT_EditActionButtons row={row} />
57
+ <>{renderRowActions({ row, tableInstance })}</>
58
+ ) : row.id === currentEditingRow?.id ? (
59
+ <MRT_EditActionButtons row={row} tableInstance={tableInstance} />
56
60
  ) : !renderRowActionMenuItems && enableRowEditing ? (
57
61
  <Tooltip placement="right" arrow title={localization.edit}>
58
62
  <IconButton sx={commonIconButtonStyles} onClick={handleEdit}>
@@ -81,9 +85,10 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
81
85
  handleEdit={handleEdit}
82
86
  row={row}
83
87
  setAnchorEl={setAnchorEl}
88
+ tableInstance={tableInstance}
84
89
  />
85
90
  </>
86
91
  ) : null}
87
- </TableCell>
92
+ </>
88
93
  );
89
94
  };
@@ -1,20 +1,32 @@
1
1
  import React, { FC } from 'react';
2
2
  import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
3
- import { useMRT } from '../useMRT';
3
+ import { MRT_TableInstance } from '..';
4
4
 
5
- interface Props extends IconButtonProps {}
5
+ interface Props extends IconButtonProps {
6
+ tableInstance: MRT_TableInstance;
7
+ }
6
8
 
7
- export const MRT_ToggleSearchButton: FC<Props> = ({ ...rest }) => {
9
+ export const MRT_ToggleSearchButton: FC<Props> = ({
10
+ tableInstance,
11
+ ...rest
12
+ }) => {
8
13
  const {
9
- icons: { SearchIcon, SearchOffIcon },
10
- idPrefix,
11
- localization,
12
- muiSearchTextFieldProps,
13
- setShowSearch,
14
- tableInstance: {
15
- state: { showSearch },
14
+ getState,
15
+ options: {
16
+ icons: { SearchIcon, SearchOffIcon },
17
+ idPrefix,
18
+ localization,
19
+ muiSearchTextFieldProps,
20
+ setShowSearch,
16
21
  },
17
- } = useMRT();
22
+ } = tableInstance;
23
+
24
+ const { showSearch } = getState();
25
+
26
+ const textFieldProps =
27
+ muiSearchTextFieldProps instanceof Function
28
+ ? muiSearchTextFieldProps({ tableInstance })
29
+ : muiSearchTextFieldProps;
18
30
 
19
31
  const handleToggleSearch = () => {
20
32
  setShowSearch(!showSearch);
@@ -22,7 +34,7 @@ export const MRT_ToggleSearchButton: FC<Props> = ({ ...rest }) => {
22
34
  () =>
23
35
  document
24
36
  .getElementById(
25
- muiSearchTextFieldProps?.id ?? `mrt-${idPrefix}-search-text-field`,
37
+ textFieldProps?.id ?? `mrt-${idPrefix}-search-text-field`,
26
38
  )
27
39
  ?.focus(),
28
40
  200,
package/src/enums.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export enum MRT_FILTER_TYPE {
2
+ BEST_MATCH = 'bestMatch',
3
+ BEST_MATCH_FIRST = 'bestMatchFirst',
2
4
  CONTAINS = 'contains',
3
5
  EMPTY = 'empty',
4
6
  ENDS_WITH = 'endsWith',
5
7
  EQUALS = 'equals',
6
- FUZZY = 'fuzzy',
7
8
  GREATER_THAN = 'greaterThan',
8
9
  LESS_THAN = 'lessThan',
9
10
  NOT_EMPTY = 'notEmpty',
package/src/filtersFNs.ts CHANGED
@@ -1,7 +1,20 @@
1
1
  import { matchSorter } from 'match-sorter';
2
2
  import { MRT_Row } from '.';
3
3
 
4
- export const fuzzy = (
4
+ export const bestMatchFirst = (
5
+ rows: MRT_Row[],
6
+ columnIds: string[] | string,
7
+ filterValue: string | number,
8
+ ) =>
9
+ matchSorter(rows, filterValue.toString().trim(), {
10
+ keys: Array.isArray(columnIds)
11
+ ? columnIds.map((c) => `values.${c}`)
12
+ : [`values.${columnIds}`],
13
+ });
14
+
15
+ bestMatchFirst.autoRemove = (val: any) => !val;
16
+
17
+ export const bestMatch = (
5
18
  rows: MRT_Row[],
6
19
  columnIds: string[] | string,
7
20
  filterValue: string | number,
@@ -13,7 +26,7 @@ export const fuzzy = (
13
26
  sorter: (rankedItems) => rankedItems,
14
27
  });
15
28
 
16
- fuzzy.autoRemove = (val: any) => !val;
29
+ bestMatch.autoRemove = (val: any) => !val;
17
30
 
18
31
  export const contains = (
19
32
  rows: MRT_Row[],
@@ -131,11 +144,12 @@ export const notEmpty = (
131
144
  notEmpty.autoRemove = (val: any) => !val;
132
145
 
133
146
  export const defaultFilterFNs = {
147
+ bestMatch,
148
+ bestMatchFirst,
134
149
  contains,
135
150
  empty,
136
151
  endsWith,
137
152
  equals,
138
- fuzzy,
139
153
  greaterThan,
140
154
  lessThan,
141
155
  notEmpty,
@@ -1,25 +1,41 @@
1
1
  import React, { FC } from 'react';
2
2
  import { TableFooter } from '@mui/material';
3
3
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
- import { useMRT } from '../useMRT';
5
- import type { MRT_HeaderGroup } from '..';
4
+ import type { MRT_HeaderGroup, MRT_TableInstance } from '..';
6
5
 
7
- interface Props {}
6
+ interface Props {
7
+ pinned: 'left' | 'center' | 'right' | 'none';
8
+ tableInstance: MRT_TableInstance;
9
+ }
8
10
 
9
- export const MRT_TableFooter: FC<Props> = () => {
10
- const { muiTableFooterProps, tableInstance } = useMRT();
11
+ export const MRT_TableFooter: FC<Props> = ({ pinned, tableInstance }) => {
12
+ const {
13
+ getCenterFooterGroups,
14
+ getFooterGroups,
15
+ getLeftFooterGroups,
16
+ getRightFooterGroups,
17
+ options: { muiTableFooterProps },
18
+ } = tableInstance;
11
19
 
12
20
  const tableFooterProps =
13
21
  muiTableFooterProps instanceof Function
14
- ? muiTableFooterProps(tableInstance)
22
+ ? muiTableFooterProps({ tableInstance })
15
23
  : muiTableFooterProps;
16
24
 
25
+ const getFooterGroupsMap = {
26
+ center: getCenterFooterGroups,
27
+ left: getLeftFooterGroups,
28
+ none: getFooterGroups,
29
+ right: getRightFooterGroups,
30
+ };
31
+
17
32
  return (
18
33
  <TableFooter {...tableFooterProps}>
19
- {tableInstance.footerGroups.map((footerGroup: MRT_HeaderGroup) => (
34
+ {getFooterGroupsMap[pinned]().map((footerGroup) => (
20
35
  <MRT_TableFooterRow
36
+ footerGroup={footerGroup as MRT_HeaderGroup}
21
37
  key={footerGroup.getFooterGroupProps().key}
22
- footerGroup={footerGroup}
38
+ tableInstance={tableInstance}
23
39
  />
24
40
  ))}
25
41
  </TableFooter>
@@ -1,58 +1,66 @@
1
1
  import React, { FC } from 'react';
2
- import { TableCell } from '@mui/material';
3
- import { useMRT } from '../useMRT';
4
- import type { MRT_HeaderGroup } from '..';
2
+ import { alpha, TableCell } from '@mui/material';
3
+ import type { MRT_Header, MRT_TableInstance } from '..';
5
4
 
6
5
  interface Props {
7
- column: MRT_HeaderGroup;
6
+ footer: MRT_Header;
7
+ tableInstance: MRT_TableInstance;
8
8
  }
9
9
 
10
- export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
10
+ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
11
11
  const {
12
- muiTableFooterCellProps,
13
- enableColumnResizing,
14
- tableInstance: {
15
- state: { densePadding },
16
- },
17
- } = useMRT();
12
+ getState,
13
+ options: { muiTableFooterCellProps, enableColumnResizing },
14
+ } = tableInstance;
18
15
 
19
- const isParentHeader = !!column?.columns?.length;
16
+ const { isDensePadding } = getState();
17
+
18
+ const { column } = footer;
20
19
 
21
20
  const mTableFooterCellProps =
22
21
  muiTableFooterCellProps instanceof Function
23
- ? muiTableFooterCellProps(column)
22
+ ? muiTableFooterCellProps({ column, tableInstance })
24
23
  : muiTableFooterCellProps;
25
24
 
26
25
  const mcTableFooterCellProps =
27
26
  column.muiTableFooterCellProps instanceof Function
28
- ? column.muiTableFooterCellProps(column)
27
+ ? column.muiTableFooterCellProps({ column, tableInstance })
29
28
  : column.muiTableFooterCellProps;
30
29
 
31
30
  const tableCellProps = {
31
+ ...footer.getFooterProps(),
32
32
  ...mTableFooterCellProps,
33
33
  ...mcTableFooterCellProps,
34
- ...column.getFooterProps(),
35
- style: {
36
- ...column.getFooterProps().style,
37
- ...mTableFooterCellProps?.style,
38
- ...mcTableFooterCellProps?.style,
39
- },
40
34
  };
41
35
 
42
36
  return (
43
37
  <TableCell
44
- align={isParentHeader ? 'center' : 'left'}
38
+ align={column.columnDefType === 'group' ? 'center' : 'left'}
45
39
  variant="head"
46
40
  {...tableCellProps}
47
- sx={{
41
+ //@ts-ignore
42
+ sx={(theme) => ({
43
+ backgroundColor: theme.palette.background.default,
44
+ backgroundImage: `linear-gradient(${alpha(
45
+ theme.palette.common.white,
46
+ 0.05,
47
+ )},${alpha(theme.palette.common.white, 0.05)})`,
48
48
  fontWeight: 'bold',
49
- verticalAlign: 'text-top',
50
- p: densePadding ? '0.5rem' : '1rem',
49
+ p: isDensePadding ? '0.5rem' : '1rem',
51
50
  transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
51
+ verticalAlign: 'text-top',
52
+ //@ts-ignore
52
53
  ...tableCellProps?.sx,
53
- }}
54
+ })}
54
55
  >
55
- {column.render('Footer')}
56
+ {footer.isPlaceholder
57
+ ? null
58
+ : column.Footer?.({
59
+ footer,
60
+ tableInstance,
61
+ }) ??
62
+ column.footer ??
63
+ null}
56
64
  </TableCell>
57
65
  );
58
66
  };