material-react-table 0.5.4 → 0.5.7

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.
@@ -1,5 +1,9 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_HeaderGroup } from '..';
3
+ export declare const commonMenuItemStyles: {
4
+ py: string;
5
+ my: string;
6
+ };
3
7
  interface Props {
4
8
  anchorEl: HTMLElement | null;
5
9
  column: MRT_HeaderGroup;
@@ -6,5 +6,5 @@ interface Props {
6
6
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
7
7
  onSelect?: () => void;
8
8
  }
9
- export declare const MRT_FilterMenu: FC<Props>;
9
+ export declare const MRT_FilterTypeMenu: FC<Props>;
10
10
  export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.4",
2
+ "version": "0.5.7",
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.",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "scripts": {
30
30
  "analyze": "size-limit --why",
31
- "build": "tsdx build && size-limit",
31
+ "build": "tsdx build && size-limit && cp -r dist material-react-table-docs/node_modules/material-react-table/dist && cp -r src material-react-table-docs/node_modules/material-react-table/src && cp -r package.json material-react-table-docs/node_modules/material-react-table/package.json",
32
32
  "build-storybook": "build-storybook",
33
33
  "format": "prettier -w .",
34
34
  "lint": "tsdx lint",
@@ -36,8 +36,7 @@
36
36
  "size": "size-limit",
37
37
  "start": "tsdx watch",
38
38
  "storybook": "start-storybook -p 6006",
39
- "test": "tsdx test --passWithNoTests",
40
- "upgrade": "ncu -u && npm i"
39
+ "test": "tsdx test --passWithNoTests"
41
40
  },
42
41
  "husky": {
43
42
  "hooks": {
@@ -60,9 +59,9 @@
60
59
  "@emotion/react": "^11.8.1",
61
60
  "@emotion/styled": "^11.8.1",
62
61
  "@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",
62
+ "@faker-js/faker": "^6.0.0-beta.0",
63
+ "@mui/icons-material": "^5.5.0",
64
+ "@mui/material": "^5.5.0",
66
65
  "@size-limit/preset-small-lib": "^7.0.8",
67
66
  "@storybook/addon-a11y": "^6.4.19",
68
67
  "@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')
@@ -11,14 +11,15 @@ import {
11
11
  import { useMRT } from '../useMRT';
12
12
  import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
13
13
  import { MRT_ColumnInstance } from '..';
14
+ import { commonMenuItemStyles } from '../menus/MRT_ColumnActionMenu';
14
15
 
15
16
  interface Props extends IconButtonProps {}
16
17
 
17
18
  export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
18
19
  const {
19
- tableInstance,
20
- localization,
21
20
  icons: { ViewColumnIcon },
21
+ localization,
22
+ tableInstance,
22
23
  } = useMRT();
23
24
 
24
25
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
@@ -43,12 +44,17 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
43
44
  anchorEl={anchorEl}
44
45
  open={!!anchorEl}
45
46
  onClose={() => setAnchorEl(null)}
47
+ MenuListProps={{
48
+ dense: tableInstance.state.densePadding,
49
+ disablePadding: true,
50
+ }}
51
+ sx={commonMenuItemStyles}
46
52
  >
47
53
  <Box
48
54
  sx={{
49
55
  display: 'flex',
50
56
  justifyContent: 'space-between',
51
- p: '0 0.5rem 0.5rem 0.5rem',
57
+ p: '0.5rem',
52
58
  }}
53
59
  >
54
60
  <Button
@@ -16,7 +16,7 @@ export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
16
16
  },
17
17
  } = useMRT();
18
18
 
19
- const isParentHeader = (column?.columns?.length ?? 0) > 0;
19
+ const isParentHeader = !!column?.columns?.length;
20
20
 
21
21
  const mTableFooterCellProps =
22
22
  muiTableFooterCellProps instanceof Function
@@ -6,6 +6,7 @@ import {
6
6
  Collapse,
7
7
  Tooltip,
8
8
  Box,
9
+ IconButton,
9
10
  } from '@mui/material';
10
11
  import { useMRT } from '../useMRT';
11
12
  import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
@@ -33,12 +34,14 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
33
34
  disableColumnActions,
34
35
  disableFilters,
35
36
  enableColumnResizing,
37
+ icons: { FilterAltIcon, FilterAltOff },
36
38
  localization,
37
39
  muiTableHeadCellProps,
40
+ setShowFilters,
38
41
  tableInstance,
39
42
  } = useMRT();
40
43
 
41
- const isParentHeader = (column?.columns?.length ?? 0) > 0;
44
+ const isParentHeader = !!column?.columns?.length;
42
45
 
43
46
  const mTableHeadCellProps =
44
47
  muiTableHeadCellProps instanceof Function
@@ -73,6 +76,23 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
73
76
  column.Header as string,
74
77
  );
75
78
 
79
+ const filterTooltip = !!column.filterValue
80
+ ? localization.filterApplied
81
+ .replace('{column}', String(column.Header))
82
+ .replace(
83
+ '{filterType}',
84
+ // @ts-ignore
85
+ localization[
86
+ `filterMenuItem${
87
+ tableInstance.state.currentFilterTypes[column.id]
88
+ .charAt(0)
89
+ .toUpperCase() +
90
+ tableInstance.state.currentFilterTypes[column.id].slice(1)
91
+ }`
92
+ ],
93
+ )
94
+ : localization.toggleFilterButtonTitle;
95
+
76
96
  const columnHeader = column.render('Header') as string;
77
97
 
78
98
  return (
@@ -115,6 +135,32 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
115
135
  />
116
136
  </Tooltip>
117
137
  )}
138
+ {!isParentHeader && !!column.canFilter && (
139
+ <Tooltip arrow title={filterTooltip}>
140
+ <IconButton
141
+ onClick={(event) => {
142
+ event.stopPropagation();
143
+ setShowFilters(!tableInstance.state.showFilters);
144
+ }}
145
+ size="small"
146
+ sx={{
147
+ opacity: !!column.filterValue ? 0.8 : 0,
148
+ p: '2px',
149
+ m: 0,
150
+ transition: 'all 0.2s ease-in-out',
151
+ '&:hover': {
152
+ opacity: 0.8,
153
+ },
154
+ }}
155
+ >
156
+ {tableInstance.state.showFilters && !column.filterValue ? (
157
+ <FilterAltOff fontSize="small" />
158
+ ) : (
159
+ <FilterAltIcon fontSize="small" />
160
+ )}
161
+ </IconButton>
162
+ </Tooltip>
163
+ )}
118
164
  </Box>
119
165
  <Box sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}>
120
166
  {!disableColumnActions && !isParentHeader && (
@@ -1,3 +1,4 @@
1
+ import ArrowRightIcon from '@mui/icons-material/ArrowRight';
1
2
  import CancelIcon from '@mui/icons-material/Cancel';
2
3
  import ClearAllIcon from '@mui/icons-material/ClearAll';
3
4
  import CloseIcon from '@mui/icons-material/Close';
@@ -8,6 +9,8 @@ import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
8
9
  import EditIcon from '@mui/icons-material/Edit';
9
10
  import ExpandLessIcon from '@mui/icons-material/ExpandLess';
10
11
  import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
12
+ import FilterAltIcon from '@mui/icons-material/FilterAlt';
13
+ import FilterAltOff from '@mui/icons-material/FilterAltOff';
11
14
  import FilterListIcon from '@mui/icons-material/FilterList';
12
15
  import FilterListOffIcon from '@mui/icons-material/FilterListOff';
13
16
  import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
@@ -22,6 +25,7 @@ import ViewColumnIcon from '@mui/icons-material/ViewColumn';
22
25
  import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
23
26
 
24
27
  export interface MRT_Icons {
28
+ ArrowRightIcon: any;
25
29
  CancelIcon: any;
26
30
  ClearAllIcon: any;
27
31
  CloseIcon: any;
@@ -32,6 +36,8 @@ export interface MRT_Icons {
32
36
  EditIcon: any;
33
37
  ExpandLessIcon: any;
34
38
  ExpandMoreIcon: any;
39
+ FilterAltIcon: any;
40
+ FilterAltOff: any;
35
41
  FilterListIcon: any;
36
42
  FilterListOffIcon: any;
37
43
  FullscreenExitIcon: any;
@@ -47,6 +53,7 @@ export interface MRT_Icons {
47
53
  }
48
54
 
49
55
  export const MRT_Default_Icons: MRT_Icons = {
56
+ ArrowRightIcon,
50
57
  CancelIcon,
51
58
  ClearAllIcon,
52
59
  CloseIcon,
@@ -57,6 +64,8 @@ export const MRT_Default_Icons: MRT_Icons = {
57
64
  EditIcon,
58
65
  ExpandLessIcon,
59
66
  ExpandMoreIcon,
67
+ FilterAltIcon,
68
+ FilterAltOff,
60
69
  FilterListIcon,
61
70
  FilterListOffIcon,
62
71
  FullscreenExitIcon,
@@ -10,7 +10,7 @@ import {
10
10
  import { useAsyncDebounce } from 'react-table';
11
11
  import { useMRT } from '../useMRT';
12
12
  import { MRT_HeaderGroup } from '..';
13
- import { MRT_FilterMenu } from '../menus/MRT_FilterMenu';
13
+ import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
14
14
 
15
15
  interface Props {
16
16
  column: MRT_HeaderGroup;
@@ -73,7 +73,7 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
73
73
  }
74
74
 
75
75
  const filterType = tableInstance.state.currentFilterTypes[column.id];
76
- const showFilterChip = ['empty', 'notEmpty'].includes(filterType);
76
+ const filterChipLabel = ['empty', 'notEmpty'].includes(filterType);
77
77
  const filterPlaceholder = localization.filterTextFieldPlaceholder?.replace(
78
78
  '{column}',
79
79
  String(column.Header),
@@ -85,13 +85,15 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
85
85
  fullWidth
86
86
  id={`mrt-${idPrefix}-${column.id}-filter-text-field`}
87
87
  inputProps={{
88
+ disabled: !!filterChipLabel,
88
89
  sx: {
89
90
  textOverflow: 'ellipsis',
91
+ width: filterChipLabel ? 0 : undefined,
90
92
  },
91
93
  title: filterPlaceholder,
92
94
  }}
93
95
  margin="none"
94
- placeholder={showFilterChip ? '' : filterPlaceholder}
96
+ placeholder={filterChipLabel ? '' : filterPlaceholder}
95
97
  onChange={(e: ChangeEvent<HTMLInputElement>) => {
96
98
  setFilterValue(e.target.value);
97
99
  handleChange(e.target.value);
@@ -111,12 +113,12 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
111
113
  <FilterListIcon />
112
114
  </IconButton>
113
115
  </Tooltip>
114
- {showFilterChip && (
116
+ {filterChipLabel && (
115
117
  <Chip onDelete={handleClearFilterChip} label={filterType} />
116
118
  )}
117
119
  </InputAdornment>
118
120
  ),
119
- endAdornment: !showFilterChip && (
121
+ endAdornment: !filterChipLabel && (
120
122
  <InputAdornment position="end">
121
123
  <Tooltip
122
124
  arrow
@@ -140,11 +142,13 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
140
142
  }}
141
143
  {...textFieldProps}
142
144
  sx={{
143
- minWidth: '6rem',
145
+ m: '0 -0.25rem',
146
+ minWidth: !filterChipLabel ? '5rem' : 'auto',
147
+ width: 'calc(100% + 0.5rem)',
144
148
  ...textFieldProps?.sx,
145
149
  }}
146
150
  />
147
- <MRT_FilterMenu
151
+ <MRT_FilterTypeMenu
148
152
  anchorEl={anchorEl}
149
153
  column={column}
150
154
  setAnchorEl={setAnchorEl}
@@ -11,6 +11,7 @@ export interface MRT_Localization {
11
11
  columnShowHideMenuShowAll: string;
12
12
  expandAllButtonTitle: string;
13
13
  expandButtonTitle: string;
14
+ filterApplied: string;
14
15
  filterMenuItemContains: string;
15
16
  filterMenuItemEmpty: string;
16
17
  filterMenuItemEndsWith: string;
@@ -20,6 +21,9 @@ export interface MRT_Localization {
20
21
  filterMenuItemNotEquals: string;
21
22
  filterMenuItemStartsWith: string;
22
23
  filterMenuTitle: string;
24
+ filterTextFieldChangeFilterButtonTitle: string;
25
+ filterTextFieldChipLabelEmpty: string;
26
+ filterTextFieldChipLabelNotEmpty: string;
23
27
  filterTextFieldClearButtonTitle: string;
24
28
  filterTextFieldPlaceholder: string;
25
29
  rowActionButtonCancel: string;
@@ -54,15 +58,19 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
54
58
  columnShowHideMenuShowAll: 'Show all',
55
59
  expandAllButtonTitle: 'Expand all',
56
60
  expandButtonTitle: 'Expand',
61
+ filterApplied: 'Filtering by {column} - ({filterType})',
57
62
  filterMenuItemContains: 'Contains Exact',
58
63
  filterMenuItemEmpty: 'Empty',
59
64
  filterMenuItemEndsWith: 'Ends With',
60
65
  filterMenuItemEquals: 'Equals',
61
- filterMenuItemFuzzy: 'Fuzzy Match',
66
+ filterMenuItemFuzzy: 'Fuzzy Match (Default)',
62
67
  filterMenuItemNotEmpty: 'Not Empty',
63
68
  filterMenuItemNotEquals: 'Not Equals',
64
69
  filterMenuItemStartsWith: 'Starts With',
65
70
  filterMenuTitle: 'Filter Mode',
71
+ filterTextFieldChangeFilterButtonTitle: 'Change Filter Mode',
72
+ filterTextFieldChipLabelEmpty: 'Empty',
73
+ filterTextFieldChipLabelNotEmpty: 'Not Empty',
66
74
  filterTextFieldClearButtonTitle: 'Clear filter',
67
75
  filterTextFieldPlaceholder: 'Filter by {column}',
68
76
  rowActionButtonCancel: 'Cancel',
@@ -76,9 +84,9 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
76
84
  selectCheckboxTitle: 'Toggle select row',
77
85
  showHideColumnsButtonTitle: 'Show/Hide columns',
78
86
  toggleDensePaddingSwitchTitle: 'Toggle dense padding',
79
- toggleFilterButtonTitle: 'Toggle filters',
87
+ toggleFilterButtonTitle: 'Show/Hide filters',
80
88
  toggleFullScreenButtonTitle: 'Toggle full screen',
81
- toggleSearchButtonTitle: 'Toggle search',
89
+ toggleSearchButtonTitle: 'Show/Hide search',
82
90
  toolbarAlertGroupedByMessage: 'Grouped by ',
83
91
  toolbarAlertGroupedThenByMessage: ', then by ',
84
92
  toolbarAlertSelectionMessage: '{selectedCount} of {rowCount} row(s) selected',
@@ -1,17 +1,19 @@
1
1
  import React, { FC, useState } from 'react';
2
2
  import {
3
- Divider,
4
3
  IconButton,
5
4
  ListItemIcon,
6
5
  ListItemText,
7
6
  Menu,
8
7
  MenuItem,
9
- MenuList,
10
8
  } from '@mui/material';
11
9
  import { useMRT } from '../useMRT';
12
10
  import { MRT_HeaderGroup } from '..';
13
- import { MRT_FilterMenu } from './MRT_FilterMenu';
14
- import ArrowRightIcon from '@mui/icons-material/ArrowRight';
11
+ import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
12
+
13
+ export const commonMenuItemStyles = {
14
+ py: '0 !important',
15
+ my: '0 !important',
16
+ };
15
17
 
16
18
  interface Props {
17
19
  anchorEl: HTMLElement | null;
@@ -30,6 +32,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
30
32
  disableSortBy,
31
33
  enableColumnGrouping,
32
34
  icons: {
35
+ ArrowRightIcon,
33
36
  ClearAllIcon,
34
37
  DynamicFeedIcon,
35
38
  FilterListIcon,
@@ -39,6 +42,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
39
42
  idPrefix,
40
43
  localization,
41
44
  setShowFilters,
45
+ tableInstance,
42
46
  } = useMRT();
43
47
 
44
48
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
@@ -95,109 +99,129 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
95
99
  anchorEl={anchorEl}
96
100
  open={!!anchorEl}
97
101
  onClose={() => setAnchorEl(null)}
102
+ MenuListProps={{
103
+ dense: tableInstance.state.densePadding,
104
+ disablePadding: true,
105
+ }}
98
106
  >
99
- <MenuList>
100
- {!disableSortBy &&
101
- column.canSort && [
102
- <MenuItem
103
- key={1}
104
- disabled={!column.isSorted}
105
- onClick={handleClearSort}
106
- >
107
- <ListItemIcon>
108
- <ClearAllIcon />
109
- </ListItemIcon>
110
- <ListItemText>
111
- {localization.columnActionMenuItemClearSort}
112
- </ListItemText>
113
- </MenuItem>,
114
- <MenuItem
115
- key={2}
116
- disabled={column.isSorted && !column.isSortedDesc}
117
- onClick={handleSortAsc}
118
- >
119
- <ListItemIcon>
120
- <SortIcon />
121
- </ListItemIcon>
122
- <ListItemText>
123
- {localization.columnActionMenuItemSortAsc?.replace(
124
- '{column}',
125
- String(column.Header),
126
- )}
127
- </ListItemText>
128
- </MenuItem>,
129
- <MenuItem
130
- key={3}
131
- disabled={column.isSorted && column.isSortedDesc}
132
- onClick={handleSortDesc}
133
- >
134
- <ListItemIcon>
135
- <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
136
- </ListItemIcon>
137
- <ListItemText>
138
- {localization.columnActionMenuItemSortDesc?.replace(
139
- '{column}',
140
- String(column.Header),
141
- )}
142
- </ListItemText>
143
- </MenuItem>,
144
- ]}
145
- {!disableFilters &&
146
- column.canFilter && [
147
- <Divider key={0} />,
148
- <MenuItem key={1} onClick={handleFilterByColumn}>
149
- <ListItemIcon>
150
- <FilterListIcon />
151
- </ListItemIcon>
152
- <ListItemText>
153
- {localization.filterTextFieldPlaceholder?.replace(
154
- '{column}',
155
- String(column.Header),
156
- )}
157
- </ListItemText>
158
- <IconButton size="small" onMouseEnter={handleOpenFilterModeMenu}>
159
- <ArrowRightIcon />
160
- </IconButton>
161
- </MenuItem>,
162
- <MRT_FilterMenu
163
- anchorEl={filterMenuAnchorEl}
164
- column={column}
165
- key={2}
166
- setAnchorEl={setFilterMenuAnchorEl}
167
- onSelect={handleFilterByColumn}
168
- />,
169
- ]}
170
- {enableColumnGrouping &&
171
- column.canGroupBy && [
172
- <Divider key={1} />,
173
- <MenuItem key={2} onClick={handleGroupByColumn}>
174
- <ListItemIcon>
175
- <DynamicFeedIcon />
176
- </ListItemIcon>
177
- <ListItemText>
178
- {localization[
179
- column.isGrouped
180
- ? 'columnActionMenuItemUnGroupBy'
181
- : 'columnActionMenuItemGroupBy'
182
- ]?.replace('{column}', String(column.Header))}
183
- </ListItemText>
184
- </MenuItem>,
185
- ]}
186
- {!disableColumnHiding && [
187
- <Divider key={0} />,
188
- <MenuItem key={1} onClick={handleHideColumn}>
107
+ {!disableSortBy &&
108
+ column.canSort && [
109
+ <MenuItem
110
+ key={1}
111
+ disabled={!column.isSorted}
112
+ onClick={handleClearSort}
113
+ sx={commonMenuItemStyles}
114
+ >
115
+ <ListItemIcon>
116
+ <ClearAllIcon />
117
+ </ListItemIcon>
118
+ <ListItemText sx={commonMenuItemStyles}>
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 sx={commonMenuItemStyles}>
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}
145
+ sx={commonMenuItemStyles}
146
+ >
189
147
  <ListItemIcon>
190
- <VisibilityOffIcon />
148
+ <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
191
149
  </ListItemIcon>
192
- <ListItemText>
193
- {localization.columnActionMenuItemHideColumn?.replace(
150
+ <ListItemText sx={commonMenuItemStyles}>
151
+ {localization.columnActionMenuItemSortDesc?.replace(
194
152
  '{column}',
195
153
  String(column.Header),
196
154
  )}
197
155
  </ListItemText>
198
156
  </MenuItem>,
199
157
  ]}
200
- </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 sx={commonMenuItemStyles}>
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 sx={commonMenuItemStyles}>
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 sx={commonMenuItemStyles}>
218
+ {localization.columnActionMenuItemHideColumn?.replace(
219
+ '{column}',
220
+ String(column.Header),
221
+ )}
222
+ </ListItemText>
223
+ </MenuItem>,
224
+ ]}
201
225
  </Menu>
202
226
  );
203
227
  };