material-react-table 0.30.2 → 0.31.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/MaterialReactTable.d.ts +21 -8
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +69 -6
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +70 -7
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/toolbar/MRT_ToolbarDropZone.d.ts +7 -0
- package/package.json +3 -3
- package/src/MaterialReactTable.tsx +14 -7
- package/src/body/MRT_TableBodyCell.tsx +4 -0
- package/src/head/MRT_TableHeadCell.tsx +3 -0
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +6 -2
- package/src/localization.ts +2 -0
- package/src/table/MRT_TableRoot.tsx +8 -7
- package/src/toolbar/MRT_ToolbarBottom.tsx +5 -0
- package/src/toolbar/MRT_ToolbarDropZone.tsx +54 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +5 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.31.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"size-limit": [
|
|
50
50
|
{
|
|
51
51
|
"path": "dist/material-react-table.cjs.production.min.js",
|
|
52
|
-
"limit": "
|
|
52
|
+
"limit": "50 KB"
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
"path": "dist/material-react-table.esm.js",
|
|
56
|
-
"limit": "
|
|
56
|
+
"limit": "50 KB"
|
|
57
57
|
}
|
|
58
58
|
],
|
|
59
59
|
"devDependencies": {
|
|
@@ -104,8 +104,12 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
|
|
|
104
104
|
}>
|
|
105
105
|
>;
|
|
106
106
|
setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
|
|
107
|
-
setCurrentHoveredColumn: Dispatch<
|
|
108
|
-
|
|
107
|
+
setCurrentHoveredColumn: Dispatch<
|
|
108
|
+
SetStateAction<MRT_Column<TData> | { id: string } | null>
|
|
109
|
+
>;
|
|
110
|
+
setCurrentHoveredRow: Dispatch<
|
|
111
|
+
SetStateAction<MRT_Row<TData> | { id: string } | null>
|
|
112
|
+
>;
|
|
109
113
|
setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
|
|
110
114
|
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
111
115
|
setShowAlertBanner: Dispatch<SetStateAction<boolean>>;
|
|
@@ -121,8 +125,8 @@ export type MRT_TableState<TData extends Record<string, any> = {}> =
|
|
|
121
125
|
currentEditingRow: MRT_Row<TData> | null;
|
|
122
126
|
currentFilterFns: Record<string, MRT_FilterOption>;
|
|
123
127
|
currentGlobalFilterFn: Record<string, MRT_FilterOption>;
|
|
124
|
-
currentHoveredColumn: MRT_Column<TData> | null;
|
|
125
|
-
currentHoveredRow: MRT_Row<TData> | null;
|
|
128
|
+
currentHoveredColumn: MRT_Column<TData> | { id: string } | null;
|
|
129
|
+
currentHoveredRow: MRT_Row<TData> | { id: string } | null;
|
|
126
130
|
density: 'comfortable' | 'compact' | 'spacious';
|
|
127
131
|
isFullScreen: boolean;
|
|
128
132
|
isLoading: boolean;
|
|
@@ -689,7 +693,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
689
693
|
}: {
|
|
690
694
|
event: DragEvent<HTMLButtonElement>;
|
|
691
695
|
draggedColumn: MRT_Column<TData>;
|
|
692
|
-
targetColumn: MRT_Column<TData> | null;
|
|
696
|
+
targetColumn: MRT_Column<TData> | { id: string } | null;
|
|
693
697
|
}) => void;
|
|
694
698
|
onCurrentDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
|
695
699
|
onCurrentDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
@@ -715,7 +719,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
715
719
|
}: {
|
|
716
720
|
event: DragEvent<HTMLButtonElement>;
|
|
717
721
|
draggedRow: MRT_Row<TData>;
|
|
718
|
-
targetRow: MRT_Row<TData> | null;
|
|
722
|
+
targetRow: MRT_Row<TData> | { id: string } | null;
|
|
719
723
|
}) => void;
|
|
720
724
|
onShowAlertBannerChange?: OnChangeFn<boolean>;
|
|
721
725
|
onShowFiltersChange?: OnChangeFn<boolean>;
|
|
@@ -725,7 +729,8 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
725
729
|
positionExpandColumn?: 'first' | 'last';
|
|
726
730
|
positionGlobalFilter?: 'left' | 'right';
|
|
727
731
|
positionPagination?: 'bottom' | 'top' | 'both';
|
|
728
|
-
positionToolbarAlertBanner?: 'bottom' | 'top';
|
|
732
|
+
positionToolbarAlertBanner?: 'bottom' | 'top' | 'none';
|
|
733
|
+
positionToolbarDropZone?: 'bottom' | 'top' | 'none' | 'both';
|
|
729
734
|
renderDetailPanel?: ({
|
|
730
735
|
row,
|
|
731
736
|
table,
|
|
@@ -833,6 +838,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
833
838
|
positionGlobalFilter = 'right',
|
|
834
839
|
positionPagination = 'bottom',
|
|
835
840
|
positionToolbarAlertBanner = 'top',
|
|
841
|
+
positionToolbarDropZone = 'top',
|
|
836
842
|
rowNumberMode = 'original',
|
|
837
843
|
selectAllMode = 'all',
|
|
838
844
|
...rest
|
|
@@ -876,6 +882,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
876
882
|
positionGlobalFilter={positionGlobalFilter}
|
|
877
883
|
positionPagination={positionPagination}
|
|
878
884
|
positionToolbarAlertBanner={positionToolbarAlertBanner}
|
|
885
|
+
positionToolbarDropZone={positionToolbarDropZone}
|
|
879
886
|
rowNumberMode={rowNumberMode}
|
|
880
887
|
selectAllMode={selectAllMode}
|
|
881
888
|
{...rest}
|
|
@@ -35,6 +35,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
35
35
|
enableClickToCopy,
|
|
36
36
|
enableColumnOrdering,
|
|
37
37
|
enableEditing,
|
|
38
|
+
enableGrouping,
|
|
38
39
|
enablePagination,
|
|
39
40
|
enableRowNumbers,
|
|
40
41
|
muiTableBodyCellProps,
|
|
@@ -129,6 +130,9 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
129
130
|
};
|
|
130
131
|
|
|
131
132
|
const handleDragEnter = (_e: DragEvent) => {
|
|
133
|
+
if (enableGrouping && currentHoveredColumn?.id === 'drop-zone') {
|
|
134
|
+
setCurrentHoveredColumn(null);
|
|
135
|
+
}
|
|
132
136
|
if (enableColumnOrdering && currentDraggingColumn) {
|
|
133
137
|
setCurrentHoveredColumn(
|
|
134
138
|
columnDef.enableColumnOrdering !== false ? column : null,
|
|
@@ -71,6 +71,9 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
const handleDragEnter = (_e: DragEvent) => {
|
|
74
|
+
if (enableGrouping && currentHoveredColumn?.id === 'drop-zone') {
|
|
75
|
+
setCurrentHoveredColumn(null);
|
|
76
|
+
}
|
|
74
77
|
if (enableColumnOrdering && currentDraggingColumn) {
|
|
75
78
|
setCurrentHoveredColumn(
|
|
76
79
|
columnDef.enableColumnOrdering !== false ? column : null,
|
|
@@ -55,12 +55,16 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
|
|
|
55
55
|
draggedColumn: column,
|
|
56
56
|
targetColumn: currentHoveredColumn,
|
|
57
57
|
});
|
|
58
|
-
if (
|
|
58
|
+
if (currentHoveredColumn?.id === 'drop-zone') {
|
|
59
|
+
column.toggleGrouping();
|
|
60
|
+
} else if (
|
|
59
61
|
enableColumnOrdering &&
|
|
60
62
|
currentHoveredColumn &&
|
|
61
63
|
currentHoveredColumn?.id !== currentDraggingColumn?.id
|
|
62
64
|
) {
|
|
63
|
-
setColumnOrder(
|
|
65
|
+
setColumnOrder(
|
|
66
|
+
reorderColumn(column, currentHoveredColumn as MRT_Column, columnOrder),
|
|
67
|
+
);
|
|
64
68
|
}
|
|
65
69
|
setCurrentDraggingColumn(null);
|
|
66
70
|
setCurrentHoveredColumn(null);
|
package/src/localization.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface MRT_Localization {
|
|
|
10
10
|
clickToCopy: string;
|
|
11
11
|
columnActions: string;
|
|
12
12
|
copiedToClipboard: string;
|
|
13
|
+
dropToGroupBy: string;
|
|
13
14
|
edit: string;
|
|
14
15
|
expand: string;
|
|
15
16
|
expandAll: string;
|
|
@@ -91,6 +92,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
91
92
|
clickToCopy: 'Click to copy',
|
|
92
93
|
columnActions: 'Column Actions',
|
|
93
94
|
copiedToClipboard: 'Copied to clipboard',
|
|
95
|
+
dropToGroupBy: 'Drop to group by {column}',
|
|
94
96
|
edit: 'Edit',
|
|
95
97
|
expand: 'Expand',
|
|
96
98
|
expandAll: 'Expand all',
|
|
@@ -80,12 +80,12 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
80
80
|
useState<MRT_Cell<TData> | null>(initialState.currentEditingCell ?? null);
|
|
81
81
|
const [currentEditingRow, setCurrentEditingRow] =
|
|
82
82
|
useState<MRT_Row<TData> | null>(initialState.currentEditingRow ?? null);
|
|
83
|
-
const [currentHoveredColumn, setCurrentHoveredColumn] =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
const [currentHoveredColumn, setCurrentHoveredColumn] = useState<
|
|
84
|
+
MRT_Column<TData> | { id: string } | null
|
|
85
|
+
>(initialState.currentHoveredColumn ?? null);
|
|
86
|
+
const [currentHoveredRow, setCurrentHoveredRow] = useState<
|
|
87
|
+
MRT_Row<TData> | { id: string } | null
|
|
88
|
+
>(initialState.currentHoveredRow ?? null);
|
|
89
89
|
const [density, setDensity] = useState(
|
|
90
90
|
initialState?.density ?? 'comfortable',
|
|
91
91
|
);
|
|
@@ -248,11 +248,12 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
248
248
|
getPaginationRowModel: getPaginationRowModel(),
|
|
249
249
|
getSortedRowModel: getSortedRowModel(),
|
|
250
250
|
onColumnOrderChange: setColumnOrder,
|
|
251
|
+
getSubRows: (row) => row?.subRows,
|
|
251
252
|
...props,
|
|
252
253
|
//@ts-ignore
|
|
253
254
|
columns: columnDefs,
|
|
254
255
|
data,
|
|
255
|
-
|
|
256
|
+
|
|
256
257
|
globalFilterFn:
|
|
257
258
|
//@ts-ignore
|
|
258
259
|
MRT_FilterFns[currentGlobalFilterFn] ?? MRT_FilterFns.fuzzy,
|
|
@@ -5,6 +5,7 @@ import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
|
5
5
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
6
6
|
import { commonToolbarStyles } from './MRT_ToolbarTop';
|
|
7
7
|
import { MRT_TableInstance } from '..';
|
|
8
|
+
import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
table: MRT_TableInstance;
|
|
@@ -18,6 +19,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
|
|
|
18
19
|
muiTableToolbarBottomProps,
|
|
19
20
|
positionPagination,
|
|
20
21
|
positionToolbarAlertBanner,
|
|
22
|
+
positionToolbarDropZone,
|
|
21
23
|
renderToolbarBottomCustomActions,
|
|
22
24
|
tableId,
|
|
23
25
|
},
|
|
@@ -56,6 +58,9 @@ export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
|
|
|
56
58
|
{positionToolbarAlertBanner === 'bottom' && (
|
|
57
59
|
<MRT_ToolbarAlertBanner table={table} />
|
|
58
60
|
)}
|
|
61
|
+
{['both', 'bottom'].includes(positionToolbarDropZone ?? '') && (
|
|
62
|
+
<MRT_ToolbarDropZone table={table} />
|
|
63
|
+
)}
|
|
59
64
|
<Box
|
|
60
65
|
sx={{
|
|
61
66
|
display: 'flex',
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { DragEvent, FC } from 'react';
|
|
2
|
+
import { alpha, Box, Fade, Typography } from '@mui/material';
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
table: MRT_TableInstance;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const MRT_ToolbarDropZone: FC<Props> = ({ table }) => {
|
|
10
|
+
const {
|
|
11
|
+
getState,
|
|
12
|
+
options: { enableGrouping, localization },
|
|
13
|
+
setCurrentHoveredColumn,
|
|
14
|
+
} = table;
|
|
15
|
+
|
|
16
|
+
const { currentDraggingColumn, currentHoveredColumn } = getState();
|
|
17
|
+
|
|
18
|
+
const handleDragEnter = (_event: DragEvent<HTMLDivElement>) => {
|
|
19
|
+
setCurrentHoveredColumn({ id: 'drop-zone' });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Fade
|
|
24
|
+
unmountOnExit
|
|
25
|
+
mountOnEnter
|
|
26
|
+
in={!!enableGrouping && !!currentDraggingColumn}
|
|
27
|
+
>
|
|
28
|
+
<Box
|
|
29
|
+
sx={(theme) => ({
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
backgroundColor: alpha(
|
|
32
|
+
theme.palette.info.main,
|
|
33
|
+
currentHoveredColumn?.id === 'drop-zone' ? 0.2 : 0.1,
|
|
34
|
+
),
|
|
35
|
+
border: `dashed ${theme.palette.info.main} 2px`,
|
|
36
|
+
display: 'flex',
|
|
37
|
+
justifyContent: 'center',
|
|
38
|
+
height: 'calc(100% - 4px)',
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
width: 'calc(100% - 4px)',
|
|
41
|
+
zIndex: 2,
|
|
42
|
+
})}
|
|
43
|
+
onDragEnter={handleDragEnter}
|
|
44
|
+
>
|
|
45
|
+
<Typography>
|
|
46
|
+
{localization.dropToGroupBy.replace(
|
|
47
|
+
'{column}',
|
|
48
|
+
currentDraggingColumn?.columnDef?.header ?? '',
|
|
49
|
+
)}
|
|
50
|
+
</Typography>
|
|
51
|
+
</Box>
|
|
52
|
+
</Fade>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -6,6 +6,7 @@ import { MRT_TableInstance } from '..';
|
|
|
6
6
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
7
7
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
8
8
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
9
|
+
import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
|
|
9
10
|
|
|
10
11
|
export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
11
12
|
alignItems: 'flex-start',
|
|
@@ -34,6 +35,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
|
|
|
34
35
|
positionGlobalFilter,
|
|
35
36
|
positionPagination,
|
|
36
37
|
positionToolbarAlertBanner,
|
|
38
|
+
positionToolbarDropZone,
|
|
37
39
|
renderToolbarTopCustomActions,
|
|
38
40
|
tableId,
|
|
39
41
|
},
|
|
@@ -73,6 +75,9 @@ export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
|
|
|
73
75
|
table={table}
|
|
74
76
|
/>
|
|
75
77
|
)}
|
|
78
|
+
{['both', 'top'].includes(positionToolbarDropZone ?? '') && (
|
|
79
|
+
<MRT_ToolbarDropZone table={table} />
|
|
80
|
+
)}
|
|
76
81
|
<Box
|
|
77
82
|
sx={{
|
|
78
83
|
alignItems: 'flex-start',
|