material-react-table 0.1.0 → 0.3.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 (102) hide show
  1. package/README.md +32 -162
  2. package/dist/MaterialReactTable.d.ts +62 -26
  3. package/dist/{MRT_TableBody.d.ts → body/MRT_TableBody.d.ts} +0 -0
  4. package/dist/{MRT_TableBodyCell.d.ts → body/MRT_TableBodyCell.d.ts} +1 -1
  5. package/dist/body/MRT_TableBodyRow.d.ts +22 -0
  6. package/dist/{MRT_TableDetailPanel.d.ts → body/MRT_TableDetailPanel.d.ts} +1 -1
  7. package/dist/{MRT_TableBodyRow.d.ts → buttons/MRT_EditActionButtons.d.ts} +2 -2
  8. package/dist/buttons/MRT_ExpandAllButton.d.ts +5 -0
  9. package/dist/{MRT_TableExpandButton.d.ts → buttons/MRT_ExpandButton.d.ts} +2 -2
  10. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +5 -0
  11. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +7 -0
  12. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
  13. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
  14. package/dist/{MRT_TableFooter.d.ts → footer/MRT_TableFooter.d.ts} +0 -0
  15. package/dist/{MRT_TableFooterCell.d.ts → footer/MRT_TableFooterCell.d.ts} +0 -0
  16. package/dist/{MRT_TableFooterRow.d.ts → footer/MRT_TableFooterRow.d.ts} +1 -1
  17. package/dist/{MRT_TableHead.d.ts → head/MRT_TableHead.d.ts} +0 -0
  18. package/dist/head/MRT_TableHeadCell.d.ts +11 -0
  19. package/dist/{MRT_TableHeadRow.d.ts → head/MRT_TableHeadRow.d.ts} +1 -1
  20. package/dist/index.d.ts +2 -0
  21. package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
  22. package/dist/inputs/MRT_EditCellTextfield.d.ts +7 -0
  23. package/dist/{MRT_TableHeadCell.d.ts → inputs/MRT_FilterTextField.d.ts} +1 -1
  24. package/dist/inputs/MRT_SearchTextField.d.ts +5 -0
  25. package/dist/inputs/MRT_SelectAllCheckbox.d.ts +2 -0
  26. package/dist/inputs/MRT_SelectCheckbox.d.ts +7 -0
  27. package/dist/material-react-table.cjs.development.js +2083 -191
  28. package/dist/material-react-table.cjs.development.js.map +1 -1
  29. package/dist/material-react-table.cjs.production.min.js +1 -1
  30. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  31. package/dist/material-react-table.esm.js +2087 -195
  32. package/dist/material-react-table.esm.js.map +1 -1
  33. package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -0
  34. package/dist/menus/MRT_RowActionMenu.d.ts +9 -0
  35. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +7 -0
  36. package/dist/{MRT_Table.d.ts → table/MRT_Table.d.ts} +0 -0
  37. package/dist/{MRT_TableContainer.d.ts → table/MRT_TableContainer.d.ts} +0 -0
  38. package/dist/table/MRT_TableSpacerCell.d.ts +6 -0
  39. package/dist/{MRT_TablePagination.d.ts → toolbar/MRT_TablePagination.d.ts} +0 -0
  40. package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
  41. package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
  42. package/dist/toolbar/MRT_ToolbarTop.d.ts +5 -0
  43. package/dist/useMaterialReactTable.d.ts +14 -12
  44. package/dist/utils/localization.d.ts +26 -0
  45. package/dist/utils/useMRTCalcs.d.ts +11 -0
  46. package/package.json +26 -21
  47. package/src/@types/faker.d.ts +4 -0
  48. package/src/@types/react-table-config.d.ts +153 -0
  49. package/src/MaterialReactTable.tsx +151 -37
  50. package/src/body/MRT_TableBody.tsx +35 -0
  51. package/src/body/MRT_TableBodyCell.tsx +69 -0
  52. package/src/body/MRT_TableBodyRow.tsx +84 -0
  53. package/src/body/MRT_TableDetailPanel.tsx +73 -0
  54. package/src/buttons/MRT_EditActionButtons.tsx +55 -0
  55. package/src/buttons/MRT_ExpandAllButton.tsx +47 -0
  56. package/src/buttons/MRT_ExpandButton.tsx +51 -0
  57. package/src/buttons/MRT_ShowHideColumnsButton.tsx +43 -0
  58. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +51 -0
  59. package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
  60. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
  61. package/src/footer/MRT_TableFooter.tsx +21 -0
  62. package/src/footer/MRT_TableFooterCell.tsx +60 -0
  63. package/src/footer/MRT_TableFooterRow.tsx +62 -0
  64. package/src/head/MRT_TableHead.tsx +26 -0
  65. package/src/head/MRT_TableHeadCell.tsx +137 -0
  66. package/src/head/MRT_TableHeadRow.tsx +90 -0
  67. package/src/index.tsx +2 -0
  68. package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
  69. package/src/inputs/MRT_EditCellTextfield.tsx +57 -0
  70. package/src/inputs/MRT_FilterTextField.tsx +63 -0
  71. package/src/inputs/MRT_SearchTextField.tsx +74 -0
  72. package/src/inputs/MRT_SelectAllCheckbox.tsx +26 -0
  73. package/src/inputs/MRT_SelectCheckbox.tsx +34 -0
  74. package/src/menus/MRT_ColumnActionMenu.tsx +107 -0
  75. package/src/menus/MRT_RowActionMenu.tsx +52 -0
  76. package/src/menus/MRT_ShowHideColumnsMenu.tsx +34 -0
  77. package/src/table/MRT_Table.tsx +30 -0
  78. package/src/table/MRT_TableContainer.tsx +50 -0
  79. package/src/table/MRT_TableSpacerCell.tsx +26 -0
  80. package/src/toolbar/MRT_TablePagination.tsx +37 -0
  81. package/src/toolbar/MRT_ToolbarBottom.tsx +43 -0
  82. package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
  83. package/src/toolbar/MRT_ToolbarTop.tsx +68 -0
  84. package/src/useMaterialReactTable.tsx +70 -32
  85. package/src/utils/localization.ts +51 -0
  86. package/src/utils/useMRTCalcs.tsx +42 -0
  87. package/dist/defaults.d.ts +0 -2
  88. package/src/MRT_Table.tsx +0 -20
  89. package/src/MRT_TableBody.tsx +0 -19
  90. package/src/MRT_TableBodyCell.tsx +0 -15
  91. package/src/MRT_TableBodyRow.tsx +0 -27
  92. package/src/MRT_TableContainer.tsx +0 -16
  93. package/src/MRT_TableDetailPanel.tsx +0 -27
  94. package/src/MRT_TableExpandButton.tsx +0 -25
  95. package/src/MRT_TableFooter.tsx +0 -31
  96. package/src/MRT_TableFooterCell.tsx +0 -25
  97. package/src/MRT_TableFooterRow.tsx +0 -22
  98. package/src/MRT_TableHead.tsx +0 -25
  99. package/src/MRT_TableHeadCell.tsx +0 -27
  100. package/src/MRT_TableHeadRow.tsx +0 -22
  101. package/src/MRT_TablePagination.tsx +0 -34
  102. package/src/defaults.ts +0 -11
@@ -0,0 +1,73 @@
1
+ import React, { FC, MouseEvent } from 'react';
2
+ import {
3
+ Collapse,
4
+ styled,
5
+ TableCell as MuiTableCell,
6
+ TableRow,
7
+ } from '@mui/material';
8
+ import { Row } from 'react-table';
9
+ import { useMaterialReactTable } from '../useMaterialReactTable';
10
+
11
+ const TableCell = styled(MuiTableCell, {
12
+ shouldForwardProp: (prop) => prop !== 'isExpanded',
13
+ })<{ isExpanded?: boolean }>(({ isExpanded }) => ({
14
+ borderBottom: !isExpanded ? 'none' : undefined,
15
+ paddingBottom: isExpanded ? '1rem' : 0,
16
+ paddingTop: isExpanded ? '1rem' : 0,
17
+ transition: 'all 0.2s ease-in-out',
18
+ }));
19
+
20
+ interface Props {
21
+ row: Row;
22
+ }
23
+
24
+ export const MRT_TableDetailPanel: FC<Props> = ({ row }) => {
25
+ const {
26
+ tableInstance,
27
+ renderDetailPanel,
28
+ muiTableDetailPanelProps,
29
+ muiTableBodyRowProps,
30
+ onDetailPanelClick,
31
+ } = useMaterialReactTable();
32
+
33
+ const mTableBodyRowProps =
34
+ muiTableBodyRowProps instanceof Function
35
+ ? muiTableBodyRowProps(row)
36
+ : muiTableBodyRowProps;
37
+
38
+ const tableRowProps = {
39
+ ...mTableBodyRowProps,
40
+ ...row.getToggleRowExpandedProps(),
41
+ style: {
42
+ ...row.getToggleRowExpandedProps().style,
43
+ ...(mTableBodyRowProps?.style ?? {}),
44
+ },
45
+ };
46
+
47
+ const mTableDetailPanelProps =
48
+ muiTableDetailPanelProps instanceof Function
49
+ ? muiTableDetailPanelProps(row)
50
+ : muiTableDetailPanelProps;
51
+
52
+ const tableCellProps = {
53
+ ...mTableDetailPanelProps,
54
+ style: {
55
+ ...(mTableDetailPanelProps?.style ?? {}),
56
+ },
57
+ };
58
+
59
+ return (
60
+ <TableRow hover {...tableRowProps}>
61
+ <TableCell
62
+ colSpan={tableInstance.visibleColumns.length + 10}
63
+ isExpanded={row.isExpanded}
64
+ onClick={(event: MouseEvent<HTMLTableCellElement>) =>
65
+ onDetailPanelClick?.(event, row)
66
+ }
67
+ {...tableCellProps}
68
+ >
69
+ <Collapse in={row.isExpanded}>{renderDetailPanel?.(row)}</Collapse>
70
+ </TableCell>
71
+ </TableRow>
72
+ );
73
+ };
@@ -0,0 +1,55 @@
1
+ import React, { FC } from 'react';
2
+ import { IconButton, styled, Tooltip } from '@mui/material';
3
+ import SaveIcon from '@mui/icons-material/Save';
4
+ import CancelIcon from '@mui/icons-material/Cancel';
5
+ import { useMaterialReactTable } from '../useMaterialReactTable';
6
+ import { Row } from 'react-table';
7
+
8
+ const EditActionButtonWrappers = styled('div')({
9
+ display: 'flex',
10
+ gap: '0.75rem',
11
+ });
12
+
13
+ interface Props {
14
+ row: Row;
15
+ }
16
+
17
+ export const MRT_EditActionButtons: FC<Props> = ({ row }) => {
18
+ const {
19
+ localization,
20
+ setCurrentEditingRow,
21
+ onRowEditSubmit,
22
+ currentEditingRow,
23
+ } = useMaterialReactTable();
24
+
25
+ const handleCancel = () => {
26
+ setCurrentEditingRow(null);
27
+ };
28
+
29
+ const handleSave = async () => {
30
+ await onRowEditSubmit?.(currentEditingRow ?? row);
31
+ setCurrentEditingRow(null);
32
+ };
33
+
34
+ return (
35
+ <EditActionButtonWrappers>
36
+ <Tooltip arrow title={localization?.rowActionButtonCancel ?? ''}>
37
+ <IconButton
38
+ aria-label={localization?.rowActionButtonCancel}
39
+ onClick={handleCancel}
40
+ >
41
+ <CancelIcon />
42
+ </IconButton>
43
+ </Tooltip>
44
+ <Tooltip arrow title={localization?.rowActionButtonSave ?? ''}>
45
+ <IconButton
46
+ aria-label={localization?.rowActionButtonSave}
47
+ color="info"
48
+ onClick={handleSave}
49
+ >
50
+ <SaveIcon />
51
+ </IconButton>
52
+ </Tooltip>
53
+ </EditActionButtonWrappers>
54
+ );
55
+ };
@@ -0,0 +1,47 @@
1
+ import React, { FC } from 'react';
2
+ import { IconButton, styled, TableCell } from '@mui/material';
3
+ import MuiArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ const ArrowRightIcon = styled(MuiArrowRightIcon, {
7
+ shouldForwardProp: (prop) => prop !== 'rotation',
8
+ })<{ rotation?: number }>(({ rotation }) => ({
9
+ transform: `rotate(${rotation}deg)`,
10
+ transition: 'transform 0.2s',
11
+ }));
12
+
13
+ interface Props {}
14
+
15
+ export const MRT_ExpandAllButton: FC<Props> = () => {
16
+ const {
17
+ tableInstance,
18
+ localization,
19
+ anyRowsExpanded,
20
+ densePadding,
21
+ renderDetailPanel,
22
+ } = useMaterialReactTable();
23
+
24
+ return (
25
+ <TableCell
26
+ size="small"
27
+ {...tableInstance.getToggleAllRowsExpandedProps()}
28
+ style={{
29
+ padding: densePadding ? '0' : '0.5rem 0.5rem',
30
+ transition: 'all 0.2s ease-in-out',
31
+ width: `${renderDetailPanel ? 2 : tableInstance.expandedDepth + 2}rem`,
32
+ }}
33
+ >
34
+ <IconButton
35
+ aria-label={localization?.expandAllButtonTitle}
36
+ title={localization?.expandAllButtonTitle}
37
+ >
38
+ <ArrowRightIcon
39
+ fontSize="small"
40
+ rotation={
41
+ tableInstance.isAllRowsExpanded ? -180 : anyRowsExpanded ? -90 : 0
42
+ }
43
+ />
44
+ </IconButton>
45
+ </TableCell>
46
+ );
47
+ };
@@ -0,0 +1,51 @@
1
+ import React, { FC } from 'react';
2
+ import { IconButton, styled, TableCell as MuiTableCell } from '@mui/material';
3
+ import { Row } from 'react-table';
4
+ import MuiExpandMoreIcon from '@mui/icons-material/ExpandMore';
5
+ import { useMaterialReactTable } from '../useMaterialReactTable';
6
+
7
+ const TableCell = styled(MuiTableCell, {
8
+ shouldForwardProp: (prop) => prop !== 'densePadding' && prop !== 'depth',
9
+ })<{ densePadding?: boolean; depth: number }>(({ densePadding, depth }) => ({
10
+ padding: densePadding ? '0' : '0.6rem',
11
+ paddingLeft: `${depth + 0.5}rem`,
12
+ transition: 'all 0.2s ease-in-out',
13
+ }));
14
+
15
+ const ExpandMoreIcon = styled(MuiExpandMoreIcon, {
16
+ shouldForwardProp: (prop) => prop !== 'rotation',
17
+ })<{ rotation?: number }>(({ rotation }) => ({
18
+ transform: `rotate(${rotation}deg)`,
19
+ transition: 'transform 0.2s',
20
+ }));
21
+
22
+ interface Props {
23
+ row: Row;
24
+ }
25
+
26
+ export const MRT_ExpandButton: FC<Props> = ({ row }) => {
27
+ const { localization, densePadding, renderDetailPanel } =
28
+ useMaterialReactTable();
29
+
30
+ return (
31
+ <TableCell size="small" densePadding={densePadding} depth={row.depth}>
32
+ <IconButton
33
+ aria-label={localization?.expandButtonTitle}
34
+ disabled={!row.canExpand && !renderDetailPanel}
35
+ title={localization?.expandButtonTitle}
36
+ {...row.getToggleRowExpandedProps()}
37
+ >
38
+ <ExpandMoreIcon
39
+ fontSize={row.canExpand || renderDetailPanel ? 'medium' : 'small'}
40
+ rotation={
41
+ !row.canExpand && !renderDetailPanel
42
+ ? -90
43
+ : row.isExpanded
44
+ ? -180
45
+ : 0
46
+ }
47
+ />
48
+ </IconButton>
49
+ </TableCell>
50
+ );
51
+ };
@@ -0,0 +1,43 @@
1
+ import React, { FC, MouseEvent, useState } from 'react';
2
+ import { IconButton, Menu, Tooltip } from '@mui/material';
3
+ import ViewColumnIcon from '@mui/icons-material/ViewColumn';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+ import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
6
+
7
+ interface Props {}
8
+
9
+ export const MRT_ShowHideColumnsButton: FC<Props> = () => {
10
+ const { tableInstance, localization } = useMaterialReactTable();
11
+
12
+ const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
13
+
14
+ const handleClick = (event: MouseEvent<HTMLElement>) => {
15
+ setAnchorEl(event.currentTarget);
16
+ };
17
+
18
+ return (
19
+ <>
20
+ <Tooltip arrow title={localization?.showHideColumnsButtonTitle ?? ''}>
21
+ <IconButton
22
+ aria-label={localization?.showHideColumnsButtonTitle}
23
+ onClick={handleClick}
24
+ size="small"
25
+ >
26
+ <ViewColumnIcon />
27
+ </IconButton>
28
+ </Tooltip>
29
+ <Menu
30
+ anchorEl={anchorEl}
31
+ open={!!anchorEl}
32
+ onClose={() => setAnchorEl(null)}
33
+ >
34
+ {tableInstance.columns.map((column, index) => (
35
+ <MRT_ShowHideColumnsMenu
36
+ key={`${index}-${column.id}`}
37
+ column={column}
38
+ />
39
+ ))}
40
+ </Menu>
41
+ </>
42
+ );
43
+ };
@@ -0,0 +1,51 @@
1
+ import React, { FC, MouseEvent, useState } from 'react';
2
+ import { IconButton as MuiIconButton, styled } from '@mui/material';
3
+ import MoreVertIcon from '@mui/icons-material/MoreVert';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+ import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
6
+ import { HeaderGroup } from 'react-table';
7
+
8
+ const IconButton = styled(MuiIconButton)({
9
+ opacity: 0.5,
10
+ transition: 'opacity 0.2s',
11
+ marginRight: '2px',
12
+ height: '2rem',
13
+ width: '2rem',
14
+ '&:hover': {
15
+ opacity: 1,
16
+ },
17
+ });
18
+
19
+ interface Props {
20
+ column: HeaderGroup;
21
+ }
22
+
23
+ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
24
+ const { localization } = useMaterialReactTable();
25
+
26
+ const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
27
+
28
+ const handleClick = (event: MouseEvent<HTMLElement>) => {
29
+ event.stopPropagation();
30
+ event.preventDefault();
31
+ setAnchorEl(event.currentTarget);
32
+ };
33
+
34
+ return (
35
+ <>
36
+ <IconButton
37
+ aria-label={localization?.columnActionMenuButtonTitle}
38
+ title={localization?.columnActionMenuButtonTitle}
39
+ onClick={handleClick}
40
+ size="small"
41
+ >
42
+ <MoreVertIcon />
43
+ </IconButton>
44
+ <MRT_ColumnActionMenu
45
+ anchorEl={anchorEl}
46
+ column={column}
47
+ setAnchorEl={setAnchorEl}
48
+ />
49
+ </>
50
+ );
51
+ };
@@ -0,0 +1,23 @@
1
+ import React, { FC } from 'react';
2
+ import { IconButton, Tooltip } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import FilterListIcon from '@mui/icons-material/FilterList';
5
+ import FilterListOffIcon from '@mui/icons-material/FilterListOff';
6
+
7
+ type Props = {};
8
+
9
+ export const MRT_ToggleFiltersButton: FC<Props> = () => {
10
+ const { localization, setShowFilters, showFilters } = useMaterialReactTable();
11
+
12
+ return (
13
+ <Tooltip arrow title={localization?.toggleFilterButtonTitle ?? ''}>
14
+ <IconButton
15
+ aria-label={localization?.toggleFilterButtonTitle}
16
+ onClick={() => setShowFilters(!showFilters)}
17
+ size="small"
18
+ >
19
+ {showFilters ? <FilterListOffIcon /> : <FilterListIcon />}
20
+ </IconButton>
21
+ </Tooltip>
22
+ );
23
+ };
@@ -0,0 +1,65 @@
1
+ import React, { FC, MouseEvent, useState } from 'react';
2
+ import { IconButton as MuiIconButton, styled } from '@mui/material';
3
+ import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+ import { Row } from 'react-table';
6
+ import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
7
+ import { MRT_EditActionButtons } from './MRT_EditActionButtons';
8
+
9
+ const IconButton = styled(MuiIconButton)({
10
+ opacity: 0.5,
11
+ transition: 'opacity 0.2s',
12
+ marginRight: '2px',
13
+ height: '2rem',
14
+ width: '2rem',
15
+ '&:hover': {
16
+ opacity: 1,
17
+ },
18
+ });
19
+
20
+ interface Props {
21
+ row: Row;
22
+ }
23
+
24
+ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
25
+ const {
26
+ localization,
27
+ currentEditingRow,
28
+ renderRowActions,
29
+ tableInstance,
30
+ } = useMaterialReactTable();
31
+
32
+ const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
33
+
34
+ const handleOpenRowActionMenu = (event: MouseEvent<HTMLElement>) => {
35
+ event.stopPropagation();
36
+ event.preventDefault();
37
+ setAnchorEl(event.currentTarget);
38
+ };
39
+
40
+ if (renderRowActions) {
41
+ return <>{renderRowActions(row, tableInstance)}</>;
42
+ }
43
+
44
+ if (row.id === currentEditingRow?.id) {
45
+ return <MRT_EditActionButtons row={row} />;
46
+ }
47
+
48
+ return (
49
+ <>
50
+ <IconButton
51
+ aria-label={localization?.rowActionMenuButtonTitle}
52
+ title={localization?.rowActionMenuButtonTitle}
53
+ onClick={handleOpenRowActionMenu}
54
+ size="small"
55
+ >
56
+ <MoreHorizIcon />
57
+ </IconButton>
58
+ <MRT_RowActionMenu
59
+ anchorEl={anchorEl}
60
+ row={row}
61
+ setAnchorEl={setAnchorEl}
62
+ />
63
+ </>
64
+ );
65
+ };
@@ -0,0 +1,21 @@
1
+ import React, { FC } from 'react';
2
+ import { TableFooter } from '@mui/material';
3
+ import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ interface Props {}
7
+
8
+ export const MRT_TableFooter: FC<Props> = () => {
9
+ const { muiTableFooterProps, tableInstance } = useMaterialReactTable();
10
+
11
+ return (
12
+ <TableFooter {...muiTableFooterProps}>
13
+ {tableInstance.footerGroups.map((footerGroup) => (
14
+ <MRT_TableFooterRow
15
+ key={footerGroup.getFooterGroupProps().key}
16
+ footerGroup={footerGroup}
17
+ />
18
+ ))}
19
+ </TableFooter>
20
+ );
21
+ };
@@ -0,0 +1,60 @@
1
+ import React, { FC } from 'react';
2
+ import { styled, TableCell as MuiTableCell } from '@mui/material';
3
+ import { HeaderGroup } from 'react-table';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ const TableCell = styled(MuiTableCell, {
7
+ shouldForwardProp: (prop) =>
8
+ prop !== 'densePadding' && prop !== 'enableColumnResizing',
9
+ })<{ densePadding?: boolean; enableColumnResizing?: boolean }>(
10
+ ({ densePadding, enableColumnResizing }) => ({
11
+ fontWeight: 'bold',
12
+ verticalAlign: 'text-top',
13
+ padding: densePadding ? '0.5rem' : '1rem',
14
+ transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
15
+ }),
16
+ );
17
+
18
+ interface Props {
19
+ column: HeaderGroup;
20
+ }
21
+
22
+ export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
23
+ const { muiTableFooterCellProps, densePadding, enableColumnResizing } =
24
+ useMaterialReactTable();
25
+
26
+ const isParentHeader = (column?.columns?.length ?? 0) > 0;
27
+
28
+ const mTableFooterCellProps =
29
+ muiTableFooterCellProps instanceof Function
30
+ ? muiTableFooterCellProps(column)
31
+ : muiTableFooterCellProps;
32
+
33
+ const mcTableFooterCellProps =
34
+ column.muiTableFooterCellProps instanceof Function
35
+ ? column.muiTableFooterCellProps(column)
36
+ : column.muiTableFooterCellProps;
37
+
38
+ const tableCellProps = {
39
+ ...mTableFooterCellProps,
40
+ ...mcTableFooterCellProps,
41
+ ...column.getFooterProps(),
42
+ style: {
43
+ ...column.getFooterProps().style,
44
+ ...(mTableFooterCellProps?.style ?? {}),
45
+ ...(mcTableFooterCellProps?.style ?? {}),
46
+ },
47
+ };
48
+
49
+ return (
50
+ <TableCell
51
+ align={isParentHeader ? 'center' : 'left'}
52
+ densePadding={densePadding}
53
+ enableColumnResizing={enableColumnResizing}
54
+ variant="head"
55
+ {...tableCellProps}
56
+ >
57
+ {column.render('Footer')}
58
+ </TableCell>
59
+ );
60
+ };
@@ -0,0 +1,62 @@
1
+ import React, { FC } from 'react';
2
+ import { TableRow } from '@mui/material';
3
+ import { HeaderGroup } from 'react-table';
4
+ import { MRT_TableFooterCell } from './MRT_TableFooterCell';
5
+ import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
6
+ import { useMaterialReactTable } from '../useMaterialReactTable';
7
+
8
+ interface Props {
9
+ footerGroup: HeaderGroup;
10
+ }
11
+
12
+ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
13
+ const {
14
+ renderDetailPanel,
15
+ columns,
16
+ anyRowsCanExpand,
17
+ enableSelection,
18
+ enableRowActions,
19
+ positionActionsColumn,
20
+ tableInstance,
21
+ muiTableFooterRowProps,
22
+ } = useMaterialReactTable();
23
+
24
+ //if no content in row, skip row
25
+ if (!columns?.some((c) => c.Footer)) return null;
26
+
27
+ const mTableFooterRowProps =
28
+ muiTableFooterRowProps instanceof Function
29
+ ? muiTableFooterRowProps(footerGroup)
30
+ : muiTableFooterRowProps;
31
+
32
+ const tableRowProps = {
33
+ ...mTableFooterRowProps,
34
+ ...footerGroup.getFooterGroupProps(),
35
+ style: {
36
+ ...footerGroup.getFooterGroupProps().style,
37
+ ...(mTableFooterRowProps?.style ?? {}),
38
+ },
39
+ };
40
+
41
+ return (
42
+ <TableRow {...tableRowProps}>
43
+ {enableRowActions && positionActionsColumn === 'first' && (
44
+ <MRT_TableSpacerCell />
45
+ )}
46
+ {(anyRowsCanExpand || renderDetailPanel) && (
47
+ <MRT_TableSpacerCell
48
+ width={`${
49
+ renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
50
+ }rem`}
51
+ />
52
+ )}
53
+ {enableSelection && <MRT_TableSpacerCell width="1rem" />}
54
+ {footerGroup.headers.map((column,) => (
55
+ <MRT_TableFooterCell key={column.getFooterProps().key} column={column} />
56
+ ))}
57
+ {enableRowActions && positionActionsColumn === 'last' && (
58
+ <MRT_TableSpacerCell />
59
+ )}
60
+ </TableRow>
61
+ );
62
+ };
@@ -0,0 +1,26 @@
1
+ import React, { FC } from 'react';
2
+ import { TableHead } from '@mui/material';
3
+ import { MRT_TableHeadRow } from './MRT_TableHeadRow';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ interface Props {}
7
+
8
+ export const MRT_TableHead: FC<Props> = () => {
9
+ const { tableInstance, muiTableHeadProps } = useMaterialReactTable();
10
+
11
+ const tableHeadProps =
12
+ muiTableHeadProps instanceof Function
13
+ ? muiTableHeadProps(tableInstance)
14
+ : muiTableHeadProps;
15
+
16
+ return (
17
+ <TableHead {...tableHeadProps}>
18
+ {tableInstance.headerGroups.map((headerGroup) => (
19
+ <MRT_TableHeadRow
20
+ key={headerGroup.getHeaderGroupProps().key}
21
+ headerGroup={headerGroup}
22
+ />
23
+ ))}
24
+ </TableHead>
25
+ );
26
+ };