material-react-table 0.33.6 → 0.35.0
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/MaterialReactTable.d.ts +45 -53
- package/dist/cjs/buttons/MRT_ColumnPinningButtons.d.ts +4 -5
- package/dist/cjs/buttons/MRT_FullScreenToggleButton.d.ts +3 -4
- package/dist/cjs/buttons/MRT_GrabHandleButton.d.ts +4 -4
- package/dist/cjs/buttons/MRT_ShowHideColumnsButton.d.ts +3 -4
- package/dist/cjs/buttons/MRT_ToggleDensePaddingButton.d.ts +3 -4
- package/dist/cjs/buttons/MRT_ToggleFiltersButton.d.ts +3 -4
- package/dist/cjs/buttons/MRT_ToggleGlobalFilterButton.d.ts +3 -4
- package/dist/cjs/index.d.ts +8 -2
- package/dist/cjs/index.js +651 -140
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_GlobalFilterTextField.d.ts +3 -4
- package/dist/cjs/menus/MRT_FilterOptionMenu.d.ts +3 -4
- package/dist/cjs/menus/MRT_ShowHideColumnsMenu.d.ts +3 -4
- package/dist/cjs/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -8
- package/dist/cjs/table/MRT_TableRoot.d.ts +0 -1
- package/dist/cjs/toolbar/MRT_ToolbarInternalButtons.d.ts +1 -1
- package/dist/esm/MaterialReactTable.d.ts +45 -53
- package/dist/esm/buttons/MRT_ColumnPinningButtons.d.ts +4 -5
- package/dist/esm/buttons/MRT_FullScreenToggleButton.d.ts +3 -4
- package/dist/esm/buttons/MRT_GrabHandleButton.d.ts +4 -4
- package/dist/esm/buttons/MRT_ShowHideColumnsButton.d.ts +3 -4
- package/dist/esm/buttons/MRT_ToggleDensePaddingButton.d.ts +3 -4
- package/dist/esm/buttons/MRT_ToggleFiltersButton.d.ts +3 -4
- package/dist/esm/buttons/MRT_ToggleGlobalFilterButton.d.ts +3 -4
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/inputs/MRT_GlobalFilterTextField.d.ts +3 -4
- package/dist/esm/material-react-table.esm.js +644 -141
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/menus/MRT_FilterOptionMenu.d.ts +3 -4
- package/dist/esm/menus/MRT_ShowHideColumnsMenu.d.ts +3 -4
- package/dist/esm/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -8
- package/dist/esm/table/MRT_TableRoot.d.ts +0 -1
- package/dist/esm/toolbar/MRT_ToolbarInternalButtons.d.ts +1 -1
- package/dist/index.d.ts +76 -54
- package/package.json +5 -5
- package/src/MaterialReactTable.tsx +49 -50
- package/src/body/MRT_TableBody.tsx +30 -11
- package/src/body/MRT_TableBodyCell.tsx +17 -18
- package/src/body/MRT_TableBodyRow.tsx +7 -10
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +5 -5
- package/src/buttons/MRT_ColumnPinningButtons.tsx +10 -5
- package/src/buttons/MRT_EditActionButtons.tsx +10 -6
- package/src/buttons/MRT_FullScreenToggleButton.tsx +10 -4
- package/src/buttons/MRT_GrabHandleButton.tsx +5 -5
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +10 -4
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +10 -4
- package/src/buttons/MRT_ToggleFiltersButton.tsx +10 -4
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +10 -4
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +4 -4
- package/src/head/MRT_TableHeadCell.tsx +11 -16
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +11 -12
- package/src/index.tsx +17 -3
- package/src/inputs/MRT_EditCellTextField.tsx +13 -13
- package/src/inputs/MRT_GlobalFilterTextField.tsx +8 -10
- package/src/menus/MRT_FilterOptionMenu.tsx +5 -5
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +13 -10
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +24 -22
- package/src/table/MRT_TableRoot.tsx +59 -66
- package/src/toolbar/MRT_ToolbarDropZone.tsx +6 -10
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +2 -7
|
@@ -50,14 +50,14 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
50
50
|
rowNumberMode,
|
|
51
51
|
tableId,
|
|
52
52
|
},
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
setEditingCell,
|
|
54
|
+
setHoveredColumn,
|
|
55
55
|
} = table;
|
|
56
56
|
const {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
draggingColumn,
|
|
58
|
+
editingCell,
|
|
59
|
+
editingRow,
|
|
60
|
+
hoveredColumn,
|
|
61
61
|
density,
|
|
62
62
|
isLoading,
|
|
63
63
|
showSkeletons,
|
|
@@ -88,8 +88,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
88
88
|
const isEditing =
|
|
89
89
|
isEditable &&
|
|
90
90
|
(editingMode === 'table' ||
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
editingRow?.id === row.id ||
|
|
92
|
+
editingCell?.id === cell.id);
|
|
93
93
|
|
|
94
94
|
const [skeletonWidth, setSkeletonWidth] = useState(0);
|
|
95
95
|
useEffect(
|
|
@@ -113,7 +113,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
113
113
|
columnDef.enableEditing !== false &&
|
|
114
114
|
editingMode === 'cell'
|
|
115
115
|
) {
|
|
116
|
-
|
|
116
|
+
setEditingCell(cell);
|
|
117
117
|
setTimeout(() => {
|
|
118
118
|
const textField = document.getElementById(
|
|
119
119
|
`mrt-${tableId}-edit-cell-text-field-${cell.id}`,
|
|
@@ -144,20 +144,20 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
const handleDragEnter = (_e: DragEvent) => {
|
|
147
|
-
if (enableGrouping &&
|
|
148
|
-
|
|
147
|
+
if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
|
|
148
|
+
setHoveredColumn(null);
|
|
149
149
|
}
|
|
150
|
-
if (enableColumnOrdering &&
|
|
151
|
-
|
|
150
|
+
if (enableColumnOrdering && draggingColumn) {
|
|
151
|
+
setHoveredColumn(
|
|
152
152
|
columnDef.enableColumnOrdering !== false ? column : null,
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
|
|
157
157
|
const draggingBorder =
|
|
158
|
-
|
|
158
|
+
draggingColumn?.id === column.id
|
|
159
159
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
160
|
-
:
|
|
160
|
+
: hoveredColumn?.id === column.id
|
|
161
161
|
? `2px dashed ${theme.palette.primary.main}`
|
|
162
162
|
: undefined;
|
|
163
163
|
|
|
@@ -197,8 +197,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
197
197
|
? `${column.getStart('left')}px`
|
|
198
198
|
: undefined,
|
|
199
199
|
opacity:
|
|
200
|
-
|
|
201
|
-
currentHoveredColumn?.id === column.id
|
|
200
|
+
draggingColumn?.id === column.id || hoveredColumn?.id === column.id
|
|
202
201
|
? 0.5
|
|
203
202
|
: 1,
|
|
204
203
|
overflow: 'hidden',
|
|
@@ -232,7 +231,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
232
231
|
transition: 'all 0.2s ease-in-out',
|
|
233
232
|
whiteSpace: density === 'compact' ? 'nowrap' : 'normal',
|
|
234
233
|
zIndex:
|
|
235
|
-
|
|
234
|
+
draggingColumn?.id === column.id
|
|
236
235
|
? 2
|
|
237
236
|
: column.getIsPinned()
|
|
238
237
|
? 1
|
|
@@ -16,9 +16,9 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
|
|
|
16
16
|
getIsSomeColumnsPinned,
|
|
17
17
|
getState,
|
|
18
18
|
options: { enableRowOrdering, muiTableBodyRowProps, renderDetailPanel },
|
|
19
|
-
|
|
19
|
+
setHoveredRow,
|
|
20
20
|
} = table;
|
|
21
|
-
const {
|
|
21
|
+
const { draggingRow, hoveredRow } = getState();
|
|
22
22
|
|
|
23
23
|
const tableRowProps =
|
|
24
24
|
muiTableBodyRowProps instanceof Function
|
|
@@ -26,17 +26,17 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
|
|
|
26
26
|
: muiTableBodyRowProps;
|
|
27
27
|
|
|
28
28
|
const handleDragEnter = (_e: DragEvent) => {
|
|
29
|
-
if (enableRowOrdering &&
|
|
30
|
-
|
|
29
|
+
if (enableRowOrdering && draggingRow) {
|
|
30
|
+
setHoveredRow(row);
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
const rowRef = useRef<HTMLTableRowElement>(null);
|
|
35
35
|
|
|
36
36
|
const draggingBorder =
|
|
37
|
-
|
|
37
|
+
draggingRow?.id === row.id
|
|
38
38
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
39
|
-
:
|
|
39
|
+
: hoveredRow?.id === row.id
|
|
40
40
|
? `2px dashed ${theme.palette.primary.main}`
|
|
41
41
|
: undefined;
|
|
42
42
|
|
|
@@ -57,10 +57,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
|
|
|
57
57
|
sx={(theme) => ({
|
|
58
58
|
backgroundColor: lighten(theme.palette.background.default, 0.06),
|
|
59
59
|
opacity:
|
|
60
|
-
|
|
61
|
-
currentHoveredRow?.id === row.id
|
|
62
|
-
? 0.5
|
|
63
|
-
: 1,
|
|
60
|
+
draggingRow?.id === row.id || hoveredRow?.id === row.id ? 0.5 : 1,
|
|
64
61
|
transition: 'all 0.2s ease-in-out',
|
|
65
62
|
'&:hover td': {
|
|
66
63
|
backgroundColor:
|
|
@@ -24,17 +24,17 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
|
|
|
24
24
|
|
|
25
25
|
const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
|
|
26
26
|
e.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
|
|
27
|
-
table.
|
|
27
|
+
table.setDraggingRow(cell.row as any);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
|
|
31
31
|
onRowDrop?.({
|
|
32
32
|
event,
|
|
33
|
-
draggedRow: table.getState().
|
|
34
|
-
targetRow: table.getState().
|
|
33
|
+
draggedRow: table.getState().draggingRow as any,
|
|
34
|
+
targetRow: table.getState().hoveredRow as any,
|
|
35
35
|
});
|
|
36
|
-
table.
|
|
37
|
-
table.
|
|
36
|
+
table.setDraggingRow(null);
|
|
37
|
+
table.setHoveredRow(null);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
return (
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { Box, IconButton, Tooltip } from '@mui/material';
|
|
3
3
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
6
|
-
column: MRT_Column
|
|
7
|
-
table: MRT_TableInstance
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
6
|
+
column: MRT_Column<TData>;
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const MRT_ColumnPinningButtons
|
|
10
|
+
export const MRT_ColumnPinningButtons = <
|
|
11
|
+
TData extends Record<string, any> = {},
|
|
12
|
+
>({
|
|
13
|
+
column,
|
|
14
|
+
table,
|
|
15
|
+
}: Props<TData>) => {
|
|
11
16
|
const {
|
|
12
17
|
options: {
|
|
13
18
|
icons: { PushPinIcon },
|
|
@@ -15,18 +15,22 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
|
|
|
15
15
|
localization,
|
|
16
16
|
onEditRowSubmit,
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
setEditingRow,
|
|
19
19
|
} = table;
|
|
20
|
-
const {
|
|
20
|
+
const { editingRow } = getState();
|
|
21
21
|
|
|
22
22
|
const handleCancel = () => {
|
|
23
|
-
row._valuesCache = row.original
|
|
24
|
-
|
|
23
|
+
row._valuesCache = { ...row.original };
|
|
24
|
+
setEditingRow(null);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const handleSave = () => {
|
|
28
|
-
onEditRowSubmit?.({
|
|
29
|
-
|
|
28
|
+
onEditRowSubmit?.({
|
|
29
|
+
row: editingRow ?? row,
|
|
30
|
+
table,
|
|
31
|
+
values: editingRow?._valuesCache ?? { ...row.original },
|
|
32
|
+
});
|
|
33
|
+
setEditingRow(null);
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
return (
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props extends
|
|
6
|
-
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}>
|
|
6
|
+
extends IconButtonProps {
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const MRT_FullScreenToggleButton
|
|
10
|
+
export const MRT_FullScreenToggleButton = <
|
|
11
|
+
TData extends Record<string, any> = {},
|
|
12
|
+
>({
|
|
13
|
+
table,
|
|
14
|
+
...rest
|
|
15
|
+
}: Props<TData>) => {
|
|
10
16
|
const {
|
|
11
17
|
getState,
|
|
12
18
|
options: {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
|
|
2
|
-
import React, { DragEventHandler
|
|
2
|
+
import React, { DragEventHandler } from 'react';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
6
6
|
iconButtonProps?: IconButtonProps;
|
|
7
7
|
onDragStart: DragEventHandler<HTMLButtonElement>;
|
|
8
8
|
onDragEnd: DragEventHandler<HTMLButtonElement>;
|
|
9
|
-
table: MRT_TableInstance
|
|
9
|
+
table: MRT_TableInstance<TData>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const MRT_GrabHandleButton
|
|
12
|
+
export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
|
|
13
13
|
iconButtonProps,
|
|
14
14
|
onDragEnd,
|
|
15
15
|
onDragStart,
|
|
16
16
|
table,
|
|
17
|
-
}) => {
|
|
17
|
+
}: Props<TData>) => {
|
|
18
18
|
const {
|
|
19
19
|
options: {
|
|
20
20
|
icons: { DragHandleIcon },
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { MouseEvent, useState } from 'react';
|
|
2
2
|
import { IconButton, Tooltip, IconButtonProps } from '@mui/material';
|
|
3
3
|
import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
|
|
4
4
|
import { MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
|
-
interface Props extends
|
|
7
|
-
|
|
6
|
+
interface Props<TData extends Record<string, any> = {}>
|
|
7
|
+
extends IconButtonProps {
|
|
8
|
+
table: MRT_TableInstance<TData>;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export const MRT_ShowHideColumnsButton
|
|
11
|
+
export const MRT_ShowHideColumnsButton = <
|
|
12
|
+
TData extends Record<string, any> = {},
|
|
13
|
+
>({
|
|
14
|
+
table,
|
|
15
|
+
...rest
|
|
16
|
+
}: Props<TData>) => {
|
|
11
17
|
const {
|
|
12
18
|
options: {
|
|
13
19
|
icons: { ViewColumnIcon },
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props extends
|
|
6
|
-
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}>
|
|
6
|
+
extends IconButtonProps {
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const MRT_ToggleDensePaddingButton
|
|
10
|
+
export const MRT_ToggleDensePaddingButton = <
|
|
11
|
+
TData extends Record<string, any> = {},
|
|
12
|
+
>({
|
|
13
|
+
table,
|
|
14
|
+
...rest
|
|
15
|
+
}: Props<TData>) => {
|
|
10
16
|
const {
|
|
11
17
|
getState,
|
|
12
18
|
options: {
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props extends
|
|
6
|
-
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}>
|
|
6
|
+
extends IconButtonProps {
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const MRT_ToggleFiltersButton
|
|
10
|
+
export const MRT_ToggleFiltersButton = <
|
|
11
|
+
TData extends Record<string, any> = {},
|
|
12
|
+
>({
|
|
13
|
+
table,
|
|
14
|
+
...rest
|
|
15
|
+
}: Props<TData>) => {
|
|
10
16
|
const {
|
|
11
17
|
getState,
|
|
12
18
|
options: {
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IconButton, IconButtonProps, Tooltip } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props extends
|
|
6
|
-
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}>
|
|
6
|
+
extends IconButtonProps {
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const MRT_ToggleGlobalFilterButton
|
|
10
|
+
export const MRT_ToggleGlobalFilterButton = <
|
|
11
|
+
TData extends Record<string, any> = {},
|
|
12
|
+
>({
|
|
13
|
+
table,
|
|
14
|
+
...rest
|
|
15
|
+
}: Props<TData>) => {
|
|
10
16
|
const {
|
|
11
17
|
getState,
|
|
12
18
|
options: {
|
|
@@ -30,10 +30,10 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
|
|
|
30
30
|
renderRowActionMenuItems,
|
|
31
31
|
renderRowActions,
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
setEditingRow,
|
|
34
34
|
} = table;
|
|
35
35
|
|
|
36
|
-
const {
|
|
36
|
+
const { editingRow } = getState();
|
|
37
37
|
|
|
38
38
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const handleStartEditMode = () => {
|
|
47
|
-
|
|
47
|
+
setEditingRow({ ...row });
|
|
48
48
|
setAnchorEl(null);
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -52,7 +52,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
|
|
|
52
52
|
<>
|
|
53
53
|
{renderRowActions ? (
|
|
54
54
|
<>{renderRowActions({ row, table })}</>
|
|
55
|
-
) : row.id ===
|
|
55
|
+
) : row.id === editingRow?.id ? (
|
|
56
56
|
<MRT_EditActionButtons row={row} table={table} />
|
|
57
57
|
) : !renderRowActionMenuItems && enableEditing ? (
|
|
58
58
|
<Tooltip placement="right" arrow title={localization.edit}>
|
|
@@ -26,14 +26,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
26
26
|
enableMultiSort,
|
|
27
27
|
muiTableHeadCellProps,
|
|
28
28
|
},
|
|
29
|
-
|
|
29
|
+
setHoveredColumn,
|
|
30
30
|
} = table;
|
|
31
|
-
const {
|
|
32
|
-
|
|
33
|
-
currentDraggingColumn,
|
|
34
|
-
currentHoveredColumn,
|
|
35
|
-
showColumnFilters,
|
|
36
|
-
} = getState();
|
|
31
|
+
const { density, draggingColumn, hoveredColumn, showColumnFilters } =
|
|
32
|
+
getState();
|
|
37
33
|
const { column } = header;
|
|
38
34
|
const { columnDef } = column;
|
|
39
35
|
const { columnDefType } = columnDef;
|
|
@@ -71,20 +67,20 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
71
67
|
};
|
|
72
68
|
|
|
73
69
|
const handleDragEnter = (_e: DragEvent) => {
|
|
74
|
-
if (enableGrouping &&
|
|
75
|
-
|
|
70
|
+
if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
|
|
71
|
+
setHoveredColumn(null);
|
|
76
72
|
}
|
|
77
|
-
if (enableColumnOrdering &&
|
|
78
|
-
|
|
73
|
+
if (enableColumnOrdering && draggingColumn) {
|
|
74
|
+
setHoveredColumn(
|
|
79
75
|
columnDef.enableColumnOrdering !== false ? column : null,
|
|
80
76
|
);
|
|
81
77
|
}
|
|
82
78
|
};
|
|
83
79
|
|
|
84
80
|
const draggingBorder =
|
|
85
|
-
|
|
81
|
+
draggingColumn?.id === column.id
|
|
86
82
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
87
|
-
:
|
|
83
|
+
: hoveredColumn?.id === column.id
|
|
88
84
|
? `2px dashed ${theme.palette.primary.main}`
|
|
89
85
|
: undefined;
|
|
90
86
|
|
|
@@ -131,8 +127,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
131
127
|
: undefined,
|
|
132
128
|
overflow: 'visible',
|
|
133
129
|
opacity:
|
|
134
|
-
|
|
135
|
-
currentHoveredColumn?.id === column.id
|
|
130
|
+
draggingColumn?.id === column.id || hoveredColumn?.id === column.id
|
|
136
131
|
? 0.5
|
|
137
132
|
: 1,
|
|
138
133
|
p:
|
|
@@ -169,7 +164,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
169
164
|
userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined,
|
|
170
165
|
verticalAlign: 'top',
|
|
171
166
|
zIndex:
|
|
172
|
-
column.getIsResizing() ||
|
|
167
|
+
column.getIsResizing() || draggingColumn?.id === column.id
|
|
173
168
|
? 3
|
|
174
169
|
: column.getIsPinned() && columnDefType !== 'group'
|
|
175
170
|
? 2
|
|
@@ -22,12 +22,11 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
|
|
|
22
22
|
onColumnDrop,
|
|
23
23
|
},
|
|
24
24
|
setColumnOrder,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
setDraggingColumn,
|
|
26
|
+
setHoveredColumn,
|
|
27
27
|
} = table;
|
|
28
28
|
const { columnDef } = column;
|
|
29
|
-
const {
|
|
30
|
-
getState();
|
|
29
|
+
const { hoveredColumn, draggingColumn, columnOrder } = getState();
|
|
31
30
|
|
|
32
31
|
const mIconButtonProps =
|
|
33
32
|
muiTableHeadCellDragHandleProps instanceof Function
|
|
@@ -45,7 +44,7 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
|
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
|
|
48
|
-
|
|
47
|
+
setDraggingColumn(column);
|
|
49
48
|
e.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
|
|
50
49
|
};
|
|
51
50
|
|
|
@@ -53,21 +52,21 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
|
|
|
53
52
|
onColumnDrop?.({
|
|
54
53
|
event,
|
|
55
54
|
draggedColumn: column,
|
|
56
|
-
targetColumn:
|
|
55
|
+
targetColumn: hoveredColumn,
|
|
57
56
|
});
|
|
58
|
-
if (
|
|
57
|
+
if (hoveredColumn?.id === 'drop-zone') {
|
|
59
58
|
column.toggleGrouping();
|
|
60
59
|
} else if (
|
|
61
60
|
enableColumnOrdering &&
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
hoveredColumn &&
|
|
62
|
+
hoveredColumn?.id !== draggingColumn?.id
|
|
64
63
|
) {
|
|
65
64
|
setColumnOrder(
|
|
66
|
-
reorderColumn(column,
|
|
65
|
+
reorderColumn(column, hoveredColumn as MRT_Column, columnOrder),
|
|
67
66
|
);
|
|
68
67
|
}
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
setDraggingColumn(null);
|
|
69
|
+
setHoveredColumn(null);
|
|
71
70
|
};
|
|
72
71
|
|
|
73
72
|
return (
|
package/src/index.tsx
CHANGED
|
@@ -3,7 +3,21 @@ export default MaterialReactTable;
|
|
|
3
3
|
export * from './MaterialReactTable';
|
|
4
4
|
|
|
5
5
|
import type { MRT_Icons } from './icons';
|
|
6
|
-
export type { MRT_Icons };
|
|
7
|
-
|
|
8
6
|
import type { MRT_Localization } from './localization';
|
|
9
|
-
export type { MRT_Localization };
|
|
7
|
+
export type { MRT_Localization, MRT_Icons };
|
|
8
|
+
|
|
9
|
+
import { MRT_FullScreenToggleButton } from './buttons/MRT_FullScreenToggleButton';
|
|
10
|
+
import { MRT_GlobalFilterTextField } from './inputs/MRT_GlobalFilterTextField';
|
|
11
|
+
import { MRT_ShowHideColumnsButton } from './buttons/MRT_ShowHideColumnsButton';
|
|
12
|
+
import { MRT_ToggleDensePaddingButton } from './buttons/MRT_ToggleDensePaddingButton';
|
|
13
|
+
import { MRT_ToggleFiltersButton } from './buttons/MRT_ToggleFiltersButton';
|
|
14
|
+
import { MRT_ToggleGlobalFilterButton } from './buttons/MRT_ToggleGlobalFilterButton';
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
MRT_FullScreenToggleButton,
|
|
18
|
+
MRT_GlobalFilterTextField,
|
|
19
|
+
MRT_ShowHideColumnsButton,
|
|
20
|
+
MRT_ToggleDensePaddingButton,
|
|
21
|
+
MRT_ToggleFiltersButton,
|
|
22
|
+
MRT_ToggleGlobalFilterButton,
|
|
23
|
+
};
|
|
@@ -18,34 +18,34 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
|
|
|
18
18
|
getState,
|
|
19
19
|
options: {
|
|
20
20
|
tableId,
|
|
21
|
-
enableEditing,
|
|
22
21
|
muiTableBodyCellEditTextFieldProps,
|
|
23
22
|
onCellEditBlur,
|
|
24
23
|
onCellEditChange,
|
|
25
24
|
},
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
setEditingCell,
|
|
26
|
+
setEditingRow,
|
|
28
27
|
} = table;
|
|
29
28
|
const { column, row } = cell;
|
|
30
29
|
const { columnDef } = column;
|
|
30
|
+
const { editingRow } = getState();
|
|
31
31
|
|
|
32
|
-
const [value, setValue] = useState(cell.getValue<string>());
|
|
32
|
+
const [value, setValue] = useState(() => cell.getValue<string>());
|
|
33
33
|
|
|
34
34
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
35
35
|
setValue(event.target.value);
|
|
36
|
-
columnDef.onCellEditChange?.({ event, cell, table });
|
|
37
|
-
onCellEditChange?.({ event, cell, table });
|
|
36
|
+
columnDef.onCellEditChange?.({ event, cell, table, value });
|
|
37
|
+
onCellEditChange?.({ event, cell, table, value });
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
41
|
-
if (
|
|
41
|
+
if (editingRow) {
|
|
42
42
|
if (!row._valuesCache) row._valuesCache = {};
|
|
43
43
|
(row._valuesCache as Record<string, any>)[column.id] = value;
|
|
44
|
-
|
|
44
|
+
setEditingRow({ ...editingRow } as MRT_Row);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
columnDef.onCellEditBlur?.({ event, cell, table });
|
|
48
|
-
onCellEditBlur?.({ event, cell, table });
|
|
46
|
+
setEditingCell(null);
|
|
47
|
+
columnDef.onCellEditBlur?.({ event, cell, table, value });
|
|
48
|
+
onCellEditBlur?.({ event, cell, table, value });
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const mTableBodyCellEditTextFieldProps =
|
|
@@ -66,14 +66,14 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
|
|
|
66
66
|
...mcTableBodyCellEditTextFieldProps,
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
if (
|
|
69
|
+
if (columnDef.Edit) {
|
|
70
70
|
return <>{columnDef.Edit?.({ cell, column, table })}</>;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
return (
|
|
74
74
|
<TextField
|
|
75
75
|
id={`mrt-${tableId}-edit-cell-text-field-${cell.id}`}
|
|
76
|
-
margin="
|
|
76
|
+
margin="none"
|
|
77
77
|
onBlur={handleBlur}
|
|
78
78
|
onChange={handleChange}
|
|
79
79
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
ChangeEvent,
|
|
3
|
-
FC,
|
|
4
|
-
MouseEvent,
|
|
5
|
-
useCallback,
|
|
6
|
-
useState,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, { ChangeEvent, MouseEvent, useCallback, useState } from 'react';
|
|
8
2
|
import {
|
|
9
3
|
Collapse,
|
|
10
4
|
debounce,
|
|
@@ -16,11 +10,15 @@ import {
|
|
|
16
10
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
17
11
|
import { MRT_TableInstance } from '..';
|
|
18
12
|
|
|
19
|
-
interface Props {
|
|
20
|
-
table: MRT_TableInstance
|
|
13
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
14
|
+
table: MRT_TableInstance<TData>;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
export const MRT_GlobalFilterTextField
|
|
17
|
+
export const MRT_GlobalFilterTextField = <
|
|
18
|
+
TData extends Record<string, any> = {},
|
|
19
|
+
>({
|
|
20
|
+
table,
|
|
21
|
+
}: Props<TData>) => {
|
|
24
22
|
const {
|
|
25
23
|
getState,
|
|
26
24
|
setGlobalFilter,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import { Box, Menu, MenuItem } from '@mui/material';
|
|
3
3
|
import type { MRT_FilterOption, MRT_Header, MRT_TableInstance } from '..';
|
|
4
4
|
import { MRT_Localization } from '../localization';
|
|
@@ -97,21 +97,21 @@ export const internalFilterOptions = (
|
|
|
97
97
|
},
|
|
98
98
|
];
|
|
99
99
|
|
|
100
|
-
interface Props {
|
|
100
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
101
101
|
anchorEl: HTMLElement | null;
|
|
102
102
|
header?: MRT_Header;
|
|
103
103
|
onSelect?: () => void;
|
|
104
104
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
105
|
-
table: MRT_TableInstance
|
|
105
|
+
table: MRT_TableInstance<TData>;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export const MRT_FilterOptionMenu
|
|
108
|
+
export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
109
109
|
anchorEl,
|
|
110
110
|
header,
|
|
111
111
|
onSelect,
|
|
112
112
|
setAnchorEl,
|
|
113
113
|
table,
|
|
114
|
-
}) => {
|
|
114
|
+
}: Props<TData>) => {
|
|
115
115
|
const {
|
|
116
116
|
getState,
|
|
117
117
|
options: {
|