material-react-table 0.38.0 → 0.38.3
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 -1
- package/dist/cjs/MaterialReactTable.d.ts +3 -2
- package/dist/cjs/index.js +42 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/MaterialReactTable.d.ts +3 -2
- package/dist/esm/material-react-table.esm.js +42 -13
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +3 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +5 -3
- package/src/buttons/MRT_GrabHandleButton.tsx +5 -3
- package/src/footer/MRT_TableFooter.tsx +22 -2
- package/src/head/MRT_TableHeadRow.tsx +3 -1
- package/src/inputs/MRT_EditCellTextField.tsx +36 -15
- package/src/inputs/MRT_FilterTextField.tsx +1 -1
- package/src/table/MRT_TablePaper.tsx +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -239,8 +239,8 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
|
|
|
239
239
|
setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
|
|
240
240
|
setDraggingColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
|
|
241
241
|
setDraggingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
|
|
242
|
-
setEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
|
|
243
|
-
setEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
|
|
242
|
+
setEditingCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
|
|
243
|
+
setEditingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
|
|
244
244
|
setGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
|
|
245
245
|
setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | {
|
|
246
246
|
id: string;
|
|
@@ -479,6 +479,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
479
479
|
enableRowSelection?: boolean | ((row: MRT_Row<TData>) => boolean);
|
|
480
480
|
enableRowVirtualization?: boolean;
|
|
481
481
|
enableSelectAll?: boolean;
|
|
482
|
+
enableStickyFooter?: boolean;
|
|
482
483
|
enableStickyHeader?: boolean;
|
|
483
484
|
enableTableFooter?: boolean;
|
|
484
485
|
enableTableHead?: boolean;
|
package/package.json
CHANGED
|
@@ -109,8 +109,8 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
|
|
|
109
109
|
setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
|
|
110
110
|
setDraggingColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
|
|
111
111
|
setDraggingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
|
|
112
|
-
setEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
|
|
113
|
-
setEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
|
|
112
|
+
setEditingCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
|
|
113
|
+
setEditingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
|
|
114
114
|
setGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
|
|
115
115
|
setHoveredColumn: Dispatch<
|
|
116
116
|
SetStateAction<MRT_Column<TData> | { id: string } | null>
|
|
@@ -488,6 +488,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
488
488
|
enableRowSelection?: boolean | ((row: MRT_Row<TData>) => boolean);
|
|
489
489
|
enableRowVirtualization?: boolean;
|
|
490
490
|
enableSelectAll?: boolean;
|
|
491
|
+
enableStickyFooter?: boolean;
|
|
491
492
|
enableStickyHeader?: boolean;
|
|
492
493
|
enableTableFooter?: boolean;
|
|
493
494
|
enableTableHead?: boolean;
|
|
@@ -40,12 +40,14 @@ export const MRT_ExpandAllButton: FC<Props> = ({ table }) => {
|
|
|
40
40
|
disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
|
|
41
41
|
onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
|
|
42
42
|
{...iconButtonProps}
|
|
43
|
-
sx={{
|
|
43
|
+
sx={(theme) => ({
|
|
44
44
|
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
45
45
|
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
46
46
|
mt: density !== 'compact' ? '-0.25rem' : undefined,
|
|
47
|
-
...iconButtonProps?.sx
|
|
48
|
-
|
|
47
|
+
...(iconButtonProps?.sx instanceof Function
|
|
48
|
+
? iconButtonProps?.sx(theme)
|
|
49
|
+
: (iconButtonProps?.sx as any)),
|
|
50
|
+
})}
|
|
49
51
|
>
|
|
50
52
|
<KeyboardDoubleArrowDownIcon
|
|
51
53
|
style={{
|
|
@@ -37,7 +37,7 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
|
|
|
37
37
|
onDragEnd={onDragEnd}
|
|
38
38
|
size="small"
|
|
39
39
|
{...iconButtonProps}
|
|
40
|
-
sx={{
|
|
40
|
+
sx={(theme) => ({
|
|
41
41
|
cursor: 'grab',
|
|
42
42
|
m: 0,
|
|
43
43
|
opacity: 0.5,
|
|
@@ -50,8 +50,10 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
|
|
|
50
50
|
'&:active': {
|
|
51
51
|
cursor: 'grabbing',
|
|
52
52
|
},
|
|
53
|
-
...iconButtonProps?.sx
|
|
54
|
-
|
|
53
|
+
...(iconButtonProps?.sx instanceof Function
|
|
54
|
+
? iconButtonProps?.sx(theme)
|
|
55
|
+
: (iconButtonProps?.sx as any)),
|
|
56
|
+
})}
|
|
55
57
|
>
|
|
56
58
|
<DragHandleIcon />
|
|
57
59
|
</IconButton>
|
|
@@ -10,16 +10,36 @@ interface Props {
|
|
|
10
10
|
export const MRT_TableFooter: FC<Props> = ({ table }) => {
|
|
11
11
|
const {
|
|
12
12
|
getFooterGroups,
|
|
13
|
-
|
|
13
|
+
getState,
|
|
14
|
+
options: { enableStickyFooter, muiTableFooterProps },
|
|
14
15
|
} = table;
|
|
16
|
+
const { isFullScreen } = getState();
|
|
15
17
|
|
|
16
18
|
const tableFooterProps =
|
|
17
19
|
muiTableFooterProps instanceof Function
|
|
18
20
|
? muiTableFooterProps({ table })
|
|
19
21
|
: muiTableFooterProps;
|
|
20
22
|
|
|
23
|
+
const stickFooter =
|
|
24
|
+
(isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
|
|
25
|
+
|
|
21
26
|
return (
|
|
22
|
-
<TableFooter
|
|
27
|
+
<TableFooter
|
|
28
|
+
{...tableFooterProps}
|
|
29
|
+
sx={(theme) => ({
|
|
30
|
+
position: stickFooter ? 'sticky' : undefined,
|
|
31
|
+
bottom: stickFooter ? 0 : undefined,
|
|
32
|
+
opacity: stickFooter ? 0.95 : undefined,
|
|
33
|
+
outline: stickFooter
|
|
34
|
+
? theme.palette.mode === 'light'
|
|
35
|
+
? `1px solid ${theme.palette.grey[300]}`
|
|
36
|
+
: `1px solid ${theme.palette.grey[700]}`
|
|
37
|
+
: undefined,
|
|
38
|
+
...(tableFooterProps?.sx instanceof Function
|
|
39
|
+
? tableFooterProps?.sx(theme)
|
|
40
|
+
: (tableFooterProps?.sx as any)),
|
|
41
|
+
})}
|
|
42
|
+
>
|
|
23
43
|
{getFooterGroups().map((footerGroup) => (
|
|
24
44
|
<MRT_TableFooterRow
|
|
25
45
|
footerGroup={footerGroup as any}
|
|
@@ -24,7 +24,9 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, table }) => {
|
|
|
24
24
|
sx={(theme) => ({
|
|
25
25
|
boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
26
26
|
backgroundColor: lighten(theme.palette.background.default, 0.04),
|
|
27
|
-
...(tableRowProps?.sx
|
|
27
|
+
...(tableRowProps?.sx instanceof Function
|
|
28
|
+
? tableRowProps?.sx(theme)
|
|
29
|
+
: (tableRowProps?.sx as any)),
|
|
28
30
|
})}
|
|
29
31
|
>
|
|
30
32
|
{headerGroup.headers.map((header: MRT_Header, index) => (
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
FocusEvent,
|
|
4
|
+
KeyboardEvent,
|
|
5
|
+
MouseEvent,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import { TextField, TextFieldProps } from '@mui/material';
|
|
3
9
|
import type { MRT_Cell, MRT_TableInstance } from '..';
|
|
4
10
|
|
|
@@ -46,22 +52,36 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
|
|
|
46
52
|
...mcTableBodyCellEditTextFieldProps,
|
|
47
53
|
};
|
|
48
54
|
|
|
55
|
+
const saveRow = (newValue: string) => {
|
|
56
|
+
if (editingRow) {
|
|
57
|
+
setEditingRow({
|
|
58
|
+
...editingRow,
|
|
59
|
+
_valuesCache: { ...editingRow._valuesCache, [column.id]: newValue },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
49
64
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
50
65
|
textFieldProps.onChange?.(event);
|
|
51
66
|
setValue(event.target.value);
|
|
67
|
+
if (textFieldProps?.select) {
|
|
68
|
+
saveRow(event.target.value);
|
|
69
|
+
}
|
|
52
70
|
};
|
|
53
71
|
|
|
54
72
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
55
73
|
textFieldProps.onBlur?.(event);
|
|
56
|
-
|
|
57
|
-
setEditingRow({
|
|
58
|
-
...editingRow,
|
|
59
|
-
_valuesCache: { ...editingRow._valuesCache, [column.id]: value },
|
|
60
|
-
} as any);
|
|
61
|
-
}
|
|
74
|
+
saveRow(value);
|
|
62
75
|
setEditingCell(null);
|
|
63
76
|
};
|
|
64
77
|
|
|
78
|
+
const handleEnterKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
79
|
+
textFieldProps.onKeyDown?.(event);
|
|
80
|
+
if (event.key === 'Enter') {
|
|
81
|
+
editInputRefs.current[column.id]?.blur();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
65
85
|
if (columnDef.Edit) {
|
|
66
86
|
return <>{columnDef.Edit?.({ cell, column, row, table })}</>;
|
|
67
87
|
}
|
|
@@ -70,14 +90,6 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
|
|
|
70
90
|
<TextField
|
|
71
91
|
disabled={columnDef.enableEditing === false}
|
|
72
92
|
fullWidth
|
|
73
|
-
label={showLabel ? column.columnDef.header : undefined}
|
|
74
|
-
margin="none"
|
|
75
|
-
name={cell.id}
|
|
76
|
-
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
77
|
-
placeholder={columnDef.header}
|
|
78
|
-
value={value}
|
|
79
|
-
variant="standard"
|
|
80
|
-
{...textFieldProps}
|
|
81
93
|
inputRef={(inputRef) => {
|
|
82
94
|
if (inputRef) {
|
|
83
95
|
editInputRefs.current[column.id] = inputRef;
|
|
@@ -86,8 +98,17 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
|
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
}}
|
|
101
|
+
label={showLabel ? column.columnDef.header : undefined}
|
|
102
|
+
margin="none"
|
|
103
|
+
name={column.id}
|
|
104
|
+
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
105
|
+
placeholder={columnDef.header}
|
|
106
|
+
value={value}
|
|
107
|
+
variant="standard"
|
|
108
|
+
{...textFieldProps}
|
|
89
109
|
onBlur={handleBlur}
|
|
90
110
|
onChange={handleChange}
|
|
111
|
+
onKeyDown={handleEnterKeyDown}
|
|
91
112
|
/>
|
|
92
113
|
);
|
|
93
114
|
};
|
|
@@ -299,7 +299,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
299
299
|
}}
|
|
300
300
|
sx={(theme) => ({
|
|
301
301
|
p: 0,
|
|
302
|
-
minWidth: !filterChipLabel ? '
|
|
302
|
+
minWidth: !filterChipLabel ? '150px' : 'auto',
|
|
303
303
|
width: '100%',
|
|
304
304
|
'& .MuiSelect-icon': {
|
|
305
305
|
mr: '1.5rem',
|
|
@@ -35,10 +35,12 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
|
|
|
35
35
|
<Paper
|
|
36
36
|
elevation={2}
|
|
37
37
|
{...tablePaperProps}
|
|
38
|
-
sx={{
|
|
38
|
+
sx={(theme) => ({
|
|
39
39
|
transition: 'all 0.2s ease-in-out',
|
|
40
|
-
...tablePaperProps?.sx
|
|
41
|
-
|
|
40
|
+
...(tablePaperProps?.sx instanceof Function
|
|
41
|
+
? tablePaperProps?.sx(theme)
|
|
42
|
+
: (tablePaperProps?.sx as any)),
|
|
43
|
+
})}
|
|
42
44
|
style={{
|
|
43
45
|
...tablePaperProps?.style,
|
|
44
46
|
height: isFullScreen ? '100vh' : undefined,
|