material-react-table 0.14.3 → 0.14.4

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.14.3",
2
+ "version": "0.14.4",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -12,32 +12,32 @@ interface Props {
12
12
  dragRef?: Ref<HTMLButtonElement>;
13
13
  dropRef?: Ref<HTMLDivElement>;
14
14
  header: MRT_Header;
15
+ instance: MRT_TableInstance;
15
16
  isDragging?: boolean;
16
17
  previewRef?: Ref<HTMLTableCellElement>;
17
- instance: MRT_TableInstance;
18
18
  }
19
19
 
20
20
  export const MRT_TableHeadCell: FC<Props> = ({
21
21
  dragRef,
22
22
  dropRef,
23
23
  header,
24
+ instance,
24
25
  isDragging,
25
26
  previewRef,
26
- instance,
27
27
  }) => {
28
28
  const {
29
29
  getState,
30
30
  options: {
31
31
  enableColumnActions,
32
- enableColumnFilters,
33
32
  enableColumnOrdering,
34
33
  enableColumnResizing,
35
34
  enableGrouping,
35
+ enableMultiSort,
36
36
  muiTableHeadCellProps,
37
37
  },
38
38
  } = instance;
39
39
 
40
- const { density } = getState();
40
+ const { density, showFilters } = getState();
41
41
 
42
42
  const { column } = header;
43
43
 
@@ -139,7 +139,9 @@ export const MRT_TableHeadCell: FC<Props> = ({
139
139
  right:
140
140
  column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
141
141
  transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
142
- verticalAlign: 'text-top',
142
+ userSelect: enableMultiSort ? 'none' : undefined,
143
+ verticalAlign:
144
+ columnDefType === 'display' && showFilters ? 'center' : 'text-top',
143
145
  zIndex: column.getIsResizing()
144
146
  ? 3
145
147
  : column.getIsPinned() && columnDefType !== 'group'
@@ -167,7 +169,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
167
169
  }}
168
170
  >
169
171
  <Box
170
- onClick={() => column.toggleSorting()}
172
+ onClick={column.getToggleSortingHandler()}
171
173
  sx={{
172
174
  alignItems: 'center',
173
175
  cursor:
@@ -184,14 +186,12 @@ export const MRT_TableHeadCell: FC<Props> = ({
184
186
  {columnDefType === 'data' && column.getCanSort() && (
185
187
  <MRT_TableHeadCellSortLabel header={header} instance={instance} />
186
188
  )}
187
- {columnDefType === 'data' &&
188
- enableColumnFilters &&
189
- column.getCanFilter() && (
190
- <MRT_TableHeadCellFilterLabel
191
- header={header}
192
- instance={instance}
193
- />
194
- )}
189
+ {columnDefType === 'data' && column.getCanFilter() && (
190
+ <MRT_TableHeadCellFilterLabel
191
+ header={header}
192
+ instance={instance}
193
+ />
194
+ )}
195
195
  </Box>
196
196
  <Box sx={{ whiteSpace: 'nowrap' }}>
197
197
  {columnDefType === 'data' &&
@@ -1,5 +1,5 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { IconButton, Tooltip } from '@mui/material';
2
+ import { Grow, IconButton, Tooltip } from '@mui/material';
3
3
  import { MRT_Header, MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
@@ -14,73 +14,71 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({
14
14
  const {
15
15
  getState,
16
16
  options: {
17
- icons: { FilterAltIcon, FilterAltOffIcon },
17
+ icons: { FilterAltIcon },
18
18
  localization,
19
19
  },
20
- setShowFilters,
21
20
  } = instance;
22
21
 
23
- const { showFilters } = getState();
22
+ const { currentFilterFns } = getState();
24
23
 
25
24
  const { column } = header;
26
25
 
27
26
  const { columnDef } = column;
28
27
 
29
- const filterFn = getState()?.currentFilterFns?.[header.id];
28
+ const filterFn = currentFilterFns?.[header.id];
30
29
 
31
- const filterTooltip = !!column.getFilterValue()
32
- ? localization.filteringByColumn
33
- .replace('{column}', String(columnDef.header))
34
- .replace(
35
- '{filterType}',
36
- filterFn instanceof Function
37
- ? ''
38
- : // @ts-ignore
39
- localization[
40
- `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
41
- ],
42
- )
43
- .replace(
44
- '{filterValue}',
45
- `"${
46
- Array.isArray(column.getFilterValue())
47
- ? (column.getFilterValue() as [string, string]).join(
48
- `" ${localization.and} "`,
49
- )
50
- : (column.getFilterValue() as string)
51
- }"`,
52
- )
53
- .replace('" "', '')
54
- : localization.showHideFilters;
30
+ const filterTooltip = localization.filteringByColumn
31
+ .replace('{column}', String(columnDef.header))
32
+ .replace(
33
+ '{filterType}',
34
+ filterFn instanceof Function
35
+ ? ''
36
+ : // @ts-ignore
37
+ localization[
38
+ `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
39
+ ],
40
+ )
41
+ .replace(
42
+ '{filterValue}',
43
+ `"${
44
+ Array.isArray(column.getFilterValue())
45
+ ? (column.getFilterValue() as [string, string]).join(
46
+ `" ${localization.and} "`,
47
+ )
48
+ : (column.getFilterValue() as string)
49
+ }"`,
50
+ )
51
+ .replace('" "', '');
55
52
 
56
53
  return (
57
- <Tooltip arrow placement="top" title={filterTooltip}>
58
- <IconButton
59
- disableRipple
60
- onClick={(event: MouseEvent<HTMLButtonElement>) => {
61
- event.stopPropagation();
62
- setShowFilters(!showFilters);
63
- }}
64
- size="small"
65
- sx={{
66
- m: 0,
67
- opacity: !!column.getFilterValue() || showFilters ? 0.8 : 0,
68
- p: '2px',
69
- transition: 'all 0.2s ease-in-out',
70
- transform: 'scale(0.66)',
71
- '&:hover': {
72
- backgroundColor: 'transparent',
73
- opacity: 0.8,
74
- },
75
- width: '1.5ch',
76
- }}
77
- >
78
- {showFilters && !column.getFilterValue() ? (
79
- <FilterAltOffIcon />
80
- ) : (
81
- <FilterAltIcon />
82
- )}
83
- </IconButton>
84
- </Tooltip>
54
+ <Grow
55
+ unmountOnExit
56
+ in={
57
+ (!!column.getFilterValue() && filterFn !== 'between') ||
58
+ (filterFn === 'between' && // @ts-ignore
59
+ (!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
60
+ }
61
+ >
62
+ <span>
63
+ <Tooltip arrow placement="top" title={filterTooltip}>
64
+ <IconButton
65
+ disableRipple
66
+ onClick={(event: MouseEvent<HTMLButtonElement>) => {
67
+ event.stopPropagation();
68
+ }}
69
+ size="small"
70
+ sx={{
71
+ m: 0,
72
+ opacity: 0.8,
73
+ p: '2px',
74
+ transform: 'scale(0.66)',
75
+ width: '1.5ch',
76
+ }}
77
+ >
78
+ <FilterAltIcon />
79
+ </IconButton>
80
+ </Tooltip>
81
+ </span>
82
+ </Grow>
85
83
  );
86
84
  };