material-react-table 0.8.0 → 0.8.3

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 (36) hide show
  1. package/README.md +1 -1
  2. package/dist/MaterialReactTable.d.ts +3 -1
  3. package/dist/head/MRT_DraggableTableHeadCell.d.ts +8 -0
  4. package/dist/head/MRT_TableHeadCell.d.ts +5 -1
  5. package/dist/head/MRT_TableHeadCellFilterContainer.d.ts +8 -0
  6. package/dist/head/MRT_TableHeadCellFilterLabel.d.ts +8 -0
  7. package/dist/head/MRT_TableHeadCellGrabHandle.d.ts +9 -0
  8. package/dist/head/MRT_TableHeadCellResizeHandle.d.ts +8 -0
  9. package/dist/head/MRT_TableHeadCellSortLabel.d.ts +8 -0
  10. package/dist/icons.d.ts +1 -0
  11. package/dist/inputs/MRT_FilterRangeFields.d.ts +2 -2
  12. package/dist/localization.d.ts +1 -0
  13. package/dist/material-react-table.cjs.development.js +306 -111
  14. package/dist/material-react-table.cjs.development.js.map +1 -1
  15. package/dist/material-react-table.cjs.production.min.js +1 -1
  16. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  17. package/dist/material-react-table.esm.js +308 -113
  18. package/dist/material-react-table.esm.js.map +1 -1
  19. package/dist/table/MRT_TableContainer.d.ts +1 -1
  20. package/dist/utils.d.ts +1 -1
  21. package/package.json +10 -8
  22. package/src/MaterialReactTable.tsx +6 -0
  23. package/src/head/MRT_DraggableTableHeadCell.tsx +52 -0
  24. package/src/head/MRT_TableHeadCell.tsx +61 -153
  25. package/src/head/MRT_TableHeadCellFilterContainer.tsx +32 -0
  26. package/src/head/MRT_TableHeadCellFilterLabel.tsx +82 -0
  27. package/src/head/MRT_TableHeadCellGrabHandle.tsx +52 -0
  28. package/src/head/MRT_TableHeadCellResizeHandle.tsx +52 -0
  29. package/src/head/MRT_TableHeadCellSortLabel.tsx +45 -0
  30. package/src/head/MRT_TableHeadRow.tsx +17 -8
  31. package/src/icons.ts +3 -0
  32. package/src/inputs/MRT_FilterRangeFields.tsx +1 -3
  33. package/src/localization.ts +2 -0
  34. package/src/table/MRT_TableContainer.tsx +1 -1
  35. package/src/table/MRT_TablePaper.tsx +26 -22
  36. package/src/table/MRT_TableRoot.tsx +8 -0
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { MRT_TableInstance } from '..';
2
+ import type { MRT_TableInstance } from '..';
3
3
  interface Props {
4
4
  tableInstance: MRT_TableInstance;
5
5
  }
package/dist/utils.d.ts CHANGED
@@ -7,6 +7,6 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
7
7
  export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
8
8
  [key: string]: MRT_FilterFn<{}>;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
10
+ export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.8.0",
2
+ "version": "0.8.3",
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.",
@@ -7,7 +7,7 @@
7
7
  "keywords": [
8
8
  "react-table",
9
9
  "material-ui",
10
- "material-table",
10
+ "material-table",
11
11
  "tanstack table"
12
12
  ],
13
13
  "repository": {
@@ -19,6 +19,7 @@
19
19
  "url": "https://github.com/KevinVandy/material-react-table/issues"
20
20
  },
21
21
  "main": "dist/index.js",
22
+ "module": "dist/material-react-table.esm.js",
22
23
  "typings": "dist/index.d.ts",
23
24
  "files": [
24
25
  "dist",
@@ -44,15 +45,14 @@
44
45
  "pre-commit": "tsdx lint && format"
45
46
  }
46
47
  },
47
- "module": "dist/material-react-table.esm.js",
48
48
  "size-limit": [
49
49
  {
50
50
  "path": "dist/material-react-table.cjs.production.min.js",
51
- "limit": "40 KB"
51
+ "limit": "60 KB"
52
52
  },
53
53
  {
54
54
  "path": "dist/material-react-table.esm.js",
55
- "limit": "40 KB"
55
+ "limit": "60 KB"
56
56
  }
57
57
  ],
58
58
  "devDependencies": {
@@ -60,8 +60,8 @@
60
60
  "@emotion/react": "^11.9.0",
61
61
  "@emotion/styled": "^11.8.1",
62
62
  "@faker-js/faker": "^6.3.1",
63
- "@mui/icons-material": "^5.8.0",
64
- "@mui/material": "^5.8.1",
63
+ "@mui/icons-material": "^5.8.2",
64
+ "@mui/material": "^5.8.2",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
66
66
  "@storybook/addon-a11y": "^6.5.5",
67
67
  "@storybook/addon-actions": "^6.5.5",
@@ -95,6 +95,8 @@
95
95
  },
96
96
  "dependencies": {
97
97
  "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
98
- "@tanstack/react-table": "^8.0.0-alpha.89"
98
+ "@tanstack/react-table": "^8.0.0-alpha.89",
99
+ "react-dnd": "^15.1.2",
100
+ "react-dnd-html5-backend": "^15.1.2"
99
101
  }
100
102
  }
@@ -178,6 +178,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
178
178
  columns?: MRT_ColumnDef<D>[];
179
179
  enableClickToCopy?: boolean;
180
180
  enableColumnActions?: boolean;
181
+ enableColumnOrdering?: boolean;
181
182
  enableEditing?: boolean;
182
183
  enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
183
184
  filterFn?: MRT_FilterFn;
@@ -332,6 +333,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
332
333
  editingMode?: 'table' | 'row' | 'cell';
333
334
  enableClickToCopy?: boolean;
334
335
  enableColumnActions?: boolean;
336
+ enableColumnOrdering?: boolean;
335
337
  enableDensePaddingToggle?: boolean;
336
338
  enableEditing?: boolean;
337
339
  enableExpandAll?: boolean;
@@ -763,12 +765,14 @@ export default <D extends Record<string, any> = {}>({
763
765
  editingMode = 'row',
764
766
  enableColumnActions = true,
765
767
  enableColumnFilters = true,
768
+ enableColumnOrdering = false,
766
769
  enableColumnResizing = false,
767
770
  enableDensePaddingToggle = true,
768
771
  enableExpandAll = true,
769
772
  enableFilters = true,
770
773
  enableFullScreenToggle = true,
771
774
  enableGlobalFilter = true,
775
+ enableGrouping = false,
772
776
  enableHiding = true,
773
777
  enableMultiRowSelection = true,
774
778
  enablePagination = true,
@@ -797,12 +801,14 @@ export default <D extends Record<string, any> = {}>({
797
801
  editingMode={editingMode}
798
802
  enableColumnActions={enableColumnActions}
799
803
  enableColumnFilters={enableColumnFilters}
804
+ enableColumnOrdering={enableColumnOrdering}
800
805
  enableColumnResizing={enableColumnResizing}
801
806
  enableDensePaddingToggle={enableDensePaddingToggle}
802
807
  enableExpandAll={enableExpandAll}
803
808
  enableFilters={enableFilters}
804
809
  enableFullScreenToggle={enableFullScreenToggle}
805
810
  enableGlobalFilter={enableGlobalFilter}
811
+ enableGrouping={enableGrouping}
806
812
  enableHiding={enableHiding}
807
813
  enableMultiRowSelection={enableMultiRowSelection}
808
814
  enablePagination={enablePagination}
@@ -0,0 +1,52 @@
1
+ import React, { FC } from 'react';
2
+ import { useDrag, useDrop } from 'react-dnd';
3
+ import { MRT_TableHeadCell } from './MRT_TableHeadCell';
4
+ import type { MRT_Header, MRT_TableInstance } from '..';
5
+
6
+ interface Props {
7
+ header: MRT_Header;
8
+ tableInstance: MRT_TableInstance;
9
+ }
10
+
11
+ export const MRT_DraggableTableHeadCell: FC<Props> = ({
12
+ header,
13
+ tableInstance,
14
+ }) => {
15
+ const {
16
+ getState,
17
+ options: {},
18
+ setColumnOrder,
19
+ } = tableInstance;
20
+
21
+ const { columnOrder } = getState();
22
+
23
+ const reorder = (item: MRT_Header, newIndex: number) => {
24
+ const { index: currentIndex } = item;
25
+ columnOrder.splice(newIndex, 0, columnOrder.splice(currentIndex, 1)[0]);
26
+ setColumnOrder([...columnOrder]);
27
+ };
28
+
29
+ const [, drop] = useDrop({
30
+ accept: 'header',
31
+ drop: (item: MRT_Header) => reorder(item, header.index),
32
+ });
33
+
34
+ const [{ isDragging }, drag, preview] = useDrag({
35
+ collect: (monitor) => ({
36
+ isDragging: monitor.isDragging(),
37
+ }),
38
+ item: () => header,
39
+ type: 'header',
40
+ });
41
+
42
+ return (
43
+ <MRT_TableHeadCell
44
+ dragRef={drag}
45
+ dropRef={drop}
46
+ header={header}
47
+ isDragging={isDragging}
48
+ previewRef={preview}
49
+ tableInstance={tableInstance}
50
+ />
51
+ );
52
+ };
@@ -1,42 +1,43 @@
1
- import React, { FC, MouseEvent, ReactNode } from 'react';
2
- import {
3
- Box,
4
- Collapse,
5
- Divider,
6
- IconButton,
7
- TableCell,
8
- TableSortLabel,
9
- Theme,
10
- Tooltip,
11
- alpha,
12
- lighten,
13
- } from '@mui/material';
14
- import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
1
+ import React, { FC, ReactNode, Ref } from 'react';
2
+ import { Box, TableCell, Theme, alpha, lighten } from '@mui/material';
3
+ import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
4
+ import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
5
+ import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
6
+ import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
7
+ import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
15
8
  import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
16
9
  import type { MRT_Header, MRT_TableInstance } from '..';
17
- import MRT_FilterRangeFields from '../inputs/MRT_FilterRangeFields';
18
- import { MRT_FILTER_OPTION } from '../enums';
19
10
 
20
11
  interface Props {
12
+ dragRef?: Ref<HTMLButtonElement>;
13
+ dropRef?: Ref<HTMLDivElement>;
21
14
  header: MRT_Header;
15
+ isDragging?: boolean;
16
+ previewRef?: Ref<HTMLTableCellElement>;
22
17
  tableInstance: MRT_TableInstance;
23
18
  }
24
19
 
25
- export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
20
+ export const MRT_TableHeadCell: FC<Props> = ({
21
+ dragRef,
22
+ dropRef,
23
+ header,
24
+ isDragging,
25
+ previewRef,
26
+ tableInstance,
27
+ }) => {
26
28
  const {
27
29
  getState,
28
30
  options: {
29
31
  enableColumnActions,
30
32
  enableColumnFilters,
33
+ enableColumnOrdering,
31
34
  enableColumnResizing,
32
- icons: { FilterAltIcon, FilterAltOff },
33
- localization,
35
+ enableGrouping,
34
36
  muiTableHeadCellProps,
35
37
  },
36
- setShowFilters,
37
38
  } = tableInstance;
38
39
 
39
- const { currentFilterFns, isDensePadding, showFilters } = getState();
40
+ const { isDensePadding } = getState();
40
41
 
41
42
  const { column } = header;
42
43
 
@@ -55,45 +56,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
55
56
  ...mcTableHeadCellProps,
56
57
  };
57
58
 
58
- const sortTooltip = !!column.getIsSorted()
59
- ? column.getIsSorted() === 'desc'
60
- ? localization.sortedByColumnDesc.replace(
61
- '{column}',
62
- column.columnDef.header,
63
- )
64
- : localization.sortedByColumnAsc.replace(
65
- '{column}',
66
- column.columnDef.header,
67
- )
68
- : localization.unsorted;
69
-
70
- const filterFn = getState()?.currentFilterFns?.[header.id];
71
-
72
- const filterTooltip = !!column.getFilterValue()
73
- ? localization.filteringByColumn
74
- .replace('{column}', String(column.columnDef.header))
75
- .replace(
76
- '{filterType}',
77
- filterFn instanceof Function
78
- ? ''
79
- : // @ts-ignore
80
- localization[
81
- `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
82
- ],
83
- )
84
- .replace(
85
- '{filterValue}',
86
- `"${
87
- Array.isArray(column.getFilterValue())
88
- ? (column.getFilterValue() as [string, string]).join(
89
- `" ${localization.and} "`,
90
- )
91
- : (column.getFilterValue() as string)
92
- }"`,
93
- )
94
- .replace('" "', '')
95
- : localization.showHideFilters;
96
-
97
59
  const headerElement = (column.columnDef?.Header?.({
98
60
  header,
99
61
  tableInstance,
@@ -124,6 +86,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
124
86
  align={column.columnDefType === 'group' ? 'center' : 'left'}
125
87
  colSpan={header.colSpan}
126
88
  {...tableCellProps}
89
+ ref={column.columnDefType === 'data' ? dropRef : undefined}
127
90
  sx={(theme: Theme) => ({
128
91
  backgroundColor:
129
92
  column.getIsPinned() && column.columnDefType !== 'group'
@@ -141,7 +104,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
141
104
  column.getIsPinned() === 'left'
142
105
  ? `${column.getStart('left')}px`
143
106
  : undefined,
144
-
145
107
  overflow: 'visible',
146
108
  p: isDensePadding
147
109
  ? column.columnDefType === 'display'
@@ -182,11 +144,13 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
182
144
  headerElement
183
145
  ) : (
184
146
  <Box
147
+ ref={previewRef}
185
148
  sx={{
186
149
  alignItems: 'flex-start',
187
150
  display: 'flex',
188
151
  justifyContent:
189
152
  column.columnDefType === 'group' ? 'center' : 'space-between',
153
+ opacity: isDragging ? 0.5 : 1,
190
154
  width: '100%',
191
155
  }}
192
156
  >
@@ -208,109 +172,53 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
208
172
  >
209
173
  {headerElement}
210
174
  {column.columnDefType === 'data' && column.getCanSort() && (
211
- <Tooltip arrow placement="top" title={sortTooltip}>
212
- <TableSortLabel
213
- aria-label={sortTooltip}
214
- active={!!column.getIsSorted()}
215
- direction={
216
- column.getIsSorted()
217
- ? (column.getIsSorted() as 'asc' | 'desc')
218
- : undefined
219
- }
220
- />
221
- </Tooltip>
175
+ <MRT_TableHeadCellSortLabel
176
+ header={header}
177
+ tableInstance={tableInstance}
178
+ />
222
179
  )}
223
180
  {column.columnDefType === 'data' &&
224
181
  enableColumnFilters &&
225
- !!column.getCanFilter() && (
226
- <Tooltip arrow placement="top" title={filterTooltip}>
227
- <IconButton
228
- disableRipple
229
- onClick={(event: MouseEvent<HTMLButtonElement>) => {
230
- event.stopPropagation();
231
- setShowFilters(!showFilters);
232
- }}
233
- size="small"
234
- sx={{
235
- m: 0,
236
- opacity: !!column.getFilterValue() ? 0.8 : 0,
237
- p: '2px',
238
- transition: 'all 0.2s ease-in-out',
239
- '&:hover': {
240
- backgroundColor: 'transparent',
241
- opacity: 0.8,
242
- },
243
- }}
244
- >
245
- {showFilters && !column.getFilterValue() ? (
246
- <FilterAltOff />
247
- ) : (
248
- <FilterAltIcon />
249
- )}
250
- </IconButton>
251
- </Tooltip>
182
+ column.getCanFilter() && (
183
+ <MRT_TableHeadCellFilterLabel
184
+ header={header}
185
+ tableInstance={tableInstance}
186
+ />
187
+ )}
188
+ </Box>
189
+ <Box sx={{ whiteSpace: 'nowrap' }}>
190
+ {column.columnDefType === 'data' &&
191
+ ((enableColumnOrdering &&
192
+ column.enableColumnOrdering !== false) ||
193
+ (enableGrouping && column.enableGrouping !== false)) && (
194
+ <MRT_TableHeadCellGrabHandle
195
+ header={header}
196
+ ref={dragRef as Ref<HTMLButtonElement>}
197
+ tableInstance={tableInstance}
198
+ />
199
+ )}
200
+ {(enableColumnActions || column.enableColumnActions) &&
201
+ column.enableColumnActions !== false &&
202
+ column.columnDefType !== 'group' && (
203
+ <MRT_ToggleColumnActionMenuButton
204
+ header={header}
205
+ tableInstance={tableInstance}
206
+ />
252
207
  )}
253
208
  </Box>
254
- {(enableColumnActions || column.enableColumnActions) &&
255
- column.enableColumnActions !== false &&
256
- column.columnDefType !== 'group' && (
257
- <MRT_ToggleColumnActionMenuButton
258
- header={header}
259
- tableInstance={tableInstance}
260
- />
261
- )}
262
209
  {column.getCanResize() && (
263
- <Divider
264
- flexItem
265
- orientation="vertical"
266
- onDoubleClick={() => column.resetSize()}
267
- sx={(theme: Theme) => ({
268
- borderRadius: '2px',
269
- borderRightWidth: '2px',
270
- cursor: 'col-resize',
271
- height:
272
- showFilters && column.columnDefType === 'data'
273
- ? '4rem'
274
- : '2rem',
275
- opacity: 0.8,
276
- position: 'absolute',
277
- right: '1px',
278
- touchAction: 'none',
279
- transition: column.getIsResizing()
280
- ? undefined
281
- : 'all 0.2s ease-in-out',
282
- userSelect: 'none',
283
- zIndex: 2000,
284
- '&:active': {
285
- backgroundColor: theme.palette.info.main,
286
- opacity: 1,
287
- },
288
- })}
289
- onMouseDown={header.getResizeHandler()}
290
- onTouchStart={header.getResizeHandler()}
291
- style={{
292
- transform: column.getIsResizing()
293
- ? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
294
- : 'none',
295
- }}
210
+ <MRT_TableHeadCellResizeHandle
211
+ header={header}
212
+ tableInstance={tableInstance}
296
213
  />
297
214
  )}
298
215
  </Box>
299
216
  )}
300
217
  {column.columnDefType === 'data' && column.getCanFilter() && (
301
- <Collapse in={showFilters} mountOnEnter unmountOnExit>
302
- {currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
303
- <MRT_FilterRangeFields
304
- header={header}
305
- tableInstance={tableInstance}
306
- />
307
- ) : (
308
- <MRT_FilterTextField
309
- header={header}
310
- tableInstance={tableInstance}
311
- />
312
- )}
313
- </Collapse>
218
+ <MRT_TableHeadCellFilterContainer
219
+ header={header}
220
+ tableInstance={tableInstance}
221
+ />
314
222
  )}
315
223
  </TableCell>
316
224
  );
@@ -0,0 +1,32 @@
1
+ import React, { FC } from 'react';
2
+ import { Collapse } from '@mui/material';
3
+ import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
4
+ import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
5
+ import { MRT_FILTER_OPTION } from '../enums';
6
+ import { MRT_Header, MRT_TableInstance } from '..';
7
+
8
+ interface Props {
9
+ header: MRT_Header;
10
+ tableInstance: MRT_TableInstance;
11
+ }
12
+
13
+ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
14
+ header,
15
+ tableInstance,
16
+ }) => {
17
+ const { getState } = tableInstance;
18
+
19
+ const { currentFilterFns, showFilters } = getState();
20
+
21
+ const { column } = header;
22
+
23
+ return (
24
+ <Collapse in={showFilters} mountOnEnter unmountOnExit>
25
+ {currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
26
+ <MRT_FilterRangeFields header={header} tableInstance={tableInstance} />
27
+ ) : (
28
+ <MRT_FilterTextField header={header} tableInstance={tableInstance} />
29
+ )}
30
+ </Collapse>
31
+ );
32
+ };
@@ -0,0 +1,82 @@
1
+ import React, { FC, MouseEvent } from 'react';
2
+ import { IconButton, Tooltip } from '@mui/material';
3
+ import { MRT_Header, MRT_TableInstance } from '..';
4
+
5
+ interface Props {
6
+ header: MRT_Header;
7
+ tableInstance: MRT_TableInstance;
8
+ }
9
+
10
+ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({
11
+ header,
12
+ tableInstance,
13
+ }) => {
14
+ const {
15
+ getState,
16
+ options: {
17
+ icons: { FilterAltIcon, FilterAltOff },
18
+ localization,
19
+ },
20
+ setShowFilters,
21
+ } = tableInstance;
22
+
23
+ const { showFilters } = getState();
24
+
25
+ const { column } = header;
26
+
27
+ const filterFn = getState()?.currentFilterFns?.[header.id];
28
+
29
+ const filterTooltip = !!column.getFilterValue()
30
+ ? localization.filteringByColumn
31
+ .replace('{column}', String(column.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('" "', '')
52
+ : localization.showHideFilters;
53
+
54
+ return (
55
+ <Tooltip arrow placement="top" title={filterTooltip}>
56
+ <IconButton
57
+ disableRipple
58
+ onClick={(event: MouseEvent<HTMLButtonElement>) => {
59
+ event.stopPropagation();
60
+ setShowFilters(!showFilters);
61
+ }}
62
+ size="small"
63
+ sx={{
64
+ m: 0,
65
+ opacity: !!column.getFilterValue() || showFilters ? 0.8 : 0,
66
+ p: '2px',
67
+ transition: 'all 0.2s ease-in-out',
68
+ '&:hover': {
69
+ backgroundColor: 'transparent',
70
+ opacity: 0.8,
71
+ },
72
+ }}
73
+ >
74
+ {showFilters && !column.getFilterValue() ? (
75
+ <FilterAltOff />
76
+ ) : (
77
+ <FilterAltIcon />
78
+ )}
79
+ </IconButton>
80
+ </Tooltip>
81
+ );
82
+ };
@@ -0,0 +1,52 @@
1
+ import { IconButton, Tooltip } from '@mui/material';
2
+ import React, { FC, forwardRef, Ref } from 'react';
3
+ import { MRT_Header, MRT_TableInstance } from '..';
4
+
5
+ interface Props {
6
+ header: MRT_Header;
7
+ ref: Ref<HTMLButtonElement>;
8
+ tableInstance: MRT_TableInstance;
9
+ }
10
+
11
+ export const MRT_TableHeadCellGrabHandle: FC<Props> = forwardRef(
12
+ ({ tableInstance }, ref) => {
13
+ const {
14
+ options: {
15
+ icons: { DragHandleIcon },
16
+ localization,
17
+ },
18
+ } = tableInstance;
19
+
20
+ return (
21
+ <Tooltip
22
+ arrow
23
+ enterDelay={1000}
24
+ enterNextDelay={1000}
25
+ placement="top"
26
+ title={localization.grab}
27
+ >
28
+ <IconButton
29
+ disableRipple
30
+ ref={ref}
31
+ size="small"
32
+ sx={{
33
+ cursor: 'grab',
34
+ m: 0,
35
+ opacity: 0.5,
36
+ p: '2px',
37
+ transition: 'all 0.2s ease-in-out',
38
+ '&:hover': {
39
+ backgroundColor: 'transparent',
40
+ opacity: 1,
41
+ },
42
+ '&:active': {
43
+ cursor: 'grabbing',
44
+ },
45
+ }}
46
+ >
47
+ <DragHandleIcon />
48
+ </IconButton>
49
+ </Tooltip>
50
+ );
51
+ },
52
+ );