material-react-table 0.1.0-beta.1 → 0.3.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 (96) hide show
  1. package/dist/MaterialReactTable.d.ts +60 -26
  2. package/dist/{MRT_TableBody.d.ts → body/MRT_TableBody.d.ts} +0 -0
  3. package/dist/{MRT_TableBodyCell.d.ts → body/MRT_TableBodyCell.d.ts} +1 -1
  4. package/dist/{MRT_TableBodyRow.d.ts → body/MRT_TableBodyRow.d.ts} +1 -1
  5. package/dist/{MRT_TableDetailPanel.d.ts → body/MRT_TableDetailPanel.d.ts} +1 -1
  6. package/dist/{MRT_TableExpandButton.d.ts → buttons/MRT_EditActionButtons.d.ts} +2 -2
  7. package/dist/buttons/MRT_ExpandAllButton.d.ts +5 -0
  8. package/dist/buttons/MRT_ExpandButton.d.ts +7 -0
  9. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +5 -0
  10. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +7 -0
  11. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
  12. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
  13. package/dist/{MRT_TableFooter.d.ts → footer/MRT_TableFooter.d.ts} +0 -0
  14. package/dist/{MRT_TableFooterCell.d.ts → footer/MRT_TableFooterCell.d.ts} +0 -0
  15. package/dist/{MRT_TableFooterRow.d.ts → footer/MRT_TableFooterRow.d.ts} +1 -1
  16. package/dist/{MRT_TableHead.d.ts → head/MRT_TableHead.d.ts} +0 -0
  17. package/dist/head/MRT_TableHeadCell.d.ts +8 -0
  18. package/dist/{MRT_TableHeadRow.d.ts → head/MRT_TableHeadRow.d.ts} +1 -1
  19. package/dist/index.d.ts +2 -0
  20. package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
  21. package/dist/{MRT_TableHeadCell.d.ts → inputs/MRT_FilterTextField.d.ts} +1 -1
  22. package/dist/inputs/MRT_SearchTextField.d.ts +5 -0
  23. package/dist/inputs/MRT_SelectAllCheckbox.d.ts +2 -0
  24. package/dist/inputs/MRT_SelectCheckbox.d.ts +7 -0
  25. package/dist/material-react-table.cjs.development.js +1933 -170
  26. package/dist/material-react-table.cjs.development.js.map +1 -1
  27. package/dist/material-react-table.cjs.production.min.js +1 -1
  28. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  29. package/dist/material-react-table.esm.js +1939 -176
  30. package/dist/material-react-table.esm.js.map +1 -1
  31. package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -0
  32. package/dist/menus/MRT_RowActionMenu.d.ts +9 -0
  33. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +7 -0
  34. package/dist/{MRT_Table.d.ts → table/MRT_Table.d.ts} +0 -0
  35. package/dist/{MRT_TableContainer.d.ts → table/MRT_TableContainer.d.ts} +0 -0
  36. package/dist/table/MRT_TableSpacerCell.d.ts +6 -0
  37. package/dist/{MRT_TablePagination.d.ts → toolbar/MRT_TablePagination.d.ts} +0 -0
  38. package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
  39. package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
  40. package/dist/toolbar/MRT_ToolbarTop.d.ts +5 -0
  41. package/dist/useMaterialReactTable.d.ts +13 -11
  42. package/dist/utils/localization.d.ts +25 -0
  43. package/dist/utils/useMRTCalcs.d.ts +11 -0
  44. package/package.json +21 -17
  45. package/src/MaterialReactTable.tsx +145 -37
  46. package/src/body/MRT_TableBody.tsx +56 -0
  47. package/src/body/MRT_TableBodyCell.tsx +48 -0
  48. package/src/body/MRT_TableBodyRow.tsx +74 -0
  49. package/src/body/MRT_TableDetailPanel.tsx +62 -0
  50. package/src/buttons/MRT_EditActionButtons.tsx +51 -0
  51. package/src/buttons/MRT_ExpandAllButton.tsx +45 -0
  52. package/src/buttons/MRT_ExpandButton.tsx +48 -0
  53. package/src/buttons/MRT_ShowHideColumnsButton.tsx +43 -0
  54. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +51 -0
  55. package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
  56. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
  57. package/src/footer/MRT_TableFooter.tsx +21 -0
  58. package/src/footer/MRT_TableFooterCell.tsx +44 -0
  59. package/src/footer/MRT_TableFooterRow.tsx +62 -0
  60. package/src/{MRT_TableHead.tsx → head/MRT_TableHead.tsx} +7 -6
  61. package/src/head/MRT_TableHeadCell.tsx +120 -0
  62. package/src/head/MRT_TableHeadRow.tsx +89 -0
  63. package/src/index.tsx +2 -0
  64. package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
  65. package/src/inputs/MRT_FilterTextField.tsx +64 -0
  66. package/src/inputs/MRT_SearchTextField.tsx +74 -0
  67. package/src/inputs/MRT_SelectAllCheckbox.tsx +26 -0
  68. package/src/inputs/MRT_SelectCheckbox.tsx +33 -0
  69. package/src/menus/MRT_ColumnActionMenu.tsx +107 -0
  70. package/src/menus/MRT_RowActionMenu.tsx +52 -0
  71. package/src/menus/MRT_ShowHideColumnsMenu.tsx +34 -0
  72. package/src/table/MRT_Table.tsx +30 -0
  73. package/src/table/MRT_TableContainer.tsx +22 -0
  74. package/src/table/MRT_TableSpacerCell.tsx +26 -0
  75. package/src/toolbar/MRT_TablePagination.tsx +37 -0
  76. package/src/toolbar/MRT_ToolbarBottom.tsx +58 -0
  77. package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
  78. package/src/toolbar/MRT_ToolbarTop.tsx +81 -0
  79. package/src/useMaterialReactTable.tsx +71 -32
  80. package/src/utils/localization.ts +49 -0
  81. package/src/utils/useMRTCalcs.tsx +42 -0
  82. package/dist/defaults.d.ts +0 -2
  83. package/src/MRT_Table.tsx +0 -20
  84. package/src/MRT_TableBody.tsx +0 -19
  85. package/src/MRT_TableBodyCell.tsx +0 -15
  86. package/src/MRT_TableBodyRow.tsx +0 -27
  87. package/src/MRT_TableContainer.tsx +0 -16
  88. package/src/MRT_TableDetailPanel.tsx +0 -27
  89. package/src/MRT_TableExpandButton.tsx +0 -25
  90. package/src/MRT_TableFooter.tsx +0 -31
  91. package/src/MRT_TableFooterCell.tsx +0 -25
  92. package/src/MRT_TableFooterRow.tsx +0 -22
  93. package/src/MRT_TableHeadCell.tsx +0 -27
  94. package/src/MRT_TableHeadRow.tsx +0 -22
  95. package/src/MRT_TablePagination.tsx +0 -34
  96. package/src/defaults.ts +0 -11
@@ -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
+ currentEditingRowId,
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 === currentEditingRowId) {
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, index) => (
14
+ <MRT_TableFooterRow
15
+ key={`${index}-${footerGroup.id}`}
16
+ footerGroup={footerGroup}
17
+ />
18
+ ))}
19
+ </TableFooter>
20
+ );
21
+ };
@@ -0,0 +1,44 @@
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
+ fontWeight: 'bold',
8
+ });
9
+
10
+ interface Props {
11
+ column: HeaderGroup;
12
+ }
13
+
14
+ export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
15
+ const { muiTableFooterCellProps, densePadding } = useMaterialReactTable();
16
+
17
+ const isParentHeader = (column?.columns?.length ?? 0) > 0;
18
+
19
+ const mTableFooterCellProps =
20
+ muiTableFooterCellProps instanceof Function
21
+ ? muiTableFooterCellProps(column)
22
+ : muiTableFooterCellProps;
23
+
24
+ const tableCellProps = {
25
+ ...mTableFooterCellProps,
26
+ ...column.getFooterProps(),
27
+ style: {
28
+ padding: densePadding ? '0.5rem' : '1rem',
29
+ transition: 'all 0.2s ease-in-out',
30
+ ...column.getFooterProps().style,
31
+ ...(mTableFooterCellProps?.style ?? {}),
32
+ },
33
+ };
34
+
35
+ return (
36
+ <TableCell
37
+ align={isParentHeader ? 'center' : 'left'}
38
+ variant="head"
39
+ {...tableCellProps}
40
+ >
41
+ {column.render('Footer')}
42
+ </TableCell>
43
+ );
44
+ };
@@ -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, index) => (
55
+ <MRT_TableFooterCell key={`${index}-${column.id}`} column={column} />
56
+ ))}
57
+ {enableRowActions && positionActionsColumn === 'last' && (
58
+ <MRT_TableSpacerCell />
59
+ )}
60
+ </TableRow>
61
+ );
62
+ };
@@ -1,19 +1,20 @@
1
1
  import React, { FC } from 'react';
2
2
  import { TableHead } from '@mui/material';
3
3
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
4
- import { useMaterialReactTable } from './useMaterialReactTable';
5
- import { MRT_TablePagination } from './MRT_TablePagination';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
6
5
 
7
6
  interface Props {}
8
7
 
9
8
  export const MRT_TableHead: FC<Props> = () => {
10
- const { tableInstance, tableHeadProps, options } = useMaterialReactTable();
9
+ const { tableInstance, muiTableHeadProps } = useMaterialReactTable();
10
+
11
+ const tableHeadProps =
12
+ muiTableHeadProps instanceof Function
13
+ ? muiTableHeadProps(tableInstance)
14
+ : muiTableHeadProps;
11
15
 
12
16
  return (
13
17
  <TableHead {...tableHeadProps}>
14
- {['top', 'both'].includes(options.enablePagination.toString()) && (
15
- <MRT_TablePagination />
16
- )}
17
18
  {tableInstance.headerGroups.map((headerGroup, index) => (
18
19
  <MRT_TableHeadRow
19
20
  key={`${index}-${headerGroup.id}`}
@@ -0,0 +1,120 @@
1
+ import React, { FC } from 'react';
2
+ import {
3
+ TableCell as MuiTableCell,
4
+ TableSortLabel,
5
+ styled,
6
+ Divider as MuiDivider,
7
+ Collapse,
8
+ } from '@mui/material';
9
+ import { HeaderGroup } from 'react-table';
10
+ import { useMaterialReactTable } from '../useMaterialReactTable';
11
+ import { MRT_FilterTextfield } from '../inputs/MRT_FilterTextField';
12
+ import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
13
+
14
+ export const StyledTableHeadCell = styled(MuiTableCell)({
15
+ fontWeight: 'bold',
16
+ verticalAlign: 'text-top',
17
+ });
18
+
19
+ const TableCellContents = styled('div')({
20
+ display: 'grid',
21
+ });
22
+
23
+ const TableCellText = styled('div')({
24
+ width: '100%',
25
+ display: 'flex',
26
+ justifyContent: 'space-between',
27
+ });
28
+
29
+ const CellFlexItem = styled('span')({
30
+ display: 'flex',
31
+ flexWrap: 'nowrap',
32
+ alignItems: 'center',
33
+ });
34
+
35
+ const Divider = styled(MuiDivider)({
36
+ borderRightWidth: '2px',
37
+ borderRadius: '2px',
38
+ maxHeight: '2rem',
39
+ });
40
+
41
+ interface Props {
42
+ column: HeaderGroup;
43
+ }
44
+
45
+ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
46
+ const {
47
+ densePadding,
48
+ disableColumnActions,
49
+ disableFilters,
50
+ enableColumnResizing,
51
+ localization,
52
+ muiTableHeadCellProps,
53
+ showFilters,
54
+ tableInstance,
55
+ } = useMaterialReactTable();
56
+
57
+ const isParentHeader = (column?.columns?.length ?? 0) > 0;
58
+
59
+ const mTableHeadCellProps =
60
+ muiTableHeadCellProps instanceof Function
61
+ ? muiTableHeadCellProps(column)
62
+ : muiTableHeadCellProps;
63
+
64
+ const tableCellProps = {
65
+ ...mTableHeadCellProps,
66
+ ...column.getHeaderProps(),
67
+ style: {
68
+ padding: densePadding ? '0.5rem' : '1rem',
69
+ transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
70
+ ...column.getHeaderProps().style,
71
+ ...(mTableHeadCellProps?.style ?? {}),
72
+ },
73
+ };
74
+
75
+ return (
76
+ <StyledTableHeadCell align={isParentHeader ? 'center' : 'left'} {...tableCellProps}>
77
+ <TableCellContents>
78
+ <TableCellText
79
+ style={{ justifyContent: isParentHeader ? 'center' : undefined }}
80
+ >
81
+ <CellFlexItem {...column.getSortByToggleProps()}>
82
+ {column.render('Header')}
83
+ {!isParentHeader && column.canSort && (
84
+ <TableSortLabel
85
+ aria-label={
86
+ column.isSorted
87
+ ? column.sortDescFirst
88
+ ? localization?.columnActionMenuItemClearSort
89
+ : localization?.columnActionMenuItemSortDesc
90
+ : localization?.columnActionMenuItemSortAsc
91
+ }
92
+ active={column.isSorted}
93
+ direction={column.isSortedDesc ? 'desc' : 'asc'}
94
+ style={{ margin: 0 }}
95
+ />
96
+ )}
97
+ </CellFlexItem>
98
+ <CellFlexItem>
99
+ {!disableColumnActions && !isParentHeader && (
100
+ <MRT_ToggleColumnActionMenuButton column={column} />
101
+ )}
102
+ {enableColumnResizing && !isParentHeader && (
103
+ <Divider
104
+ flexItem
105
+ orientation="vertical"
106
+ onDoubleClick={() => tableInstance.resetResizing()}
107
+ {...column.getResizerProps()}
108
+ />
109
+ )}
110
+ </CellFlexItem>
111
+ </TableCellText>
112
+ {!disableFilters && column.canFilter && (
113
+ <Collapse in={showFilters}>
114
+ <MRT_FilterTextfield column={column} />
115
+ </Collapse>
116
+ )}
117
+ </TableCellContents>
118
+ </StyledTableHeadCell>
119
+ );
120
+ };
@@ -0,0 +1,89 @@
1
+ import React, { FC, useMemo } from 'react';
2
+ import { TableRow } from '@mui/material';
3
+ import { HeaderGroup } from 'react-table';
4
+ import { MRT_TableHeadCell, StyledTableHeadCell } from './MRT_TableHeadCell';
5
+ import { useMaterialReactTable } from '../useMaterialReactTable';
6
+ import { MRT_SelectAllCheckbox } from '../inputs/MRT_SelectAllCheckbox';
7
+ import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
8
+ import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
9
+
10
+ interface Props {
11
+ headerGroup: HeaderGroup;
12
+ }
13
+
14
+ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
15
+ const {
16
+ anyRowsCanExpand,
17
+ disableExpandAll,
18
+ enableRowActions,
19
+ enableSelection,
20
+ localization,
21
+ muiTableHeadRowProps,
22
+ positionActionsColumn,
23
+ renderDetailPanel,
24
+ tableInstance,
25
+ } = useMaterialReactTable();
26
+
27
+ const isParentHeader = useMemo(
28
+ () => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
29
+ [headerGroup.headers],
30
+ );
31
+
32
+ const mTableHeadRowProps =
33
+ muiTableHeadRowProps instanceof Function
34
+ ? muiTableHeadRowProps(headerGroup)
35
+ : muiTableHeadRowProps;
36
+
37
+ const tableRowProps = {
38
+ ...mTableHeadRowProps,
39
+ ...headerGroup.getHeaderGroupProps(),
40
+ style: {
41
+ ...headerGroup.getHeaderGroupProps().style,
42
+ ...(mTableHeadRowProps?.style ?? {}),
43
+ },
44
+ };
45
+
46
+ return (
47
+ <TableRow {...tableRowProps}>
48
+ {enableRowActions &&
49
+ positionActionsColumn === 'first' &&
50
+ (isParentHeader ? (
51
+ <MRT_TableSpacerCell />
52
+ ) : (
53
+ <StyledTableHeadCell>
54
+ {localization?.actionsHeadColumnTitle}
55
+ </StyledTableHeadCell>
56
+ ))}
57
+ {anyRowsCanExpand || renderDetailPanel ? (
58
+ !disableExpandAll && !isParentHeader ? (
59
+ <MRT_ExpandAllButton />
60
+ ) : (
61
+ <MRT_TableSpacerCell
62
+ width={`${
63
+ renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
64
+ }rem`}
65
+ />
66
+ )
67
+ ) : null}
68
+ {enableSelection ? (
69
+ !isParentHeader ? (
70
+ <MRT_SelectAllCheckbox />
71
+ ) : (
72
+ <MRT_TableSpacerCell width="1rem" />
73
+ )
74
+ ) : null}
75
+ {headerGroup.headers.map((column) => (
76
+ <MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
77
+ ))}
78
+ {enableRowActions &&
79
+ positionActionsColumn === 'last' &&
80
+ (isParentHeader ? (
81
+ <MRT_TableSpacerCell />
82
+ ) : (
83
+ <StyledTableHeadCell>
84
+ {localization?.actionsHeadColumnTitle}
85
+ </StyledTableHeadCell>
86
+ ))}
87
+ </TableRow>
88
+ );
89
+ };
package/src/index.tsx CHANGED
@@ -1 +1,3 @@
1
+ import MaterialReactTable from './MaterialReactTable';
2
+ export default MaterialReactTable;
1
3
  export * from './MaterialReactTable';
@@ -0,0 +1,21 @@
1
+ import React, { FC } from 'react';
2
+ import { Switch, Tooltip } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+
5
+ interface Props {}
6
+
7
+ export const MRT_DensePaddingSwitch: FC<Props> = () => {
8
+ const { densePadding, setDensePadding, localization } =
9
+ useMaterialReactTable();
10
+
11
+ return (
12
+ <Tooltip arrow title={localization?.toggleDensePaddingSwitchTitle ?? ''}>
13
+ <Switch
14
+ color="default"
15
+ checked={densePadding}
16
+ size="small"
17
+ onChange={() => setDensePadding(!densePadding)}
18
+ />
19
+ </Tooltip>
20
+ );
21
+ };
@@ -0,0 +1,64 @@
1
+ import React, { ChangeEvent, FC, useState } from 'react';
2
+ import { IconButton, InputAdornment, TextField } from '@mui/material';
3
+ import CloseIcon from '@mui/icons-material/Close';
4
+ import FilterIcon from '@mui/icons-material/FilterList';
5
+ import { HeaderGroup, useAsyncDebounce } from 'react-table';
6
+ import { useMaterialReactTable } from '../useMaterialReactTable';
7
+
8
+ interface Props {
9
+ column: HeaderGroup;
10
+ }
11
+
12
+ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
13
+ const { localization } = useMaterialReactTable();
14
+
15
+ const [filterValue, setFilterValue] = useState('');
16
+
17
+ const handleChange = useAsyncDebounce((value) => {
18
+ column.setFilter(value ?? undefined);
19
+ }, 150);
20
+
21
+ const handleClear = () => {
22
+ setFilterValue('');
23
+ column.setFilter(undefined);
24
+ };
25
+
26
+ if (column.Filter) {
27
+ //@ts-ignore
28
+ return <>{column.Filter({ column })}</>;
29
+ }
30
+
31
+ return (
32
+ <TextField
33
+ margin="dense"
34
+ placeholder={localization?.filterTextFieldPlaceholder}
35
+ onChange={(e: ChangeEvent<HTMLInputElement>) => {
36
+ setFilterValue(e.target.value);
37
+ handleChange(e.target.value);
38
+ }}
39
+ onClick={(e) => e.stopPropagation()}
40
+ value={filterValue ?? ''}
41
+ variant="standard"
42
+ InputProps={{
43
+ startAdornment: (
44
+ <InputAdornment position="start">
45
+ <FilterIcon />
46
+ </InputAdornment>
47
+ ),
48
+ endAdornment: (
49
+ <InputAdornment position="end">
50
+ <IconButton
51
+ aria-label={localization?.filterTextFieldClearButtonTitle}
52
+ disabled={filterValue?.length === 0}
53
+ onClick={handleClear}
54
+ size="small"
55
+ title={localization?.filterTextFieldClearButtonTitle}
56
+ >
57
+ <CloseIcon fontSize="small" />
58
+ </IconButton>
59
+ </InputAdornment>
60
+ ),
61
+ }}
62
+ />
63
+ );
64
+ };