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.
- package/README.md +2 -2
- package/dist/cjs/index.js +2480 -2392
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +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_GrabHandleButton.d.ts +1 -1
- 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 +7 -6
- package/dist/cjs/types/filterFns.d.ts +14 -14
- package/dist/cjs/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/cjs/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/cjs/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
- package/dist/cjs/types/icons.d.ts +1 -1
- package/dist/cjs/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
- package/dist/cjs/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
- package/dist/cjs/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/cjs/types/toolbar/MRT_TopToolbar.d.ts +1 -1
- package/dist/cjs/types/types.d.ts +203 -197
- package/dist/esm/material-react-table.esm.js +2442 -2358
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +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_GrabHandleButton.d.ts +1 -1
- 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 +7 -6
- package/dist/esm/types/filterFns.d.ts +14 -14
- package/dist/esm/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/esm/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/esm/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
- package/dist/esm/types/icons.d.ts +1 -1
- package/dist/esm/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
- package/dist/esm/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
- package/dist/esm/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/esm/types/toolbar/MRT_TopToolbar.d.ts +1 -1
- package/dist/esm/types/types.d.ts +203 -197
- package/dist/index.d.ts +293 -272
- 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/locales/fr.esm.js +1 -1
- package/locales/fr.esm.js.map +1 -1
- package/locales/fr.js +1 -1
- package/locales/fr.js.map +1 -1
- package/package.json +10 -9
- package/src/MaterialReactTable.tsx +2 -2
- package/src/body/MRT_TableBody.tsx +180 -76
- package/src/body/MRT_TableBodyCell.tsx +45 -43
- package/src/body/MRT_TableBodyCellValue.tsx +5 -5
- package/src/body/MRT_TableBodyRow.tsx +117 -29
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +6 -5
- package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
- package/src/body/MRT_TableDetailPanel.tsx +16 -22
- package/src/body/index.ts +2 -1
- package/src/buttons/MRT_CopyButton.tsx +14 -20
- package/src/buttons/MRT_EditActionButtons.tsx +4 -4
- package/src/buttons/MRT_ExpandAllButton.tsx +7 -9
- package/src/buttons/MRT_ExpandButton.tsx +6 -7
- package/src/buttons/MRT_GrabHandleButton.tsx +12 -13
- package/src/buttons/MRT_RowPinButton.tsx +74 -0
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -1
- package/src/buttons/MRT_ToggleFullScreenButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +9 -10
- package/src/buttons/index.ts +2 -1
- package/src/column.utils.ts +33 -21
- package/src/filterFns.ts +29 -29
- package/src/footer/MRT_TableFooter.tsx +14 -8
- package/src/footer/MRT_TableFooterCell.tsx +8 -21
- package/src/footer/MRT_TableFooterRow.tsx +7 -8
- package/src/head/MRT_TableHead.tsx +12 -8
- package/src/head/MRT_TableHeadCell.tsx +18 -25
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +18 -23
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +11 -4
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +106 -61
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +8 -15
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +11 -11
- package/src/head/MRT_TableHeadCellSortLabel.tsx +8 -8
- package/src/head/MRT_TableHeadRow.tsx +7 -8
- package/src/hooks/useMRT_DisplayColumns.tsx +17 -4
- package/src/hooks/useMRT_Effects.ts +3 -3
- package/src/hooks/useMRT_TableInstance.ts +17 -10
- package/src/hooks/useMRT_TableOptions.ts +9 -5
- package/src/icons.ts +2 -2
- package/src/inputs/MRT_EditCellTextField.tsx +23 -31
- package/src/inputs/MRT_FilterCheckbox.tsx +17 -29
- package/src/inputs/MRT_FilterRangeFields.tsx +1 -1
- package/src/inputs/MRT_FilterRangeSlider.tsx +12 -29
- package/src/inputs/MRT_FilterTextField.tsx +83 -99
- package/src/inputs/MRT_GlobalFilterTextField.tsx +29 -29
- package/src/inputs/MRT_SelectCheckbox.tsx +35 -21
- package/src/locales/en.ts +1 -1
- package/src/locales/fr.ts +1 -1
- package/src/menus/MRT_ColumnActionMenu.tsx +14 -14
- package/src/menus/MRT_FilterOptionMenu.tsx +35 -35
- package/src/menus/MRT_RowActionMenu.tsx +17 -18
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -6
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +5 -5
- package/src/modals/MRT_EditRowModal.tsx +12 -20
- package/src/sortingFns.ts +1 -1
- package/src/table/MRT_Table.tsx +14 -19
- package/src/table/MRT_TableContainer.tsx +14 -20
- package/src/table/MRT_TablePaper.tsx +16 -20
- package/src/toolbar/MRT_BottomToolbar.tsx +18 -24
- package/src/toolbar/MRT_LinearProgressBar.tsx +8 -7
- package/src/toolbar/MRT_TablePagination.tsx +23 -25
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +11 -14
- package/src/toolbar/MRT_ToolbarDropZone.tsx +6 -6
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -5
- package/src/toolbar/MRT_TopToolbar.tsx +14 -20
- package/src/types.ts +269 -252
- package/src/useMaterialReactTable.ts +1 -1
@@ -1,8 +1,8 @@
|
|
1
1
|
import Box from '@mui/material/Box';
|
2
2
|
import Button from '@mui/material/Button';
|
3
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
3
4
|
import IconButton from '@mui/material/IconButton';
|
4
5
|
import Tooltip from '@mui/material/Tooltip';
|
5
|
-
import CircularProgress from '@mui/material/CircularProgress';
|
6
6
|
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
7
7
|
|
8
8
|
interface Props<TData extends Record<string, any>> {
|
@@ -23,8 +23,8 @@ export const MRT_EditActionButtons = <TData extends Record<string, any>>({
|
|
23
23
|
localization,
|
24
24
|
onCreatingRowCancel,
|
25
25
|
onCreatingRowSave,
|
26
|
-
onEditingRowSave,
|
27
26
|
onEditingRowCancel,
|
27
|
+
onEditingRowSave,
|
28
28
|
},
|
29
29
|
refs: { editInputRefs },
|
30
30
|
setCreatingRow,
|
@@ -100,12 +100,12 @@ export const MRT_EditActionButtons = <TData extends Record<string, any>>({
|
|
100
100
|
</>
|
101
101
|
) : (
|
102
102
|
<>
|
103
|
-
<Button sx={{ minWidth: '100px' }}
|
103
|
+
<Button onClick={handleCancel} sx={{ minWidth: '100px' }}>
|
104
104
|
{localization.cancel}
|
105
105
|
</Button>
|
106
106
|
<Button
|
107
|
-
sx={{ minWidth: '100px' }}
|
108
107
|
onClick={handleSubmitRow}
|
108
|
+
sx={{ minWidth: '100px' }}
|
109
109
|
variant="contained"
|
110
110
|
>
|
111
111
|
{isSaving && <CircularProgress color="inherit" size={18} />}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import IconButton from '@mui/material/IconButton';
|
2
2
|
import Tooltip from '@mui/material/Tooltip';
|
3
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
3
4
|
import { type MRT_TableInstance } from '../types';
|
4
5
|
|
5
6
|
interface Props<TData extends Record<string, any>> {
|
@@ -10,9 +11,9 @@ export const MRT_ExpandAllButton = <TData extends Record<string, any>>({
|
|
10
11
|
table,
|
11
12
|
}: Props<TData>) => {
|
12
13
|
const {
|
14
|
+
getCanSomeRowsExpand,
|
13
15
|
getIsAllRowsExpanded,
|
14
16
|
getIsSomeRowsExpanded,
|
15
|
-
getCanSomeRowsExpand,
|
16
17
|
getState,
|
17
18
|
options: {
|
18
19
|
icons: { KeyboardDoubleArrowDownIcon },
|
@@ -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
|
|
@@ -52,11 +52,9 @@ export const MRT_ExpandAllButton = <TData extends Record<string, any>>({
|
|
52
52
|
{...iconButtonProps}
|
53
53
|
sx={(theme) => ({
|
54
54
|
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
55
|
-
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
56
55
|
mt: density !== 'compact' ? '-0.25rem' : undefined,
|
57
|
-
|
58
|
-
|
59
|
-
: (iconButtonProps?.sx as any)),
|
56
|
+
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
57
|
+
...(parseFromValuesOrFunc(iconButtonProps?.sx, theme) as any),
|
60
58
|
})}
|
61
59
|
title={undefined}
|
62
60
|
>
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { type MouseEvent } 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 { type MRT_Row, type MRT_TableInstance } from '../types';
|
5
6
|
|
6
7
|
interface Props<TData extends Record<string, any>> {
|
@@ -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
|
>
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import { type DragEventHandler } from 'react';
|
2
2
|
import IconButton from '@mui/material/IconButton';
|
3
|
-
import Tooltip from '@mui/material/Tooltip';
|
4
3
|
import { type IconButtonProps } from '@mui/material/IconButton';
|
4
|
+
import Tooltip from '@mui/material/Tooltip';
|
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>> {
|
8
9
|
iconButtonProps?: IconButtonProps;
|
9
|
-
onDragStart: DragEventHandler<HTMLButtonElement>;
|
10
10
|
onDragEnd: DragEventHandler<HTMLButtonElement>;
|
11
|
+
onDragStart: DragEventHandler<HTMLButtonElement>;
|
11
12
|
table: MRT_TableInstance<TData>;
|
12
13
|
}
|
13
14
|
|
@@ -41,24 +42,22 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any>>({
|
|
41
42
|
e.stopPropagation();
|
42
43
|
iconButtonProps?.onClick?.(e);
|
43
44
|
}}
|
44
|
-
onDragStart={onDragStart}
|
45
45
|
onDragEnd={onDragEnd}
|
46
|
+
onDragStart={onDragStart}
|
46
47
|
sx={(theme) => ({
|
48
|
+
'&:active': {
|
49
|
+
cursor: 'grabbing',
|
50
|
+
},
|
51
|
+
'&:hover': {
|
52
|
+
backgroundColor: 'transparent',
|
53
|
+
opacity: 1,
|
54
|
+
},
|
47
55
|
cursor: 'grab',
|
48
56
|
m: '0 -0.1rem',
|
49
57
|
opacity: 0.5,
|
50
58
|
p: '2px',
|
51
59
|
transition: 'all 150ms ease-in-out',
|
52
|
-
|
53
|
-
backgroundColor: 'transparent',
|
54
|
-
opacity: 1,
|
55
|
-
},
|
56
|
-
'&:active': {
|
57
|
-
cursor: 'grabbing',
|
58
|
-
},
|
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 { type MouseEvent, useState } 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
|
+
pinningPosition: RowPinningPosition;
|
9
|
+
row: MRT_Row<TData>;
|
10
|
+
table: MRT_TableInstance<TData>;
|
11
|
+
}
|
12
|
+
|
13
|
+
export const MRT_RowPinButton = <TData extends Record<string, any>>({
|
14
|
+
pinningPosition,
|
15
|
+
row,
|
16
|
+
table,
|
17
|
+
}: Props<TData>) => {
|
18
|
+
const {
|
19
|
+
options: {
|
20
|
+
icons: { CloseIcon, PushPinIcon },
|
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
|
+
enterDelay={1000}
|
40
|
+
enterNextDelay={1000}
|
41
|
+
open={tooltipOpened}
|
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
|
+
};
|
@@ -20,7 +20,7 @@ export const MRT_ShowHideColumnsButton = <TData extends Record<string, any>>({
|
|
20
20
|
},
|
21
21
|
} = table;
|
22
22
|
|
23
|
-
const [anchorEl, setAnchorEl] = useState<
|
23
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
24
24
|
|
25
25
|
const handleClick = (event: MouseEvent<HTMLElement>) => {
|
26
26
|
setAnchorEl(event.currentTarget);
|
@@ -1,8 +1,8 @@
|
|
1
|
+
import { useState } from 'react';
|
1
2
|
import IconButton from '@mui/material/IconButton';
|
2
3
|
import { type IconButtonProps } from '@mui/material/IconButton';
|
3
4
|
import Tooltip from '@mui/material/Tooltip';
|
4
5
|
import { type MRT_TableInstance } from '../types';
|
5
|
-
import { useState } from 'react';
|
6
6
|
|
7
7
|
interface Props<TData extends Record<string, any>> extends IconButtonProps {
|
8
8
|
table: MRT_TableInstance<TData>;
|
@@ -31,8 +31,8 @@ export const MRT_ToggleFullScreenButton = <TData extends Record<string, any>>({
|
|
31
31
|
|
32
32
|
return (
|
33
33
|
<Tooltip
|
34
|
-
open={tooltipOpened}
|
35
34
|
arrow
|
35
|
+
open={tooltipOpened}
|
36
36
|
title={rest?.title ?? localization.toggleFullScreen}
|
37
37
|
>
|
38
38
|
<IconButton
|
@@ -1,19 +1,20 @@
|
|
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 { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
|
5
4
|
import { MRT_EditActionButtons } from './MRT_EditActionButtons';
|
5
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
6
|
+
import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
|
6
7
|
import { type MRT_Cell, type MRT_Row, type MRT_TableInstance } from '../types';
|
7
8
|
|
8
9
|
const commonIconButtonStyles = {
|
10
|
+
'&:hover': {
|
11
|
+
opacity: 1,
|
12
|
+
},
|
9
13
|
height: '2rem',
|
10
14
|
ml: '10px',
|
11
15
|
opacity: 0.5,
|
12
16
|
transition: 'opacity 150ms',
|
13
17
|
width: '2rem',
|
14
|
-
'&:hover': {
|
15
|
-
opacity: 1,
|
16
|
-
},
|
17
18
|
};
|
18
19
|
|
19
20
|
interface Props<TData extends Record<string, any>> {
|
@@ -52,7 +53,7 @@ export const MRT_ToggleRowActionMenuButton = <
|
|
52
53
|
(isCreating && createDisplayMode === 'row') ||
|
53
54
|
(isEditing && editDisplayMode === 'row');
|
54
55
|
|
55
|
-
const [anchorEl, setAnchorEl] = useState<
|
56
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
56
57
|
|
57
58
|
const handleOpenRowActionMenu = (event: MouseEvent<HTMLElement>) => {
|
58
59
|
event.stopPropagation();
|
@@ -73,14 +74,12 @@ export const MRT_ToggleRowActionMenuButton = <
|
|
73
74
|
) : showEditActionButtons ? (
|
74
75
|
<MRT_EditActionButtons row={row} table={table} />
|
75
76
|
) : !renderRowActionMenuItems &&
|
76
|
-
(enableEditing
|
77
|
-
|
78
|
-
: enableEditing) ? (
|
79
|
-
<Tooltip placement="right" arrow title={localization.edit}>
|
77
|
+
parseFromValuesOrFunc(enableEditing, row) ? (
|
78
|
+
<Tooltip arrow placement="right" title={localization.edit}>
|
80
79
|
<IconButton
|
81
80
|
aria-label={localization.edit}
|
82
|
-
sx={commonIconButtonStyles}
|
83
81
|
onClick={handleStartEditMode}
|
82
|
+
sx={commonIconButtonStyles}
|
84
83
|
>
|
85
84
|
<EditIcon />
|
86
85
|
</IconButton>
|
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
@@ -1,18 +1,17 @@
|
|
1
1
|
import { type ReactNode } from 'react';
|
2
2
|
import {
|
3
|
-
type Row,
|
4
|
-
type Renderable,
|
5
|
-
flexRender as _flexRender,
|
6
3
|
createRow as _createRow,
|
4
|
+
flexRender as _flexRender,
|
5
|
+
type Renderable,
|
6
|
+
type Row,
|
7
7
|
} from '@tanstack/react-table';
|
8
|
+
import { type TableCellProps } from '@mui/material/TableCell';
|
8
9
|
import { alpha, lighten } from '@mui/material/styles';
|
10
|
+
import { type Theme } from '@mui/material/styles';
|
9
11
|
import { type MRT_AggregationFns } from './aggregationFns';
|
10
12
|
import { type MRT_FilterFns } from './filterFns';
|
11
13
|
import { type MRT_SortingFns } from './sortingFns';
|
12
|
-
import { type TableCellProps } from '@mui/material/TableCell';
|
13
|
-
import { type Theme } from '@mui/material/styles';
|
14
14
|
import {
|
15
|
-
type MRT_TableOptions,
|
16
15
|
type MRT_Column,
|
17
16
|
type MRT_ColumnDef,
|
18
17
|
type MRT_ColumnOrderState,
|
@@ -21,8 +20,9 @@ import {
|
|
21
20
|
type MRT_FilterOption,
|
22
21
|
type MRT_GroupingState,
|
23
22
|
type MRT_Header,
|
24
|
-
type MRT_TableInstance,
|
25
23
|
type MRT_Row,
|
24
|
+
type MRT_TableInstance,
|
25
|
+
type MRT_TableOptions,
|
26
26
|
} from './types';
|
27
27
|
|
28
28
|
export const getColumnId = <TData extends Record<string, any>>(
|
@@ -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,11 +152,14 @@ 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 ||
|
158
161
|
(props.enableEditing &&
|
159
|
-
['
|
162
|
+
['modal', 'row'].includes(props.editDisplayMode ?? ''))) &&
|
160
163
|
'mrt-row-actions',
|
161
164
|
props.positionExpandColumn === 'first' &&
|
162
165
|
showExpandColumn(props) &&
|
@@ -172,7 +175,7 @@ export const getTrailingDisplayColumnIds = <TData extends Record<string, any>>(
|
|
172
175
|
props.positionActionsColumn === 'last' &&
|
173
176
|
(props.enableRowActions ||
|
174
177
|
(props.enableEditing &&
|
175
|
-
['
|
178
|
+
['modal', 'row'].includes(props.editDisplayMode ?? ''))) &&
|
176
179
|
'mrt-row-actions',
|
177
180
|
props.positionExpandColumn === 'last' &&
|
178
181
|
showExpandColumn(props) &&
|
@@ -215,15 +218,21 @@ export const getIsFirstColumn = <TData extends Record<string, any>>(
|
|
215
218
|
column: MRT_Column<TData>,
|
216
219
|
table: MRT_TableInstance<TData>,
|
217
220
|
) => {
|
218
|
-
|
221
|
+
const leftColumns = table.getLeftVisibleLeafColumns();
|
222
|
+
return leftColumns.length
|
223
|
+
? leftColumns[0].id === column.id
|
224
|
+
: table.getVisibleLeafColumns()[0].id === column.id;
|
219
225
|
};
|
220
226
|
|
221
227
|
export const getIsLastColumn = <TData extends Record<string, any>>(
|
222
228
|
column: MRT_Column<TData>,
|
223
229
|
table: MRT_TableInstance<TData>,
|
224
230
|
) => {
|
231
|
+
const rightColumns = table.getRightVisibleLeafColumns();
|
225
232
|
const columns = table.getVisibleLeafColumns();
|
226
|
-
return
|
233
|
+
return rightColumns.length
|
234
|
+
? rightColumns[rightColumns.length - 1].id === column.id
|
235
|
+
: columns[columns.length - 1].id === column.id;
|
227
236
|
};
|
228
237
|
|
229
238
|
export const getIsLastLeftPinnedColumn = <TData extends Record<string, any>>(
|
@@ -255,15 +264,15 @@ export const getTotalRight = <TData extends Record<string, any>>(
|
|
255
264
|
export const getCanRankRows = <TData extends Record<string, any>>(
|
256
265
|
table: MRT_TableInstance<TData>,
|
257
266
|
) => {
|
258
|
-
const {
|
267
|
+
const { getState, options } = table;
|
259
268
|
const {
|
269
|
+
enableGlobalFilterRankedResults,
|
260
270
|
manualExpanding,
|
261
271
|
manualFiltering,
|
262
272
|
manualGrouping,
|
263
273
|
manualSorting,
|
264
|
-
enableGlobalFilterRankedResults,
|
265
274
|
} = options;
|
266
|
-
const {
|
275
|
+
const { expanded, globalFilterFn } = getState();
|
267
276
|
|
268
277
|
return (
|
269
278
|
!manualExpanding &&
|
@@ -356,17 +365,15 @@ export const getCommonCellStyles = <TData extends Record<string, any>>({
|
|
356
365
|
? 'none'
|
357
366
|
: `padding 150ms ease-in-out`,
|
358
367
|
...(!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)),
|
368
|
+
...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
|
362
369
|
...(table.options.enableColumnResizing && widthStyles), //don't let devs pass in width styles if column resizing is enabled
|
363
370
|
};
|
364
371
|
};
|
365
372
|
|
366
373
|
export const MRT_DefaultColumn = {
|
367
374
|
filterVariant: 'text',
|
368
|
-
minSize: 40,
|
369
375
|
maxSize: 1000,
|
376
|
+
minSize: 40,
|
370
377
|
size: 180,
|
371
378
|
} as const;
|
372
379
|
|
@@ -385,12 +392,17 @@ export const MRT_DefaultDisplayColumn = {
|
|
385
392
|
enableSorting: false,
|
386
393
|
} as const;
|
387
394
|
|
395
|
+
export const parseFromValuesOrFunc = <T, U>(
|
396
|
+
fn: ((arg: U) => T) | T | undefined,
|
397
|
+
arg: U,
|
398
|
+
): T | undefined => (fn instanceof Function ? fn(arg) : fn);
|
399
|
+
|
388
400
|
export const parseCSSVarId = (id: string) => id.replace(/[^a-zA-Z0-9]/g, '_');
|
389
401
|
|
390
402
|
export const flexRender = _flexRender as (
|
391
403
|
Comp: Renderable<any>,
|
392
404
|
props: any,
|
393
|
-
) =>
|
405
|
+
) => JSX.Element | ReactNode;
|
394
406
|
|
395
407
|
export const createRow = <TData extends Record<string, any>>(
|
396
408
|
table: MRT_TableInstance<TData>,
|
package/src/filterFns.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import {
|
2
|
+
type RankingInfo,
|
2
3
|
rankItem,
|
3
4
|
rankings,
|
4
|
-
type RankingInfo,
|
5
5
|
} from '@tanstack/match-sorter-utils';
|
6
|
-
import {
|
6
|
+
import { type Row, filterFns } from '@tanstack/react-table';
|
7
7
|
|
8
8
|
const fuzzy = <TData extends Record<string, any>>(
|
9
9
|
row: Row<TData>,
|
10
10
|
columnId: string,
|
11
|
-
filterValue:
|
11
|
+
filterValue: number | string,
|
12
12
|
addMeta: (item: RankingInfo) => void,
|
13
13
|
) => {
|
14
14
|
const itemRank = rankItem(row.getValue(columnId), filterValue as string, {
|
@@ -23,10 +23,10 @@ fuzzy.autoRemove = (val: any) => !val;
|
|
23
23
|
const contains = <TData extends Record<string, any>>(
|
24
24
|
row: Row<TData>,
|
25
25
|
id: string,
|
26
|
-
filterValue:
|
26
|
+
filterValue: number | string,
|
27
27
|
) =>
|
28
28
|
row
|
29
|
-
.getValue<
|
29
|
+
.getValue<number | string>(id)
|
30
30
|
.toString()
|
31
31
|
.toLowerCase()
|
32
32
|
.trim()
|
@@ -37,10 +37,10 @@ contains.autoRemove = (val: any) => !val;
|
|
37
37
|
const startsWith = <TData extends Record<string, any>>(
|
38
38
|
row: Row<TData>,
|
39
39
|
id: string,
|
40
|
-
filterValue:
|
40
|
+
filterValue: number | string,
|
41
41
|
) =>
|
42
42
|
row
|
43
|
-
.getValue<
|
43
|
+
.getValue<number | string>(id)
|
44
44
|
.toString()
|
45
45
|
.toLowerCase()
|
46
46
|
.trim()
|
@@ -51,10 +51,10 @@ startsWith.autoRemove = (val: any) => !val;
|
|
51
51
|
const endsWith = <TData extends Record<string, any>>(
|
52
52
|
row: Row<TData>,
|
53
53
|
id: string,
|
54
|
-
filterValue:
|
54
|
+
filterValue: number | string,
|
55
55
|
) =>
|
56
56
|
row
|
57
|
-
.getValue<
|
57
|
+
.getValue<number | string>(id)
|
58
58
|
.toString()
|
59
59
|
.toLowerCase()
|
60
60
|
.trim()
|
@@ -65,9 +65,9 @@ endsWith.autoRemove = (val: any) => !val;
|
|
65
65
|
const equals = <TData extends Record<string, any>>(
|
66
66
|
row: Row<TData>,
|
67
67
|
id: string,
|
68
|
-
filterValue:
|
68
|
+
filterValue: number | string,
|
69
69
|
) =>
|
70
|
-
row.getValue<
|
70
|
+
row.getValue<number | string>(id).toString().toLowerCase().trim() ===
|
71
71
|
filterValue.toString().toLowerCase().trim();
|
72
72
|
|
73
73
|
equals.autoRemove = (val: any) => !val;
|
@@ -75,9 +75,9 @@ equals.autoRemove = (val: any) => !val;
|
|
75
75
|
const notEquals = <TData extends Record<string, any>>(
|
76
76
|
row: Row<TData>,
|
77
77
|
id: string,
|
78
|
-
filterValue:
|
78
|
+
filterValue: number | string,
|
79
79
|
) =>
|
80
|
-
row.getValue<
|
80
|
+
row.getValue<number | string>(id).toString().toLowerCase().trim() !==
|
81
81
|
filterValue.toString().toLowerCase().trim();
|
82
82
|
|
83
83
|
notEquals.autoRemove = (val: any) => !val;
|
@@ -85,11 +85,11 @@ notEquals.autoRemove = (val: any) => !val;
|
|
85
85
|
const greaterThan = <TData extends Record<string, any>>(
|
86
86
|
row: Row<TData>,
|
87
87
|
id: string,
|
88
|
-
filterValue:
|
88
|
+
filterValue: number | string,
|
89
89
|
) =>
|
90
|
-
!isNaN(+filterValue) && !isNaN(+row.getValue<
|
91
|
-
? +row.getValue<
|
92
|
-
: row.getValue<
|
90
|
+
!isNaN(+filterValue) && !isNaN(+row.getValue<number | string>(id))
|
91
|
+
? +row.getValue<number | string>(id) > +filterValue
|
92
|
+
: row.getValue<number | string>(id).toString().toLowerCase().trim() >
|
93
93
|
filterValue.toString().toLowerCase().trim();
|
94
94
|
|
95
95
|
greaterThan.autoRemove = (val: any) => !val;
|
@@ -97,7 +97,7 @@ greaterThan.autoRemove = (val: any) => !val;
|
|
97
97
|
const greaterThanOrEqualTo = <TData extends Record<string, any>>(
|
98
98
|
row: Row<TData>,
|
99
99
|
id: string,
|
100
|
-
filterValue:
|
100
|
+
filterValue: number | string,
|
101
101
|
) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
|
102
102
|
|
103
103
|
greaterThanOrEqualTo.autoRemove = (val: any) => !val;
|
@@ -105,11 +105,11 @@ greaterThanOrEqualTo.autoRemove = (val: any) => !val;
|
|
105
105
|
const lessThan = <TData extends Record<string, any>>(
|
106
106
|
row: Row<TData>,
|
107
107
|
id: string,
|
108
|
-
filterValue:
|
108
|
+
filterValue: number | string,
|
109
109
|
) =>
|
110
|
-
!isNaN(+filterValue) && !isNaN(+row.getValue<
|
111
|
-
? +row.getValue<
|
112
|
-
: row.getValue<
|
110
|
+
!isNaN(+filterValue) && !isNaN(+row.getValue<number | string>(id))
|
111
|
+
? +row.getValue<number | string>(id) < +filterValue
|
112
|
+
: row.getValue<number | string>(id).toString().toLowerCase().trim() <
|
113
113
|
filterValue.toString().toLowerCase().trim();
|
114
114
|
|
115
115
|
lessThan.autoRemove = (val: any) => !val;
|
@@ -117,7 +117,7 @@ lessThan.autoRemove = (val: any) => !val;
|
|
117
117
|
const lessThanOrEqualTo = <TData extends Record<string, any>>(
|
118
118
|
row: Row<TData>,
|
119
119
|
id: string,
|
120
|
-
filterValue:
|
120
|
+
filterValue: number | string,
|
121
121
|
) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
|
122
122
|
|
123
123
|
lessThanOrEqualTo.autoRemove = (val: any) => !val;
|
@@ -125,7 +125,7 @@ lessThanOrEqualTo.autoRemove = (val: any) => !val;
|
|
125
125
|
const between = <TData extends Record<string, any>>(
|
126
126
|
row: Row<TData>,
|
127
127
|
id: string,
|
128
|
-
filterValues: [
|
128
|
+
filterValues: [number | string, number | string],
|
129
129
|
) =>
|
130
130
|
((['', undefined] as any[]).includes(filterValues[0]) ||
|
131
131
|
greaterThan(row, id, filterValues[0])) &&
|
@@ -140,7 +140,7 @@ between.autoRemove = (val: any) => !val;
|
|
140
140
|
const betweenInclusive = <TData extends Record<string, any>>(
|
141
141
|
row: Row<TData>,
|
142
142
|
id: string,
|
143
|
-
filterValues: [
|
143
|
+
filterValues: [number | string, number | string],
|
144
144
|
) =>
|
145
145
|
((['', undefined] as any[]).includes(filterValues[0]) ||
|
146
146
|
greaterThanOrEqualTo(row, id, filterValues[0])) &&
|
@@ -155,16 +155,16 @@ betweenInclusive.autoRemove = (val: any) => !val;
|
|
155
155
|
const empty = <TData extends Record<string, any>>(
|
156
156
|
row: Row<TData>,
|
157
157
|
id: string,
|
158
|
-
_filterValue:
|
159
|
-
) => !row.getValue<
|
158
|
+
_filterValue: number | string,
|
159
|
+
) => !row.getValue<number | string>(id).toString().trim();
|
160
160
|
|
161
161
|
empty.autoRemove = (val: any) => !val;
|
162
162
|
|
163
163
|
const notEmpty = <TData extends Record<string, any>>(
|
164
164
|
row: Row<TData>,
|
165
165
|
id: string,
|
166
|
-
_filterValue:
|
167
|
-
) => !!row.getValue<
|
166
|
+
_filterValue: number | string,
|
167
|
+
) => !!row.getValue<number | string>(id).toString().trim();
|
168
168
|
|
169
169
|
notEmpty.autoRemove = (val: any) => !val;
|
170
170
|
|