material-react-table 0.5.5 → 0.5.6

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.5.5",
2
+ "version": "0.5.6",
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 DataGrid, written from the ground up in TypeScript.",
@@ -60,9 +60,9 @@
60
60
  "@emotion/react": "^11.8.1",
61
61
  "@emotion/styled": "^11.8.1",
62
62
  "@etchteam/storybook-addon-status": "^4.2.0",
63
- "@faker-js/faker": "^6.0.0-alpha.7",
64
- "@mui/icons-material": "^5.4.4",
65
- "@mui/material": "^5.4.4",
63
+ "@faker-js/faker": "^6.0.0-beta.0",
64
+ "@mui/icons-material": "^5.5.0",
65
+ "@mui/material": "^5.5.0",
66
66
  "@size-limit/preset-small-lib": "^7.0.8",
67
67
  "@storybook/addon-a11y": "^6.4.19",
68
68
  "@storybook/addon-actions": "^6.4.19",
@@ -2,6 +2,8 @@ import React, { ChangeEvent, FC, MouseEvent, ReactNode } from 'react';
2
2
  import {
3
3
  AlertProps,
4
4
  IconButtonProps,
5
+ LinearProgressProps,
6
+ SkeletonProps,
5
7
  TableBodyProps,
6
8
  TableCellProps,
7
9
  TableContainerProps,
@@ -244,6 +246,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
244
246
  isFetching?: boolean;
245
247
  isLoading?: boolean;
246
248
  localization?: Partial<MRT_Localization>;
249
+ muiLinearProgressProps?:
250
+ | LinearProgressProps
251
+ | ((tableInstance: MRT_TableInstance) => LinearProgressProps);
247
252
  muiSearchTextFieldProps?: TextFieldProps;
248
253
  muiTableBodyCellEditTextFieldProps?:
249
254
  | TextFieldProps
@@ -251,6 +256,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
251
256
  muiTableBodyCellProps?:
252
257
  | TableCellProps
253
258
  | ((cell?: MRT_Cell<D>) => TableCellProps);
259
+ muiTableBodyCellSkeletonProps?:
260
+ | SkeletonProps
261
+ | ((cell?: MRT_Cell<D>) => SkeletonProps);
254
262
  muiTableBodyProps?:
255
263
  | TableBodyProps
256
264
  | ((tableInstance: MRT_TableInstance<D>) => TableBodyProps);
@@ -1,5 +1,5 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { TableCell, TableCellProps } from '@mui/material';
2
+ import { Skeleton, TableCell, TableCellProps } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
5
5
  import { MRT_Cell } from '..';
@@ -22,8 +22,10 @@ interface Props {
22
22
 
23
23
  export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
24
24
  const {
25
- onCellClick,
25
+ isLoading,
26
26
  muiTableBodyCellProps,
27
+ muiTableBodyCellSkeletonProps,
28
+ onCellClick,
27
29
  tableInstance: {
28
30
  state: { currentEditingRow, densePadding },
29
31
  },
@@ -63,7 +65,14 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
63
65
  } as TableCellProps['sx']
64
66
  }
65
67
  >
66
- {currentEditingRow?.id === cell.row.id ? (
68
+ {isLoading ? (
69
+ <Skeleton
70
+ animation="wave"
71
+ height={20}
72
+ width={Math.random() * (120 - 60) + 60}
73
+ {...muiTableBodyCellSkeletonProps}
74
+ />
75
+ ) : currentEditingRow?.id === cell.row.id ? (
67
76
  <MRT_EditCellTextField cell={cell} />
68
77
  ) : cell.isPlaceholder ? null : cell.isAggregated ? (
69
78
  cell.render('Aggregated')
@@ -7,7 +7,6 @@ import {
7
7
  Divider,
8
8
  IconButtonProps,
9
9
  Box,
10
- MenuList,
11
10
  } from '@mui/material';
12
11
  import { useMRT } from '../useMRT';
13
12
  import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
@@ -44,39 +43,41 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
44
43
  anchorEl={anchorEl}
45
44
  open={!!anchorEl}
46
45
  onClose={() => setAnchorEl(null)}
46
+ MenuListProps={{
47
+ dense: tableInstance.state.densePadding,
48
+ disablePadding: true,
49
+ }}
47
50
  >
48
- <MenuList dense={tableInstance.state.densePadding} disablePadding>
49
- <Box
50
- sx={{
51
- display: 'flex',
52
- justifyContent: 'space-between',
53
- p: '0 0.5rem 0.5rem 0.5rem',
54
- }}
51
+ <Box
52
+ sx={{
53
+ display: 'flex',
54
+ justifyContent: 'space-between',
55
+ p: '0.5rem',
56
+ }}
57
+ >
58
+ <Button
59
+ disabled={
60
+ !tableInstance.getToggleHideAllColumnsProps().checked &&
61
+ !tableInstance.getToggleHideAllColumnsProps().indeterminate
62
+ }
63
+ onClick={() => tableInstance.toggleHideAllColumns(true)}
64
+ >
65
+ {localization.columnShowHideMenuHideAll}
66
+ </Button>
67
+ <Button
68
+ disabled={tableInstance.getToggleHideAllColumnsProps().checked}
69
+ onClick={() => tableInstance.toggleHideAllColumns(false)}
55
70
  >
56
- <Button
57
- disabled={
58
- !tableInstance.getToggleHideAllColumnsProps().checked &&
59
- !tableInstance.getToggleHideAllColumnsProps().indeterminate
60
- }
61
- onClick={() => tableInstance.toggleHideAllColumns(true)}
62
- >
63
- {localization.columnShowHideMenuHideAll}
64
- </Button>
65
- <Button
66
- disabled={tableInstance.getToggleHideAllColumnsProps().checked}
67
- onClick={() => tableInstance.toggleHideAllColumns(false)}
68
- >
69
- {localization.columnShowHideMenuShowAll}
70
- </Button>
71
- </Box>
72
- <Divider />
73
- {tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
74
- <MRT_ShowHideColumnsMenu
75
- key={`${index}-${column.id}`}
76
- column={column}
77
- />
78
- ))}
79
- </MenuList>
71
+ {localization.columnShowHideMenuShowAll}
72
+ </Button>
73
+ </Box>
74
+ <Divider />
75
+ {tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
76
+ <MRT_ShowHideColumnsMenu
77
+ key={`${index}-${column.id}`}
78
+ column={column}
79
+ />
80
+ ))}
80
81
  </Menu>
81
82
  </>
82
83
  );
@@ -88,7 +88,7 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
88
88
  disabled: !!filterChipLabel,
89
89
  sx: {
90
90
  textOverflow: 'ellipsis',
91
- width: filterChipLabel ? 0 : 'auto',
91
+ width: filterChipLabel ? 0 : undefined,
92
92
  },
93
93
  title: filterPlaceholder,
94
94
  }}
@@ -5,7 +5,6 @@ import {
5
5
  ListItemText,
6
6
  Menu,
7
7
  MenuItem,
8
- MenuList,
9
8
  } from '@mui/material';
10
9
  import { useMRT } from '../useMRT';
11
10
  import { MRT_HeaderGroup } from '..';
@@ -100,131 +99,129 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
100
99
  anchorEl={anchorEl}
101
100
  open={!!anchorEl}
102
101
  onClose={() => setAnchorEl(null)}
102
+ MenuListProps={{
103
+ dense: tableInstance.state.densePadding,
104
+ disablePadding: true,
105
+ }}
103
106
  >
104
- <MenuList dense={tableInstance.state.densePadding} disablePadding>
105
- {!disableSortBy &&
106
- column.canSort && [
107
- <MenuItem
108
- key={1}
109
- disabled={!column.isSorted}
110
- onClick={handleClearSort}
111
- sx={commonMenuItemStyles}
112
- >
113
- <ListItemIcon>
114
- <ClearAllIcon />
115
- </ListItemIcon>
116
- <ListItemText>
117
- {localization.columnActionMenuItemClearSort}
118
- </ListItemText>
119
- </MenuItem>,
120
- <MenuItem
121
- disabled={column.isSorted && !column.isSortedDesc}
122
- key={2}
123
- onClick={handleSortAsc}
124
- sx={commonMenuItemStyles}
125
- >
126
- <ListItemIcon>
127
- <SortIcon />
128
- </ListItemIcon>
129
- <ListItemText>
130
- {localization.columnActionMenuItemSortAsc?.replace(
131
- '{column}',
132
- String(column.Header),
133
- )}
134
- </ListItemText>
135
- </MenuItem>,
136
- <MenuItem
137
- divider={
138
- !disableFilters || enableColumnGrouping || !disableColumnHiding
139
- }
140
- key={3}
141
- disabled={column.isSorted && column.isSortedDesc}
142
- onClick={handleSortDesc}
143
- sx={commonMenuItemStyles}
144
- >
145
- <ListItemIcon>
146
- <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
147
- </ListItemIcon>
148
- <ListItemText>
149
- {localization.columnActionMenuItemSortDesc?.replace(
150
- '{column}',
151
- String(column.Header),
152
- )}
153
- </ListItemText>
154
- </MenuItem>,
155
- ]}
156
- {!disableFilters &&
157
- column.canFilter && [
158
- <MenuItem
159
- divider={enableColumnGrouping || !disableColumnHiding}
160
- key={1}
161
- onClick={handleFilterByColumn}
162
- sx={commonMenuItemStyles}
163
- >
164
- <ListItemIcon>
165
- <FilterListIcon />
166
- </ListItemIcon>
167
- <ListItemText>
168
- {localization.filterTextFieldPlaceholder?.replace(
169
- '{column}',
170
- String(column.Header),
171
- )}
172
- </ListItemText>
173
- <IconButton
174
- onClick={handleOpenFilterModeMenu}
175
- onMouseEnter={handleOpenFilterModeMenu}
176
- size="small"
177
- sx={{ p: 0 }}
178
- >
179
- <ArrowRightIcon />
180
- </IconButton>
181
- </MenuItem>,
182
- <MRT_FilterTypeMenu
183
- anchorEl={filterMenuAnchorEl}
184
- column={column}
185
- key={2}
186
- setAnchorEl={setFilterMenuAnchorEl}
187
- onSelect={handleFilterByColumn}
188
- />,
189
- ]}
190
- {enableColumnGrouping &&
191
- column.canGroupBy && [
192
- <MenuItem
193
- divider={!disableColumnHiding}
194
- key={2}
195
- onClick={handleGroupByColumn}
196
- sx={commonMenuItemStyles}
197
- >
198
- <ListItemIcon>
199
- <DynamicFeedIcon />
200
- </ListItemIcon>
201
- <ListItemText>
202
- {localization[
203
- column.isGrouped
204
- ? 'columnActionMenuItemUnGroupBy'
205
- : 'columnActionMenuItemGroupBy'
206
- ]?.replace('{column}', String(column.Header))}
207
- </ListItemText>
208
- </MenuItem>,
209
- ]}
210
- {!disableColumnHiding && [
107
+ {!disableSortBy &&
108
+ column.canSort && [
211
109
  <MenuItem
212
110
  key={1}
213
- onClick={handleHideColumn}
111
+ disabled={!column.isSorted}
112
+ onClick={handleClearSort}
113
+ sx={commonMenuItemStyles}
114
+ >
115
+ <ListItemIcon>
116
+ <ClearAllIcon />
117
+ </ListItemIcon>
118
+ <ListItemText>
119
+ {localization.columnActionMenuItemClearSort}
120
+ </ListItemText>
121
+ </MenuItem>,
122
+ <MenuItem
123
+ disabled={column.isSorted && !column.isSortedDesc}
124
+ key={2}
125
+ onClick={handleSortAsc}
126
+ sx={commonMenuItemStyles}
127
+ >
128
+ <ListItemIcon>
129
+ <SortIcon />
130
+ </ListItemIcon>
131
+ <ListItemText>
132
+ {localization.columnActionMenuItemSortAsc?.replace(
133
+ '{column}',
134
+ String(column.Header),
135
+ )}
136
+ </ListItemText>
137
+ </MenuItem>,
138
+ <MenuItem
139
+ divider={
140
+ !disableFilters || enableColumnGrouping || !disableColumnHiding
141
+ }
142
+ key={3}
143
+ disabled={column.isSorted && column.isSortedDesc}
144
+ onClick={handleSortDesc}
214
145
  sx={commonMenuItemStyles}
215
146
  >
216
147
  <ListItemIcon>
217
- <VisibilityOffIcon />
148
+ <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
218
149
  </ListItemIcon>
219
150
  <ListItemText>
220
- {localization.columnActionMenuItemHideColumn?.replace(
151
+ {localization.columnActionMenuItemSortDesc?.replace(
221
152
  '{column}',
222
153
  String(column.Header),
223
154
  )}
224
155
  </ListItemText>
225
156
  </MenuItem>,
226
157
  ]}
227
- </MenuList>
158
+ {!disableFilters &&
159
+ column.canFilter && [
160
+ <MenuItem
161
+ divider={enableColumnGrouping || !disableColumnHiding}
162
+ key={1}
163
+ onClick={handleFilterByColumn}
164
+ sx={commonMenuItemStyles}
165
+ >
166
+ <ListItemIcon>
167
+ <FilterListIcon />
168
+ </ListItemIcon>
169
+ <ListItemText>
170
+ {localization.filterTextFieldPlaceholder?.replace(
171
+ '{column}',
172
+ String(column.Header),
173
+ )}
174
+ </ListItemText>
175
+ <IconButton
176
+ onClick={handleOpenFilterModeMenu}
177
+ onMouseEnter={handleOpenFilterModeMenu}
178
+ size="small"
179
+ sx={{ p: 0 }}
180
+ >
181
+ <ArrowRightIcon />
182
+ </IconButton>
183
+ </MenuItem>,
184
+ <MRT_FilterTypeMenu
185
+ anchorEl={filterMenuAnchorEl}
186
+ column={column}
187
+ key={2}
188
+ setAnchorEl={setFilterMenuAnchorEl}
189
+ onSelect={handleFilterByColumn}
190
+ />,
191
+ ]}
192
+ {enableColumnGrouping &&
193
+ column.canGroupBy && [
194
+ <MenuItem
195
+ divider={!disableColumnHiding}
196
+ key={2}
197
+ onClick={handleGroupByColumn}
198
+ sx={commonMenuItemStyles}
199
+ >
200
+ <ListItemIcon>
201
+ <DynamicFeedIcon />
202
+ </ListItemIcon>
203
+ <ListItemText>
204
+ {localization[
205
+ column.isGrouped
206
+ ? 'columnActionMenuItemUnGroupBy'
207
+ : 'columnActionMenuItemGroupBy'
208
+ ]?.replace('{column}', String(column.Header))}
209
+ </ListItemText>
210
+ </MenuItem>,
211
+ ]}
212
+ {!disableColumnHiding && [
213
+ <MenuItem key={1} onClick={handleHideColumn} sx={commonMenuItemStyles}>
214
+ <ListItemIcon>
215
+ <VisibilityOffIcon />
216
+ </ListItemIcon>
217
+ <ListItemText>
218
+ {localization.columnActionMenuItemHideColumn?.replace(
219
+ '{column}',
220
+ String(column.Header),
221
+ )}
222
+ </ListItemText>
223
+ </MenuItem>,
224
+ ]}
228
225
  </Menu>
229
226
  );
230
227
  };
@@ -1,5 +1,5 @@
1
1
  import React, { FC, useMemo } from 'react';
2
- import { Menu, MenuItem, MenuList } from '@mui/material';
2
+ import { Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_FilterType, MRT_HeaderGroup } from '..';
5
5
 
@@ -88,20 +88,22 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
88
88
  anchorOrigin={{ vertical: 'center', horizontal: 'right' }}
89
89
  onClose={() => setAnchorEl(null)}
90
90
  open={!!anchorEl}
91
+ MenuListProps={{
92
+ dense: tableInstance.state.densePadding,
93
+ disablePadding: true,
94
+ }}
91
95
  >
92
- <MenuList dense={tableInstance.state.densePadding} disablePadding>
93
- {filterTypes.map(({ type, label, divider }) => (
94
- <MenuItem
95
- divider={divider}
96
- key={type}
97
- onClick={() => handleSelectFilterType(type)}
98
- selected={type === filterType}
99
- value={type}
100
- >
101
- {label}
102
- </MenuItem>
103
- ))}
104
- </MenuList>
96
+ {filterTypes.map(({ type, label, divider }) => (
97
+ <MenuItem
98
+ divider={divider}
99
+ key={type}
100
+ onClick={() => handleSelectFilterType(type)}
101
+ selected={type === filterType}
102
+ value={type}
103
+ >
104
+ {label}
105
+ </MenuItem>
106
+ ))}
105
107
  </Menu>
106
108
  );
107
109
  };
@@ -1,11 +1,5 @@
1
1
  import React, { FC } from 'react';
2
- import {
3
- ListItemIcon,
4
- ListItemText,
5
- Menu,
6
- MenuItem,
7
- MenuList,
8
- } from '@mui/material';
2
+ import { ListItemIcon, ListItemText, Menu, MenuItem } from '@mui/material';
9
3
  import { useMRT } from '../useMRT';
10
4
  import { MRT_Row } from '..';
11
5
 
@@ -35,20 +29,22 @@ export const MRT_RowActionMenu: FC<Props> = ({
35
29
  anchorEl={anchorEl}
36
30
  open={!!anchorEl}
37
31
  onClose={() => setAnchorEl(null)}
32
+ MenuListProps={{
33
+ dense: tableInstance.state.densePadding,
34
+ disablePadding: true,
35
+ }}
38
36
  >
39
- <MenuList dense={tableInstance.state.densePadding} disablePadding>
40
- {enableRowEditing && (
41
- <MenuItem onClick={handleEdit}>
42
- <ListItemIcon>
43
- <EditIcon />
44
- </ListItemIcon>
45
- <ListItemText>{localization.rowActionMenuItemEdit}</ListItemText>
46
- </MenuItem>
47
- )}
48
- {renderRowActionMenuItems?.(row, tableInstance, () =>
49
- setAnchorEl(null),
50
- ) ?? null}
51
- </MenuList>
37
+ {enableRowEditing && (
38
+ <MenuItem onClick={handleEdit}>
39
+ <ListItemIcon>
40
+ <EditIcon />
41
+ </ListItemIcon>
42
+ <ListItemText>{localization.rowActionMenuItemEdit}</ListItemText>
43
+ </MenuItem>
44
+ )}
45
+ {renderRowActionMenuItems?.(row, tableInstance, () =>
46
+ setAnchorEl(null),
47
+ ) ?? null}
52
48
  </Menu>
53
49
  );
54
50
  };
@@ -19,6 +19,7 @@ export const MRT_TableContainer: FC<Props> = () => {
19
19
  hideToolbarTop,
20
20
  isFetching,
21
21
  isLoading,
22
+ muiLinearProgressProps,
22
23
  muiTableContainerProps,
23
24
  tableInstance,
24
25
  } = useMRT();
@@ -47,6 +48,11 @@ export const MRT_TableContainer: FC<Props> = () => {
47
48
  ? muiTableContainerProps(tableInstance)
48
49
  : muiTableContainerProps;
49
50
 
51
+ const linearProgressProps =
52
+ muiLinearProgressProps instanceof Function
53
+ ? muiLinearProgressProps(tableInstance)
54
+ : muiLinearProgressProps;
55
+
50
56
  return (
51
57
  <TableContainer
52
58
  component={Paper}
@@ -67,7 +73,7 @@ export const MRT_TableContainer: FC<Props> = () => {
67
73
  >
68
74
  {!hideToolbarTop && <MRT_ToolbarTop />}
69
75
  <Collapse in={isFetching || isLoading} unmountOnExit>
70
- <LinearProgress />
76
+ <LinearProgress {...linearProgressProps} />
71
77
  </Collapse>
72
78
  <Box
73
79
  sx={{