material-react-table 0.14.1 → 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.1",
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.",
@@ -5,39 +5,39 @@ import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
5
5
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
6
6
  import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
7
7
  import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
8
- import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
8
+ import { MRT_TableHeadCellColumnActionsButton } from './MRT_TableHeadCellColumnActionsButton';
9
9
  import type { MRT_Header, MRT_TableInstance } from '..';
10
10
 
11
11
  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'
@@ -162,11 +164,12 @@ export const MRT_TableHeadCell: FC<Props> = ({
162
164
  justifyContent:
163
165
  columnDefType === 'group' ? 'center' : 'space-between',
164
166
  opacity: isDragging ? 0.5 : 1,
167
+ position: 'relative',
165
168
  width: '100%',
166
169
  }}
167
170
  >
168
171
  <Box
169
- onClick={() => column.toggleSorting()}
172
+ onClick={column.getToggleSortingHandler()}
170
173
  sx={{
171
174
  alignItems: 'center',
172
175
  cursor:
@@ -183,14 +186,12 @@ export const MRT_TableHeadCell: FC<Props> = ({
183
186
  {columnDefType === 'data' && column.getCanSort() && (
184
187
  <MRT_TableHeadCellSortLabel header={header} instance={instance} />
185
188
  )}
186
- {columnDefType === 'data' &&
187
- enableColumnFilters &&
188
- column.getCanFilter() && (
189
- <MRT_TableHeadCellFilterLabel
190
- header={header}
191
- instance={instance}
192
- />
193
- )}
189
+ {columnDefType === 'data' && column.getCanFilter() && (
190
+ <MRT_TableHeadCellFilterLabel
191
+ header={header}
192
+ instance={instance}
193
+ />
194
+ )}
194
195
  </Box>
195
196
  <Box sx={{ whiteSpace: 'nowrap' }}>
196
197
  {columnDefType === 'data' &&
@@ -205,7 +206,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
205
206
  {(enableColumnActions || columnDef.enableColumnActions) &&
206
207
  columnDef.enableColumnActions !== false &&
207
208
  columnDefType !== 'group' && (
208
- <MRT_ToggleColumnActionMenuButton
209
+ <MRT_TableHeadCellColumnActionsButton
209
210
  header={header}
210
211
  instance={instance}
211
212
  />
@@ -8,7 +8,7 @@ interface Props {
8
8
  instance: MRT_TableInstance;
9
9
  }
10
10
 
11
- export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
11
+ export const MRT_TableHeadCellColumnActionsButton: FC<Props> = ({
12
12
  header,
13
13
  instance,
14
14
  }) => {
@@ -66,7 +66,6 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
66
66
  {...iconButtonProps}
67
67
  sx={{
68
68
  height: '2rem',
69
- mr: '2px',
70
69
  mt: '-0.2rem',
71
70
  opacity: 0.5,
72
71
  transition: 'opacity 0.2s',
@@ -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,72 +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
- }}
76
- >
77
- {showFilters && !column.getFilterValue() ? (
78
- <FilterAltOffIcon />
79
- ) : (
80
- <FilterAltIcon />
81
- )}
82
- </IconButton>
83
- </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>
84
83
  );
85
84
  };
@@ -31,6 +31,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
31
31
  height: showFilters && columnDefType === 'data' ? '4rem' : '2rem',
32
32
  opacity: 0.8,
33
33
  position: 'absolute',
34
+ mr: '-1rem',
34
35
  right: '1px',
35
36
  touchAction: 'none',
36
37
  transition: column.getIsResizing() ? undefined : 'all 0.2s ease-in-out',
@@ -32,6 +32,10 @@ export const MRT_TableHeadCellSortLabel: FC<Props> = ({ header, instance }) => {
32
32
  ? (column.getIsSorted() as 'asc' | 'desc')
33
33
  : undefined
34
34
  }
35
+ sx={{
36
+ width: '2ch',
37
+ transform: 'translateX(-0.5ch)',
38
+ }}
35
39
  />
36
40
  </Tooltip>
37
41
  );
@@ -47,7 +47,9 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
47
47
  ...commonToolbarStyles({ theme }),
48
48
  bottom: isFullScreen ? '0' : undefined,
49
49
  boxShadow: `-3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
50
+ left: 0,
50
51
  position: isFullScreen ? 'fixed' : 'relative',
52
+ right: 0,
51
53
  ...toolbarProps?.sx,
52
54
  } as any)
53
55
  }