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,7 +1,7 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { TextField } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Cell } from '..';
4
+ import type { MRT_Cell } from '..';
5
5
 
6
6
  interface Props {
7
7
  cell: MRT_Cell;
@@ -3,14 +3,16 @@ import {
3
3
  Chip,
4
4
  IconButton,
5
5
  InputAdornment,
6
+ MenuItem,
6
7
  TextField,
7
8
  TextFieldProps,
8
9
  Tooltip,
9
10
  } from '@mui/material';
10
11
  import { useAsyncDebounce } from 'react-table';
11
12
  import { useMRT } from '../useMRT';
12
- import { MRT_HeaderGroup } from '..';
13
+ import type { MRT_HeaderGroup } from '..';
13
14
  import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
15
+ import { MRT_FILTER_TYPE } from '../enums';
14
16
 
15
17
  interface Props {
16
18
  column: MRT_HeaderGroup;
@@ -65,7 +67,10 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
65
67
  const handleClearFilterChip = () => {
66
68
  setFilterValue('');
67
69
  column.setFilter(undefined);
68
- setCurrentFilterTypes((prev) => ({ ...prev, [column.id]: 'fuzzy' }));
70
+ setCurrentFilterTypes((prev) => ({
71
+ ...prev,
72
+ [column.id]: MRT_FILTER_TYPE.FUZZY,
73
+ }));
69
74
  };
70
75
 
71
76
  if (column.Filter) {
@@ -73,8 +78,18 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
73
78
  }
74
79
 
75
80
  const filterType = tableInstance.state.currentFilterTypes[column.id];
76
- const filterChipLabel = ['empty', 'notEmpty'].includes(filterType);
77
- const filterPlaceholder = localization.filterTextFieldPlaceholder?.replace(
81
+ const isSelectFilter = !!column.filterSelectOptions;
82
+ const filterChipLabel =
83
+ !(filterType instanceof Function) &&
84
+ [MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(
85
+ filterType as MRT_FILTER_TYPE,
86
+ )
87
+ ? //@ts-ignore
88
+ localization[
89
+ `filter${filterType.charAt(0).toUpperCase() + filterType.slice(1)}`
90
+ ]
91
+ : '';
92
+ const filterPlaceholder = localization.filterByColumn?.replace(
78
93
  '{column}',
79
94
  String(column.Header),
80
95
  );
@@ -92,29 +107,61 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
92
107
  },
93
108
  title: filterPlaceholder,
94
109
  }}
110
+ helperText={
111
+ filterType instanceof Function
112
+ ? ''
113
+ : localization.filterMode.replace(
114
+ '{filterType}',
115
+ // @ts-ignore
116
+ localization[
117
+ `filter${
118
+ filterType.charAt(0).toUpperCase() + filterType.slice(1)
119
+ }`
120
+ ],
121
+ )
122
+ }
123
+ FormHelperTextProps={{
124
+ sx: { fontSize: '0.6rem', lineHeight: '0.8rem' },
125
+ }}
126
+ label={isSelectFilter && !filterValue ? filterPlaceholder : undefined}
127
+ InputLabelProps={{
128
+ shrink: false,
129
+ sx: {
130
+ maxWidth: 'calc(100% - 2.5rem)',
131
+ },
132
+ title: filterPlaceholder,
133
+ }}
95
134
  margin="none"
96
- placeholder={filterChipLabel ? '' : filterPlaceholder}
135
+ placeholder={
136
+ filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
137
+ }
97
138
  onChange={(e: ChangeEvent<HTMLInputElement>) => {
98
139
  setFilterValue(e.target.value);
99
140
  handleChange(e.target.value);
100
141
  }}
101
142
  onClick={(e) => e.stopPropagation()}
143
+ select={isSelectFilter}
102
144
  value={filterValue ?? ''}
103
145
  variant="standard"
104
146
  InputProps={{
105
- startAdornment: (
147
+ startAdornment: !isSelectFilter && (
106
148
  <InputAdornment position="start">
107
- <Tooltip arrow title="Change Filter Mode">
108
- <IconButton
109
- onClick={handleFilterMenuOpen}
110
- size="small"
111
- sx={{ height: '1.75rem', width: '1.75rem' }}
112
- >
113
- <FilterListIcon />
114
- </IconButton>
149
+ <Tooltip arrow title={localization.changeFilterMode}>
150
+ <span>
151
+ <IconButton
152
+ onClick={handleFilterMenuOpen}
153
+ size="small"
154
+ sx={{ height: '1.75rem', width: '1.75rem' }}
155
+ >
156
+ <FilterListIcon />
157
+ </IconButton>
158
+ </span>
115
159
  </Tooltip>
116
160
  {filterChipLabel && (
117
- <Chip onDelete={handleClearFilterChip} label={filterType} />
161
+ <Chip
162
+ onDelete={handleClearFilterChip}
163
+ label={filterChipLabel}
164
+ />
118
165
  )}
119
166
  </InputAdornment>
120
167
  ),
@@ -122,16 +169,20 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
122
169
  <InputAdornment position="end">
123
170
  <Tooltip
124
171
  arrow
172
+ disableHoverListener={isSelectFilter}
125
173
  placement="right"
126
- title={localization.filterTextFieldClearButtonTitle ?? ''}
174
+ title={localization.clearFilter ?? ''}
127
175
  >
128
176
  <span>
129
177
  <IconButton
130
- aria-label={localization.filterTextFieldClearButtonTitle}
131
- disabled={filterValue?.length === 0}
178
+ aria-label={localization.clearFilter}
179
+ disabled={!filterValue?.length}
132
180
  onClick={handleClear}
133
181
  size="small"
134
- sx={{ height: '1.75rem', width: '1.75rem' }}
182
+ sx={{
183
+ height: '1.75rem',
184
+ width: '1.75rem',
185
+ }}
135
186
  >
136
187
  <CloseIcon fontSize="small" />
137
188
  </IconButton>
@@ -142,12 +193,39 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
142
193
  }}
143
194
  {...textFieldProps}
144
195
  sx={{
145
- m: '0 -0.25rem',
196
+ m: '-0.25rem',
197
+ p: 0,
146
198
  minWidth: !filterChipLabel ? '5rem' : 'auto',
147
199
  width: 'calc(100% + 0.5rem)',
200
+ mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
201
+ '& .MuiSelect-icon': {
202
+ mr: '1.5rem',
203
+ },
148
204
  ...textFieldProps?.sx,
149
205
  }}
150
- />
206
+ >
207
+ {isSelectFilter && (
208
+ <MenuItem divider disabled={!filterValue} value="">
209
+ {localization.clearFilter}
210
+ </MenuItem>
211
+ )}
212
+ {column?.filterSelectOptions?.map((option) => {
213
+ let value;
214
+ let text;
215
+ if (typeof option === 'string') {
216
+ value = option;
217
+ text = option;
218
+ } else if (typeof option === 'object') {
219
+ value = option.value;
220
+ text = option.text;
221
+ }
222
+ return (
223
+ <MenuItem key={value} value={value}>
224
+ {text}
225
+ </MenuItem>
226
+ );
227
+ })}
228
+ </TextField>
151
229
  <MRT_FilterTypeMenu
152
230
  anchorEl={anchorEl}
153
231
  column={column}
@@ -34,7 +34,7 @@ export const MRT_SearchTextField: FC<Props> = () => {
34
34
  <Collapse in={tableInstance.state.showSearch} orientation="horizontal">
35
35
  <TextField
36
36
  id={`mrt-${idPrefix}-search-text-field`}
37
- placeholder={localization.searchTextFieldPlaceholder}
37
+ placeholder={localization.search}
38
38
  onChange={(event: ChangeEvent<HTMLInputElement>) => {
39
39
  setSearchValue(event.target.value);
40
40
  handleChange(event);
@@ -50,11 +50,11 @@ export const MRT_SearchTextField: FC<Props> = () => {
50
50
  endAdornment: (
51
51
  <InputAdornment position="end">
52
52
  <IconButton
53
- aria-label={localization.searchTextFieldClearButtonTitle}
53
+ aria-label={localization.clearSearch}
54
54
  disabled={searchValue?.length === 0}
55
55
  onClick={handleClear}
56
56
  size="small"
57
- title={localization.searchTextFieldClearButtonTitle}
57
+ title={localization.clearSearch}
58
58
  >
59
59
  <CloseIcon fontSize="small" />
60
60
  </IconButton>
@@ -1,7 +1,7 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { Checkbox, TableCell, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
  import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
6
6
 
7
7
  interface Props {
@@ -37,15 +37,15 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
37
37
  enterNextDelay={1000}
38
38
  title={
39
39
  selectAll
40
- ? localization.selectAllCheckboxTitle
41
- : localization.selectCheckboxTitle
40
+ ? localization.toggleSelectAll
41
+ : localization.toggleSelectRow
42
42
  }
43
43
  >
44
44
  <Checkbox
45
45
  inputProps={{
46
46
  'aria-label': selectAll
47
- ? localization.selectAllCheckboxTitle
48
- : localization.selectCheckboxTitle,
47
+ ? localization.toggleSelectAll
48
+ : localization.toggleSelectRow,
49
49
  }}
50
50
  onChange={onSelectChange}
51
51
  {...checkboxProps}
@@ -1,93 +1,94 @@
1
1
  export interface MRT_Localization {
2
- actionsHeadColumnTitle: string;
3
- columnActionMenuButtonTitle: string;
4
- columnActionMenuItemClearSort: string;
5
- columnActionMenuItemGroupBy: string;
6
- columnActionMenuItemHideColumn: string;
7
- columnActionMenuItemSortAsc: string;
8
- columnActionMenuItemSortDesc: string;
9
- columnActionMenuItemUnGroupBy: string;
10
- columnShowHideMenuHideAll: string;
11
- columnShowHideMenuShowAll: string;
12
- expandAllButtonTitle: string;
13
- expandButtonTitle: string;
14
- filterApplied: string;
15
- filterMenuItemContains: string;
16
- filterMenuItemEmpty: string;
17
- filterMenuItemEndsWith: string;
18
- filterMenuItemEquals: string;
19
- filterMenuItemFuzzy: string;
20
- filterMenuItemNotEmpty: string;
21
- filterMenuItemNotEquals: string;
22
- filterMenuItemStartsWith: string;
23
- filterMenuTitle: string;
24
- filterTextFieldChangeFilterButtonTitle: string;
25
- filterTextFieldChipLabelEmpty: string;
26
- filterTextFieldChipLabelNotEmpty: string;
27
- filterTextFieldClearButtonTitle: string;
28
- filterTextFieldPlaceholder: string;
29
- rowActionButtonCancel: string;
30
- rowActionButtonSave: string;
31
- rowActionMenuButtonTitle: string;
32
- rowActionMenuItemEdit: string;
33
- rowActionsColumnTitle: string;
34
- searchTextFieldClearButtonTitle: string;
35
- searchTextFieldPlaceholder: string;
36
- selectAllCheckboxTitle: string;
37
- selectCheckboxTitle: string;
38
- showHideColumnsButtonTitle: string;
39
- toggleDensePaddingSwitchTitle: string;
40
- toggleFilterButtonTitle: string;
41
- toggleFullScreenButtonTitle: string;
42
- toggleSearchButtonTitle: string;
43
- toolbarAlertGroupedByMessage: string;
44
- toolbarAlertGroupedThenByMessage: string;
45
- toolbarAlertSelectionMessage: string;
2
+ actions: string;
3
+ cancel: string;
4
+ changeFilterMode: string;
5
+ clearFilter: string;
6
+ clearSearch: string;
7
+ clearSort: string;
8
+ columnActions: string;
9
+ edit: string;
10
+ expand: string;
11
+ expandAll: string;
12
+ filterByColumn: string;
13
+ filterContains: string;
14
+ filterEmpty: string;
15
+ filterEndsWith: string;
16
+ filterEquals: string;
17
+ filterFuzzy: string;
18
+ filterGreaterThan: string;
19
+ filterLessThan: string;
20
+ filterMode: string;
21
+ filterNotEmpty: string;
22
+ filterNotEquals: string;
23
+ filterStartsWith: string;
24
+ filteringByColumn: string;
25
+ groupByColumn: string;
26
+ groupedBy: string;
27
+ hideAll: string;
28
+ hideColumn: string;
29
+ rowActions: string;
30
+ save: string;
31
+ search: string;
32
+ selectedCountOfRowCountRowsSelected: string;
33
+ showAll: string;
34
+ showHideColumns: string;
35
+ showAllColumns: string;
36
+ showHideFilters: string;
37
+ showHideSearch: string;
38
+ sortByColumnAsc: string;
39
+ sortByColumnDesc: string;
40
+ thenBy: string;
41
+ toggleDensePadding: string;
42
+ toggleFullScreen: string;
43
+ toggleSelectAll: string;
44
+ toggleSelectRow: string;
45
+ ungroupByColumn: string;
46
46
  }
47
47
 
48
48
  export const MRT_DefaultLocalization_EN: MRT_Localization = {
49
- actionsHeadColumnTitle: 'Actions',
50
- columnActionMenuButtonTitle: 'Column Actions',
51
- columnActionMenuItemClearSort: 'Clear sort',
52
- columnActionMenuItemGroupBy: 'Group by {column}',
53
- columnActionMenuItemHideColumn: 'Hide {column} column',
54
- columnActionMenuItemSortAsc: 'Sort by {column} ascending',
55
- columnActionMenuItemSortDesc: 'Sort by {column} descending',
56
- columnActionMenuItemUnGroupBy: 'Ungroup by {column}',
57
- columnShowHideMenuHideAll: 'Hide all',
58
- columnShowHideMenuShowAll: 'Show all',
59
- expandAllButtonTitle: 'Expand all',
60
- expandButtonTitle: 'Expand',
61
- filterApplied: 'Filtering by {column} - ({filterType})',
62
- filterMenuItemContains: 'Contains Exact',
63
- filterMenuItemEmpty: 'Empty',
64
- filterMenuItemEndsWith: 'Ends With',
65
- filterMenuItemEquals: 'Equals',
66
- filterMenuItemFuzzy: 'Fuzzy Match (Default)',
67
- filterMenuItemNotEmpty: 'Not Empty',
68
- filterMenuItemNotEquals: 'Not Equals',
69
- filterMenuItemStartsWith: 'Starts With',
70
- filterMenuTitle: 'Filter Mode',
71
- filterTextFieldChangeFilterButtonTitle: 'Change Filter Mode',
72
- filterTextFieldChipLabelEmpty: 'Empty',
73
- filterTextFieldChipLabelNotEmpty: 'Not Empty',
74
- filterTextFieldClearButtonTitle: 'Clear filter',
75
- filterTextFieldPlaceholder: 'Filter by {column}',
76
- rowActionButtonCancel: 'Cancel',
77
- rowActionButtonSave: 'Save',
78
- rowActionMenuButtonTitle: 'Row Actions',
79
- rowActionMenuItemEdit: 'Edit',
80
- rowActionsColumnTitle: 'Actions',
81
- searchTextFieldClearButtonTitle: 'Clear search',
82
- searchTextFieldPlaceholder: 'Search',
83
- selectAllCheckboxTitle: 'Toggle select all',
84
- selectCheckboxTitle: 'Toggle select row',
85
- showHideColumnsButtonTitle: 'Show/Hide columns',
86
- toggleDensePaddingSwitchTitle: 'Toggle dense padding',
87
- toggleFilterButtonTitle: 'Show/Hide filters',
88
- toggleFullScreenButtonTitle: 'Toggle full screen',
89
- toggleSearchButtonTitle: 'Show/Hide search',
90
- toolbarAlertGroupedByMessage: 'Grouped by ',
91
- toolbarAlertGroupedThenByMessage: ', then by ',
92
- toolbarAlertSelectionMessage: '{selectedCount} of {rowCount} row(s) selected',
49
+ actions: 'Actions',
50
+ cancel: 'Cancel',
51
+ changeFilterMode: 'Change filter mode',
52
+ clearFilter: 'Clear filter',
53
+ clearSearch: 'Clear search',
54
+ clearSort: 'Clear sort',
55
+ columnActions: 'Column Actions',
56
+ edit: 'Edit',
57
+ expand: 'Expand',
58
+ expandAll: 'Expand all',
59
+ filterByColumn: 'Filter by {column}',
60
+ filterContains: 'Contains Exact',
61
+ filterEmpty: 'Empty',
62
+ filterEndsWith: 'Ends With',
63
+ filterEquals: 'Equals',
64
+ filterFuzzy: 'Fuzzy Match',
65
+ filterGreaterThan: 'Greater Than',
66
+ filterLessThan: 'Less Than',
67
+ filterMode: 'Filter Mode: {filterType}',
68
+ filterNotEmpty: 'Not Empty',
69
+ filterNotEquals: 'Not Equals',
70
+ filterStartsWith: 'Starts With',
71
+ filteringByColumn: 'Filtering by {column} - {filterType} "{filterValue}"',
72
+ groupByColumn: 'Group by {column}',
73
+ groupedBy: 'Grouped by ',
74
+ hideAll: 'Hide all',
75
+ hideColumn: 'Hide {column} column',
76
+ rowActions: 'Row Actions',
77
+ save: 'Save',
78
+ search: 'Search',
79
+ selectedCountOfRowCountRowsSelected:
80
+ '{selectedCount} of {rowCount} row(s) selected',
81
+ showAll: 'Show all',
82
+ showAllColumns: 'Show all columns',
83
+ showHideColumns: 'Show/Hide columns',
84
+ showHideFilters: 'Show/Hide filters',
85
+ showHideSearch: 'Show/Hide search',
86
+ sortByColumnAsc: 'Sort by {column} ascending',
87
+ sortByColumnDesc: 'Sort by {column} descending',
88
+ thenBy: ', then by ',
89
+ toggleDensePadding: 'Toggle dense padding',
90
+ toggleFullScreen: 'Toggle full screen',
91
+ toggleSelectAll: 'Toggle select all',
92
+ toggleSelectRow: 'Toggle select row',
93
+ ungroupByColumn: 'Ungroup by {column}',
93
94
  };