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.
- package/dist/cjs/index.js +437 -384
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/cjs/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
- package/dist/cjs/types/body/index.d.ts +1 -0
- package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +9 -0
- package/dist/cjs/types/buttons/index.d.ts +2 -1
- package/dist/cjs/types/column.utils.d.ts +1 -0
- package/dist/cjs/types/types.d.ts +15 -9
- package/dist/esm/material-react-table.esm.js +433 -383
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/esm/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
- package/dist/esm/types/body/index.d.ts +1 -0
- package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +9 -0
- package/dist/esm/types/buttons/index.d.ts +2 -1
- package/dist/esm/types/column.utils.d.ts +1 -0
- package/dist/esm/types/types.d.ts +15 -9
- package/dist/index.d.ts +68 -47
- package/locales/en.esm.js +1 -0
- package/locales/en.esm.js.map +1 -1
- package/locales/en.js +1 -0
- package/locales/en.js.map +1 -1
- package/package.json +9 -9
- package/src/body/MRT_TableBody.tsx +178 -74
- package/src/body/MRT_TableBodyCell.tsx +23 -21
- package/src/body/MRT_TableBodyRow.tsx +104 -16
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +5 -4
- package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
- package/src/body/MRT_TableDetailPanel.tsx +13 -19
- package/src/body/index.ts +2 -1
- package/src/buttons/MRT_CopyButton.tsx +14 -20
- package/src/buttons/MRT_ExpandAllButton.tsx +5 -7
- package/src/buttons/MRT_ExpandButton.tsx +6 -7
- package/src/buttons/MRT_GrabHandleButton.tsx +2 -3
- package/src/buttons/MRT_RowPinButton.tsx +74 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -3
- package/src/buttons/index.ts +2 -1
- package/src/column.utils.ts +11 -5
- package/src/footer/MRT_TableFooter.tsx +13 -7
- package/src/footer/MRT_TableFooterCell.tsx +7 -20
- package/src/footer/MRT_TableFooterRow.tsx +6 -7
- package/src/head/MRT_TableHead.tsx +11 -7
- package/src/head/MRT_TableHeadCell.tsx +9 -20
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -18
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +6 -13
- package/src/head/MRT_TableHeadRow.tsx +6 -7
- package/src/hooks/useMRT_DisplayColumns.tsx +13 -0
- package/src/hooks/useMRT_TableInstance.ts +6 -0
- package/src/hooks/useMRT_TableOptions.ts +6 -2
- package/src/inputs/MRT_EditCellTextField.tsx +14 -22
- package/src/inputs/MRT_FilterCheckbox.tsx +11 -23
- package/src/inputs/MRT_FilterRangeSlider.tsx +6 -23
- package/src/inputs/MRT_FilterTextField.tsx +9 -25
- package/src/inputs/MRT_GlobalFilterTextField.tsx +4 -4
- package/src/inputs/MRT_SelectCheckbox.tsx +31 -17
- package/src/locales/en.ts +1 -1
- package/src/menus/MRT_RowActionMenu.tsx +11 -12
- package/src/modals/MRT_EditRowModal.tsx +5 -13
- package/src/table/MRT_Table.tsx +8 -13
- package/src/table/MRT_TableContainer.tsx +6 -12
- package/src/table/MRT_TablePaper.tsx +9 -13
- package/src/toolbar/MRT_BottomToolbar.tsx +14 -20
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -4
- package/src/toolbar/MRT_TablePagination.tsx +5 -7
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +8 -11
- package/src/toolbar/MRT_TopToolbar.tsx +8 -14
- package/src/types.ts +25 -8
- package/locales/tr.d.ts +0 -2
- package/locales/tr.esm.d.ts +0 -2
- package/locales/tr.esm.js +0 -93
- package/locales/tr.esm.js.map +0 -1
- package/locales/tr.js +0 -97
- package/locales/tr.js.map +0 -1
- package/locales/uk.d.ts +0 -2
- package/locales/uk.esm.d.ts +0 -2
- package/locales/uk.esm.js +0 -93
- package/locales/uk.esm.js.map +0 -1
- package/locales/uk.js +0 -97
- package/locales/uk.js.map +0 -1
- package/locales/vi.d.ts +0 -2
- package/locales/vi.esm.d.ts +0 -2
- package/locales/vi.esm.js +0 -93
- package/locales/vi.esm.js.map +0 -1
- package/locales/vi.js +0 -97
- package/locales/vi.js.map +0 -1
- package/locales/zh-Hans.d.ts +0 -2
- package/locales/zh-Hans.esm.d.ts +0 -2
- package/locales/zh-Hans.esm.js +0 -93
- package/locales/zh-Hans.esm.js.map +0 -1
- package/locales/zh-Hans.js +0 -97
- package/locales/zh-Hans.js.map +0 -1
- package/locales/zh-Hant.d.ts +0 -2
- package/locales/zh-Hant.esm.d.ts +0 -2
- package/locales/zh-Hant.esm.js +0 -93
- package/locales/zh-Hant.esm.js.map +0 -1
- package/locales/zh-Hant.js +0 -97
- 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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
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
|
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 './
|
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
|
-
...
|
49
|
-
|
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
|
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
|
-
|
29
|
-
|
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
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
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
|
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
|
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}
|
package/src/buttons/index.ts
CHANGED
@@ -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';
|
package/src/column.utils.ts
CHANGED
@@ -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(
|
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
|
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
|
-
|
28
|
-
|
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
|
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
|
-
...
|
35
|
-
...
|
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
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
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
|
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,
|
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
|
-
...
|
62
|
-
...
|
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
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
...
|
51
|
-
|
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
|
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
|
-
...
|
39
|
-
...
|
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>) => {
|