material-react-table 0.6.10 → 0.7.0-alpha.11

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 (104) hide show
  1. package/README.md +29 -21
  2. package/dist/MaterialReactTable.d.ts +311 -110
  3. package/dist/body/MRT_TableBody.d.ts +3 -0
  4. package/dist/body/MRT_TableBodyCell.d.ts +2 -11
  5. package/dist/body/MRT_TableBodyRow.d.ts +3 -1
  6. package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
  7. package/dist/buttons/MRT_CopyButton.d.ts +2 -1
  8. package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
  9. package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
  10. package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
  11. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
  12. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
  13. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
  14. package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
  15. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
  16. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
  17. package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
  18. package/dist/footer/MRT_TableFooter.d.ts +3 -0
  19. package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
  20. package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
  21. package/dist/head/MRT_TableHead.d.ts +3 -0
  22. package/dist/head/MRT_TableHeadCell.d.ts +4 -18
  23. package/dist/head/MRT_TableHeadRow.d.ts +2 -1
  24. package/dist/icons.d.ts +1 -1
  25. package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
  26. package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
  27. package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
  28. package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
  29. package/dist/localization.d.ts +8 -2
  30. package/dist/material-react-table.cjs.development.js +2253 -2482
  31. package/dist/material-react-table.cjs.development.js.map +1 -1
  32. package/dist/material-react-table.cjs.production.min.js +1 -1
  33. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  34. package/dist/material-react-table.esm.js +2254 -2483
  35. package/dist/material-react-table.esm.js.map +1 -1
  36. package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
  37. package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
  38. package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
  39. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
  40. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
  41. package/dist/table/MRT_Table.d.ts +3 -0
  42. package/dist/table/MRT_TableContainer.d.ts +2 -0
  43. package/dist/table/MRT_TablePaper.d.ts +7 -0
  44. package/dist/table/MRT_TableRoot.d.ts +3 -0
  45. package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
  46. package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
  47. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
  48. package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
  49. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
  50. package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
  51. package/dist/utils.d.ts +12 -2
  52. package/package.json +29 -30
  53. package/src/MaterialReactTable.tsx +615 -302
  54. package/src/body/MRT_TableBody.tsx +26 -22
  55. package/src/body/MRT_TableBodyCell.tsx +78 -60
  56. package/src/body/MRT_TableBodyRow.tsx +37 -76
  57. package/src/body/MRT_TableDetailPanel.tsx +21 -17
  58. package/src/buttons/MRT_CopyButton.tsx +14 -8
  59. package/src/buttons/MRT_EditActionButtons.tsx +16 -13
  60. package/src/buttons/MRT_ExpandAllButton.tsx +24 -9
  61. package/src/buttons/MRT_ExpandButton.tsx +22 -15
  62. package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
  63. package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
  64. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +22 -11
  65. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
  66. package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
  67. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +30 -25
  68. package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
  69. package/src/footer/MRT_TableFooter.tsx +24 -8
  70. package/src/footer/MRT_TableFooterCell.tsx +34 -26
  71. package/src/footer/MRT_TableFooterRow.tsx +21 -39
  72. package/src/head/MRT_TableHead.tsx +24 -8
  73. package/src/head/MRT_TableHeadCell.tsx +183 -141
  74. package/src/head/MRT_TableHeadRow.tsx +16 -104
  75. package/src/icons.ts +3 -3
  76. package/src/inputs/MRT_EditCellTextField.tsx +36 -24
  77. package/src/inputs/MRT_FilterTextField.tsx +52 -31
  78. package/src/inputs/MRT_SearchTextField.tsx +46 -24
  79. package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
  80. package/src/localization.ts +14 -2
  81. package/src/menus/MRT_ColumnActionMenu.tsx +128 -68
  82. package/src/menus/MRT_FilterTypeMenu.tsx +23 -20
  83. package/src/menus/MRT_RowActionMenu.tsx +22 -15
  84. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
  85. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +27 -17
  86. package/src/table/MRT_Table.tsx +25 -15
  87. package/src/table/MRT_TableContainer.tsx +106 -45
  88. package/src/table/MRT_TablePaper.tsx +65 -0
  89. package/src/table/MRT_TableRoot.tsx +240 -0
  90. package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
  91. package/src/toolbar/MRT_TablePagination.tsx +33 -19
  92. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +33 -20
  93. package/src/toolbar/MRT_ToolbarBottom.tsx +32 -21
  94. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +35 -20
  95. package/src/toolbar/MRT_ToolbarTop.tsx +36 -29
  96. package/src/utils.ts +37 -8
  97. package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
  98. package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
  99. package/dist/useMRT.d.ts +0 -28
  100. package/src/@types/faker.d.ts +0 -4
  101. package/src/@types/react-table-config.d.ts +0 -53
  102. package/src/head/MRT_TableHeadCellActions.tsx +0 -29
  103. package/src/table/MRT_TableSpacerCell.tsx +0 -20
  104. package/src/useMRT.tsx +0 -226
@@ -1,4 +1,4 @@
1
- import React, { CSSProperties, FC } from 'react';
1
+ import React, { FC, MouseEvent } from 'react';
2
2
  import {
3
3
  TableCell,
4
4
  TableSortLabel,
@@ -7,86 +7,64 @@ import {
7
7
  Tooltip,
8
8
  Box,
9
9
  IconButton,
10
+ alpha,
11
+ Theme,
10
12
  } from '@mui/material';
11
- import { useMRT } from '../useMRT';
12
13
  import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
13
14
  import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
14
- import type { MRT_HeaderGroup } from '..';
15
-
16
- export const commonTableHeadCellStyles = (
17
- densePadding: boolean,
18
- enableColumnResizing?: boolean,
19
- widths?: {
20
- maxWidth?: CSSProperties['maxWidth'];
21
- minWidth?: CSSProperties['minWidth'];
22
- width?: CSSProperties['width'];
23
- },
24
- ) => ({
25
- fontWeight: 'bold',
26
- height: '100%',
27
- p: densePadding ? '0.5rem' : '1rem',
28
- pt: densePadding ? '0.75rem' : '1.25rem',
29
- transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
30
- verticalAlign: 'text-top',
31
- ...widths,
32
- });
15
+ import type { MRT_Header, MRT_TableInstance } from '..';
16
+ import { ColumnResizerProps } from '@tanstack/react-table';
33
17
 
34
18
  interface Props {
35
- column: MRT_HeaderGroup;
19
+ header: MRT_Header;
20
+ tableInstance: MRT_TableInstance;
36
21
  }
37
22
 
38
- export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
23
+ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
39
24
  const {
40
- disableColumnActions,
41
- disableFilters,
42
- enableColumnResizing,
43
- icons: { FilterAltIcon, FilterAltOff },
44
- localization,
45
- muiTableHeadCellProps,
25
+ getState,
26
+ options: {
27
+ enableColumnActions,
28
+ enableColumnFilters,
29
+ enableColumnResizing,
30
+ icons: { FilterAltIcon, FilterAltOff },
31
+ localization,
32
+ muiTableHeadCellProps,
33
+ },
46
34
  setShowFilters,
47
- tableInstance,
48
- } = useMRT();
35
+ } = tableInstance;
36
+
37
+ const { isDensePadding, showFilters } = getState();
49
38
 
50
- const isParentHeader = !!column?.columns?.length;
39
+ const { column } = header;
51
40
 
52
41
  const mTableHeadCellProps =
53
42
  muiTableHeadCellProps instanceof Function
54
- ? muiTableHeadCellProps(column)
43
+ ? muiTableHeadCellProps({ column, tableInstance })
55
44
  : muiTableHeadCellProps;
56
45
 
57
46
  const mcTableHeadCellProps =
58
47
  column.muiTableHeadCellProps instanceof Function
59
- ? column.muiTableHeadCellProps(column)
48
+ ? column.muiTableHeadCellProps({ column, tableInstance })
60
49
  : column.muiTableHeadCellProps;
61
50
 
62
51
  const tableCellProps = {
52
+ ...header.getHeaderProps(),
63
53
  ...mTableHeadCellProps,
64
54
  ...mcTableHeadCellProps,
65
- ...column.getHeaderProps(),
66
- style: {
67
- ...column.getHeaderProps().style,
68
- ...mTableHeadCellProps?.style,
69
- ...mcTableHeadCellProps?.style,
70
- },
71
55
  };
72
56
 
73
- const sortTooltip = column.isSorted
74
- ? column.isSortedDesc
57
+ const sortTooltip = !!column.getIsSorted()
58
+ ? column.getIsSorted() === 'desc'
75
59
  ? localization.clearSort
76
- : localization.sortByColumnDesc?.replace(
77
- '{column}',
78
- column.Header as string,
79
- )
80
- : localization.sortByColumnAsc?.replace(
81
- '{column}',
82
- column.Header as string,
83
- );
60
+ : localization.sortByColumnDesc.replace('{column}', column.header)
61
+ : localization.sortByColumnAsc.replace('{column}', column.header);
84
62
 
85
- const filterType = tableInstance.state.currentFilterTypes[column.id];
63
+ const filterType = getState()?.currentFilterTypes?.[header.id];
86
64
 
87
- const filterTooltip = !!column.filterValue
65
+ const filterTooltip = !!column.getColumnFilterValue()
88
66
  ? localization.filteringByColumn
89
- .replace('{column}', String(column.Header))
67
+ .replace('{column}', String(column.header))
90
68
  .replace(
91
69
  '{filterType}',
92
70
  filterType instanceof Function
@@ -98,112 +76,176 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
98
76
  }`
99
77
  ],
100
78
  )
101
- .replace('{filterValue}', column.filterValue)
79
+ .replace('{filterValue}', column.getColumnFilterValue() as string)
102
80
  .replace('" "', '')
103
81
  : localization.showHideFilters;
104
82
 
105
- const columnHeader = column.render('Header') as string;
83
+ const headerElement =
84
+ column?.Header?.({
85
+ header,
86
+ tableInstance,
87
+ }) ?? column.header;
106
88
 
107
89
  return (
108
90
  <TableCell
109
- align={isParentHeader ? 'center' : 'left'}
91
+ align={column.columnDefType === 'group' ? 'center' : 'left'}
110
92
  {...tableCellProps}
111
- sx={{
112
- ...commonTableHeadCellStyles(
113
- tableInstance.state.densePadding,
114
- enableColumnResizing,
115
- {
116
- maxWidth: column.maxWidth,
117
- minWidth: column.minWidth,
118
- width: column.width,
119
- },
120
- ),
93
+ //@ts-ignore
94
+ sx={(theme: Theme) => ({
95
+ backgroundColor: theme.palette.background.default,
96
+ backgroundImage: `linear-gradient(${alpha(
97
+ theme.palette.common.white,
98
+ 0.05,
99
+ )},${alpha(theme.palette.common.white, 0.05)})`,
100
+ boxShadow: `3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
101
+ fontWeight: 'bold',
102
+ height: '100%',
103
+ minWidth: `max(${header.getWidth()}, 100px)`,
104
+ p: isDensePadding
105
+ ? column.columnDefType === 'display'
106
+ ? '0 0.5rem'
107
+ : '0.5rem'
108
+ : column.columnDefType === 'display'
109
+ ? '0.5rem 0.75rem'
110
+ : '1rem',
111
+ pt:
112
+ column.columnDefType === 'display'
113
+ ? 0
114
+ : isDensePadding
115
+ ? '0.75rem'
116
+ : '1.25rem',
117
+ pb: column.columnDefType === 'display' ? 0 : undefined,
118
+ transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
119
+ verticalAlign: 'text-top',
120
+ width: header.getWidth(),
121
+ //@ts-ignore
121
122
  ...tableCellProps?.sx,
122
- }}
123
+ })}
123
124
  >
124
- <Box
125
- sx={{
126
- alignItems: 'flex-start',
127
- display: 'flex',
128
- justifyContent: isParentHeader ? 'center' : 'space-between',
129
- width: '100%',
130
- }}
131
- >
125
+ {header.isPlaceholder ? null : column.columnDefType === 'display' ? (
126
+ headerElement
127
+ ) : (
132
128
  <Box
133
- {...column.getSortByToggleProps()}
134
129
  sx={{
135
- alignItems: 'center',
130
+ alignItems: 'flex-start',
136
131
  display: 'flex',
137
- flexWrap: 'nowrap',
138
- whiteSpace: columnHeader.length < 15 ? 'nowrap' : 'normal',
132
+ justifyContent:
133
+ column.columnDefType === 'group' ? 'center' : 'space-between',
134
+ width: '100%',
139
135
  }}
140
- title={undefined}
141
136
  >
142
- {column.render('Header')}
143
- {!isParentHeader && column.canSort && (
144
- <Tooltip arrow placement="top" title={sortTooltip}>
145
- <TableSortLabel
146
- aria-label={sortTooltip}
147
- active={column.isSorted}
148
- direction={column.isSortedDesc ? 'desc' : 'asc'}
149
- />
150
- </Tooltip>
151
- )}
152
- {!isParentHeader && !!column.canFilter && (
153
- <Tooltip arrow placement="top" title={filterTooltip}>
154
- <IconButton
155
- disableRipple
156
- onClick={(event) => {
157
- event.stopPropagation();
158
- setShowFilters(!tableInstance.state.showFilters);
159
- }}
160
- size="small"
161
- sx={{
162
- m: 0,
163
- opacity: !!column.filterValue ? 0.8 : 0,
164
- p: '2px',
165
- transition: 'all 0.2s ease-in-out',
166
- '&:hover': {
167
- backgroundColor: 'transparent',
168
- opacity: 0.8,
137
+ <Box
138
+ {...column.getToggleSortingProps()}
139
+ sx={{
140
+ alignItems: 'center',
141
+ cursor:
142
+ column.getCanSort() && column.columnDefType !== 'group'
143
+ ? 'pointer'
144
+ : undefined,
145
+ display: 'flex',
146
+ flexWrap: 'nowrap',
147
+ whiteSpace: column.header.length < 15 ? 'nowrap' : 'normal',
148
+ }}
149
+ title={undefined}
150
+ >
151
+ {headerElement}
152
+ {column.columnDefType !== 'group' && column.getCanSort() && (
153
+ <Tooltip arrow placement="top" title={sortTooltip}>
154
+ <TableSortLabel
155
+ aria-label={sortTooltip}
156
+ active={!!column.getIsSorted()}
157
+ direction={
158
+ column.getIsSorted()
159
+ ? (column.getIsSorted() as 'asc' | 'desc')
160
+ : undefined
161
+ }
162
+ />
163
+ </Tooltip>
164
+ )}
165
+ {column.columnDefType !== 'group' &&
166
+ enableColumnFilters &&
167
+ !!column.getCanColumnFilter() && (
168
+ <Tooltip arrow placement="top" title={filterTooltip}>
169
+ <IconButton
170
+ disableRipple
171
+ onClick={(event: MouseEvent<HTMLButtonElement>) => {
172
+ event.stopPropagation();
173
+ setShowFilters(!showFilters);
174
+ }}
175
+ size="small"
176
+ sx={{
177
+ m: 0,
178
+ opacity: !!column.getColumnFilterValue() ? 0.8 : 0,
179
+ p: '2px',
180
+ transition: 'all 0.2s ease-in-out',
181
+ '&:hover': {
182
+ backgroundColor: 'transparent',
183
+ opacity: 0.8,
184
+ },
185
+ }}
186
+ >
187
+ {showFilters && !column.getColumnFilterValue() ? (
188
+ <FilterAltOff fontSize="small" />
189
+ ) : (
190
+ <FilterAltIcon fontSize="small" />
191
+ )}
192
+ </IconButton>
193
+ </Tooltip>
194
+ )}
195
+ </Box>
196
+ <Box
197
+ sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}
198
+ >
199
+ {(enableColumnActions || column.enableColumnActions) &&
200
+ column.enableColumnActions !== false &&
201
+ column.columnDefType !== 'group' && (
202
+ <MRT_ToggleColumnActionMenuButton
203
+ header={header}
204
+ tableInstance={tableInstance}
205
+ />
206
+ )}
207
+ {enableColumnResizing && column.columnDefType !== 'group' && (
208
+ <Divider
209
+ flexItem
210
+ orientation="vertical"
211
+ onDoubleClick={() => header.resetSize()}
212
+ sx={(theme: Theme) => ({
213
+ borderRightWidth: '2px',
214
+ borderRadius: '2px',
215
+ maxHeight: '2rem',
216
+ cursor: 'col-resize',
217
+ userSelect: 'none',
218
+ touchAction: 'none',
219
+ '&:active': {
220
+ backgroundColor: theme.palette.secondary.dark,
221
+ opacity: 1,
169
222
  },
170
- }}
171
- >
172
- {tableInstance.state.showFilters && !column.filterValue ? (
173
- <FilterAltOff fontSize="small" />
174
- ) : (
175
- <FilterAltIcon fontSize="small" />
176
- )}
177
- </IconButton>
178
- </Tooltip>
179
- )}
180
- </Box>
181
- <Box sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}>
182
- {!disableColumnActions &&
183
- !column.disableColumnActions &&
184
- !isParentHeader && (
185
- <MRT_ToggleColumnActionMenuButton column={column} />
223
+ })}
224
+ {...(header.getResizerProps((props: ColumnResizerProps) => ({
225
+ ...props,
226
+ style: {
227
+ transform: column.getIsResizing()
228
+ ? `translateX(${
229
+ getState().columnSizingInfo.deltaOffset
230
+ }px)`
231
+ : '',
232
+ },
233
+ })) as any)}
234
+ />
186
235
  )}
187
- {enableColumnResizing && !isParentHeader && (
188
- <Divider
189
- flexItem
190
- orientation="vertical"
191
- onDoubleClick={() => tableInstance.resetResizing()}
192
- {...column.getResizerProps()}
193
- sx={{
194
- borderRightWidth: '2px',
195
- borderRadius: '2px',
196
- maxHeight: '2rem',
197
- }}
198
- />
199
- )}
236
+ </Box>
200
237
  </Box>
201
- </Box>
202
- {!disableFilters && column.canFilter && (
203
- <Collapse in={tableInstance.state.showFilters}>
204
- <MRT_FilterTextField column={column} />
205
- </Collapse>
206
238
  )}
239
+ {column.columnDefType === 'data' &&
240
+ enableColumnFilters &&
241
+ column.getCanColumnFilter() && (
242
+ <Collapse in={showFilters}>
243
+ <MRT_FilterTextField
244
+ header={header}
245
+ tableInstance={tableInstance}
246
+ />
247
+ </Collapse>
248
+ )}
207
249
  </TableCell>
208
250
  );
209
251
  };
@@ -1,125 +1,37 @@
1
- import React, { FC, useMemo } from 'react';
2
- import { TableCell, TableRow } from '@mui/material';
3
- import {
4
- commonTableHeadCellStyles,
5
- MRT_TableHeadCell,
6
- } from './MRT_TableHeadCell';
7
- import { useMRT } from '../useMRT';
8
- import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
9
- import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
10
- import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
11
- import { MRT_TableHeadCellActions } from './MRT_TableHeadCellActions';
12
- import type { MRT_HeaderGroup } from '..';
1
+ import React, { FC } from 'react';
2
+ import { TableRow } from '@mui/material';
3
+ import { MRT_TableHeadCell } from './MRT_TableHeadCell';
4
+ import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
13
5
 
14
6
  interface Props {
15
7
  headerGroup: MRT_HeaderGroup;
8
+ tableInstance: MRT_TableInstance;
16
9
  }
17
10
 
18
- export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
11
+ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
19
12
  const {
20
- anyRowsCanExpand,
21
- disableExpandAll,
22
- disableSelectAll,
23
- enableRowActions,
24
- enableRowEditing,
25
- enableRowNumbers,
26
- enableSelection,
27
- muiTableHeadRowProps,
28
- positionActionsColumn,
29
- renderDetailPanel,
30
- tableInstance,
31
- } = useMRT();
32
-
33
- const isParentHeader = useMemo(
34
- () => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
35
- [headerGroup.headers],
36
- );
13
+ options: { muiTableHeadRowProps },
14
+ } = tableInstance;
37
15
 
38
16
  const mTableHeadRowProps =
39
17
  muiTableHeadRowProps instanceof Function
40
- ? muiTableHeadRowProps(headerGroup)
18
+ ? muiTableHeadRowProps({ headerGroup, tableInstance })
41
19
  : muiTableHeadRowProps;
42
20
 
43
21
  const tableRowProps = {
22
+ ...headerGroup?.getHeaderGroupProps(),
44
23
  ...mTableHeadRowProps,
45
- ...headerGroup.getHeaderGroupProps(),
46
- style: {
47
- ...headerGroup.getHeaderGroupProps().style,
48
- ...mTableHeadRowProps?.style,
49
- },
50
24
  };
51
25
 
52
26
  return (
53
27
  <TableRow {...tableRowProps}>
54
- {(enableRowActions || enableRowEditing) &&
55
- positionActionsColumn === 'first' &&
56
- (isParentHeader ? (
57
- <MRT_TableSpacerCell />
58
- ) : (
59
- <MRT_TableHeadCellActions />
60
- ))}
61
- {anyRowsCanExpand || renderDetailPanel ? (
62
- !disableExpandAll && !isParentHeader ? (
63
- <TableCell
64
- size="small"
65
- {...tableInstance.getToggleAllRowsExpandedProps()}
66
- sx={{
67
- ...commonTableHeadCellStyles(tableInstance.state.densePadding),
68
- width: '3rem',
69
- maxWidth: '3rem',
70
- textAlign: 'center',
71
- }}
72
- >
73
- <MRT_ExpandAllButton />
74
- </TableCell>
75
- ) : (
76
- <MRT_TableSpacerCell
77
- width={`${
78
- renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
79
- }rem`}
80
- />
81
- )
82
- ) : null}
83
- {enableSelection ? (
84
- !isParentHeader && !disableSelectAll ? (
85
- <TableCell
86
- sx={{
87
- ...commonTableHeadCellStyles(tableInstance.state.densePadding),
88
- maxWidth: '3rem',
89
- width: '3rem',
90
- textAlign: 'center',
91
- }}
92
- >
93
- <MRT_SelectCheckbox selectAll />
94
- </TableCell>
95
- ) : (
96
- <MRT_TableSpacerCell width="1rem" />
97
- )
98
- ) : null}
99
- {enableRowNumbers &&
100
- (isParentHeader ? (
101
- <MRT_TableSpacerCell />
102
- ) : (
103
- <TableCell
104
- sx={{
105
- ...commonTableHeadCellStyles(tableInstance.state.densePadding),
106
- width: '2rem',
107
- maxWidth: '2rem',
108
- }}
109
- >
110
- #
111
- </TableCell>
112
- ))}
113
- {headerGroup.headers.map((column: MRT_HeaderGroup) => (
114
- <MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
28
+ {headerGroup.headers.map((header: MRT_Header, index) => (
29
+ <MRT_TableHeadCell
30
+ header={header}
31
+ key={header.id || index}
32
+ tableInstance={tableInstance}
33
+ />
115
34
  ))}
116
- {(enableRowActions || enableRowEditing) &&
117
- positionActionsColumn === 'last' &&
118
- (isParentHeader ? (
119
- <MRT_TableSpacerCell />
120
- ) : (
121
- <MRT_TableHeadCellActions />
122
- ))}
123
35
  </TableRow>
124
36
  );
125
37
  };
package/src/icons.ts CHANGED
@@ -3,7 +3,6 @@ import CancelIcon from '@mui/icons-material/Cancel';
3
3
  import CheckBoxIcon from '@mui/icons-material/CheckBox';
4
4
  import ClearAllIcon from '@mui/icons-material/ClearAll';
5
5
  import CloseIcon from '@mui/icons-material/Close';
6
- import ContentCopyIcon from '@mui/icons-material/ContentCopy';
7
6
  import DensityMediumIcon from '@mui/icons-material/DensityMedium';
8
7
  import DensitySmallIcon from '@mui/icons-material/DensitySmall';
9
8
  import DoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
@@ -19,6 +18,7 @@ import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
19
18
  import FullscreenIcon from '@mui/icons-material/Fullscreen';
20
19
  import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
21
20
  import MoreVertIcon from '@mui/icons-material/MoreVert';
21
+ import PushPinIcon from '@mui/icons-material/PushPin';
22
22
  import SaveIcon from '@mui/icons-material/Save';
23
23
  import SearchIcon from '@mui/icons-material/Search';
24
24
  import SearchOffIcon from '@mui/icons-material/SearchOff';
@@ -32,7 +32,6 @@ export interface MRT_Icons {
32
32
  CheckBoxIcon: any;
33
33
  ClearAllIcon: any;
34
34
  CloseIcon: any;
35
- ContentCopyIcon: any;
36
35
  DensityMediumIcon: any;
37
36
  DensitySmallIcon: any;
38
37
  DoubleArrowDownIcon: any;
@@ -48,6 +47,7 @@ export interface MRT_Icons {
48
47
  FullscreenIcon: any;
49
48
  MoreHorizIcon: any;
50
49
  MoreVertIcon: any;
50
+ PushPinIcon: any;
51
51
  SaveIcon: any;
52
52
  SearchIcon: any;
53
53
  SearchOffIcon: any;
@@ -62,7 +62,6 @@ export const MRT_Default_Icons: MRT_Icons = {
62
62
  CheckBoxIcon,
63
63
  ClearAllIcon,
64
64
  CloseIcon,
65
- ContentCopyIcon,
66
65
  DensityMediumIcon,
67
66
  DensitySmallIcon,
68
67
  DoubleArrowDownIcon,
@@ -78,6 +77,7 @@ export const MRT_Default_Icons: MRT_Icons = {
78
77
  FullscreenIcon,
79
78
  MoreHorizIcon,
80
79
  MoreVertIcon,
80
+ PushPinIcon,
81
81
  SaveIcon,
82
82
  SearchIcon,
83
83
  SearchOffIcon,
@@ -1,57 +1,69 @@
1
- import React, { ChangeEvent, FC } from 'react';
1
+ import React, {
2
+ ChangeEvent,
3
+ FC,
4
+ FocusEvent,
5
+ MouseEvent,
6
+ useState,
7
+ } from 'react';
2
8
  import { TextField } from '@mui/material';
3
- import { useMRT } from '../useMRT';
4
- import type { MRT_Cell } from '..';
9
+ import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
5
10
 
6
11
  interface Props {
7
12
  cell: MRT_Cell;
13
+ tableInstance: MRT_TableInstance;
8
14
  }
9
15
 
10
- export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
16
+ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
11
17
  const {
12
- muiTableBodyCellEditTextFieldProps,
18
+ getState,
19
+ options: { enableEditing, muiTableBodyCellEditTextFieldProps },
13
20
  setCurrentEditingRow,
14
- tableInstance: {
15
- state: { currentEditingRow },
16
- },
17
- } = useMRT();
21
+ } = tableInstance;
22
+
23
+ const [value, setValue] = useState(cell.value);
24
+
25
+ const { column, row } = cell;
18
26
 
19
27
  const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
20
- if (currentEditingRow) {
21
- cell.row.values[cell.column.id] = event.target.value;
22
- setCurrentEditingRow({
23
- ...currentEditingRow,
24
- });
28
+ setValue(event.target.value);
29
+ column.onCellEditChange?.({ event, cell, tableInstance });
30
+ };
31
+
32
+ const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
33
+ if (getState().currentEditingRow) {
34
+ row.values[column.id] = value;
35
+ setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
25
36
  }
26
- cell.column.onCellEditChange?.(event, cell);
37
+ column.onCellEditBlur?.({ event, cell, tableInstance });
27
38
  };
28
39
 
29
40
  const mTableBodyCellEditTextFieldProps =
30
41
  muiTableBodyCellEditTextFieldProps instanceof Function
31
- ? muiTableBodyCellEditTextFieldProps(cell)
42
+ ? muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
32
43
  : muiTableBodyCellEditTextFieldProps;
33
44
 
34
45
  const mcTableBodyCellEditTextFieldProps =
35
- cell.column.muiTableBodyCellEditTextFieldProps instanceof Function
36
- ? cell.column.muiTableBodyCellEditTextFieldProps(cell)
37
- : cell.column.muiTableBodyCellEditTextFieldProps;
46
+ column.muiTableBodyCellEditTextFieldProps instanceof Function
47
+ ? column.muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
48
+ : column.muiTableBodyCellEditTextFieldProps;
38
49
 
39
50
  const textFieldProps = {
40
51
  ...mTableBodyCellEditTextFieldProps,
41
52
  ...mcTableBodyCellEditTextFieldProps,
42
53
  };
43
54
 
44
- if (!cell.column.disableEditing && cell.column.Edit) {
45
- return <>{cell.column.Edit({ ...textFieldProps, cell })}</>;
55
+ if (enableEditing && column.enableEditing !== false && column.Edit) {
56
+ return <>{column.Edit?.({ cell, tableInstance })}</>;
46
57
  }
47
58
 
48
59
  return (
49
60
  <TextField
50
61
  margin="dense"
62
+ onBlur={handleBlur}
51
63
  onChange={handleChange}
52
- onClick={(e) => e.stopPropagation()}
53
- placeholder={cell.column.Header as string}
54
- value={cell.value}
64
+ onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
65
+ placeholder={column.header}
66
+ value={value}
55
67
  variant="standard"
56
68
  {...textFieldProps}
57
69
  />