material-react-table 2.0.0-alpha.0 → 2.0.0-alpha.2

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 (119) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/index.js +2480 -2392
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/MaterialReactTable.d.ts +1 -1
  5. package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -2
  6. package/dist/cjs/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
  7. package/dist/cjs/types/body/index.d.ts +1 -0
  8. package/dist/cjs/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
  9. package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +9 -0
  10. package/dist/cjs/types/buttons/index.d.ts +2 -1
  11. package/dist/cjs/types/column.utils.d.ts +7 -6
  12. package/dist/cjs/types/filterFns.d.ts +14 -14
  13. package/dist/cjs/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
  14. package/dist/cjs/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
  15. package/dist/cjs/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
  16. package/dist/cjs/types/icons.d.ts +1 -1
  17. package/dist/cjs/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
  18. package/dist/cjs/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
  19. package/dist/cjs/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
  20. package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
  21. package/dist/cjs/types/toolbar/MRT_TopToolbar.d.ts +1 -1
  22. package/dist/cjs/types/types.d.ts +203 -197
  23. package/dist/esm/material-react-table.esm.js +2442 -2358
  24. package/dist/esm/material-react-table.esm.js.map +1 -1
  25. package/dist/esm/types/MaterialReactTable.d.ts +1 -1
  26. package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -2
  27. package/dist/esm/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
  28. package/dist/esm/types/body/index.d.ts +1 -0
  29. package/dist/esm/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
  30. package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +9 -0
  31. package/dist/esm/types/buttons/index.d.ts +2 -1
  32. package/dist/esm/types/column.utils.d.ts +7 -6
  33. package/dist/esm/types/filterFns.d.ts +14 -14
  34. package/dist/esm/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
  35. package/dist/esm/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
  36. package/dist/esm/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
  37. package/dist/esm/types/icons.d.ts +1 -1
  38. package/dist/esm/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
  39. package/dist/esm/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
  40. package/dist/esm/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
  41. package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
  42. package/dist/esm/types/toolbar/MRT_TopToolbar.d.ts +1 -1
  43. package/dist/esm/types/types.d.ts +203 -197
  44. package/dist/index.d.ts +293 -272
  45. package/locales/en.esm.js +1 -0
  46. package/locales/en.esm.js.map +1 -1
  47. package/locales/en.js +1 -0
  48. package/locales/en.js.map +1 -1
  49. package/locales/fr.esm.js +1 -1
  50. package/locales/fr.esm.js.map +1 -1
  51. package/locales/fr.js +1 -1
  52. package/locales/fr.js.map +1 -1
  53. package/package.json +10 -9
  54. package/src/MaterialReactTable.tsx +2 -2
  55. package/src/body/MRT_TableBody.tsx +180 -76
  56. package/src/body/MRT_TableBodyCell.tsx +45 -43
  57. package/src/body/MRT_TableBodyCellValue.tsx +5 -5
  58. package/src/body/MRT_TableBodyRow.tsx +117 -29
  59. package/src/body/MRT_TableBodyRowGrabHandle.tsx +6 -5
  60. package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
  61. package/src/body/MRT_TableDetailPanel.tsx +16 -22
  62. package/src/body/index.ts +2 -1
  63. package/src/buttons/MRT_CopyButton.tsx +14 -20
  64. package/src/buttons/MRT_EditActionButtons.tsx +4 -4
  65. package/src/buttons/MRT_ExpandAllButton.tsx +7 -9
  66. package/src/buttons/MRT_ExpandButton.tsx +6 -7
  67. package/src/buttons/MRT_GrabHandleButton.tsx +12 -13
  68. package/src/buttons/MRT_RowPinButton.tsx +74 -0
  69. package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -1
  70. package/src/buttons/MRT_ToggleFullScreenButton.tsx +2 -2
  71. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +9 -10
  72. package/src/buttons/index.ts +2 -1
  73. package/src/column.utils.ts +33 -21
  74. package/src/filterFns.ts +29 -29
  75. package/src/footer/MRT_TableFooter.tsx +14 -8
  76. package/src/footer/MRT_TableFooterCell.tsx +8 -21
  77. package/src/footer/MRT_TableFooterRow.tsx +7 -8
  78. package/src/head/MRT_TableHead.tsx +12 -8
  79. package/src/head/MRT_TableHeadCell.tsx +18 -25
  80. package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +18 -23
  81. package/src/head/MRT_TableHeadCellFilterContainer.tsx +11 -4
  82. package/src/head/MRT_TableHeadCellFilterLabel.tsx +106 -61
  83. package/src/head/MRT_TableHeadCellGrabHandle.tsx +8 -15
  84. package/src/head/MRT_TableHeadCellResizeHandle.tsx +11 -11
  85. package/src/head/MRT_TableHeadCellSortLabel.tsx +8 -8
  86. package/src/head/MRT_TableHeadRow.tsx +7 -8
  87. package/src/hooks/useMRT_DisplayColumns.tsx +17 -4
  88. package/src/hooks/useMRT_Effects.ts +3 -3
  89. package/src/hooks/useMRT_TableInstance.ts +17 -10
  90. package/src/hooks/useMRT_TableOptions.ts +9 -5
  91. package/src/icons.ts +2 -2
  92. package/src/inputs/MRT_EditCellTextField.tsx +23 -31
  93. package/src/inputs/MRT_FilterCheckbox.tsx +17 -29
  94. package/src/inputs/MRT_FilterRangeFields.tsx +1 -1
  95. package/src/inputs/MRT_FilterRangeSlider.tsx +12 -29
  96. package/src/inputs/MRT_FilterTextField.tsx +83 -99
  97. package/src/inputs/MRT_GlobalFilterTextField.tsx +29 -29
  98. package/src/inputs/MRT_SelectCheckbox.tsx +35 -21
  99. package/src/locales/en.ts +1 -1
  100. package/src/locales/fr.ts +1 -1
  101. package/src/menus/MRT_ColumnActionMenu.tsx +14 -14
  102. package/src/menus/MRT_FilterOptionMenu.tsx +35 -35
  103. package/src/menus/MRT_RowActionMenu.tsx +17 -18
  104. package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -6
  105. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +5 -5
  106. package/src/modals/MRT_EditRowModal.tsx +12 -20
  107. package/src/sortingFns.ts +1 -1
  108. package/src/table/MRT_Table.tsx +14 -19
  109. package/src/table/MRT_TableContainer.tsx +14 -20
  110. package/src/table/MRT_TablePaper.tsx +16 -20
  111. package/src/toolbar/MRT_BottomToolbar.tsx +18 -24
  112. package/src/toolbar/MRT_LinearProgressBar.tsx +8 -7
  113. package/src/toolbar/MRT_TablePagination.tsx +23 -25
  114. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +11 -14
  115. package/src/toolbar/MRT_ToolbarDropZone.tsx +6 -6
  116. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -5
  117. package/src/toolbar/MRT_TopToolbar.tsx +14 -20
  118. package/src/types.ts +269 -252
  119. package/src/useMaterialReactTable.ts +1 -1
@@ -1,6 +1,7 @@
1
+ import { type VirtualItem } from '@tanstack/react-virtual';
1
2
  import TableFooter from '@mui/material/TableFooter';
2
3
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
3
- import { type VirtualItem } from '@tanstack/react-virtual';
4
+ import { parseFromValuesOrFunc } from '../column.utils';
4
5
  import { type MRT_TableInstance } from '../types';
5
6
 
6
7
  interface Props<TData extends Record<string, any>> {
@@ -20,13 +21,13 @@ export const MRT_TableFooter = <TData extends Record<string, any>>({
20
21
  getFooterGroups,
21
22
  getState,
22
23
  options: { enableStickyFooter, layoutMode, muiTableFooterProps },
24
+ refs: { tableFooterRef },
23
25
  } = table;
24
26
  const { isFullScreen } = getState();
25
27
 
26
- const tableFooterProps =
27
- muiTableFooterProps instanceof Function
28
- ? muiTableFooterProps({ table })
29
- : muiTableFooterProps;
28
+ const tableFooterProps = parseFromValuesOrFunc(muiTableFooterProps, {
29
+ table,
30
+ });
30
31
 
31
32
  const stickFooter =
32
33
  (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
@@ -34,6 +35,13 @@ export const MRT_TableFooter = <TData extends Record<string, any>>({
34
35
  return (
35
36
  <TableFooter
36
37
  {...tableFooterProps}
38
+ ref={(ref: HTMLTableSectionElement) => {
39
+ tableFooterRef.current = ref;
40
+ if (tableFooterProps?.ref) {
41
+ // @ts-ignore
42
+ tableFooterProps.ref.current = ref;
43
+ }
44
+ }}
37
45
  sx={(theme) => ({
38
46
  bottom: stickFooter ? 0 : undefined,
39
47
  display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
@@ -45,9 +53,7 @@ export const MRT_TableFooter = <TData extends Record<string, any>>({
45
53
  : undefined,
46
54
  position: stickFooter ? 'sticky' : undefined,
47
55
  zIndex: stickFooter ? 1 : undefined,
48
- ...(tableFooterProps?.sx instanceof Function
49
- ? tableFooterProps?.sx(theme)
50
- : (tableFooterProps?.sx as any)),
56
+ ...(parseFromValuesOrFunc(tableFooterProps?.sx, theme) as any),
51
57
  })}
52
58
  >
53
59
  {getFooterGroups().map((footerGroup) => (
@@ -1,5 +1,5 @@
1
1
  import TableCell from '@mui/material/TableCell';
2
- import { getCommonCellStyles } from '../column.utils';
2
+ import { getCommonCellStyles, parseFromValuesOrFunc } from '../column.utils';
3
3
  import { type MRT_Header, type MRT_TableInstance } from '../types';
4
4
 
5
5
  interface Props<TData extends Record<string, any>> {
@@ -20,19 +20,12 @@ export const MRT_TableFooterCell = <TData extends Record<string, any>>({
20
20
  const { columnDef } = column;
21
21
  const { columnDefType } = columnDef;
22
22
 
23
- const mTableFooterCellProps =
24
- muiTableFooterCellProps instanceof Function
25
- ? muiTableFooterCellProps({ column, table })
26
- : muiTableFooterCellProps;
27
-
28
- const mcTableFooterCellProps =
29
- columnDef.muiTableFooterCellProps instanceof Function
30
- ? columnDef.muiTableFooterCellProps({ column, table })
31
- : columnDef.muiTableFooterCellProps;
32
-
33
23
  const tableCellProps = {
34
- ...mTableFooterCellProps,
35
- ...mcTableFooterCellProps,
24
+ ...parseFromValuesOrFunc(muiTableFooterCellProps, { column, table }),
25
+ ...parseFromValuesOrFunc(columnDef.muiTableFooterCellProps, {
26
+ column,
27
+ table,
28
+ }),
36
29
  };
37
30
 
38
31
  return (
@@ -56,21 +49,15 @@ export const MRT_TableFooterCell = <TData extends Record<string, any>>({
56
49
  ...getCommonCellStyles({
57
50
  column,
58
51
  table,
59
- theme,
60
52
  tableCellProps,
53
+ theme,
61
54
  }),
62
55
  })}
63
56
  >
64
57
  <>
65
58
  {footer.isPlaceholder
66
59
  ? null
67
- : (columnDef.Footer instanceof Function
68
- ? columnDef.Footer?.({
69
- column,
70
- footer,
71
- table,
72
- })
73
- : columnDef.Footer) ??
60
+ : parseFromValuesOrFunc(columnDef.Footer, { column, footer, table }) ??
74
61
  columnDef.footer ??
75
62
  null}
76
63
  </>
@@ -1,7 +1,8 @@
1
+ import { type VirtualItem } from '@tanstack/react-virtual';
1
2
  import TableRow from '@mui/material/TableRow';
2
3
  import { lighten } from '@mui/material/styles';
3
4
  import { MRT_TableFooterCell } from './MRT_TableFooterCell';
4
- import { type VirtualItem } from '@tanstack/react-virtual';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
  import {
6
7
  type MRT_Header,
7
8
  type MRT_HeaderGroup,
@@ -38,10 +39,10 @@ export const MRT_TableFooterRow = <TData extends Record<string, any>>({
38
39
  )
39
40
  return null;
40
41
 
41
- const tableRowProps =
42
- muiTableFooterRowProps instanceof Function
43
- ? muiTableFooterRowProps({ footerGroup, table })
44
- : muiTableFooterRowProps;
42
+ const tableRowProps = parseFromValuesOrFunc(muiTableFooterRowProps, {
43
+ footerGroup,
44
+ table,
45
+ });
45
46
 
46
47
  return (
47
48
  <TableRow
@@ -50,9 +51,7 @@ export const MRT_TableFooterRow = <TData extends Record<string, any>>({
50
51
  backgroundColor: lighten(theme.palette.background.default, 0.04),
51
52
  display: layoutMode === 'grid' ? 'flex' : 'table-row',
52
53
  width: '100%',
53
- ...(tableRowProps?.sx instanceof Function
54
- ? tableRowProps?.sx(theme)
55
- : (tableRowProps?.sx as any)),
54
+ ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as any),
56
55
  })}
57
56
  >
58
57
  {virtualPaddingLeft ? (
@@ -1,6 +1,7 @@
1
+ import { type VirtualItem } from '@tanstack/react-virtual';
1
2
  import TableHead from '@mui/material/TableHead';
2
3
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
3
- import { type VirtualItem } from '@tanstack/react-virtual';
4
+ import { parseFromValuesOrFunc } from '../column.utils';
4
5
  import { type MRT_TableInstance } from '../types';
5
6
 
6
7
  interface Props<TData extends Record<string, any>> {
@@ -20,28 +21,31 @@ export const MRT_TableHead = <TData extends Record<string, any>>({
20
21
  getHeaderGroups,
21
22
  getState,
22
23
  options: { enableStickyHeader, layoutMode, muiTableHeadProps },
24
+ refs: { tableHeadRef },
23
25
  } = table;
24
26
  const { isFullScreen } = getState();
25
27
 
26
- const tableHeadProps =
27
- muiTableHeadProps instanceof Function
28
- ? muiTableHeadProps({ table })
29
- : muiTableHeadProps;
28
+ const tableHeadProps = parseFromValuesOrFunc(muiTableHeadProps, { table });
30
29
 
31
30
  const stickyHeader = enableStickyHeader || isFullScreen;
32
31
 
33
32
  return (
34
33
  <TableHead
35
34
  {...tableHeadProps}
35
+ ref={(ref: HTMLTableSectionElement) => {
36
+ tableHeadRef.current = ref;
37
+ if (tableHeadProps?.ref) {
38
+ // @ts-ignore
39
+ tableHeadProps.ref.current = ref;
40
+ }
41
+ }}
36
42
  sx={(theme) => ({
37
43
  display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
38
44
  opacity: 0.97,
39
45
  position: stickyHeader ? 'sticky' : 'relative',
40
46
  top: stickyHeader && layoutMode === 'grid' ? 0 : undefined,
41
47
  zIndex: stickyHeader ? 2 : undefined,
42
- ...(tableHeadProps?.sx instanceof Function
43
- ? tableHeadProps?.sx(theme)
44
- : (tableHeadProps?.sx as any)),
48
+ ...(parseFromValuesOrFunc(tableHeadProps?.sx, theme) as any),
45
49
  })}
46
50
  >
47
51
  {getHeaderGroups().map((headerGroup) => (
@@ -1,7 +1,8 @@
1
- import { type DragEvent, type ReactNode, useMemo } from 'react';
1
+ import { type DragEvent, useMemo } from 'react';
2
2
  import Box from '@mui/material/Box';
3
3
  import TableCell from '@mui/material/TableCell';
4
4
  import { useTheme } from '@mui/material/styles';
5
+ import { type Theme } from '@mui/material/styles';
5
6
  import { MRT_TableHeadCellColumnActionsButton } from './MRT_TableHeadCellColumnActionsButton';
6
7
  import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
7
8
  import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
@@ -9,7 +10,7 @@ import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
9
10
  import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
10
11
  import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
11
12
  import { getCommonCellStyles } from '../column.utils';
12
- import { type Theme } from '@mui/material/styles';
13
+ import { parseFromValuesOrFunc } from '../column.utils';
13
14
  import { type MRT_Header, type MRT_TableInstance } from '../types';
14
15
 
15
16
  interface Props<TData extends Record<string, any>> {
@@ -25,6 +26,7 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
25
26
  const {
26
27
  getState,
27
28
  options: {
29
+ columnFilterDisplayMode,
28
30
  enableColumnActions,
29
31
  enableColumnDragging,
30
32
  enableColumnOrdering,
@@ -47,19 +49,12 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
47
49
  const { columnDef } = column;
48
50
  const { columnDefType } = columnDef;
49
51
 
50
- const mTableHeadCellProps =
51
- muiTableHeadCellProps instanceof Function
52
- ? muiTableHeadCellProps({ column, table })
53
- : muiTableHeadCellProps;
54
-
55
- const mcTableHeadCellProps =
56
- columnDef.muiTableHeadCellProps instanceof Function
57
- ? columnDef.muiTableHeadCellProps({ column, table })
58
- : columnDef.muiTableHeadCellProps;
59
-
60
52
  const tableCellProps = {
61
- ...mTableHeadCellProps,
62
- ...mcTableHeadCellProps,
53
+ ...parseFromValuesOrFunc(muiTableHeadCellProps, { column, table }),
54
+ ...parseFromValuesOrFunc(columnDef.muiTableHeadCellProps, {
55
+ column,
56
+ table,
57
+ }),
63
58
  };
64
59
 
65
60
  const showColumnActions =
@@ -113,13 +108,11 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
113
108
  };
114
109
 
115
110
  const headerElement =
116
- columnDef?.Header instanceof Function
117
- ? columnDef?.Header?.({
118
- column,
119
- header,
120
- table,
121
- })
122
- : columnDef?.Header ?? (columnDef.header as ReactNode);
111
+ parseFromValuesOrFunc(columnDef.Header, {
112
+ column,
113
+ header,
114
+ table,
115
+ }) ?? columnDef.header;
123
116
 
124
117
  return (
125
118
  <TableCell
@@ -216,14 +209,14 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
216
209
  <Box
217
210
  className="Mui-TableHeadCell-Content-Wrapper"
218
211
  sx={{
212
+ '&:hover': {
213
+ textOverflow: 'clip',
214
+ },
219
215
  minWidth: `${Math.min(columnDef.header?.length ?? 0, 5)}ch`,
220
216
  overflow: columnDefType === 'data' ? 'hidden' : undefined,
221
217
  textOverflow: 'ellipsis',
222
218
  whiteSpace:
223
219
  (columnDef.header?.length ?? 0) < 20 ? 'nowrap' : 'normal',
224
- '&:hover': {
225
- textOverflow: 'clip',
226
- },
227
220
  }}
228
221
  title={columnDefType === 'data' ? columnDef.header : undefined}
229
222
  >
@@ -267,7 +260,7 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
267
260
  )}
268
261
  </Box>
269
262
  )}
270
- {column.getCanFilter() && (
263
+ {columnFilterDisplayMode === 'subheader' && column.getCanFilter() && (
271
264
  <MRT_TableHeadCellFilterContainer header={header} table={table} />
272
265
  )}
273
266
  </TableCell>
@@ -1,6 +1,7 @@
1
1
  import { type MouseEvent, useState } from 'react';
2
2
  import IconButton from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
+ import { parseFromValuesOrFunc } from '../column.utils';
4
5
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
5
6
  import { type MRT_Header, type MRT_TableInstance } from '../types';
6
7
 
@@ -17,6 +18,7 @@ export const MRT_TableHeadCellColumnActionsButton = <
17
18
  }: Props<TData>) => {
18
19
  const {
19
20
  options: {
21
+ columnFilterDisplayMode,
20
22
  icons: { MoreVertIcon },
21
23
  localization,
22
24
  muiColumnActionsButtonProps,
@@ -25,7 +27,7 @@ export const MRT_TableHeadCellColumnActionsButton = <
25
27
  const { column } = header;
26
28
  const { columnDef } = column;
27
29
 
28
- const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
30
+ const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
29
31
 
30
32
  const handleClick = (event: MouseEvent<HTMLElement>) => {
31
33
  event.stopPropagation();
@@ -33,22 +35,15 @@ export const MRT_TableHeadCellColumnActionsButton = <
33
35
  setAnchorEl(event.currentTarget);
34
36
  };
35
37
 
36
- const mTableHeadCellColumnActionsButtonProps =
37
- muiColumnActionsButtonProps instanceof Function
38
- ? muiColumnActionsButtonProps({ column, table })
39
- : muiColumnActionsButtonProps;
40
-
41
- const mcTableHeadCellColumnActionsButtonProps =
42
- columnDef.muiColumnActionsButtonProps instanceof Function
43
- ? columnDef.muiColumnActionsButtonProps({
44
- column,
45
- table,
46
- })
47
- : columnDef.muiColumnActionsButtonProps;
48
-
49
38
  const iconButtonProps = {
50
- ...mTableHeadCellColumnActionsButtonProps,
51
- ...mcTableHeadCellColumnActionsButtonProps,
39
+ ...parseFromValuesOrFunc(muiColumnActionsButtonProps, {
40
+ column,
41
+ table,
42
+ }),
43
+ ...parseFromValuesOrFunc(columnDef.muiColumnActionsButtonProps, {
44
+ column,
45
+ table,
46
+ }),
52
47
  };
53
48
 
54
49
  return (
@@ -66,18 +61,18 @@ export const MRT_TableHeadCellColumnActionsButton = <
66
61
  size="small"
67
62
  {...iconButtonProps}
68
63
  sx={(theme) => ({
64
+ '&:hover': {
65
+ opacity: 1,
66
+ },
69
67
  height: '2rem',
70
68
  m: '-8px -4px',
71
69
  opacity: 0.5,
72
- transform: 'scale(0.85) translateX(-4px)',
70
+ transform: `scale(0.85) ${
71
+ columnFilterDisplayMode !== 'popover' ? 'translateX(-4px)' : ''
72
+ }`,
73
73
  transition: 'opacity 150ms',
74
74
  width: '2rem',
75
- '&:hover': {
76
- opacity: 1,
77
- },
78
- ...(iconButtonProps?.sx instanceof Function
79
- ? iconButtonProps.sx(theme)
80
- : (iconButtonProps?.sx as any)),
75
+ ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
81
76
  })}
82
77
  title={undefined}
83
78
  >
@@ -1,8 +1,8 @@
1
1
  import Collapse from '@mui/material/Collapse';
2
- import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
3
- import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
4
2
  import { MRT_FilterCheckbox } from '../inputs/MRT_FilterCheckbox';
3
+ import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
5
4
  import { MRT_FilterRangeSlider } from '../inputs/MRT_FilterRangeSlider';
5
+ import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
6
6
  import { type MRT_Header, type MRT_TableInstance } from '../types';
7
7
 
8
8
  interface Props<TData extends Record<string, any>> {
@@ -16,13 +16,20 @@ export const MRT_TableHeadCellFilterContainer = <
16
16
  header,
17
17
  table,
18
18
  }: Props<TData>) => {
19
- const { getState } = table;
19
+ const {
20
+ getState,
21
+ options: { columnFilterDisplayMode },
22
+ } = table;
20
23
  const { showColumnFilters } = getState();
21
24
  const { column } = header;
22
25
  const { columnDef } = column;
23
26
 
24
27
  return (
25
- <Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
28
+ <Collapse
29
+ in={showColumnFilters || columnFilterDisplayMode === 'popover'}
30
+ mountOnEnter
31
+ unmountOnExit
32
+ >
26
33
  {columnDef.filterVariant === 'checkbox' ? (
27
34
  <MRT_FilterCheckbox column={column} table={table} />
28
35
  ) : columnDef.filterVariant === 'range-slider' ? (
@@ -1,8 +1,10 @@
1
- import { type MouseEvent } from 'react';
1
+ import { type MouseEvent, useState } from 'react';
2
2
  import Box from '@mui/material/Box';
3
3
  import Grow from '@mui/material/Grow';
4
4
  import IconButton from '@mui/material/IconButton';
5
+ import Popover from '@mui/material/Popover';
5
6
  import Tooltip from '@mui/material/Tooltip';
7
+ import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
6
8
  import { type MRT_Header, type MRT_TableInstance } from '../types';
7
9
 
8
10
  interface Props<TData extends Record<string, any>> {
@@ -11,13 +13,14 @@ interface Props<TData extends Record<string, any>> {
11
13
  }
12
14
 
13
15
  export const MRT_TableHeadCellFilterLabel = <
14
- TData extends Record<string, any>,
16
+ TData extends Record<string, any> = {},
15
17
  >({
16
18
  header,
17
19
  table,
18
20
  }: Props<TData>) => {
19
21
  const {
20
22
  options: {
23
+ columnFilterDisplayMode,
21
24
  icons: { FilterAltIcon },
22
25
  localization,
23
26
  },
@@ -27,71 +30,113 @@ export const MRT_TableHeadCellFilterLabel = <
27
30
  const { column } = header;
28
31
  const { columnDef } = column;
29
32
 
33
+ const filterValue = column.getFilterValue();
34
+
35
+ const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
36
+
37
+ const isFilterActive =
38
+ (Array.isArray(filterValue) && filterValue.some(Boolean)) ||
39
+ (!!filterValue && !Array.isArray(filterValue));
40
+
30
41
  const isRangeFilter =
31
- ['range', 'ranger-slider'].includes(columnDef.filterVariant ?? '') ||
42
+ columnDef.filterVariant === 'range' ||
32
43
  ['between', 'betweenInclusive', 'inNumberRange'].includes(
33
44
  columnDef._filterFn,
34
45
  );
35
46
  const currentFilterOption = columnDef._filterFn;
36
- const filterTooltip = localization.filteringByColumn
37
- .replace('{column}', String(columnDef.header))
38
- .replace(
39
- '{filterType}',
40
- // @ts-ignore
41
- localization[
42
- `filter${
43
- currentFilterOption?.charAt(0)?.toUpperCase() +
44
- currentFilterOption?.slice(1)
45
- }`
46
- ],
47
- )
48
- .replace(
49
- '{filterValue}',
50
- `"${
51
- Array.isArray(column.getFilterValue())
52
- ? (column.getFilterValue() as [string, string]).join(
53
- `" ${isRangeFilter ? localization.and : localization.or} "`,
54
- )
55
- : (column.getFilterValue() as string)
56
- }"`,
57
- )
58
- .replace('" "', '');
47
+ const filterTooltip =
48
+ columnFilterDisplayMode === 'popover' && !isFilterActive
49
+ ? localization.filterByColumn?.replace(
50
+ '{column}',
51
+ String(columnDef.header),
52
+ )
53
+ : localization.filteringByColumn
54
+ .replace('{column}', String(columnDef.header))
55
+ .replace(
56
+ '{filterType}',
57
+ currentFilterOption
58
+ ? // @ts-ignore
59
+ localization[
60
+ `filter${
61
+ currentFilterOption?.charAt(0)?.toUpperCase() +
62
+ currentFilterOption?.slice(1)
63
+ }`
64
+ ]
65
+ : '',
66
+ )
67
+ .replace(
68
+ '{filterValue}',
69
+ `"${
70
+ Array.isArray(column.getFilterValue())
71
+ ? (column.getFilterValue() as [string, string]).join(
72
+ `" ${isRangeFilter ? localization.and : localization.or} "`,
73
+ )
74
+ : (column.getFilterValue() as string)
75
+ }"`,
76
+ )
77
+ .replace('" "', '');
59
78
 
60
79
  return (
61
- <Grow
62
- unmountOnExit
63
- in={
64
- (!!column.getFilterValue() && !isRangeFilter) ||
65
- (isRangeFilter && // @ts-ignore
66
- (!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
67
- }
68
- >
69
- <Box component="span" sx={{ flex: '0 0' }}>
70
- <Tooltip arrow placement="top" title={filterTooltip}>
71
- <IconButton
72
- disableRipple
73
- onClick={(event: MouseEvent<HTMLButtonElement>) => {
74
- setShowColumnFilters(true);
75
- queueMicrotask(() => {
76
- filterInputRefs.current[`${column.id}-0`]?.focus();
77
- filterInputRefs.current[`${column.id}-0`]?.select();
78
- });
79
- event.stopPropagation();
80
- }}
81
- size="small"
82
- sx={{
83
- height: '12px',
84
- m: 0,
85
- opacity: 0.8,
86
- p: '2px',
87
- transform: 'scale(0.66)',
88
- width: '12px',
89
- }}
90
- >
91
- <FilterAltIcon />
92
- </IconButton>
93
- </Tooltip>
94
- </Box>
95
- </Grow>
80
+ <>
81
+ <Grow
82
+ in={
83
+ columnFilterDisplayMode === 'popover' ||
84
+ (!!column.getFilterValue() && !isRangeFilter) ||
85
+ (isRangeFilter && // @ts-ignore
86
+ (!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
87
+ }
88
+ unmountOnExit
89
+ >
90
+ <Box component="span" sx={{ flex: '0 0' }}>
91
+ <Tooltip arrow placement="top" title={filterTooltip}>
92
+ <IconButton
93
+ disableRipple
94
+ onClick={(event: MouseEvent<HTMLButtonElement>) => {
95
+ if (columnFilterDisplayMode === 'popover') {
96
+ setAnchorEl(event.currentTarget);
97
+ } else {
98
+ setShowColumnFilters(true);
99
+ }
100
+ queueMicrotask(() => {
101
+ filterInputRefs.current[`${column.id}-0`]?.focus();
102
+ filterInputRefs.current[`${column.id}-0`]?.select();
103
+ });
104
+ event.stopPropagation();
105
+ }}
106
+ sx={{
107
+ height: '16px',
108
+ opacity: 0.8,
109
+ p: '8px',
110
+ transform: 'scale(0.75)',
111
+ width: '16px',
112
+ }}
113
+ >
114
+ <FilterAltIcon />
115
+ </IconButton>
116
+ </Tooltip>
117
+ </Box>
118
+ </Grow>
119
+ <Popover
120
+ anchorEl={anchorEl}
121
+ anchorOrigin={{
122
+ horizontal: 'center',
123
+ vertical: 'top',
124
+ }}
125
+ onClose={(event) => {
126
+ //@ts-ignore
127
+ event.stopPropagation();
128
+ setAnchorEl(null);
129
+ }}
130
+ open={!!anchorEl}
131
+ transformOrigin={{
132
+ horizontal: 'center',
133
+ vertical: 'bottom',
134
+ }}
135
+ >
136
+ <Box sx={{ p: '1rem' }}>
137
+ <MRT_TableHeadCellFilterContainer header={header} table={table} />
138
+ </Box>
139
+ </Popover>
140
+ </>
96
141
  );
97
142
  };
@@ -1,6 +1,6 @@
1
1
  import { type DragEvent, type RefObject } from 'react';
2
2
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
3
- import { reorderColumn } from '../column.utils';
3
+ import { parseFromValuesOrFunc, reorderColumn } from '../column.utils';
4
4
  import { type MRT_Column, type MRT_TableInstance } from '../types';
5
5
 
6
6
  interface Props<TData extends Record<string, any>> {
@@ -22,21 +22,14 @@ export const MRT_TableHeadCellGrabHandle = <TData extends Record<string, any>>({
22
22
  setHoveredColumn,
23
23
  } = table;
24
24
  const { columnDef } = column;
25
- const { hoveredColumn, draggingColumn, columnOrder } = getState();
26
-
27
- const mIconButtonProps =
28
- muiColumnDragHandleProps instanceof Function
29
- ? muiColumnDragHandleProps({ column, table })
30
- : muiColumnDragHandleProps;
31
-
32
- const mcIconButtonProps =
33
- columnDef.muiColumnDragHandleProps instanceof Function
34
- ? columnDef.muiColumnDragHandleProps({ column, table })
35
- : columnDef.muiColumnDragHandleProps;
25
+ const { columnOrder, draggingColumn, hoveredColumn } = getState();
36
26
 
37
27
  const iconButtonProps = {
38
- ...mIconButtonProps,
39
- ...mcIconButtonProps,
28
+ ...parseFromValuesOrFunc(muiColumnDragHandleProps, { column, table }),
29
+ ...parseFromValuesOrFunc(columnDef.muiColumnDragHandleProps, {
30
+ column,
31
+ table,
32
+ }),
40
33
  };
41
34
 
42
35
  const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
@@ -69,8 +62,8 @@ export const MRT_TableHeadCellGrabHandle = <TData extends Record<string, any>>({
69
62
  return (
70
63
  <MRT_GrabHandleButton
71
64
  iconButtonProps={iconButtonProps}
72
- onDragStart={handleDragStart}
73
65
  onDragEnd={handleDragEnd}
66
+ onDragStart={handleDragStart}
74
67
  table={table}
75
68
  />
76
69
  );