material-react-table 1.5.11 → 1.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.
@@ -1,5 +1,10 @@
1
- import React, { FC } from 'react';
2
- import { MRT_Cell, MRT_TableInstance } from '..';
1
+ import React, { FC, ReactNode } from 'react';
2
+ import Box from '@mui/material/Box';
3
+ import { darken, lighten } from '@mui/material/styles';
4
+ import highlightWords from 'highlight-words';
5
+ import type { MRT_Cell, MRT_TableInstance } from '..';
6
+
7
+ const allowedTypes = ['string', 'number'];
3
8
 
4
9
  interface Props {
5
10
  cell: MRT_Cell;
@@ -7,28 +12,93 @@ interface Props {
7
12
  }
8
13
 
9
14
  export const MRT_TableBodyCellValue: FC<Props> = ({ cell, table }) => {
15
+ const {
16
+ getState,
17
+ options: { enableFilterMatchHighlighting },
18
+ } = table;
10
19
  const { column, row } = cell;
11
20
  const { columnDef } = column;
21
+ const { globalFilter } = getState();
22
+ const filterValue = column.getFilterValue();
23
+
24
+ let renderedCellValue =
25
+ cell.getIsAggregated() && columnDef.AggregatedCell
26
+ ? columnDef.AggregatedCell({
27
+ cell,
28
+ column,
29
+ row,
30
+ table,
31
+ })
32
+ : row.getIsGrouped() && !cell.getIsGrouped()
33
+ ? null
34
+ : cell.getIsGrouped() && columnDef.GroupedCell
35
+ ? columnDef.GroupedCell({
36
+ cell,
37
+ column,
38
+ row,
39
+ table,
40
+ })
41
+ : undefined;
42
+
43
+ const isGroupedValue = renderedCellValue !== undefined;
44
+
45
+ if (!isGroupedValue) {
46
+ renderedCellValue = cell.renderValue() as number | string | ReactNode;
47
+ }
48
+
49
+ if (
50
+ enableFilterMatchHighlighting &&
51
+ renderedCellValue &&
52
+ allowedTypes.includes(typeof renderedCellValue) &&
53
+ ((filterValue &&
54
+ allowedTypes.includes(typeof filterValue) &&
55
+ columnDef.filterVariant === 'text') ||
56
+ (globalFilter && allowedTypes.includes(typeof globalFilter)))
57
+ ) {
58
+ const chunks = highlightWords?.({
59
+ text: renderedCellValue?.toString() as string,
60
+ query: (column.getFilterValue() ?? globalFilter ?? '').toString(),
61
+ });
62
+ if (chunks?.length > 1 || chunks?.[0]?.match) {
63
+ renderedCellValue = (
64
+ <span aria-label={renderedCellValue as string} role="note">
65
+ {chunks?.map(({ key, match, text }) => (
66
+ <Box
67
+ aria-hidden="true"
68
+ component="span"
69
+ key={key}
70
+ sx={
71
+ match
72
+ ? {
73
+ backgroundColor: (theme) =>
74
+ theme.palette.mode === 'dark'
75
+ ? darken(theme.palette.warning.dark, 0.25)
76
+ : lighten(theme.palette.warning.light, 0.5),
77
+ borderRadius: '2px',
78
+ color: (theme) =>
79
+ theme.palette.mode === 'dark' ? 'white' : 'black',
80
+ padding: '2px 1px',
81
+ }
82
+ : undefined
83
+ }
84
+ >
85
+ {text}
86
+ </Box>
87
+ )) ?? renderedCellValue}
88
+ </span>
89
+ );
90
+ }
91
+ }
92
+
93
+ if (columnDef.Cell && !isGroupedValue) {
94
+ renderedCellValue = columnDef.Cell({
95
+ cell,
96
+ renderedCellValue,
97
+ column,
98
+ row,
99
+ table,
100
+ });
101
+ }
12
102
 
13
- return (
14
- <>
15
- {cell.getIsAggregated() && columnDef.AggregatedCell
16
- ? columnDef.AggregatedCell({
17
- cell,
18
- column,
19
- row,
20
- table,
21
- })
22
- : row.getIsGrouped() && !cell.getIsGrouped()
23
- ? null
24
- : cell.getIsGrouped() && columnDef.GroupedCell
25
- ? columnDef.GroupedCell({
26
- cell,
27
- column,
28
- row,
29
- table,
30
- })
31
- : columnDef?.Cell?.({ cell, column, row, table }) ?? cell.renderValue()}
32
- </>
33
- );
103
+ return <>{renderedCellValue}</>;
34
104
  };
@@ -35,6 +35,7 @@ export const MRT_ToggleGlobalFilterButton = <
35
35
  return (
36
36
  <Tooltip arrow title={rest?.title ?? localization.showHideSearch}>
37
37
  <IconButton
38
+ aria-label={rest?.title ?? localization.showHideSearch}
38
39
  disabled={!!globalFilter}
39
40
  onClick={handleToggleSearch}
40
41
  {...rest}
@@ -300,12 +300,13 @@ export const getCommonCellStyles = ({
300
300
  });
301
301
 
302
302
  export const MRT_DefaultColumn = {
303
+ filterVariant: 'text',
303
304
  minSize: 40,
304
305
  maxSize: 1000,
305
306
  size: 180,
306
- };
307
+ } as const;
307
308
 
308
- export const MRT_DefaultDisplayColumn: Partial<MRT_ColumnDef> = {
309
+ export const MRT_DefaultDisplayColumn = {
309
310
  columnDefType: 'display',
310
311
  enableClickToCopy: false,
311
312
  enableColumnActions: false,
@@ -318,4 +319,4 @@ export const MRT_DefaultDisplayColumn: Partial<MRT_ColumnDef> = {
318
319
  enableHiding: false,
319
320
  enableResizing: false,
320
321
  enableSorting: false,
321
- };
322
+ } as const;
package/src/index.tsx CHANGED
@@ -6,6 +6,7 @@ import type { MRT_Icons } from './icons';
6
6
  export type { MRT_Icons };
7
7
 
8
8
  import { MRT_CopyButton } from './buttons/MRT_CopyButton';
9
+ import { MRT_EditActionButtons } from './buttons/MRT_EditActionButtons';
9
10
  import { MRT_FilterOptionMenu } from './menus/MRT_FilterOptionMenu';
10
11
  import { MRT_FullScreenToggleButton } from './buttons/MRT_FullScreenToggleButton';
11
12
  import { MRT_GlobalFilterTextField } from './inputs/MRT_GlobalFilterTextField';
@@ -23,6 +24,7 @@ import { MRT_BottomToolbar } from './toolbar/MRT_BottomToolbar';
23
24
 
24
25
  export {
25
26
  MRT_CopyButton,
27
+ MRT_EditActionButtons,
26
28
  MRT_FilterOptionMenu,
27
29
  MRT_FullScreenToggleButton,
28
30
  MRT_GlobalFilterTextField,
@@ -46,17 +46,19 @@ export const MRT_ToolbarDropZone = <TData extends Record<string, any> = {}>({
46
46
  theme.palette.info.main,
47
47
  hoveredColumn?.id === 'drop-zone' ? 0.2 : 0.1,
48
48
  ),
49
+ backdropFilter: 'blur(4px)',
50
+ boxSizing: 'border-box',
49
51
  border: `dashed ${theme.palette.info.main} 2px`,
50
52
  display: 'flex',
51
53
  justifyContent: 'center',
52
- height: 'calc(100% - 4px)',
54
+ height: '100%',
53
55
  position: 'absolute',
54
- width: 'calc(100% - 4px)',
55
- zIndex: 2,
56
+ width: '100%',
57
+ zIndex: 4,
56
58
  })}
57
59
  onDragEnter={handleDragEnter}
58
60
  >
59
- <Typography>
61
+ <Typography fontStyle="italic">
60
62
  {localization.dropToGroupBy.replace(
61
63
  '{column}',
62
64
  draggingColumn?.columnDef?.header ?? '',
@@ -5,11 +5,11 @@ import useMediaQuery from '@mui/material/useMediaQuery';
5
5
  import { lighten } from '@mui/material/styles';
6
6
  import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
7
7
  import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
8
- import type { MRT_TableInstance } from '..';
9
8
  import { MRT_TablePagination } from './MRT_TablePagination';
10
9
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
11
10
  import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
12
11
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
12
+ import type { MRT_TableInstance } from '..';
13
13
  import type { Theme } from '@mui/material/styles';
14
14
 
15
15
  export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
@@ -102,6 +102,7 @@ export const MRT_TopToolbar = <TData extends Record<string, any> = {}>({
102
102
  right: 0,
103
103
  top: 0,
104
104
  width: '100%',
105
+ zIndex: 2,
105
106
  }}
106
107
  >
107
108
  {enableGlobalFilter && positionGlobalFilter === 'left' && (