material-react-table 0.5.7 → 0.6.0

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 (67) hide show
  1. package/dist/MaterialReactTable.d.ts +8 -2
  2. package/dist/body/MRT_TableBodyCell.d.ts +1 -1
  3. package/dist/body/MRT_TableBodyRow.d.ts +1 -1
  4. package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
  5. package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
  6. package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
  7. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +1 -1
  8. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
  9. package/dist/enums.d.ts +12 -0
  10. package/dist/filtersFNs.d.ts +20 -0
  11. package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
  12. package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
  13. package/dist/head/MRT_TableHeadCell.d.ts +1 -1
  14. package/dist/head/MRT_TableHeadRow.d.ts +1 -1
  15. package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
  16. package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
  17. package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
  18. package/dist/localization.d.ts +44 -44
  19. package/dist/material-react-table.cjs.development.js +569 -360
  20. package/dist/material-react-table.cjs.development.js.map +1 -1
  21. package/dist/material-react-table.cjs.production.min.js +1 -1
  22. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  23. package/dist/material-react-table.esm.js +570 -361
  24. package/dist/material-react-table.esm.js.map +1 -1
  25. package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -2
  26. package/dist/menus/MRT_FilterTypeMenu.d.ts +1 -1
  27. package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
  28. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +3 -2
  29. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -0
  30. package/dist/useMRT.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/src/MaterialReactTable.tsx +5 -9
  33. package/src/body/MRT_TableBody.tsx +1 -1
  34. package/src/body/MRT_TableBodyCell.tsx +1 -1
  35. package/src/body/MRT_TableBodyRow.tsx +1 -1
  36. package/src/body/MRT_TableDetailPanel.tsx +1 -1
  37. package/src/buttons/MRT_EditActionButtons.tsx +5 -8
  38. package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
  39. package/src/buttons/MRT_ExpandButton.tsx +3 -3
  40. package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
  41. package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -55
  42. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
  43. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
  44. package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
  45. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +4 -8
  46. package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
  47. package/src/enums.ts +12 -0
  48. package/src/filtersFNs.ts +42 -0
  49. package/src/footer/MRT_TableFooter.tsx +1 -1
  50. package/src/footer/MRT_TableFooterCell.tsx +1 -1
  51. package/src/footer/MRT_TableFooterRow.tsx +1 -1
  52. package/src/head/MRT_TableHead.tsx +1 -1
  53. package/src/head/MRT_TableHeadCell.tsx +22 -18
  54. package/src/head/MRT_TableHeadCellActions.tsx +1 -1
  55. package/src/head/MRT_TableHeadRow.tsx +1 -1
  56. package/src/inputs/MRT_EditCellTextField.tsx +1 -1
  57. package/src/inputs/MRT_FilterTextField.tsx +99 -21
  58. package/src/inputs/MRT_SearchTextField.tsx +3 -3
  59. package/src/inputs/MRT_SelectCheckbox.tsx +5 -5
  60. package/src/localization.ts +89 -88
  61. package/src/menus/MRT_ColumnActionMenu.tsx +109 -56
  62. package/src/menus/MRT_FilterTypeMenu.tsx +63 -26
  63. package/src/menus/MRT_RowActionMenu.tsx +4 -10
  64. package/src/menus/MRT_ShowHideColumnsMenu.tsx +54 -33
  65. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
  66. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
  67. package/src/useMRT.tsx +36 -14
@@ -1,18 +1,21 @@
1
1
  import React, { FC, useState } from 'react';
2
- import {
3
- IconButton,
4
- ListItemIcon,
5
- ListItemText,
6
- Menu,
7
- MenuItem,
8
- } from '@mui/material';
2
+ import { Box, IconButton, Menu, MenuItem } from '@mui/material';
9
3
  import { useMRT } from '../useMRT';
10
- import { MRT_HeaderGroup } from '..';
4
+ import type { MRT_HeaderGroup } from '..';
11
5
  import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
6
+ import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
12
7
 
13
8
  export const commonMenuItemStyles = {
14
- py: '0 !important',
15
- my: '0 !important',
9
+ py: '6px',
10
+ my: 0,
11
+ justifyContent: 'space-between',
12
+ alignItems: 'center',
13
+ };
14
+
15
+ export const commonListItemStyles = {
16
+ display: 'flex',
17
+ gap: '0.75rem',
18
+ alignItems: 'center',
16
19
  };
17
20
 
18
21
  interface Props {
@@ -34,8 +37,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
34
37
  icons: {
35
38
  ArrowRightIcon,
36
39
  ClearAllIcon,
40
+ ViewColumnIcon,
37
41
  DynamicFeedIcon,
38
42
  FilterListIcon,
43
+ FilterListOffIcon,
39
44
  SortIcon,
40
45
  VisibilityOffIcon,
41
46
  },
@@ -48,6 +53,9 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
48
53
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
49
54
  useState<null | HTMLElement>(null);
50
55
 
56
+ const [showHideColumnsMenuAnchorEl, setShowHideColumnsMenuAnchorEl] =
57
+ useState<null | HTMLElement>(null);
58
+
51
59
  const handleClearSort = () => {
52
60
  column.clearSortBy();
53
61
  setAnchorEl(null);
@@ -73,6 +81,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
73
81
  setAnchorEl(null);
74
82
  };
75
83
 
84
+ const handleClearFilter = () => {
85
+ column.setFilter('');
86
+ setAnchorEl(null);
87
+ };
88
+
76
89
  const handleFilterByColumn = () => {
77
90
  setShowFilters(true);
78
91
  setTimeout(
@@ -94,6 +107,17 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
94
107
  setFilterMenuAnchorEl(event.currentTarget);
95
108
  };
96
109
 
110
+ const handleShowAllColumns = () => {
111
+ tableInstance.toggleHideAllColumns(false);
112
+ };
113
+
114
+ const handleOpenShowHideColumnsMenu = (
115
+ event: React.MouseEvent<HTMLElement>,
116
+ ) => {
117
+ event.stopPropagation();
118
+ setShowHideColumnsMenuAnchorEl(event.currentTarget);
119
+ };
120
+
97
121
  return (
98
122
  <Menu
99
123
  anchorEl={anchorEl}
@@ -101,85 +125,89 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
101
125
  onClose={() => setAnchorEl(null)}
102
126
  MenuListProps={{
103
127
  dense: tableInstance.state.densePadding,
104
- disablePadding: true,
105
128
  }}
106
129
  >
107
130
  {!disableSortBy &&
108
131
  column.canSort && [
109
132
  <MenuItem
110
- key={1}
111
133
  disabled={!column.isSorted}
134
+ key={0}
112
135
  onClick={handleClearSort}
113
136
  sx={commonMenuItemStyles}
114
137
  >
115
- <ListItemIcon>
138
+ <Box sx={commonListItemStyles}>
116
139
  <ClearAllIcon />
117
- </ListItemIcon>
118
- <ListItemText sx={commonMenuItemStyles}>
119
- {localization.columnActionMenuItemClearSort}
120
- </ListItemText>
140
+ {localization.clearSort}
141
+ </Box>
121
142
  </MenuItem>,
122
143
  <MenuItem
123
144
  disabled={column.isSorted && !column.isSortedDesc}
124
- key={2}
145
+ key={1}
125
146
  onClick={handleSortAsc}
126
147
  sx={commonMenuItemStyles}
127
148
  >
128
- <ListItemIcon>
149
+ <Box sx={commonListItemStyles}>
129
150
  <SortIcon />
130
- </ListItemIcon>
131
- <ListItemText sx={commonMenuItemStyles}>
132
- {localization.columnActionMenuItemSortAsc?.replace(
151
+ {localization.sortByColumnAsc?.replace(
133
152
  '{column}',
134
153
  String(column.Header),
135
154
  )}
136
- </ListItemText>
155
+ </Box>
137
156
  </MenuItem>,
138
157
  <MenuItem
139
158
  divider={
140
159
  !disableFilters || enableColumnGrouping || !disableColumnHiding
141
160
  }
142
- key={3}
161
+ key={2}
143
162
  disabled={column.isSorted && column.isSortedDesc}
144
163
  onClick={handleSortDesc}
145
164
  sx={commonMenuItemStyles}
146
165
  >
147
- <ListItemIcon>
166
+ <Box sx={commonListItemStyles}>
148
167
  <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
149
- </ListItemIcon>
150
- <ListItemText sx={commonMenuItemStyles}>
151
- {localization.columnActionMenuItemSortDesc?.replace(
168
+ {localization.sortByColumnDesc?.replace(
152
169
  '{column}',
153
170
  String(column.Header),
154
171
  )}
155
- </ListItemText>
172
+ </Box>
156
173
  </MenuItem>,
157
174
  ]}
158
175
  {!disableFilters &&
159
176
  column.canFilter && [
177
+ <MenuItem
178
+ disabled={!column.filterValue}
179
+ key={0}
180
+ onClick={handleClearFilter}
181
+ sx={commonMenuItemStyles}
182
+ >
183
+ <Box sx={commonListItemStyles}>
184
+ <FilterListOffIcon />
185
+ {localization.clearFilter}
186
+ </Box>
187
+ </MenuItem>,
160
188
  <MenuItem
161
189
  divider={enableColumnGrouping || !disableColumnHiding}
162
190
  key={1}
163
191
  onClick={handleFilterByColumn}
164
192
  sx={commonMenuItemStyles}
165
193
  >
166
- <ListItemIcon>
194
+ <Box sx={commonListItemStyles}>
167
195
  <FilterListIcon />
168
- </ListItemIcon>
169
- <ListItemText sx={commonMenuItemStyles}>
170
- {localization.filterTextFieldPlaceholder?.replace(
196
+ {localization.filterByColumn?.replace(
171
197
  '{column}',
172
198
  String(column.Header),
173
199
  )}
174
- </ListItemText>
175
- <IconButton
176
- onClick={handleOpenFilterModeMenu}
177
- onMouseEnter={handleOpenFilterModeMenu}
178
- size="small"
179
- sx={{ p: 0 }}
180
- >
181
- <ArrowRightIcon />
182
- </IconButton>
200
+ </Box>
201
+ {!column.filterSelectOptions && (
202
+ <IconButton
203
+ onClick={handleOpenFilterModeMenu}
204
+ onMouseEnter={handleOpenFilterModeMenu}
205
+ size="small"
206
+ sx={{ p: 0 }}
207
+ >
208
+ <ArrowRightIcon />
209
+ </IconButton>
210
+ )}
183
211
  </MenuItem>,
184
212
  <MRT_FilterTypeMenu
185
213
  anchorEl={filterMenuAnchorEl}
@@ -193,34 +221,59 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
193
221
  column.canGroupBy && [
194
222
  <MenuItem
195
223
  divider={!disableColumnHiding}
196
- key={2}
224
+ key={0}
197
225
  onClick={handleGroupByColumn}
198
226
  sx={commonMenuItemStyles}
199
227
  >
200
- <ListItemIcon>
228
+ <Box sx={commonListItemStyles}>
201
229
  <DynamicFeedIcon />
202
- </ListItemIcon>
203
- <ListItemText sx={commonMenuItemStyles}>
204
230
  {localization[
205
- column.isGrouped
206
- ? 'columnActionMenuItemUnGroupBy'
207
- : 'columnActionMenuItemGroupBy'
231
+ column.isGrouped ? 'ungroupByColumn' : 'groupByColumn'
208
232
  ]?.replace('{column}', String(column.Header))}
209
- </ListItemText>
233
+ </Box>
210
234
  </MenuItem>,
211
235
  ]}
212
236
  {!disableColumnHiding && [
213
- <MenuItem key={1} onClick={handleHideColumn} sx={commonMenuItemStyles}>
214
- <ListItemIcon>
237
+ <MenuItem key={0} onClick={handleHideColumn} sx={commonMenuItemStyles}>
238
+ <Box sx={commonListItemStyles}>
215
239
  <VisibilityOffIcon />
216
- </ListItemIcon>
217
- <ListItemText sx={commonMenuItemStyles}>
218
- {localization.columnActionMenuItemHideColumn?.replace(
240
+ {localization.hideColumn?.replace(
219
241
  '{column}',
220
242
  String(column.Header),
221
243
  )}
222
- </ListItemText>
244
+ </Box>
245
+ </MenuItem>,
246
+ <MenuItem
247
+ disabled={!tableInstance.state.hiddenColumns?.length}
248
+ key={1}
249
+ onClick={handleShowAllColumns}
250
+ sx={commonMenuItemStyles}
251
+ >
252
+ <Box sx={commonListItemStyles}>
253
+ <ViewColumnIcon />
254
+
255
+ {localization.showAllColumns?.replace(
256
+ '{column}',
257
+ String(column.Header),
258
+ )}
259
+ </Box>
260
+ {!column.filterSelectOptions && (
261
+ <IconButton
262
+ onClick={handleOpenShowHideColumnsMenu}
263
+ onMouseEnter={handleOpenShowHideColumnsMenu}
264
+ size="small"
265
+ sx={{ p: 0 }}
266
+ >
267
+ <ArrowRightIcon />
268
+ </IconButton>
269
+ )}
223
270
  </MenuItem>,
271
+ <MRT_ShowHideColumnsMenu
272
+ anchorEl={showHideColumnsMenuAnchorEl}
273
+ isSubMenu
274
+ key={2}
275
+ setAnchorEl={setShowHideColumnsMenuAnchorEl}
276
+ />,
224
277
  ]}
225
278
  </Menu>
226
279
  );
@@ -1,9 +1,26 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_FilterType, MRT_HeaderGroup } from '..';
5
- import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
4
+ import type { MRT_FilterType, MRT_HeaderGroup } from '..';
5
+ import { MRT_FILTER_TYPE } from '../enums';
6
+ import {
7
+ containsFilterFN,
8
+ emptyFilterFN,
9
+ endsWithFilterFN,
10
+ equalsFilterFN,
11
+ fuzzyFilterFN,
12
+ greaterThanFilterFN,
13
+ lessThanFilterFN,
14
+ notEmptyFilterFN,
15
+ notEqualsFilterFN,
16
+ startsWithFilterFN,
17
+ } from '../filtersFNs';
6
18
 
19
+ const commonMenuItemStyles = {
20
+ py: '6px',
21
+ my: 0,
22
+ alignItems: 'center',
23
+ };
7
24
 
8
25
  interface Props {
9
26
  anchorEl: HTMLElement | null;
@@ -21,62 +38,83 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
21
38
  const { localization, setCurrentFilterTypes, tableInstance } = useMRT();
22
39
 
23
40
  const filterTypes: {
24
- type: MRT_FilterType;
41
+ type: MRT_FILTER_TYPE;
25
42
  label: string;
26
43
  divider: boolean;
44
+ fn: Function;
27
45
  }[] = useMemo(
28
46
  () => [
29
47
  {
30
- type: 'fuzzy',
31
- label: localization.filterMenuItemFuzzy,
48
+ type: MRT_FILTER_TYPE.FUZZY,
49
+ label: localization.filterFuzzy,
32
50
  divider: false,
51
+ fn: fuzzyFilterFN,
33
52
  },
34
53
  {
35
- type: 'contains',
36
- label: localization.filterMenuItemContains,
54
+ type: MRT_FILTER_TYPE.CONTAINS,
55
+ label: localization.filterContains,
37
56
  divider: true,
57
+ fn: containsFilterFN,
38
58
  },
39
59
  {
40
- type: 'startsWith',
41
- label: localization.filterMenuItemStartsWith,
60
+ type: MRT_FILTER_TYPE.STARTS_WITH,
61
+ label: localization.filterStartsWith,
42
62
  divider: false,
63
+ fn: startsWithFilterFN,
43
64
  },
44
65
  {
45
- type: 'endsWith',
46
- label: localization.filterMenuItemEndsWith,
66
+ type: MRT_FILTER_TYPE.ENDS_WITH,
67
+ label: localization.filterEndsWith,
47
68
  divider: true,
69
+ fn: endsWithFilterFN,
48
70
  },
49
71
  {
50
- type: 'equals',
51
- label: localization.filterMenuItemEquals,
72
+ type: MRT_FILTER_TYPE.EQUALS,
73
+ label: localization.filterEquals,
52
74
  divider: false,
75
+ fn: equalsFilterFN,
53
76
  },
54
77
  {
55
- type: 'notEquals',
56
- label: localization.filterMenuItemNotEquals,
78
+ type: MRT_FILTER_TYPE.NOT_EQUALS,
79
+ label: localization.filterNotEquals,
57
80
  divider: true,
81
+ fn: notEqualsFilterFN,
58
82
  },
59
83
  {
60
- type: 'empty',
61
- label: localization.filterMenuItemEmpty,
84
+ type: MRT_FILTER_TYPE.GREATER_THAN,
85
+ label: localization.filterGreaterThan,
62
86
  divider: false,
87
+ fn: greaterThanFilterFN,
63
88
  },
64
89
  {
65
- type: 'notEmpty',
66
- label: localization.filterMenuItemNotEmpty,
90
+ type: MRT_FILTER_TYPE.LESS_THAN,
91
+ label: localization.filterLessThan,
92
+ divider: true,
93
+ fn: lessThanFilterFN,
94
+ },
95
+ {
96
+ type: MRT_FILTER_TYPE.EMPTY,
97
+ label: localization.filterEmpty,
67
98
  divider: false,
99
+ fn: emptyFilterFN,
100
+ },
101
+ {
102
+ type: MRT_FILTER_TYPE.NOT_EMPTY,
103
+ label: localization.filterNotEmpty,
104
+ divider: false,
105
+ fn: notEmptyFilterFN,
68
106
  },
69
107
  ],
70
108
  [],
71
109
  );
72
110
 
73
- const handleSelectFilterType = (value: MRT_FilterType) => {
111
+ const handleSelectFilterType = (value: MRT_FILTER_TYPE) => {
74
112
  setAnchorEl(null);
75
113
  setCurrentFilterTypes((prev: { [key: string]: MRT_FilterType }) => ({
76
114
  ...prev,
77
115
  [column.id]: value,
78
116
  }));
79
- if (['empty', 'notEmpty'].includes(value)) {
117
+ if ([MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(value)) {
80
118
  column.setFilter(' ');
81
119
  }
82
120
  onSelect?.();
@@ -92,17 +130,16 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
92
130
  open={!!anchorEl}
93
131
  MenuListProps={{
94
132
  dense: tableInstance.state.densePadding,
95
- disablePadding: true,
96
133
  }}
97
134
  >
98
- {filterTypes.map(({ type, label, divider }) => (
135
+ {filterTypes.map(({ type, label, divider, fn }, index) => (
99
136
  <MenuItem
100
137
  divider={divider}
101
- key={type}
138
+ key={index}
102
139
  onClick={() => handleSelectFilterType(type)}
103
- selected={type === filterType}
104
- value={type}
140
+ selected={type === filterType || fn === filterType}
105
141
  sx={commonMenuItemStyles}
142
+ value={type}
106
143
  >
107
144
  {label}
108
145
  </MenuItem>
@@ -1,10 +1,9 @@
1
1
  import React, { FC } from 'react';
2
- import { ListItemIcon, ListItemText, Menu, MenuItem } from '@mui/material';
2
+ import { Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
  import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
6
6
 
7
-
8
7
  interface Props {
9
8
  anchorEl: HTMLElement | null;
10
9
  row: MRT_Row;
@@ -33,17 +32,12 @@ export const MRT_RowActionMenu: FC<Props> = ({
33
32
  onClose={() => setAnchorEl(null)}
34
33
  MenuListProps={{
35
34
  dense: tableInstance.state.densePadding,
36
- disablePadding: true,
37
35
  }}
38
36
  >
39
37
  {enableRowEditing && (
40
38
  <MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
41
- <ListItemIcon>
42
- <EditIcon />
43
- </ListItemIcon>
44
- <ListItemText sx={commonMenuItemStyles}>
45
- {localization.rowActionMenuItemEdit}
46
- </ListItemText>
39
+ <EditIcon />
40
+ {localization.edit}
47
41
  </MenuItem>
48
42
  )}
49
43
  {renderRowActionMenuItems?.(row, tableInstance, () =>
@@ -1,44 +1,65 @@
1
1
  import React, { FC } from 'react';
2
- import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
- import { ColumnInstance } from 'react-table';
4
- import { MRT_ColumnInstance } from '..';
2
+ import { Button, Menu, Divider, Box } from '@mui/material';
3
+ import type { MRT_ColumnInstance } from '..';
4
+ import { useMRT } from '../useMRT';
5
+ import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
5
6
 
6
7
  interface Props {
7
- column: MRT_ColumnInstance;
8
+ anchorEl: HTMLElement | null;
9
+ isSubMenu?: boolean;
10
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
8
11
  }
9
12
 
10
- export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
11
- const isParentHeader = !!column?.columns?.length;
12
-
13
- const allChildColumnsVisible =
14
- isParentHeader &&
15
- !!column.columns?.every((childColumn) => childColumn.isVisible);
16
-
17
- const switchChecked = column.isVisible ?? allChildColumnsVisible;
18
-
19
- const handleToggleColumnHidden = (column: ColumnInstance) => {
20
- if (isParentHeader) {
21
- column?.columns?.forEach?.((childColumn) => {
22
- childColumn.toggleHidden(switchChecked);
23
- });
24
- } else {
25
- column.toggleHidden();
26
- }
27
- };
13
+ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
14
+ anchorEl,
15
+ isSubMenu,
16
+ setAnchorEl,
17
+ }) => {
18
+ const { localization, tableInstance } = useMRT();
28
19
 
29
20
  return (
30
- <>
31
- <MenuItem sx={{ pl: `${(column.depth + 0.5) * 2}rem` }}>
32
- <FormControlLabel
33
- checked={switchChecked}
34
- control={<Switch />}
35
- label={column.Header as string}
36
- onChange={() => handleToggleColumnHidden(column)}
21
+ <Menu
22
+ anchorEl={anchorEl}
23
+ open={!!anchorEl}
24
+ onClose={() => setAnchorEl(null)}
25
+ MenuListProps={{
26
+ dense: tableInstance.state.densePadding,
27
+ }}
28
+ >
29
+ <Box
30
+ sx={{
31
+ display: 'flex',
32
+ justifyContent: isSubMenu ? 'center' : 'space-between',
33
+ p: '0.5rem',
34
+ pt: 0,
35
+ }}
36
+ >
37
+ {!isSubMenu && (
38
+ <Button
39
+ disabled={
40
+ !tableInstance.getToggleHideAllColumnsProps().checked &&
41
+ !tableInstance.getToggleHideAllColumnsProps().indeterminate
42
+ }
43
+ onClick={() => tableInstance.toggleHideAllColumns(true)}
44
+ >
45
+ {localization.hideAll}
46
+ </Button>
47
+ )}
48
+ <Button
49
+ disabled={tableInstance.getToggleHideAllColumnsProps().checked}
50
+ onClick={() => tableInstance.toggleHideAllColumns(false)}
51
+ >
52
+ {localization.showAll}
53
+ </Button>
54
+ </Box>
55
+ <Divider />
56
+ {tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
57
+ <MRT_ShowHideColumnsMenuItems
58
+ column={column}
59
+ isSubMenu={isSubMenu}
60
+ key={`${index}-${column.id}`}
37
61
  />
38
- </MenuItem>
39
- {column.columns?.map((c: MRT_ColumnInstance, i) => (
40
- <MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
41
62
  ))}
42
- </>
63
+ </Menu>
43
64
  );
44
65
  };
@@ -0,0 +1,57 @@
1
+ import React, { FC } from 'react';
2
+ import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
+ import { ColumnInstance } from 'react-table';
4
+ import type { MRT_ColumnInstance } from '..';
5
+ import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
6
+
7
+ interface Props {
8
+ column: MRT_ColumnInstance;
9
+ isSubMenu?: boolean;
10
+ }
11
+
12
+ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
13
+ column,
14
+ isSubMenu,
15
+ }) => {
16
+ const isParentHeader = !!column?.columns?.length;
17
+
18
+ const allChildColumnsVisible =
19
+ isParentHeader &&
20
+ !!column.columns?.every((childColumn) => childColumn.isVisible);
21
+
22
+ const switchChecked = column.isVisible ?? allChildColumnsVisible;
23
+
24
+ const handleToggleColumnHidden = (column: ColumnInstance) => {
25
+ if (isParentHeader) {
26
+ column?.columns?.forEach?.((childColumn) => {
27
+ childColumn.toggleHidden(switchChecked);
28
+ });
29
+ } else {
30
+ column.toggleHidden();
31
+ }
32
+ };
33
+
34
+ return (
35
+ <>
36
+ <MenuItem
37
+ sx={{ ...commonMenuItemStyles, pl: `${(column.depth + 0.5) * 2}rem` }}
38
+ >
39
+ <FormControlLabel
40
+ componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
41
+ checked={switchChecked}
42
+ control={<Switch />}
43
+ disabled={isSubMenu && switchChecked}
44
+ label={column.Header as string}
45
+ onChange={() => handleToggleColumnHidden(column)}
46
+ />
47
+ </MenuItem>
48
+ {column.columns?.map((c: MRT_ColumnInstance, i) => (
49
+ <MRT_ShowHideColumnsMenuItems
50
+ key={`${i}-${c.id}`}
51
+ column={c}
52
+ isSubMenu={isSubMenu}
53
+ />
54
+ ))}
55
+ </>
56
+ );
57
+ };
@@ -23,7 +23,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
23
23
 
24
24
  const selectMessage =
25
25
  tableInstance.selectedFlatRows.length > 0
26
- ? localization.toolbarAlertSelectionMessage
26
+ ? localization.selectedCountOfRowCountRowsSelected
27
27
  ?.replace(
28
28
  '{selectedCount}',
29
29
  tableInstance.selectedFlatRows.length.toString(),
@@ -34,10 +34,10 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
34
34
  const groupedByMessage =
35
35
  tableInstance.state.groupBy.length > 0 ? (
36
36
  <span>
37
- {localization.toolbarAlertGroupedByMessage}{' '}
37
+ {localization.groupedBy}{' '}
38
38
  {tableInstance.state.groupBy.map((columnId, index) => (
39
39
  <Fragment key={`${index}-${columnId}`}>
40
- {index > 0 ? localization.toolbarAlertGroupedThenByMessage : ''}
40
+ {index > 0 ? localization.thenBy : ''}
41
41
  <Chip
42
42
  color="secondary"
43
43
  label={