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,137 @@
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
+ shouldForwardProp: (prop) =>
16
+ prop !== 'densePadding' && prop !== 'enableColumnResizing',
17
+ })<{ densePadding?: boolean; enableColumnResizing?: boolean }>(
18
+ ({ densePadding, enableColumnResizing }) => ({
19
+ fontWeight: 'bold',
20
+ verticalAlign: 'text-top',
21
+ padding: densePadding ? '0.5rem' : '1rem',
22
+ transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
23
+ }),
24
+ );
25
+
26
+ const TableCellContents = styled('div')({
27
+ display: 'grid',
28
+ });
29
+
30
+ const TableCellText = styled('div')({
31
+ width: '100%',
32
+ display: 'flex',
33
+ justifyContent: 'space-between',
34
+ });
35
+
36
+ const CellFlexItem = styled('span')({
37
+ display: 'flex',
38
+ flexWrap: 'nowrap',
39
+ alignItems: 'center',
40
+ });
41
+
42
+ const Divider = styled(MuiDivider)({
43
+ borderRightWidth: '2px',
44
+ borderRadius: '2px',
45
+ maxHeight: '2rem',
46
+ });
47
+
48
+ interface Props {
49
+ column: HeaderGroup;
50
+ }
51
+
52
+ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
53
+ const {
54
+ densePadding,
55
+ disableColumnActions,
56
+ disableFilters,
57
+ enableColumnResizing,
58
+ localization,
59
+ muiTableHeadCellProps,
60
+ showFilters,
61
+ tableInstance,
62
+ } = useMaterialReactTable();
63
+
64
+ const isParentHeader = (column?.columns?.length ?? 0) > 0;
65
+
66
+ const mTableHeadCellProps =
67
+ muiTableHeadCellProps instanceof Function
68
+ ? muiTableHeadCellProps(column)
69
+ : muiTableHeadCellProps;
70
+
71
+ const mcTableHeadCellProps =
72
+ column.muiTableHeadCellProps instanceof Function
73
+ ? column.muiTableHeadCellProps(column)
74
+ : column.muiTableHeadCellProps;
75
+
76
+ const tableCellProps = {
77
+ ...mTableHeadCellProps,
78
+ ...mcTableHeadCellProps,
79
+ ...column.getHeaderProps(),
80
+ style: {
81
+ ...column.getHeaderProps().style,
82
+ ...(mTableHeadCellProps?.style ?? {}),
83
+ ...(mcTableHeadCellProps?.style ?? {}),
84
+ },
85
+ };
86
+
87
+ return (
88
+ <StyledTableHeadCell
89
+ align={isParentHeader ? 'center' : 'left'}
90
+ densePadding={densePadding}
91
+ enableColumnResizing={enableColumnResizing}
92
+ {...tableCellProps}
93
+ >
94
+ <TableCellContents>
95
+ <TableCellText
96
+ style={{ justifyContent: isParentHeader ? 'center' : undefined }}
97
+ >
98
+ <CellFlexItem {...column.getSortByToggleProps()}>
99
+ {column.render('Header')}
100
+ {!isParentHeader && column.canSort && (
101
+ <TableSortLabel
102
+ aria-label={
103
+ column.isSorted
104
+ ? column.sortDescFirst
105
+ ? localization?.columnActionMenuItemClearSort
106
+ : localization?.columnActionMenuItemSortDesc
107
+ : localization?.columnActionMenuItemSortAsc
108
+ }
109
+ active={column.isSorted}
110
+ direction={column.isSortedDesc ? 'desc' : 'asc'}
111
+ style={{ margin: 0 }}
112
+ />
113
+ )}
114
+ </CellFlexItem>
115
+ <CellFlexItem>
116
+ {!disableColumnActions && !isParentHeader && (
117
+ <MRT_ToggleColumnActionMenuButton column={column} />
118
+ )}
119
+ {enableColumnResizing && !isParentHeader && (
120
+ <Divider
121
+ flexItem
122
+ orientation="vertical"
123
+ onDoubleClick={() => tableInstance.resetResizing()}
124
+ {...column.getResizerProps()}
125
+ />
126
+ )}
127
+ </CellFlexItem>
128
+ </TableCellText>
129
+ {!disableFilters && column.canFilter && (
130
+ <Collapse in={showFilters}>
131
+ <MRT_FilterTextfield column={column} />
132
+ </Collapse>
133
+ )}
134
+ </TableCellContents>
135
+ </StyledTableHeadCell>
136
+ );
137
+ };
@@ -0,0 +1,90 @@
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
+ densePadding,
18
+ disableExpandAll,
19
+ enableRowActions,
20
+ enableSelection,
21
+ localization,
22
+ muiTableHeadRowProps,
23
+ positionActionsColumn,
24
+ renderDetailPanel,
25
+ tableInstance,
26
+ } = useMaterialReactTable();
27
+
28
+ const isParentHeader = useMemo(
29
+ () => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
30
+ [headerGroup.headers],
31
+ );
32
+
33
+ const mTableHeadRowProps =
34
+ muiTableHeadRowProps instanceof Function
35
+ ? muiTableHeadRowProps(headerGroup)
36
+ : muiTableHeadRowProps;
37
+
38
+ const tableRowProps = {
39
+ ...mTableHeadRowProps,
40
+ ...headerGroup.getHeaderGroupProps(),
41
+ style: {
42
+ ...headerGroup.getHeaderGroupProps().style,
43
+ ...(mTableHeadRowProps?.style ?? {}),
44
+ },
45
+ };
46
+
47
+ return (
48
+ <TableRow {...tableRowProps}>
49
+ {enableRowActions &&
50
+ positionActionsColumn === 'first' &&
51
+ (isParentHeader ? (
52
+ <MRT_TableSpacerCell />
53
+ ) : (
54
+ <StyledTableHeadCell>
55
+ {localization?.actionsHeadColumnTitle}
56
+ </StyledTableHeadCell>
57
+ ))}
58
+ {anyRowsCanExpand || renderDetailPanel ? (
59
+ !disableExpandAll && !isParentHeader ? (
60
+ <MRT_ExpandAllButton />
61
+ ) : (
62
+ <MRT_TableSpacerCell
63
+ width={`${
64
+ renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
65
+ }rem`}
66
+ />
67
+ )
68
+ ) : null}
69
+ {enableSelection ? (
70
+ !isParentHeader ? (
71
+ <MRT_SelectAllCheckbox />
72
+ ) : (
73
+ <MRT_TableSpacerCell width="1rem" />
74
+ )
75
+ ) : null}
76
+ {headerGroup.headers.map((column: HeaderGroup) => (
77
+ <MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
78
+ ))}
79
+ {enableRowActions &&
80
+ positionActionsColumn === 'last' &&
81
+ (isParentHeader ? (
82
+ <MRT_TableSpacerCell />
83
+ ) : (
84
+ <StyledTableHeadCell densePadding={densePadding}>
85
+ {localization?.actionsHeadColumnTitle}
86
+ </StyledTableHeadCell>
87
+ ))}
88
+ </TableRow>
89
+ );
90
+ };
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,57 @@
1
+ import { TextField } from '@mui/material';
2
+ import React, { ChangeEvent, FC } from 'react';
3
+ import { Cell } from 'react-table';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ interface Props {
7
+ cell: Cell;
8
+ }
9
+
10
+ export const MRT_EditCellTextfield: FC<Props> = ({ cell }) => {
11
+ const {
12
+ localization,
13
+ currentEditingRow,
14
+ setCurrentEditingRow,
15
+ muiTableBodyCellEditTextFieldProps,
16
+ } = useMaterialReactTable();
17
+
18
+ const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
19
+ if (currentEditingRow) {
20
+ setCurrentEditingRow({
21
+ ...currentEditingRow,
22
+ values: { ...cell.row.values, [cell.column.id]: event.target.value },
23
+ });
24
+ }
25
+ };
26
+
27
+ const textFieldProps = {
28
+ ...muiTableBodyCellEditTextFieldProps,
29
+ ...cell.column.muiTableBodyCellEditTextFieldProps,
30
+ style: {
31
+ //@ts-ignore
32
+ ...muiTableBodyCellEditTextFieldProps?.style,
33
+ //@ts-ignore
34
+ ...cell.column.muiTableBodyCellEditTextFieldProps?.style,
35
+ },
36
+ };
37
+
38
+ if (cell.column.editable && cell.column.Edit) {
39
+ return (
40
+ <>
41
+ {cell.column.Edit({ ...textFieldProps, cell, onChange: handleChange })}
42
+ </>
43
+ );
44
+ }
45
+
46
+ return (
47
+ <TextField
48
+ margin="dense"
49
+ placeholder={localization?.filterTextFieldPlaceholder}
50
+ onChange={handleChange}
51
+ onClick={(e) => e.stopPropagation()}
52
+ value={currentEditingRow?.values?.[cell.column.id]}
53
+ variant="standard"
54
+ {...textFieldProps}
55
+ />
56
+ );
57
+ };
@@ -0,0 +1,63 @@
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
+ return <>{column.Filter({ column })}</>;
28
+ }
29
+
30
+ return (
31
+ <TextField
32
+ margin="dense"
33
+ placeholder={localization?.filterTextFieldPlaceholder}
34
+ onChange={(e: ChangeEvent<HTMLInputElement>) => {
35
+ setFilterValue(e.target.value);
36
+ handleChange(e.target.value);
37
+ }}
38
+ onClick={(e) => e.stopPropagation()}
39
+ value={filterValue ?? ''}
40
+ variant="standard"
41
+ InputProps={{
42
+ startAdornment: (
43
+ <InputAdornment position="start">
44
+ <FilterIcon />
45
+ </InputAdornment>
46
+ ),
47
+ endAdornment: (
48
+ <InputAdornment position="end">
49
+ <IconButton
50
+ aria-label={localization?.filterTextFieldClearButtonTitle}
51
+ disabled={filterValue?.length === 0}
52
+ onClick={handleClear}
53
+ size="small"
54
+ title={localization?.filterTextFieldClearButtonTitle}
55
+ >
56
+ <CloseIcon fontSize="small" />
57
+ </IconButton>
58
+ </InputAdornment>
59
+ ),
60
+ }}
61
+ />
62
+ );
63
+ };
@@ -0,0 +1,74 @@
1
+ import React, { ChangeEvent, FC, useState } from 'react';
2
+ import {
3
+ IconButton,
4
+ InputAdornment,
5
+ styled,
6
+ TextField as MuiTextField,
7
+ } from '@mui/material';
8
+ import SearchIcon from '@mui/icons-material/Search';
9
+ import CloseIcon from '@mui/icons-material/Close';
10
+ import { useMaterialReactTable } from '../useMaterialReactTable';
11
+ import { useAsyncDebounce } from 'react-table';
12
+
13
+ const TextField = styled(MuiTextField)({
14
+ justifySelf: 'end',
15
+ });
16
+
17
+ interface Props {}
18
+
19
+ export const MRT_SearchTextField: FC<Props> = () => {
20
+ const {
21
+ tableInstance,
22
+ muiSearchTextFieldProps,
23
+ localization,
24
+ onGlobalFilterChange,
25
+ } = useMaterialReactTable();
26
+
27
+ const [searchValue, setSearchValue] = useState('');
28
+
29
+ const handleChange = useAsyncDebounce(
30
+ (event: ChangeEvent<HTMLInputElement>) => {
31
+ tableInstance.setGlobalFilter(event.target.value ?? undefined);
32
+ onGlobalFilterChange?.(event);
33
+ },
34
+ 200,
35
+ );
36
+
37
+ const handleClear = () => {
38
+ setSearchValue('');
39
+ tableInstance.setGlobalFilter(undefined);
40
+ };
41
+
42
+ return (
43
+ <TextField
44
+ placeholder={localization?.searchTextFieldPlaceholder}
45
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
46
+ setSearchValue(event.target.value);
47
+ handleChange(event);
48
+ }}
49
+ value={searchValue ?? ''}
50
+ variant="standard"
51
+ InputProps={{
52
+ startAdornment: (
53
+ <InputAdornment position="start">
54
+ <SearchIcon fontSize="small" />
55
+ </InputAdornment>
56
+ ),
57
+ endAdornment: (
58
+ <InputAdornment position="end">
59
+ <IconButton
60
+ aria-label={localization?.searchTextFieldClearButtonTitle}
61
+ disabled={searchValue?.length === 0}
62
+ onClick={handleClear}
63
+ size="small"
64
+ title={localization?.searchTextFieldClearButtonTitle}
65
+ >
66
+ <CloseIcon fontSize="small" />
67
+ </IconButton>
68
+ </InputAdornment>
69
+ ),
70
+ }}
71
+ {...muiSearchTextFieldProps}
72
+ />
73
+ );
74
+ };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { Checkbox, TableCell as MuiTableCell, styled } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+
5
+ const TableCell = styled(MuiTableCell, {
6
+ shouldForwardProp: (prop) => prop !== 'densePadding',
7
+ })<{ densePadding?: boolean }>(({ densePadding }) => ({
8
+ padding: densePadding ? '0' : '0.6rem',
9
+ transition: 'all 0.2s ease-in-out',
10
+ }));
11
+
12
+ export const MRT_SelectAllCheckbox = () => {
13
+ const { tableInstance, disableSelectAll, densePadding, localization } =
14
+ useMaterialReactTable();
15
+
16
+ return (
17
+ <TableCell densePadding={densePadding} variant="head">
18
+ {!disableSelectAll ? (
19
+ <Checkbox
20
+ aria-label={localization?.selectAllCheckboxTitle}
21
+ {...tableInstance.getToggleAllPageRowsSelectedProps()}
22
+ />
23
+ ) : null}
24
+ </TableCell>
25
+ );
26
+ };
@@ -0,0 +1,34 @@
1
+ import React, { ChangeEvent, FC } from 'react';
2
+ import { Checkbox, TableCell as MuiTableCell, styled } from '@mui/material';
3
+ import { Row } from 'react-table';
4
+ import { useMaterialReactTable } from '../useMaterialReactTable';
5
+
6
+ const TableCell = styled(MuiTableCell, {
7
+ shouldForwardProp: (prop) => prop !== 'densePadding',
8
+ })<{ densePadding?: boolean }>(({ densePadding }) => ({
9
+ padding: densePadding ? '0' : '0.6rem',
10
+ transition: 'all 0.2s ease-in-out',
11
+ }));
12
+
13
+ interface Props {
14
+ row: Row;
15
+ }
16
+
17
+ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
18
+ const { tableInstance, onRowSelectChange, densePadding } =
19
+ useMaterialReactTable();
20
+
21
+ const onSelectChange = (event: ChangeEvent) => {
22
+ row.getToggleRowSelectedProps()?.onChange?.(event);
23
+ onRowSelectChange?.(event, row, tableInstance.selectedFlatRows);
24
+ };
25
+
26
+ return (
27
+ <TableCell densePadding={densePadding}>
28
+ <Checkbox
29
+ {...row.getToggleRowSelectedProps()}
30
+ onChange={onSelectChange}
31
+ />
32
+ </TableCell>
33
+ );
34
+ };
@@ -0,0 +1,107 @@
1
+ import React, { FC } from 'react';
2
+ import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import { ColumnInstance } from 'react-table';
5
+ import ClearAllIcon from '@mui/icons-material/ClearAll';
6
+ import SortIcon from '@mui/icons-material/Sort';
7
+ import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
8
+ import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
9
+
10
+ const MenuItem = styled(MuiMenuItem)({
11
+ display: 'flex',
12
+ gap: '0.75rem',
13
+ });
14
+
15
+ interface Props {
16
+ anchorEl: HTMLElement | null;
17
+ column: ColumnInstance;
18
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
19
+ }
20
+
21
+ export const MRT_ColumnActionMenu: FC<Props> = ({
22
+ anchorEl,
23
+ column,
24
+ setAnchorEl,
25
+ }) => {
26
+ const {
27
+ disableColumnHiding,
28
+ enableColumnGrouping,
29
+ disableSortBy,
30
+ localization,
31
+ } = useMaterialReactTable();
32
+
33
+ const handleClearSort = () => {
34
+ column.clearSortBy();
35
+ setAnchorEl(null);
36
+ };
37
+
38
+ const handleSortAsc = () => {
39
+ column.toggleSortBy(false);
40
+ setAnchorEl(null);
41
+ };
42
+
43
+ const handleSortDesc = () => {
44
+ column.toggleSortBy(true);
45
+ setAnchorEl(null);
46
+ };
47
+
48
+ const handleHideColumn = () => {
49
+ column.toggleHidden();
50
+ setAnchorEl(null);
51
+ };
52
+
53
+ const handleGroupByColumn = () => {
54
+ column.toggleGroupBy();
55
+ setAnchorEl(null);
56
+ };
57
+
58
+ return (
59
+ <Menu
60
+ anchorEl={anchorEl}
61
+ open={!!anchorEl}
62
+ onClose={() => setAnchorEl(null)}
63
+ >
64
+ {!disableSortBy &&
65
+ column.canSort && [
66
+ <MenuItem
67
+ key={1}
68
+ disabled={!column.isSorted}
69
+ onClick={handleClearSort}
70
+ >
71
+ <ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
72
+ </MenuItem>,
73
+ <MenuItem
74
+ key={2}
75
+ disabled={column.isSorted && !column.isSortedDesc}
76
+ onClick={handleSortAsc}
77
+ >
78
+ <SortIcon /> {localization?.columnActionMenuItemSortAsc}
79
+ </MenuItem>,
80
+ <MenuItem
81
+ key={3}
82
+ disabled={column.isSorted && column.isSortedDesc}
83
+ onClick={handleSortDesc}
84
+ >
85
+ <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
86
+ {localization?.columnActionMenuItemSortDesc}
87
+ </MenuItem>,
88
+ <Divider key={4} />,
89
+ ]}
90
+ {!disableColumnHiding && (
91
+ <MenuItem onClick={handleHideColumn}>
92
+ <VisibilityOffIcon /> {localization?.columnActionMenuItemHideColumn}
93
+ </MenuItem>
94
+ )}
95
+ {enableColumnGrouping && column.canGroupBy && (
96
+ <MenuItem disabled={column.isGrouped} onClick={handleGroupByColumn}>
97
+ <DynamicFeedIcon /> {localization?.columnActionMenuItemGroupBy}
98
+ </MenuItem>
99
+ )}
100
+ {enableColumnGrouping && column.canGroupBy && (
101
+ <MenuItem disabled={!column.isGrouped} onClick={handleGroupByColumn}>
102
+ <DynamicFeedIcon /> {localization?.columnActionMenuItemUnGroupBy}
103
+ </MenuItem>
104
+ )}
105
+ </Menu>
106
+ );
107
+ };
@@ -0,0 +1,52 @@
1
+ import React, { FC } from 'react';
2
+ import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
3
+ import { useMaterialReactTable } from '../useMaterialReactTable';
4
+ import { Row } from 'react-table';
5
+ import EditIcon from '@mui/icons-material/Edit';
6
+
7
+ const MenuItem = styled(MuiMenuItem)({
8
+ display: 'flex',
9
+ gap: '0.75rem',
10
+ });
11
+
12
+ interface Props {
13
+ anchorEl: HTMLElement | null;
14
+ row: Row;
15
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
16
+ }
17
+
18
+ export const MRT_RowActionMenu: FC<Props> = ({
19
+ anchorEl,
20
+ row,
21
+ setAnchorEl,
22
+ }) => {
23
+ const {
24
+ enableRowEditing,
25
+ localization,
26
+ renderRowActionMenuItems,
27
+ setCurrentEditingRow,
28
+ tableInstance,
29
+ } = useMaterialReactTable();
30
+
31
+ const handleEdit = () => {
32
+ setCurrentEditingRow({ ...row });
33
+ setAnchorEl(null);
34
+ };
35
+
36
+ return (
37
+ <Menu
38
+ anchorEl={anchorEl}
39
+ open={!!anchorEl}
40
+ onClose={() => setAnchorEl(null)}
41
+ >
42
+ {enableRowEditing && (
43
+ <MenuItem onClick={handleEdit}>
44
+ <EditIcon /> {localization?.rowActionMenuItemEdit}
45
+ </MenuItem>
46
+ )}
47
+ {renderRowActionMenuItems?.(row, tableInstance, () =>
48
+ setAnchorEl(null),
49
+ ) ?? null}
50
+ </Menu>
51
+ );
52
+ };