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,25 +1,26 @@
|
|
1
1
|
import {
|
2
|
-
memo,
|
3
2
|
type DragEvent,
|
4
3
|
type MouseEvent,
|
5
4
|
type RefObject,
|
5
|
+
memo,
|
6
6
|
useEffect,
|
7
7
|
useMemo,
|
8
8
|
useState,
|
9
9
|
} from 'react';
|
10
|
+
import { type VirtualItem } from '@tanstack/react-virtual';
|
10
11
|
import Skeleton from '@mui/material/Skeleton';
|
11
12
|
import TableCell from '@mui/material/TableCell';
|
12
13
|
import { useTheme } from '@mui/material/styles';
|
13
|
-
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
14
|
-
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
15
|
-
import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
|
16
14
|
import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
|
15
|
+
import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
|
16
|
+
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
17
17
|
import {
|
18
18
|
getCommonCellStyles,
|
19
19
|
getIsFirstColumn,
|
20
20
|
getIsLastColumn,
|
21
|
+
parseFromValuesOrFunc,
|
21
22
|
} from '../column.utils';
|
22
|
-
import {
|
23
|
+
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
23
24
|
import { type MRT_Cell, type MRT_TableInstance } from '../types';
|
24
25
|
|
25
26
|
interface Props<TData extends Record<string, any>> {
|
@@ -53,8 +54,8 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
53
54
|
enableGrouping,
|
54
55
|
enableRowNumbers,
|
55
56
|
layoutMode,
|
56
|
-
muiTableBodyCellProps,
|
57
57
|
muiSkeletonProps,
|
58
|
+
muiTableBodyCellProps,
|
58
59
|
rowNumberMode,
|
59
60
|
},
|
60
61
|
refs: { editInputRefs },
|
@@ -63,13 +64,13 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
63
64
|
} = table;
|
64
65
|
const {
|
65
66
|
creatingRow,
|
67
|
+
density,
|
66
68
|
draggingColumn,
|
67
69
|
draggingRow,
|
68
70
|
editingCell,
|
69
71
|
editingRow,
|
70
72
|
hoveredColumn,
|
71
73
|
hoveredRow,
|
72
|
-
density,
|
73
74
|
isLoading,
|
74
75
|
showSkeletons,
|
75
76
|
} = getState();
|
@@ -77,25 +78,27 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
77
78
|
const { columnDef } = column;
|
78
79
|
const { columnDefType } = columnDef;
|
79
80
|
|
80
|
-
const mTableCellBodyProps =
|
81
|
-
muiTableBodyCellProps instanceof Function
|
82
|
-
? muiTableBodyCellProps({ cell, column, row, table })
|
83
|
-
: muiTableBodyCellProps;
|
84
|
-
|
85
|
-
const mcTableCellBodyProps =
|
86
|
-
columnDef.muiTableBodyCellProps instanceof Function
|
87
|
-
? columnDef.muiTableBodyCellProps({ cell, column, row, table })
|
88
|
-
: columnDef.muiTableBodyCellProps;
|
89
|
-
|
90
81
|
const tableCellProps = {
|
91
|
-
...
|
92
|
-
|
82
|
+
...parseFromValuesOrFunc(muiTableBodyCellProps, {
|
83
|
+
cell,
|
84
|
+
column,
|
85
|
+
row,
|
86
|
+
table,
|
87
|
+
}),
|
88
|
+
...parseFromValuesOrFunc(columnDef.muiTableBodyCellProps, {
|
89
|
+
cell,
|
90
|
+
column,
|
91
|
+
row,
|
92
|
+
table,
|
93
|
+
}),
|
93
94
|
};
|
94
95
|
|
95
|
-
const skeletonProps =
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
const skeletonProps = parseFromValuesOrFunc(muiSkeletonProps, {
|
97
|
+
cell,
|
98
|
+
column,
|
99
|
+
row,
|
100
|
+
table,
|
101
|
+
});
|
99
102
|
|
100
103
|
const [skeletonWidth, setSkeletonWidth] = useState(100);
|
101
104
|
useEffect(() => {
|
@@ -126,6 +129,10 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
126
129
|
|
127
130
|
return borderStyle
|
128
131
|
? {
|
132
|
+
borderBottom:
|
133
|
+
isDraggingRow || isHoveredRow || isLastRow
|
134
|
+
? borderStyle
|
135
|
+
: undefined,
|
129
136
|
borderLeft:
|
130
137
|
isDraggingColumn ||
|
131
138
|
isHoveredColumn ||
|
@@ -138,24 +145,18 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
138
145
|
((isDraggingRow || isHoveredRow) && isLastColumn)
|
139
146
|
? borderStyle
|
140
147
|
: undefined,
|
141
|
-
borderBottom:
|
142
|
-
isDraggingRow || isHoveredRow || isLastRow
|
143
|
-
? borderStyle
|
144
|
-
: undefined,
|
145
148
|
borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
|
146
149
|
}
|
147
150
|
: undefined;
|
148
151
|
}, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
|
149
152
|
|
150
153
|
const isEditable =
|
151
|
-
(enableEditing
|
152
|
-
(columnDef.enableEditing
|
153
|
-
? columnDef.enableEditing(row)
|
154
|
-
: columnDef.enableEditing) !== false;
|
154
|
+
parseFromValuesOrFunc(enableEditing, row) &&
|
155
|
+
parseFromValuesOrFunc(columnDef.enableEditing, row) !== false;
|
155
156
|
|
156
157
|
const isEditing =
|
157
158
|
isEditable &&
|
158
|
-
!['
|
159
|
+
!['custom', 'modal'].includes(editDisplayMode as string) &&
|
159
160
|
(editDisplayMode === 'table' ||
|
160
161
|
editingRow?.id === row.id ||
|
161
162
|
editingCell?.id === cell.id) &&
|
@@ -199,9 +200,16 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
199
200
|
}
|
200
201
|
}}
|
201
202
|
{...tableCellProps}
|
202
|
-
onDragEnter={handleDragEnter}
|
203
203
|
onDoubleClick={handleDoubleClick}
|
204
|
+
onDragEnter={handleDragEnter}
|
204
205
|
sx={(theme) => ({
|
206
|
+
'&:hover': {
|
207
|
+
outline: ['cell', 'table'].includes(editDisplayMode ?? '')
|
208
|
+
? `1px solid ${theme.palette.text.secondary}`
|
209
|
+
: undefined,
|
210
|
+
outlineOffset: '-1px',
|
211
|
+
textOverflow: 'clip',
|
212
|
+
},
|
205
213
|
alignItems: layoutMode === 'grid' ? 'center' : undefined,
|
206
214
|
cursor:
|
207
215
|
isEditable && editDisplayMode === 'cell' ? 'pointer' : 'inherit',
|
@@ -232,21 +240,15 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
232
240
|
}rem`
|
233
241
|
: undefined,
|
234
242
|
textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
|
235
|
-
whiteSpace:
|
243
|
+
whiteSpace:
|
244
|
+
row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal',
|
236
245
|
zIndex:
|
237
246
|
draggingColumn?.id === column.id ? 2 : column.getIsPinned() ? 1 : 0,
|
238
|
-
'&:hover': {
|
239
|
-
outline: ['table', 'cell'].includes(editDisplayMode ?? '')
|
240
|
-
? `1px solid ${theme.palette.text.secondary}`
|
241
|
-
: undefined,
|
242
|
-
outlineOffset: '-1px',
|
243
|
-
textOverflow: 'clip',
|
244
|
-
},
|
245
247
|
...getCommonCellStyles({
|
246
248
|
column,
|
247
249
|
table,
|
248
|
-
theme,
|
249
250
|
tableCellProps,
|
251
|
+
theme,
|
250
252
|
}),
|
251
253
|
...draggingBorders,
|
252
254
|
})}
|
@@ -273,8 +275,8 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
273
275
|
!row.getIsGrouped()) ? (
|
274
276
|
columnDef.Cell?.({
|
275
277
|
cell,
|
276
|
-
renderedCellValue: cell.renderValue() as any,
|
277
278
|
column,
|
279
|
+
renderedCellValue: cell.renderValue() as any,
|
278
280
|
row,
|
279
281
|
table,
|
280
282
|
})
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { type ReactNode } from 'react';
|
2
2
|
import Box from '@mui/material/Box';
|
3
3
|
import { darken, lighten } from '@mui/material/styles';
|
4
|
-
import highlightWords from 'highlight-words';
|
5
4
|
import { type MRT_Cell, type MRT_TableInstance } from '../types';
|
5
|
+
import highlightWords from 'highlight-words';
|
6
6
|
|
7
7
|
const allowedTypes = ['string', 'number'];
|
8
8
|
|
@@ -46,7 +46,7 @@ export const MRT_TableBodyCellValue = <TData extends Record<string, any>>({
|
|
46
46
|
const isGroupedValue = renderedCellValue !== undefined;
|
47
47
|
|
48
48
|
if (!isGroupedValue) {
|
49
|
-
renderedCellValue = cell.renderValue() as
|
49
|
+
renderedCellValue = cell.renderValue() as ReactNode | number | string;
|
50
50
|
}
|
51
51
|
|
52
52
|
if (
|
@@ -62,10 +62,10 @@ export const MRT_TableBodyCellValue = <TData extends Record<string, any>>({
|
|
62
62
|
column.getCanGlobalFilter()))
|
63
63
|
) {
|
64
64
|
const chunks = highlightWords?.({
|
65
|
-
text: renderedCellValue?.toString() as string,
|
66
|
-
query: (filterValue ?? globalFilter ?? '').toString(),
|
67
65
|
matchExactly:
|
68
66
|
(filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
67
|
+
query: (filterValue ?? globalFilter ?? '').toString(),
|
68
|
+
text: renderedCellValue?.toString() as string,
|
69
69
|
});
|
70
70
|
if (chunks?.length > 1 || chunks?.[0]?.match) {
|
71
71
|
renderedCellValue = (
|
@@ -101,8 +101,8 @@ export const MRT_TableBodyCellValue = <TData extends Record<string, any>>({
|
|
101
101
|
if (columnDef.Cell && !isGroupedValue) {
|
102
102
|
renderedCellValue = columnDef.Cell({
|
103
103
|
cell,
|
104
|
-
renderedCellValue,
|
105
104
|
column,
|
105
|
+
renderedCellValue,
|
106
106
|
row,
|
107
107
|
table,
|
108
108
|
});
|
@@ -1,15 +1,23 @@
|
|
1
|
-
import { type DragEvent, memo, useRef } from 'react';
|
1
|
+
import { type DragEvent, memo, useMemo, useRef } from 'react';
|
2
|
+
import { type VirtualItem, type Virtualizer } from '@tanstack/react-virtual';
|
2
3
|
import TableRow from '@mui/material/TableRow';
|
3
|
-
import {
|
4
|
-
|
4
|
+
import {
|
5
|
+
type Theme,
|
6
|
+
alpha,
|
7
|
+
darken,
|
8
|
+
lighten,
|
9
|
+
useTheme,
|
10
|
+
} from '@mui/material/styles';
|
11
|
+
import { MRT_TableBodyCell, Memo_MRT_TableBodyCell } from './MRT_TableBodyCell';
|
5
12
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
6
|
-
import {
|
13
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
7
14
|
import { type MRT_Cell, type MRT_Row, type MRT_TableInstance } from '../types';
|
8
15
|
|
9
16
|
interface Props<TData extends Record<string, any>> {
|
10
17
|
columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
11
18
|
measureElement?: (element: HTMLTableRowElement) => void;
|
12
19
|
numRows: number;
|
20
|
+
pinnedRowIds?: string[];
|
13
21
|
row: MRT_Row<TData>;
|
14
22
|
rowIndex: number;
|
15
23
|
table: MRT_TableInstance<TData>;
|
@@ -23,6 +31,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
23
31
|
columnVirtualizer,
|
24
32
|
measureElement,
|
25
33
|
numRows,
|
34
|
+
pinnedRowIds,
|
26
35
|
row,
|
27
36
|
rowIndex,
|
28
37
|
table,
|
@@ -31,24 +40,70 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
31
40
|
virtualPaddingRight,
|
32
41
|
virtualRow,
|
33
42
|
}: Props<TData>) => {
|
43
|
+
const theme = useTheme();
|
44
|
+
|
34
45
|
const {
|
35
46
|
getState,
|
36
47
|
options: {
|
37
48
|
enableRowOrdering,
|
49
|
+
enableRowPinning,
|
50
|
+
enableStickyFooter,
|
51
|
+
enableStickyHeader,
|
38
52
|
layoutMode,
|
39
53
|
memoMode,
|
40
54
|
muiTableBodyRowProps,
|
41
55
|
renderDetailPanel,
|
56
|
+
rowPinningDisplayMode,
|
42
57
|
},
|
58
|
+
refs: { tableFooterRef, tableHeadRef },
|
43
59
|
setHoveredRow,
|
44
60
|
} = table;
|
45
|
-
const {
|
46
|
-
|
61
|
+
const {
|
62
|
+
density,
|
63
|
+
draggingColumn,
|
64
|
+
draggingRow,
|
65
|
+
editingCell,
|
66
|
+
editingRow,
|
67
|
+
hoveredRow,
|
68
|
+
isFullScreen,
|
69
|
+
rowPinning,
|
70
|
+
} = getState();
|
71
|
+
|
72
|
+
const isPinned = enableRowPinning && row.getIsPinned();
|
47
73
|
|
48
|
-
const tableRowProps =
|
49
|
-
|
50
|
-
|
51
|
-
|
74
|
+
const tableRowProps = parseFromValuesOrFunc(muiTableBodyRowProps, {
|
75
|
+
row,
|
76
|
+
staticRowIndex: rowIndex,
|
77
|
+
table,
|
78
|
+
});
|
79
|
+
|
80
|
+
const [bottomPinnedIndex, topPinnedIndex] = useMemo(() => {
|
81
|
+
if (
|
82
|
+
!enableRowPinning ||
|
83
|
+
!rowPinningDisplayMode?.includes('sticky') ||
|
84
|
+
!pinnedRowIds ||
|
85
|
+
!row.getIsPinned()
|
86
|
+
)
|
87
|
+
return [];
|
88
|
+
return [
|
89
|
+
[...pinnedRowIds].reverse().indexOf(row.id),
|
90
|
+
pinnedRowIds.indexOf(row.id),
|
91
|
+
];
|
92
|
+
}, [pinnedRowIds, rowPinning]);
|
93
|
+
|
94
|
+
const tableHeadHeight =
|
95
|
+
((enableStickyHeader || isFullScreen) &&
|
96
|
+
tableHeadRef.current?.clientHeight) ||
|
97
|
+
0;
|
98
|
+
const tableFooterHeight =
|
99
|
+
(enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
|
100
|
+
|
101
|
+
const sx = parseFromValuesOrFunc(tableRowProps?.sx, theme as any);
|
102
|
+
|
103
|
+
const rowHeight =
|
104
|
+
// @ts-ignore
|
105
|
+
parseInt(tableRowProps?.style?.height ?? sx?.height, 10) ||
|
106
|
+
(density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69);
|
52
107
|
|
53
108
|
const handleDragEnter = (_e: DragEvent) => {
|
54
109
|
if (enableRowOrdering && draggingRow) {
|
@@ -63,24 +118,21 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
63
118
|
<TableRow
|
64
119
|
data-index={virtualRow?.index}
|
65
120
|
onDragEnter={handleDragEnter}
|
66
|
-
selected={row.getIsSelected()}
|
67
121
|
ref={(node: HTMLTableRowElement) => {
|
68
122
|
if (node) {
|
69
123
|
rowRef.current = node;
|
70
124
|
measureElement?.(node);
|
71
125
|
}
|
72
126
|
}}
|
127
|
+
selected={row.getIsSelected()}
|
73
128
|
{...tableRowProps}
|
129
|
+
style={{
|
130
|
+
transform: virtualRow
|
131
|
+
? `translateY(${virtualRow?.start}px)`
|
132
|
+
: undefined,
|
133
|
+
...tableRowProps?.style,
|
134
|
+
}}
|
74
135
|
sx={(theme: Theme) => ({
|
75
|
-
backgroundColor: lighten(theme.palette.background.default, 0.06),
|
76
|
-
boxSizing: 'border-box',
|
77
|
-
display: layoutMode === 'grid' ? 'flex' : 'table-row',
|
78
|
-
opacity:
|
79
|
-
draggingRow?.id === row.id || hoveredRow?.id === row.id ? 0.5 : 1,
|
80
|
-
position: virtualRow ? 'absolute' : undefined,
|
81
|
-
transition: virtualRow ? 'none' : 'all 150ms ease-in-out',
|
82
|
-
top: virtualRow ? 0 : undefined,
|
83
|
-
width: '100%',
|
84
136
|
'&:hover td': {
|
85
137
|
backgroundColor:
|
86
138
|
tableRowProps?.hover !== false
|
@@ -91,16 +143,52 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
91
143
|
: `${darken(theme.palette.background.default, 0.05)}`
|
92
144
|
: undefined,
|
93
145
|
},
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
146
|
+
backgroundColor: `${lighten(
|
147
|
+
theme.palette.background.default,
|
148
|
+
0.06,
|
149
|
+
)} !important`,
|
150
|
+
bottom:
|
151
|
+
!virtualRow && bottomPinnedIndex !== undefined && isPinned
|
152
|
+
? `${
|
153
|
+
bottomPinnedIndex * rowHeight +
|
154
|
+
(enableStickyFooter ? tableFooterHeight - 1 : 0)
|
155
|
+
}px`
|
156
|
+
: undefined,
|
157
|
+
boxSizing: 'border-box',
|
158
|
+
display: layoutMode === 'grid' ? 'flex' : 'table-row',
|
159
|
+
opacity: isPinned
|
160
|
+
? 0.98
|
161
|
+
: draggingRow?.id === row.id || hoveredRow?.id === row.id
|
162
|
+
? 0.5
|
163
|
+
: 1,
|
164
|
+
position: virtualRow
|
165
|
+
? 'absolute'
|
166
|
+
: rowPinningDisplayMode?.includes('sticky') && isPinned
|
167
|
+
? 'sticky'
|
101
168
|
: undefined,
|
102
|
-
|
103
|
-
|
169
|
+
td: {
|
170
|
+
backgroundColor: row.getIsSelected()
|
171
|
+
? alpha(theme.palette.primary.main, 0.2)
|
172
|
+
: isPinned
|
173
|
+
? alpha(theme.palette.primary.main, 0.1)
|
174
|
+
: undefined,
|
175
|
+
},
|
176
|
+
top: virtualRow
|
177
|
+
? 0
|
178
|
+
: topPinnedIndex !== undefined && isPinned
|
179
|
+
? `${
|
180
|
+
topPinnedIndex * rowHeight +
|
181
|
+
(enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0)
|
182
|
+
}px`
|
183
|
+
: undefined,
|
184
|
+
transition: virtualRow ? 'none' : 'all 150ms ease-in-out',
|
185
|
+
width: '100%',
|
186
|
+
zIndex:
|
187
|
+
rowPinningDisplayMode?.includes('sticky') && isPinned
|
188
|
+
? 1
|
189
|
+
: undefined,
|
190
|
+
...(sx as any),
|
191
|
+
})}
|
104
192
|
>
|
105
193
|
{virtualPaddingLeft ? (
|
106
194
|
<td style={{ display: 'flex', width: virtualPaddingLeft }} />
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { type DragEvent, type RefObject } from 'react';
|
2
2
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
3
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
3
4
|
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
4
5
|
|
5
6
|
interface Props<TData extends Record<string, any>> {
|
@@ -17,10 +18,10 @@ export const MRT_TableBodyRowGrabHandle = <TData extends Record<string, any>>({
|
|
17
18
|
options: { muiRowDragHandleProps },
|
18
19
|
} = table;
|
19
20
|
|
20
|
-
const iconButtonProps =
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
const iconButtonProps = parseFromValuesOrFunc(muiRowDragHandleProps, {
|
22
|
+
row,
|
23
|
+
table,
|
24
|
+
});
|
24
25
|
|
25
26
|
const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
|
26
27
|
iconButtonProps?.onDragStart?.(event);
|
@@ -37,8 +38,8 @@ export const MRT_TableBodyRowGrabHandle = <TData extends Record<string, any>>({
|
|
37
38
|
return (
|
38
39
|
<MRT_GrabHandleButton
|
39
40
|
iconButtonProps={iconButtonProps}
|
40
|
-
onDragStart={handleDragStart}
|
41
41
|
onDragEnd={handleDragEnd}
|
42
|
+
onDragStart={handleDragStart}
|
42
43
|
table={table}
|
43
44
|
/>
|
44
45
|
);
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import Box from '@mui/material/Box';
|
2
|
+
import { MRT_RowPinButton } from '../buttons/MRT_RowPinButton';
|
3
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
4
|
+
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
5
|
+
|
6
|
+
interface Props<TData extends Record<string, any>> {
|
7
|
+
row: MRT_Row<TData>;
|
8
|
+
table: MRT_TableInstance<TData>;
|
9
|
+
}
|
10
|
+
|
11
|
+
export const MRT_TableBodyRowPinButton = <TData extends Record<string, any>>({
|
12
|
+
row,
|
13
|
+
table,
|
14
|
+
}: Props<TData>) => {
|
15
|
+
const {
|
16
|
+
getState,
|
17
|
+
options: { enableRowPinning, rowPinningDisplayMode },
|
18
|
+
} = table;
|
19
|
+
const { density } = getState();
|
20
|
+
|
21
|
+
const canPin = parseFromValuesOrFunc(enableRowPinning, row as any);
|
22
|
+
|
23
|
+
if (!canPin) return null;
|
24
|
+
|
25
|
+
if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
|
26
|
+
return (
|
27
|
+
<Box
|
28
|
+
sx={{
|
29
|
+
display: 'flex',
|
30
|
+
flexDirection: density === 'compact' ? 'row' : 'column',
|
31
|
+
}}
|
32
|
+
>
|
33
|
+
<MRT_RowPinButton pinningPosition="top" row={row} table={table} />
|
34
|
+
<MRT_RowPinButton pinningPosition="bottom" row={row} table={table} />
|
35
|
+
</Box>
|
36
|
+
);
|
37
|
+
}
|
38
|
+
|
39
|
+
return (
|
40
|
+
<MRT_RowPinButton
|
41
|
+
pinningPosition={rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top'}
|
42
|
+
row={row}
|
43
|
+
table={table}
|
44
|
+
/>
|
45
|
+
);
|
46
|
+
};
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { type RefObject } from 'react';
|
2
|
+
import { type VirtualItem } from '@tanstack/react-virtual';
|
2
3
|
import Collapse from '@mui/material/Collapse';
|
3
4
|
import TableCell from '@mui/material/TableCell';
|
4
5
|
import TableRow from '@mui/material/TableRow';
|
5
6
|
import { lighten } from '@mui/material/styles';
|
6
|
-
import {
|
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>> {
|
@@ -22,31 +23,28 @@ export const MRT_TableDetailPanel = <TData extends Record<string, any>>({
|
|
22
23
|
virtualRow,
|
23
24
|
}: Props<TData>) => {
|
24
25
|
const {
|
25
|
-
getVisibleLeafColumns,
|
26
26
|
getState,
|
27
|
+
getVisibleLeafColumns,
|
27
28
|
options: {
|
28
29
|
layoutMode,
|
29
|
-
muiTableBodyRowProps,
|
30
30
|
muiDetailPanelProps,
|
31
|
+
muiTableBodyRowProps,
|
31
32
|
renderDetailPanel,
|
32
33
|
},
|
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';
|
@@ -1,6 +1,7 @@
|
|
1
1
|
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
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
4
5
|
import { type MRT_Cell, type MRT_TableInstance } from '../types';
|
5
6
|
|
6
7
|
interface Props<TData extends Record<string, any>> {
|
@@ -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
|
>
|