material-react-table 0.8.0-alpha.1 → 0.8.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.8.0-alpha.1",
2
+ "version": "0.8.0-alpha.2",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -58,18 +58,15 @@
58
58
  "@babel/core": "^7.18.2",
59
59
  "@emotion/react": "^11.9.0",
60
60
  "@emotion/styled": "^11.8.1",
61
- "@etchteam/storybook-addon-status": "^4.2.1",
62
- "@faker-js/faker": "^7.1.0",
61
+ "@faker-js/faker": "^6.3.1",
63
62
  "@mui/icons-material": "^5.8.0",
64
63
  "@mui/material": "^5.8.1",
65
64
  "@size-limit/preset-small-lib": "^7.0.8",
66
65
  "@storybook/addon-a11y": "^6.5.5",
67
66
  "@storybook/addon-actions": "^6.5.5",
68
- "@storybook/addon-console": "^1.2.3",
69
67
  "@storybook/addon-essentials": "^6.5.5",
70
68
  "@storybook/addon-info": "^5.3.21",
71
69
  "@storybook/addon-links": "^6.5.5",
72
- "@storybook/addon-storysource": "^6.5.5",
73
70
  "@storybook/addons": "^6.5.5",
74
71
  "@storybook/react": "^6.5.5",
75
72
  "@types/react": "^18.0.9",
@@ -79,11 +76,10 @@
79
76
  "eslint-plugin-react-hooks": "^4.5.0",
80
77
  "husky": "^8.0.1",
81
78
  "prettier": "^2.6.2",
82
- "react": "^18.1.0",
83
- "react-dom": "^18.1.0",
79
+ "react": "^17.0.2",
80
+ "react-dom": "^17.0.2",
84
81
  "react-is": "^18.1.0",
85
82
  "size-limit": "^7.0.8",
86
- "storybook-addon-paddings": "^4.3.0",
87
83
  "storybook-dark-mode": "^1.1.0",
88
84
  "tsdx": "^0.14.1",
89
85
  "tslib": "^2.4.0",
@@ -98,6 +94,6 @@
98
94
  },
99
95
  "dependencies": {
100
96
  "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
101
- "@tanstack/react-table": "^8.0.0-alpha.87"
97
+ "@tanstack/react-table": "^8.0.0-beta.2"
102
98
  }
103
99
  }
@@ -280,6 +280,9 @@ export type MRT_Column<D extends Record<string, any> = {}> = Omit<
280
280
  > &
281
281
  MRT_ColumnDef<D> & {
282
282
  columns?: MRT_Column<D>[];
283
+ columnDef: MRT_ColumnDef<D>;
284
+ header: string;
285
+ footer: string;
283
286
  };
284
287
 
285
288
  export type MRT_Header<D extends Record<string, any> = {}> = Omit<
@@ -171,7 +171,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
171
171
  {...muiTableBodyCellSkeletonProps}
172
172
  />
173
173
  ) : column.columnDefType === 'display' ? (
174
- column.Cell?.({ cell, tableInstance })
174
+ column.columnDef.Cell?.({ cell, tableInstance })
175
175
  ) : cell.getIsPlaceholder() ||
176
176
  (row.getIsGrouped() &&
177
177
  column.id !==
@@ -184,7 +184,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
184
184
  <>
185
185
  <MRT_CopyButton cell={cell} tableInstance={tableInstance}>
186
186
  <>
187
- {cell.column?.Cell?.({ cell, tableInstance }) ??
187
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ??
188
188
  cell.renderCell()}
189
189
  </>
190
190
  </MRT_CopyButton>
@@ -192,8 +192,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
192
192
  </>
193
193
  ) : (
194
194
  <>
195
- {cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
196
- {row.getIsGrouped() && <> ({row.subRows?.length})</>}
195
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
196
+ {row.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
197
197
  </>
198
198
  )}
199
199
  </>
@@ -4,7 +4,7 @@ import { MRT_Cell, MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
6
6
  cell: MRT_Cell;
7
- children: ReactNode
7
+ children: ReactNode;
8
8
  tableInstance: MRT_TableInstance;
9
9
  }
10
10
 
@@ -1,5 +1,5 @@
1
1
  import React, { FC } from 'react';
2
- import { IconButton } from '@mui/material';
2
+ import { IconButton, Tooltip } from '@mui/material';
3
3
  import { MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
@@ -18,27 +18,32 @@ export const MRT_ExpandAllButton: FC<Props> = ({ tableInstance }) => {
18
18
  toggleAllRowsExpanded,
19
19
  } = tableInstance;
20
20
 
21
- const { isDensePadding, isLoading } = getState();
21
+ const { isDensePadding } = getState();
22
22
 
23
23
  return (
24
- <IconButton
25
- aria-label={localization.expandAll}
26
- disabled={isLoading}
24
+ <Tooltip
25
+ arrow
26
+ enterDelay={1000}
27
+ enterNextDelay={1000}
27
28
  title={localization.expandAll}
28
- onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
29
- sx={{
30
- height: isDensePadding ? '1.75rem' : '2.25rem',
31
- width: isDensePadding ? '1.75rem' : '2.25rem',
32
- }}
33
29
  >
34
- <DoubleArrowDownIcon
35
- style={{
36
- transform: `rotate(${
37
- getIsAllRowsExpanded() ? -180 : getIsSomeRowsExpanded() ? -90 : 0
38
- }deg)`,
39
- transition: 'transform 0.2s',
30
+ <IconButton
31
+ aria-label={localization.expandAll}
32
+ onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
33
+ sx={{
34
+ height: isDensePadding ? '1.75rem' : '2.25rem',
35
+ width: isDensePadding ? '1.75rem' : '2.25rem',
40
36
  }}
41
- />
42
- </IconButton>
37
+ >
38
+ <DoubleArrowDownIcon
39
+ style={{
40
+ transform: `rotate(${
41
+ getIsAllRowsExpanded() ? -180 : getIsSomeRowsExpanded() ? -90 : 0
42
+ }deg)`,
43
+ transition: 'transform 0.2s',
44
+ }}
45
+ />
46
+ </IconButton>
47
+ </Tooltip>
43
48
  );
44
49
  };
@@ -1,5 +1,5 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { IconButton } from '@mui/material';
2
+ import { IconButton, Tooltip } from '@mui/material';
3
3
  import type { MRT_Row, MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
@@ -26,28 +26,34 @@ export const MRT_ExpandButton: FC<Props> = ({ row, tableInstance }) => {
26
26
  };
27
27
 
28
28
  return (
29
- <IconButton
30
- aria-label={localization.expand}
31
- disabled={!row.getCanExpand() && !renderDetailPanel}
29
+ <Tooltip
30
+ arrow
31
+ enterDelay={1000}
32
+ enterNextDelay={1000}
32
33
  title={localization.expand}
33
- onClick={handleToggleExpand}
34
- sx={{
35
- height: isDensePadding ? '1.75rem' : '2.25rem',
36
- width: isDensePadding ? '1.75rem' : '2.25rem',
37
- }}
38
34
  >
39
- <ExpandMoreIcon
40
- style={{
41
- transform: `rotate(${
42
- !row.getCanExpand() && !renderDetailPanel
43
- ? -90
44
- : row.getIsExpanded()
45
- ? -180
46
- : 0
47
- }deg)`,
48
- transition: 'transform 0.2s',
35
+ <IconButton
36
+ aria-label={localization.expand}
37
+ disabled={!row.getCanExpand() && !renderDetailPanel}
38
+ onClick={handleToggleExpand}
39
+ sx={{
40
+ height: isDensePadding ? '1.75rem' : '2.25rem',
41
+ width: isDensePadding ? '1.75rem' : '2.25rem',
49
42
  }}
50
- />
51
- </IconButton>
43
+ >
44
+ <ExpandMoreIcon
45
+ style={{
46
+ transform: `rotate(${
47
+ !row.getCanExpand() && !renderDetailPanel
48
+ ? -90
49
+ : row.getIsExpanded()
50
+ ? -180
51
+ : 0
52
+ }deg)`,
53
+ transition: 'transform 0.2s',
54
+ }}
55
+ />
56
+ </IconButton>
57
+ </Tooltip>
52
58
  );
53
59
  };
@@ -54,14 +54,16 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
54
54
  ...(tableCellProps?.sx as any),
55
55
  })}
56
56
  >
57
- {footer.isPlaceholder
58
- ? null
59
- : column.Footer?.({
60
- footer,
61
- tableInstance,
62
- }) ??
63
- column.footer ??
64
- null}
57
+ <>
58
+ {footer.isPlaceholder
59
+ ? null
60
+ : column.columnDef.Footer?.({
61
+ footer,
62
+ tableInstance,
63
+ }) ??
64
+ footer.renderFooter() ??
65
+ null}
66
+ </>
65
67
  </TableCell>
66
68
  );
67
69
  };
@@ -20,8 +20,9 @@ export const MRT_TableFooterRow: FC<Props> = ({
20
20
  if (
21
21
  !footerGroup.headers?.some(
22
22
  (h) =>
23
- (typeof h.column.footer === 'string' && !!h.column.footer) ||
24
- h.column.Footer,
23
+ (typeof h.column.columnDef.footer === 'string' &&
24
+ !!h.column.columnDef.footer) ||
25
+ h.column.columnDef.Footer,
25
26
  )
26
27
  )
27
28
  return null;
@@ -1,4 +1,4 @@
1
- import React, { FC, MouseEvent } from 'react';
1
+ import React, { FC, MouseEvent, ReactNode } from 'react';
2
2
  import {
3
3
  Box,
4
4
  Collapse,
@@ -57,15 +57,21 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
57
57
 
58
58
  const sortTooltip = !!column.getIsSorted()
59
59
  ? column.getIsSorted() === 'desc'
60
- ? localization.sortedByColumnDesc.replace('{column}', column.header)
61
- : localization.sortedByColumnAsc.replace('{column}', column.header)
60
+ ? localization.sortedByColumnDesc.replace(
61
+ '{column}',
62
+ column.columnDef.header,
63
+ )
64
+ : localization.sortedByColumnAsc.replace(
65
+ '{column}',
66
+ column.columnDef.header,
67
+ )
62
68
  : localization.unsorted;
63
69
 
64
70
  const filterFn = getState()?.currentFilterFns?.[header.id];
65
71
 
66
72
  const filterTooltip = !!column.getFilterValue()
67
73
  ? localization.filteringByColumn
68
- .replace('{column}', String(column.header))
74
+ .replace('{column}', String(column.columnDef.header))
69
75
  .replace(
70
76
  '{filterType}',
71
77
  filterFn instanceof Function
@@ -88,11 +94,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
88
94
  .replace('" "', '')
89
95
  : localization.showHideFilters;
90
96
 
91
- const headerElement =
92
- column?.Header?.({
93
- header,
94
- tableInstance,
95
- }) ?? column.header;
97
+ const headerElement = (column.columnDef?.Header?.({
98
+ header,
99
+ tableInstance,
100
+ }) ?? header.renderHeader()) as ReactNode;
96
101
 
97
102
  const getIsLastLeftPinnedColumn = () => {
98
103
  return (
@@ -192,7 +197,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
192
197
  : undefined,
193
198
  display: 'flex',
194
199
  flexWrap: 'nowrap',
195
- whiteSpace: column.header.length < 24 ? 'nowrap' : 'normal',
200
+ whiteSpace:
201
+ (column.columnDef.header?.length ?? 0) < 24
202
+ ? 'nowrap'
203
+ : 'normal',
196
204
  }}
197
205
  >
198
206
  {headerElement}
@@ -73,7 +73,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
73
73
  onBlur={handleBlur}
74
74
  onChange={handleChange}
75
75
  onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
76
- placeholder={column.header}
76
+ placeholder={column.columnDef.header}
77
77
  value={value}
78
78
  variant="standard"
79
79
  {...textFieldProps}
@@ -130,7 +130,10 @@ export const MRT_FilterTextField: FC<Props> = ({
130
130
  : '';
131
131
  const filterPlaceholder =
132
132
  inputIndex === undefined
133
- ? localization.filterByColumn?.replace('{column}', String(column.header))
133
+ ? localization.filterByColumn?.replace(
134
+ '{column}',
135
+ String(column.columnDef.header),
136
+ )
134
137
  : inputIndex === 0
135
138
  ? localization.min
136
139
  : inputIndex === 1
@@ -25,7 +25,7 @@ export const MRT_SelectCheckbox: FC<Props> = ({
25
25
  },
26
26
  } = tableInstance;
27
27
 
28
- const { isDensePadding, isLoading } = getState();
28
+ const { isDensePadding } = getState();
29
29
 
30
30
  const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
31
31
  if (selectAll) {
@@ -70,7 +70,6 @@ export const MRT_SelectCheckbox: FC<Props> = ({
70
70
  ? tableInstance.getIsAllRowsSelected()
71
71
  : row?.getIsSelected()
72
72
  }
73
- disabled={isLoading}
74
73
  indeterminate={
75
74
  selectAll
76
75
  ? tableInstance.getIsSomeRowsSelected()
@@ -178,7 +178,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
178
178
  </ListItemIcon>
179
179
  {localization.sortByColumnAsc?.replace(
180
180
  '{column}',
181
- String(column.header),
181
+ String(column.columnDef.header),
182
182
  )}
183
183
  </Box>
184
184
  </MenuItem>,
@@ -195,7 +195,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
195
195
  </ListItemIcon>
196
196
  {localization.sortByColumnDesc?.replace(
197
197
  '{column}',
198
- String(column.header),
198
+ String(column.columnDef.header),
199
199
  )}
200
200
  </Box>
201
201
  </MenuItem>,
@@ -227,7 +227,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
227
227
  </ListItemIcon>
228
228
  {localization.filterByColumn?.replace(
229
229
  '{column}',
230
- String(column.header),
230
+ String(column.columnDef.header),
231
231
  )}
232
232
  </Box>
233
233
  {!column.filterSelectOptions && (
@@ -264,7 +264,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
264
264
  </ListItemIcon>
265
265
  {localization[
266
266
  column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn'
267
- ]?.replace('{column}', String(column.header))}
267
+ ]?.replace('{column}', String(column.columnDef.header))}
268
268
  </Box>
269
269
  </MenuItem>,
270
270
  ]}
@@ -339,7 +339,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
339
339
  </ListItemIcon>
340
340
  {localization.hideColumn?.replace(
341
341
  '{column}',
342
- String(column.header),
342
+ String(column.columnDef.header),
343
343
  )}
344
344
  </Box>
345
345
  </MenuItem>,
@@ -358,7 +358,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
358
358
  </ListItemIcon>
359
359
  {localization.showAllColumns?.replace(
360
360
  '{column}',
361
- String(column.header),
361
+ String(column.columnDef.header),
362
362
  )}
363
363
  </Box>
364
364
  <IconButton
@@ -63,7 +63,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
63
63
  checked={switchChecked}
64
64
  control={<Switch />}
65
65
  disabled={(isSubMenu && switchChecked) || !column.getCanHide()}
66
- label={column.header}
66
+ label={column.columnDef.header}
67
67
  onChange={() => handleToggleColumnHidden(column)}
68
68
  />
69
69
  </MenuItem>
@@ -227,22 +227,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
227
227
  //@ts-ignore
228
228
  ...useTableInstance(table, {
229
229
  filterFns: defaultFilterFNs,
230
- //@ts-ignore
231
230
  getCoreRowModel: getCoreRowModel(),
232
- //@ts-ignore
233
231
  getExpandedRowModel: getExpandedRowModel(),
234
- //@ts-ignore
235
232
  getFacetedRowModel: getFacetedRowModel(),
236
- //@ts-ignore
237
233
  getFilteredRowModel: getFilteredRowModel(),
238
- //@ts-ignore
239
234
  getGroupedRowModel: getGroupedRowModel(),
240
- //@ts-ignore
241
235
  getPaginationRowModel: getPaginationRowModel(),
242
- //@ts-ignore
243
236
  getSortedRowModel: getSortedRowModel(),
244
- //@ts-ignore
245
- getSubRows: (row) => row?.subRows,
237
+ getSubRows: (row) => (row as MRT_Row)?.subRows,
246
238
  //@ts-ignore
247
239
  globalFilterFn: currentGlobalFilterFn,
248
240
  onPaginationChange: (updater: any) =>