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

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 (98) hide show
  1. package/dist/cjs/index.js +437 -384
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -2
  4. package/dist/cjs/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
  5. package/dist/cjs/types/body/index.d.ts +1 -0
  6. package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +9 -0
  7. package/dist/cjs/types/buttons/index.d.ts +2 -1
  8. package/dist/cjs/types/column.utils.d.ts +1 -0
  9. package/dist/cjs/types/types.d.ts +15 -9
  10. package/dist/esm/material-react-table.esm.js +433 -383
  11. package/dist/esm/material-react-table.esm.js.map +1 -1
  12. package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -2
  13. package/dist/esm/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
  14. package/dist/esm/types/body/index.d.ts +1 -0
  15. package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +9 -0
  16. package/dist/esm/types/buttons/index.d.ts +2 -1
  17. package/dist/esm/types/column.utils.d.ts +1 -0
  18. package/dist/esm/types/types.d.ts +15 -9
  19. package/dist/index.d.ts +68 -47
  20. package/locales/en.esm.js +1 -0
  21. package/locales/en.esm.js.map +1 -1
  22. package/locales/en.js +1 -0
  23. package/locales/en.js.map +1 -1
  24. package/package.json +9 -9
  25. package/src/body/MRT_TableBody.tsx +178 -74
  26. package/src/body/MRT_TableBodyCell.tsx +23 -21
  27. package/src/body/MRT_TableBodyRow.tsx +104 -16
  28. package/src/body/MRT_TableBodyRowGrabHandle.tsx +5 -4
  29. package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
  30. package/src/body/MRT_TableDetailPanel.tsx +13 -19
  31. package/src/body/index.ts +2 -1
  32. package/src/buttons/MRT_CopyButton.tsx +14 -20
  33. package/src/buttons/MRT_ExpandAllButton.tsx +5 -7
  34. package/src/buttons/MRT_ExpandButton.tsx +6 -7
  35. package/src/buttons/MRT_GrabHandleButton.tsx +2 -3
  36. package/src/buttons/MRT_RowPinButton.tsx +74 -0
  37. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -3
  38. package/src/buttons/index.ts +2 -1
  39. package/src/column.utils.ts +11 -5
  40. package/src/footer/MRT_TableFooter.tsx +13 -7
  41. package/src/footer/MRT_TableFooterCell.tsx +7 -20
  42. package/src/footer/MRT_TableFooterRow.tsx +6 -7
  43. package/src/head/MRT_TableHead.tsx +11 -7
  44. package/src/head/MRT_TableHeadCell.tsx +9 -20
  45. package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -18
  46. package/src/head/MRT_TableHeadCellGrabHandle.tsx +6 -13
  47. package/src/head/MRT_TableHeadRow.tsx +6 -7
  48. package/src/hooks/useMRT_DisplayColumns.tsx +13 -0
  49. package/src/hooks/useMRT_TableInstance.ts +6 -0
  50. package/src/hooks/useMRT_TableOptions.ts +6 -2
  51. package/src/inputs/MRT_EditCellTextField.tsx +14 -22
  52. package/src/inputs/MRT_FilterCheckbox.tsx +11 -23
  53. package/src/inputs/MRT_FilterRangeSlider.tsx +6 -23
  54. package/src/inputs/MRT_FilterTextField.tsx +9 -25
  55. package/src/inputs/MRT_GlobalFilterTextField.tsx +4 -4
  56. package/src/inputs/MRT_SelectCheckbox.tsx +31 -17
  57. package/src/locales/en.ts +1 -1
  58. package/src/menus/MRT_RowActionMenu.tsx +11 -12
  59. package/src/modals/MRT_EditRowModal.tsx +5 -13
  60. package/src/table/MRT_Table.tsx +8 -13
  61. package/src/table/MRT_TableContainer.tsx +6 -12
  62. package/src/table/MRT_TablePaper.tsx +9 -13
  63. package/src/toolbar/MRT_BottomToolbar.tsx +14 -20
  64. package/src/toolbar/MRT_LinearProgressBar.tsx +5 -4
  65. package/src/toolbar/MRT_TablePagination.tsx +5 -7
  66. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +8 -11
  67. package/src/toolbar/MRT_TopToolbar.tsx +8 -14
  68. package/src/types.ts +25 -8
  69. package/locales/tr.d.ts +0 -2
  70. package/locales/tr.esm.d.ts +0 -2
  71. package/locales/tr.esm.js +0 -93
  72. package/locales/tr.esm.js.map +0 -1
  73. package/locales/tr.js +0 -97
  74. package/locales/tr.js.map +0 -1
  75. package/locales/uk.d.ts +0 -2
  76. package/locales/uk.esm.d.ts +0 -2
  77. package/locales/uk.esm.js +0 -93
  78. package/locales/uk.esm.js.map +0 -1
  79. package/locales/uk.js +0 -97
  80. package/locales/uk.js.map +0 -1
  81. package/locales/vi.d.ts +0 -2
  82. package/locales/vi.esm.d.ts +0 -2
  83. package/locales/vi.esm.js +0 -93
  84. package/locales/vi.esm.js.map +0 -1
  85. package/locales/vi.js +0 -97
  86. package/locales/vi.js.map +0 -1
  87. package/locales/zh-Hans.d.ts +0 -2
  88. package/locales/zh-Hans.esm.d.ts +0 -2
  89. package/locales/zh-Hans.esm.js +0 -93
  90. package/locales/zh-Hans.esm.js.map +0 -1
  91. package/locales/zh-Hans.js +0 -97
  92. package/locales/zh-Hans.js.map +0 -1
  93. package/locales/zh-Hant.d.ts +0 -2
  94. package/locales/zh-Hant.esm.d.ts +0 -2
  95. package/locales/zh-Hant.esm.js +0 -93
  96. package/locales/zh-Hant.esm.js.map +0 -1
  97. package/locales/zh-Hant.js +0 -97
  98. package/locales/zh-Hant.js.map +0 -1
@@ -4,6 +4,7 @@ import TableCell from '@mui/material/TableCell';
4
4
  import TableRow from '@mui/material/TableRow';
5
5
  import { lighten } from '@mui/material/styles';
6
6
  import { type VirtualItem } from '@tanstack/react-virtual';
7
+ import { parseFromValuesOrFunc } from '../column.utils';
7
8
  import { type MRT_Row, type MRT_TableInstance } from '../types';
8
9
 
9
10
  interface Props<TData extends Record<string, any>> {
@@ -33,20 +34,17 @@ export const MRT_TableDetailPanel = <TData extends Record<string, any>>({
33
34
  } = table;
34
35
  const { isLoading } = getState();
35
36
 
36
- const tableRowProps =
37
- muiTableBodyRowProps instanceof Function
38
- ? muiTableBodyRowProps({
39
- isDetailPanel: true,
40
- row,
41
- staticRowIndex: rowIndex,
42
- table,
43
- })
44
- : muiTableBodyRowProps;
37
+ const tableRowProps = parseFromValuesOrFunc(muiTableBodyRowProps, {
38
+ isDetailPanel: true,
39
+ row,
40
+ staticRowIndex: rowIndex,
41
+ table,
42
+ });
45
43
 
46
- const tableCellProps =
47
- muiDetailPanelProps instanceof Function
48
- ? muiDetailPanelProps({ row, table })
49
- : muiDetailPanelProps;
44
+ const tableCellProps = parseFromValuesOrFunc(muiDetailPanelProps, {
45
+ row,
46
+ table,
47
+ });
50
48
 
51
49
  return (
52
50
  <TableRow
@@ -63,9 +61,7 @@ export const MRT_TableDetailPanel = <TData extends Record<string, any>>({
63
61
  : undefined,
64
62
  width: '100%',
65
63
  zIndex: virtualRow ? 2 : undefined,
66
- ...(tableRowProps?.sx instanceof Function
67
- ? tableRowProps.sx(theme)
68
- : (tableRowProps?.sx as any)),
64
+ ...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as any),
69
65
  })}
70
66
  >
71
67
  <TableCell
@@ -82,9 +78,7 @@ export const MRT_TableDetailPanel = <TData extends Record<string, any>>({
82
78
  pt: row.getIsExpanded() ? '1rem' : 0,
83
79
  transition: 'all 150ms ease-in-out',
84
80
  width: `${table.getTotalSize()}px`,
85
- ...(tableCellProps?.sx instanceof Function
86
- ? tableCellProps.sx(theme)
87
- : (tableCellProps?.sx as any)),
81
+ ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
88
82
  })}
89
83
  >
90
84
  {renderDetailPanel && (
package/src/body/index.ts CHANGED
@@ -3,4 +3,5 @@ export * from './MRT_TableBodyCell';
3
3
  export * from './MRT_TableBodyCellValue';
4
4
  export * from './MRT_TableBodyRow';
5
5
  export * from './MRT_TableBodyRowGrabHandle';
6
- export * from './MRT_TableDetailPanel';
6
+ export * from './MRT_TableBodyRowPinButton';
7
+ export * from './MRT_TableDetailPanel';
@@ -2,6 +2,7 @@ import { type MouseEvent, type ReactNode, useState } from 'react';
2
2
  import Button from '@mui/material/Button';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { type MRT_Cell, type MRT_TableInstance } from '../types';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
 
6
7
  interface Props<TData extends Record<string, any>> {
7
8
  cell: MRT_Cell<TData>;
@@ -29,24 +30,19 @@ export const MRT_CopyButton = <TData extends Record<string, any>>({
29
30
  setTimeout(() => setCopied(false), 4000);
30
31
  };
31
32
 
32
- const mTableBodyCellCopyButtonProps =
33
- muiCopyButtonProps instanceof Function
34
- ? muiCopyButtonProps({ cell, column, row, table })
35
- : muiCopyButtonProps;
36
-
37
- const mcTableBodyCellCopyButtonProps =
38
- columnDef.muiCopyButtonProps instanceof Function
39
- ? columnDef.muiCopyButtonProps({
40
- cell,
41
- column,
42
- row,
43
- table,
44
- })
45
- : columnDef.muiCopyButtonProps;
46
-
47
33
  const buttonProps = {
48
- ...mTableBodyCellCopyButtonProps,
49
- ...mcTableBodyCellCopyButtonProps,
34
+ ...parseFromValuesOrFunc(muiCopyButtonProps, {
35
+ cell,
36
+ column,
37
+ row,
38
+ table,
39
+ }),
40
+ ...parseFromValuesOrFunc(columnDef.muiCopyButtonProps, {
41
+ cell,
42
+ column,
43
+ row,
44
+ table,
45
+ }),
50
46
  };
51
47
 
52
48
  return (
@@ -78,9 +74,7 @@ export const MRT_CopyButton = <TData extends Record<string, any>>({
78
74
  minWidth: 'unset',
79
75
  textAlign: 'inherit',
80
76
  textTransform: 'inherit',
81
- ...(buttonProps?.sx instanceof Function
82
- ? buttonProps.sx(theme)
83
- : (buttonProps?.sx as any)),
77
+ ...(parseFromValuesOrFunc(buttonProps?.sx, theme) as any),
84
78
  })}
85
79
  title={undefined}
86
80
  >
@@ -1,6 +1,7 @@
1
1
  import IconButton from '@mui/material/IconButton';
2
2
  import Tooltip from '@mui/material/Tooltip';
3
3
  import { type MRT_TableInstance } from '../types';
4
+ import { parseFromValuesOrFunc } from '../column.utils';
4
5
 
5
6
  interface Props<TData extends Record<string, any>> {
6
7
  table: MRT_TableInstance<TData>;
@@ -24,10 +25,9 @@ export const MRT_ExpandAllButton = <TData extends Record<string, any>>({
24
25
  } = table;
25
26
  const { density, isLoading } = getState();
26
27
 
27
- const iconButtonProps =
28
- muiExpandAllButtonProps instanceof Function
29
- ? muiExpandAllButtonProps({ table })
30
- : muiExpandAllButtonProps;
28
+ const iconButtonProps = parseFromValuesOrFunc(muiExpandAllButtonProps, {
29
+ table,
30
+ });
31
31
 
32
32
  const isAllRowsExpanded = getIsAllRowsExpanded();
33
33
 
@@ -54,9 +54,7 @@ export const MRT_ExpandAllButton = <TData extends Record<string, any>>({
54
54
  height: density === 'compact' ? '1.75rem' : '2.25rem',
55
55
  width: density === 'compact' ? '1.75rem' : '2.25rem',
56
56
  mt: density !== 'compact' ? '-0.25rem' : undefined,
57
- ...(iconButtonProps?.sx instanceof Function
58
- ? iconButtonProps?.sx(theme)
59
- : (iconButtonProps?.sx as any)),
57
+ ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
60
58
  })}
61
59
  title={undefined}
62
60
  >
@@ -2,6 +2,7 @@ import { type MouseEvent } from 'react';
2
2
  import IconButton from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { type MRT_Row, type MRT_TableInstance } from '../types';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
 
6
7
  interface Props<TData extends Record<string, any>> {
7
8
  row: MRT_Row<TData>;
@@ -23,10 +24,10 @@ export const MRT_ExpandButton = <TData extends Record<string, any>>({
23
24
  } = table;
24
25
  const { density } = getState();
25
26
 
26
- const iconButtonProps =
27
- muiExpandButtonProps instanceof Function
28
- ? muiExpandButtonProps({ table, row })
29
- : muiExpandButtonProps;
27
+ const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, {
28
+ row,
29
+ table,
30
+ });
30
31
 
31
32
  const canExpand = row.getCanExpand();
32
33
  const isExpanded = row.getIsExpanded();
@@ -58,9 +59,7 @@ export const MRT_ExpandButton = <TData extends Record<string, any>>({
58
59
  sx={(theme) => ({
59
60
  height: density === 'compact' ? '1.75rem' : '2.25rem',
60
61
  width: density === 'compact' ? '1.75rem' : '2.25rem',
61
- ...(iconButtonProps?.sx instanceof Function
62
- ? iconButtonProps.sx(theme)
63
- : (iconButtonProps?.sx as any)),
62
+ ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
64
63
  })}
65
64
  title={undefined}
66
65
  >
@@ -2,6 +2,7 @@ import { type DragEventHandler } from 'react';
2
2
  import IconButton from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { type IconButtonProps } from '@mui/material/IconButton';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
  import { type MRT_TableInstance } from '../types';
6
7
 
7
8
  interface Props<TData extends Record<string, any>> {
@@ -56,9 +57,7 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any>>({
56
57
  '&:active': {
57
58
  cursor: 'grabbing',
58
59
  },
59
- ...(iconButtonProps?.sx instanceof Function
60
- ? iconButtonProps?.sx(theme)
61
- : (iconButtonProps?.sx as any)),
60
+ ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
62
61
  })}
63
62
  title={undefined}
64
63
  >
@@ -0,0 +1,74 @@
1
+ import { useState, type MouseEvent } from 'react';
2
+ import { type RowPinningPosition } from '@tanstack/react-table';
3
+ import IconButton from '@mui/material/IconButton';
4
+ import Tooltip from '@mui/material/Tooltip';
5
+ import { type MRT_Row, type MRT_TableInstance } from '../types';
6
+
7
+ interface Props<TData extends Record<string, any>> {
8
+ row: MRT_Row<TData>;
9
+ table: MRT_TableInstance<TData>;
10
+ pinningPosition: RowPinningPosition;
11
+ }
12
+
13
+ export const MRT_RowPinButton = <TData extends Record<string, any>>({
14
+ row,
15
+ table,
16
+ pinningPosition,
17
+ }: Props<TData>) => {
18
+ const {
19
+ options: {
20
+ icons: { PushPinIcon, CloseIcon },
21
+ localization,
22
+ rowPinningDisplayMode,
23
+ },
24
+ } = table;
25
+
26
+ const isPinned = row.getIsPinned();
27
+
28
+ const [tooltipOpened, setTooltipOpened] = useState(false);
29
+
30
+ const handleTogglePin = (event: MouseEvent<HTMLButtonElement>) => {
31
+ setTooltipOpened(false);
32
+ event.stopPropagation();
33
+ row.pin(isPinned ? false : pinningPosition);
34
+ };
35
+
36
+ return (
37
+ <Tooltip
38
+ arrow
39
+ open={tooltipOpened}
40
+ enterDelay={1000}
41
+ enterNextDelay={1000}
42
+ title={isPinned ? localization.unpin : localization.pin}
43
+ >
44
+ <IconButton
45
+ aria-label={localization.pin}
46
+ onClick={handleTogglePin}
47
+ onMouseEnter={() => setTooltipOpened(true)}
48
+ onMouseLeave={() => setTooltipOpened(false)}
49
+ size="small"
50
+ sx={{
51
+ height: '24px',
52
+ width: '24px',
53
+ }}
54
+ >
55
+ {isPinned ? (
56
+ <CloseIcon />
57
+ ) : (
58
+ <PushPinIcon
59
+ fontSize="small"
60
+ style={{
61
+ transform: `rotate(${
62
+ rowPinningDisplayMode === 'sticky'
63
+ ? 135
64
+ : pinningPosition === 'top'
65
+ ? 180
66
+ : 0
67
+ }deg)`,
68
+ }}
69
+ />
70
+ )}
71
+ </IconButton>
72
+ </Tooltip>
73
+ );
74
+ };
@@ -4,6 +4,7 @@ import Tooltip from '@mui/material/Tooltip';
4
4
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
5
5
  import { MRT_EditActionButtons } from './MRT_EditActionButtons';
6
6
  import { type MRT_Cell, type MRT_Row, type MRT_TableInstance } from '../types';
7
+ import { parseFromValuesOrFunc } from '../column.utils';
7
8
 
8
9
  const commonIconButtonStyles = {
9
10
  height: '2rem',
@@ -73,9 +74,7 @@ export const MRT_ToggleRowActionMenuButton = <
73
74
  ) : showEditActionButtons ? (
74
75
  <MRT_EditActionButtons row={row} table={table} />
75
76
  ) : !renderRowActionMenuItems &&
76
- (enableEditing instanceof Function
77
- ? enableEditing(row)
78
- : enableEditing) ? (
77
+ parseFromValuesOrFunc(enableEditing, row) ? (
79
78
  <Tooltip placement="right" arrow title={localization.edit}>
80
79
  <IconButton
81
80
  aria-label={localization.edit}
@@ -3,10 +3,11 @@ export * from './MRT_CopyButton';
3
3
  export * from './MRT_EditActionButtons';
4
4
  export * from './MRT_ExpandAllButton';
5
5
  export * from './MRT_ExpandButton';
6
- export * from './MRT_ToggleFullScreenButton';
7
6
  export * from './MRT_GrabHandleButton';
7
+ export * from './MRT_RowPinButton';
8
8
  export * from './MRT_ShowHideColumnsButton';
9
9
  export * from './MRT_ToggleDensePaddingButton';
10
10
  export * from './MRT_ToggleFiltersButton';
11
+ export * from './MRT_ToggleFullScreenButton';
11
12
  export * from './MRT_ToggleGlobalFilterButton';
12
13
  export * from './MRT_ToggleRowActionMenuButton';
@@ -94,8 +94,8 @@ export const prepareColumns = <TData extends Record<string, any>>({
94
94
  leafRows: Row<TData>[],
95
95
  childRows: Row<TData>[],
96
96
  ) =>
97
- aggFns.map((fn) =>
98
- aggregationFns[fn]?.(columnId, leafRows, childRows),
97
+ aggFns.map(
98
+ (fn) => aggregationFns[fn]?.(columnId, leafRows, childRows),
99
99
  );
100
100
  }
101
101
 
@@ -152,6 +152,9 @@ export const getLeadingDisplayColumnIds = <TData extends Record<string, any>>(
152
152
  props: MRT_TableOptions<TData>,
153
153
  ) =>
154
154
  [
155
+ props.enableRowPinning &&
156
+ !props.rowPinningDisplayMode?.startsWith('select') &&
157
+ 'mrt-row-pin',
155
158
  (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
156
159
  props.positionActionsColumn === 'first' &&
157
160
  (props.enableRowActions ||
@@ -356,9 +359,7 @@ export const getCommonCellStyles = <TData extends Record<string, any>>({
356
359
  ? 'none'
357
360
  : `padding 150ms ease-in-out`,
358
361
  ...(!table.options.enableColumnResizing && widthStyles), //let devs pass in width styles if column resizing is disabled
359
- ...(tableCellProps?.sx instanceof Function
360
- ? tableCellProps.sx(theme)
361
- : (tableCellProps?.sx as any)),
362
+ ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
362
363
  ...(table.options.enableColumnResizing && widthStyles), //don't let devs pass in width styles if column resizing is enabled
363
364
  };
364
365
  };
@@ -385,6 +386,11 @@ export const MRT_DefaultDisplayColumn = {
385
386
  enableSorting: false,
386
387
  } as const;
387
388
 
389
+ export const parseFromValuesOrFunc = <T, U>(
390
+ fn: T | ((arg: U) => T) | undefined,
391
+ arg: U,
392
+ ): T | undefined => (fn instanceof Function ? fn(arg) : fn);
393
+
388
394
  export const parseCSSVarId = (id: string) => id.replace(/[^a-zA-Z0-9]/g, '_');
389
395
 
390
396
  export const flexRender = _flexRender as (
@@ -2,6 +2,7 @@ import TableFooter from '@mui/material/TableFooter';
2
2
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
3
3
  import { type VirtualItem } from '@tanstack/react-virtual';
4
4
  import { type MRT_TableInstance } from '../types';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
 
6
7
  interface Props<TData extends Record<string, any>> {
7
8
  table: MRT_TableInstance<TData>;
@@ -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;
@@ -45,10 +46,15 @@ export const MRT_TableFooter = <TData extends Record<string, any>>({
45
46
  : undefined,
46
47
  position: stickFooter ? 'sticky' : undefined,
47
48
  zIndex: stickFooter ? 1 : undefined,
48
- ...(tableFooterProps?.sx instanceof Function
49
- ? tableFooterProps?.sx(theme)
50
- : (tableFooterProps?.sx as any)),
49
+ ...(parseFromValuesOrFunc(tableFooterProps?.sx, theme) as any),
51
50
  })}
51
+ ref={(ref: HTMLTableSectionElement) => {
52
+ tableFooterRef.current = ref;
53
+ if (tableFooterProps?.ref) {
54
+ // @ts-ignore
55
+ tableFooterProps.ref.current = ref;
56
+ }
57
+ }}
52
58
  >
53
59
  {getFooterGroups().map((footerGroup) => (
54
60
  <MRT_TableFooterRow
@@ -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 (
@@ -64,13 +57,7 @@ export const MRT_TableFooterCell = <TData extends Record<string, any>>({
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
  </>
@@ -7,6 +7,7 @@ import {
7
7
  type MRT_HeaderGroup,
8
8
  type MRT_TableInstance,
9
9
  } from '../types';
10
+ import { parseFromValuesOrFunc } from '../column.utils';
10
11
 
11
12
  interface Props<TData extends Record<string, any>> {
12
13
  footerGroup: MRT_HeaderGroup<TData>;
@@ -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 ? (
@@ -2,6 +2,7 @@ import TableHead from '@mui/material/TableHead';
2
2
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
3
3
  import { type VirtualItem } from '@tanstack/react-virtual';
4
4
  import { type MRT_TableInstance } from '../types';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
 
6
7
  interface Props<TData extends Record<string, any>> {
7
8
  table: MRT_TableInstance<TData>;
@@ -20,13 +21,11 @@ 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
 
@@ -39,10 +38,15 @@ export const MRT_TableHead = <TData extends Record<string, any>>({
39
38
  position: stickyHeader ? 'sticky' : 'relative',
40
39
  top: stickyHeader && layoutMode === 'grid' ? 0 : undefined,
41
40
  zIndex: stickyHeader ? 2 : undefined,
42
- ...(tableHeadProps?.sx instanceof Function
43
- ? tableHeadProps?.sx(theme)
44
- : (tableHeadProps?.sx as any)),
41
+ ...(parseFromValuesOrFunc(tableHeadProps?.sx, theme) as any),
45
42
  })}
43
+ ref={(ref: HTMLTableSectionElement) => {
44
+ tableHeadRef.current = ref;
45
+ if (tableHeadProps?.ref) {
46
+ // @ts-ignore
47
+ tableHeadProps.ref.current = ref;
48
+ }
49
+ }}
46
50
  >
47
51
  {getHeaderGroups().map((headerGroup) => (
48
52
  <MRT_TableHeadRow
@@ -1,4 +1,4 @@
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';
@@ -10,6 +10,7 @@ import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
10
10
  import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
11
11
  import { getCommonCellStyles } from '../column.utils';
12
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>> {
@@ -47,19 +48,9 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
47
48
  const { columnDef } = column;
48
49
  const { columnDefType } = columnDef;
49
50
 
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
51
  const tableCellProps = {
61
- ...mTableHeadCellProps,
62
- ...mcTableHeadCellProps,
52
+ ...parseFromValuesOrFunc(muiTableHeadCellProps, { column, table }),
53
+ ...parseFromValuesOrFunc(columnDef.muiTableHeadCellProps, { column, table }),
63
54
  };
64
55
 
65
56
  const showColumnActions =
@@ -113,13 +104,11 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
113
104
  };
114
105
 
115
106
  const headerElement =
116
- columnDef?.Header instanceof Function
117
- ? columnDef?.Header?.({
118
- column,
119
- header,
120
- table,
121
- })
122
- : columnDef?.Header ?? (columnDef.header as ReactNode);
107
+ parseFromValuesOrFunc(columnDef.Header, {
108
+ column,
109
+ header,
110
+ table,
111
+ }) ?? columnDef.header;
123
112
 
124
113
  return (
125
114
  <TableCell
@@ -2,6 +2,7 @@ import { type MouseEvent, useState } from 'react';
2
2
  import IconButton from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
5
+ import { parseFromValuesOrFunc } from '../column.utils';
5
6
  import { type MRT_Header, type MRT_TableInstance } from '../types';
6
7
 
7
8
  interface Props<TData extends Record<string, any>> {
@@ -33,22 +34,15 @@ export const MRT_TableHeadCellColumnActionsButton = <
33
34
  setAnchorEl(event.currentTarget);
34
35
  };
35
36
 
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
37
  const iconButtonProps = {
50
- ...mTableHeadCellColumnActionsButtonProps,
51
- ...mcTableHeadCellColumnActionsButtonProps,
38
+ ...parseFromValuesOrFunc(muiColumnActionsButtonProps, {
39
+ column,
40
+ table,
41
+ }),
42
+ ...parseFromValuesOrFunc(columnDef.muiColumnActionsButtonProps, {
43
+ column,
44
+ table,
45
+ }),
52
46
  };
53
47
 
54
48
  return (
@@ -75,9 +69,7 @@ export const MRT_TableHeadCellColumnActionsButton = <
75
69
  '&:hover': {
76
70
  opacity: 1,
77
71
  },
78
- ...(iconButtonProps?.sx instanceof Function
79
- ? iconButtonProps.sx(theme)
80
- : (iconButtonProps?.sx as any)),
72
+ ...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
81
73
  })}
82
74
  title={undefined}
83
75
  >
@@ -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>> {
@@ -24,19 +24,12 @@ export const MRT_TableHeadCellGrabHandle = <TData extends Record<string, any>>({
24
24
  const { columnDef } = column;
25
25
  const { hoveredColumn, draggingColumn, columnOrder } = getState();
26
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;
36
-
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>) => {