material-react-table 0.7.0-alpha.6 → 0.7.0-alpha.7
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 +8 -3
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +42 -23
- 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 +42 -23
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +12 -2
- package/src/body/MRT_TableBodyCell.tsx +2 -1
- package/src/buttons/MRT_EditActionButtons.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +5 -5
- package/src/inputs/MRT_EditCellTextField.tsx +26 -10
- package/src/localization.ts +2 -0
- package/src/menus/MRT_RowActionMenu.tsx +2 -2
- package/src/table/MRT_TableRoot.tsx +5 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChangeEvent, Dispatch, FC, MouseEvent, ReactNode, SetStateAction } from 'react';
|
|
1
|
+
import { ChangeEvent, Dispatch, FC, FocusEvent, MouseEvent, ReactNode, SetStateAction } from 'react';
|
|
2
2
|
import { AlertProps, ButtonProps, CheckboxProps, IconButtonProps, LinearProgressProps, PaperProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
|
|
3
3
|
import { Cell, Column, ColumnDef, DefaultGenerics, FilterType, Header, HeaderGroup, Options, Overwrite, PaginationState, Row, TableInstance, TableState, VisibilityState } from '@tanstack/react-table';
|
|
4
4
|
import { MRT_Localization } from './localization';
|
|
@@ -119,6 +119,11 @@ export declare type MRT_ColumnInterface<D extends Record<string, any> = {}> = Om
|
|
|
119
119
|
tableInstance: MRT_TableInstance;
|
|
120
120
|
column: MRT_ColumnInstance<D>;
|
|
121
121
|
}) => TableCellProps);
|
|
122
|
+
onCellEditBlur?: ({ cell, event, tableInstance, }: {
|
|
123
|
+
event: FocusEvent<HTMLInputElement>;
|
|
124
|
+
cell: MRT_Cell<D>;
|
|
125
|
+
tableInstance: MRT_TableInstance<D>;
|
|
126
|
+
}) => void;
|
|
122
127
|
onCellEditChange?: ({ cell, event, tableInstance, }: {
|
|
123
128
|
event: ChangeEvent<HTMLInputElement>;
|
|
124
129
|
cell: MRT_Cell<D>;
|
|
@@ -162,7 +167,7 @@ export declare type MaterialReactTableProps<D extends Record<string, any> = {}>
|
|
|
162
167
|
enablePagination?: boolean;
|
|
163
168
|
enableRowActions?: boolean;
|
|
164
169
|
enableStickyHeader?: boolean;
|
|
165
|
-
|
|
170
|
+
enableEditing?: boolean;
|
|
166
171
|
enableRowNumbers?: boolean;
|
|
167
172
|
enableSelectAll?: boolean;
|
|
168
173
|
enabledGlobalFilterTypes?: (MRT_FILTER_TYPE | string)[];
|
|
@@ -292,7 +297,7 @@ export declare type MaterialReactTableProps<D extends Record<string, any> = {}>
|
|
|
292
297
|
row: MRT_Row<D>;
|
|
293
298
|
tableInstance: MRT_TableInstance<D>;
|
|
294
299
|
}) => void;
|
|
295
|
-
|
|
300
|
+
onEditSubmit?: ({ row, tableInstance, }: {
|
|
296
301
|
row: MRT_Row<D>;
|
|
297
302
|
tableInstance: MRT_TableInstance<D>;
|
|
298
303
|
}) => Promise<void> | void;
|
package/dist/localization.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ var MRT_DefaultLocalization_EN = {
|
|
|
105
105
|
pinToLeft: 'Pin to left',
|
|
106
106
|
pinToRight: 'Pin to right',
|
|
107
107
|
rowActions: 'Row Actions',
|
|
108
|
+
rowNumber: '#',
|
|
108
109
|
rowNumbers: 'Row Numbers',
|
|
109
110
|
save: 'Save',
|
|
110
111
|
search: 'Search',
|
|
@@ -919,7 +920,7 @@ var MRT_RowActionMenu = function MRT_RowActionMenu(_ref) {
|
|
|
919
920
|
var getState = tableInstance.getState,
|
|
920
921
|
_tableInstance$option = tableInstance.options,
|
|
921
922
|
EditIcon = _tableInstance$option.icons.EditIcon,
|
|
922
|
-
|
|
923
|
+
enableEditing = _tableInstance$option.enableEditing,
|
|
923
924
|
localization = _tableInstance$option.localization,
|
|
924
925
|
renderRowActionMenuItems = _tableInstance$option.renderRowActionMenuItems;
|
|
925
926
|
|
|
@@ -935,7 +936,7 @@ var MRT_RowActionMenu = function MRT_RowActionMenu(_ref) {
|
|
|
935
936
|
MenuListProps: {
|
|
936
937
|
dense: isDensePadding
|
|
937
938
|
}
|
|
938
|
-
},
|
|
939
|
+
}, enableEditing && React__default.createElement(material.MenuItem, {
|
|
939
940
|
onClick: handleEdit,
|
|
940
941
|
sx: commonMenuItemStyles$1
|
|
941
942
|
}, React__default.createElement(material.Box, {
|
|
@@ -958,7 +959,7 @@ var MRT_EditActionButtons = function MRT_EditActionButtons(_ref) {
|
|
|
958
959
|
CancelIcon = _tableInstance$option2.CancelIcon,
|
|
959
960
|
SaveIcon = _tableInstance$option2.SaveIcon,
|
|
960
961
|
localization = _tableInstance$option.localization,
|
|
961
|
-
|
|
962
|
+
onEditSubmit = _tableInstance$option.onEditSubmit,
|
|
962
963
|
setCurrentEditingRow = _tableInstance$option.setCurrentEditingRow;
|
|
963
964
|
|
|
964
965
|
var _getState = getState(),
|
|
@@ -972,7 +973,7 @@ var MRT_EditActionButtons = function MRT_EditActionButtons(_ref) {
|
|
|
972
973
|
};
|
|
973
974
|
|
|
974
975
|
var handleSave = function handleSave() {
|
|
975
|
-
|
|
976
|
+
onEditSubmit == null ? void 0 : onEditSubmit({
|
|
976
977
|
row: currentEditingRow != null ? currentEditingRow : row,
|
|
977
978
|
tableInstance: tableInstance
|
|
978
979
|
});
|
|
@@ -1015,7 +1016,7 @@ var MRT_ToggleRowActionMenuButton = function MRT_ToggleRowActionMenuButton(_ref)
|
|
|
1015
1016
|
tableInstance = _ref.tableInstance;
|
|
1016
1017
|
var getState = tableInstance.getState,
|
|
1017
1018
|
_tableInstance$option = tableInstance.options,
|
|
1018
|
-
|
|
1019
|
+
enableEditing = _tableInstance$option.enableEditing,
|
|
1019
1020
|
_tableInstance$option2 = _tableInstance$option.icons,
|
|
1020
1021
|
EditIcon = _tableInstance$option2.EditIcon,
|
|
1021
1022
|
MoreHorizIcon = _tableInstance$option2.MoreHorizIcon,
|
|
@@ -1037,7 +1038,7 @@ var MRT_ToggleRowActionMenuButton = function MRT_ToggleRowActionMenuButton(_ref)
|
|
|
1037
1038
|
setAnchorEl(event.currentTarget);
|
|
1038
1039
|
};
|
|
1039
1040
|
|
|
1040
|
-
var
|
|
1041
|
+
var handleStartEditMode = function handleStartEditMode() {
|
|
1041
1042
|
setCurrentEditingRow(_extends({}, row));
|
|
1042
1043
|
setAnchorEl(null);
|
|
1043
1044
|
};
|
|
@@ -1048,13 +1049,13 @@ var MRT_ToggleRowActionMenuButton = function MRT_ToggleRowActionMenuButton(_ref)
|
|
|
1048
1049
|
})) : row.id === (currentEditingRow == null ? void 0 : currentEditingRow.id) ? React__default.createElement(MRT_EditActionButtons, {
|
|
1049
1050
|
row: row,
|
|
1050
1051
|
tableInstance: tableInstance
|
|
1051
|
-
}) : !renderRowActionMenuItems &&
|
|
1052
|
+
}) : !renderRowActionMenuItems && enableEditing ? React__default.createElement(material.Tooltip, {
|
|
1052
1053
|
placement: "right",
|
|
1053
1054
|
arrow: true,
|
|
1054
1055
|
title: localization.edit
|
|
1055
1056
|
}, React__default.createElement(material.IconButton, {
|
|
1056
1057
|
sx: commonIconButtonStyles,
|
|
1057
|
-
onClick:
|
|
1058
|
+
onClick: handleStartEditMode
|
|
1058
1059
|
}, React__default.createElement(EditIcon, null))) : renderRowActionMenuItems ? React__default.createElement(React__default.Fragment, null, React__default.createElement(material.Tooltip, {
|
|
1059
1060
|
arrow: true,
|
|
1060
1061
|
enterDelay: 1000,
|
|
@@ -1067,7 +1068,7 @@ var MRT_ToggleRowActionMenuButton = function MRT_ToggleRowActionMenuButton(_ref)
|
|
|
1067
1068
|
sx: commonIconButtonStyles
|
|
1068
1069
|
}, React__default.createElement(MoreHorizIcon, null))), React__default.createElement(MRT_RowActionMenu, {
|
|
1069
1070
|
anchorEl: anchorEl,
|
|
1070
|
-
handleEdit:
|
|
1071
|
+
handleEdit: handleStartEditMode,
|
|
1071
1072
|
row: row,
|
|
1072
1073
|
setAnchorEl: setAnchorEl,
|
|
1073
1074
|
tableInstance: tableInstance
|
|
@@ -2152,19 +2153,33 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
|
|
|
2152
2153
|
tableInstance = _ref.tableInstance;
|
|
2153
2154
|
var getState = tableInstance.getState,
|
|
2154
2155
|
_tableInstance$option = tableInstance.options,
|
|
2155
|
-
|
|
2156
|
-
muiTableBodyCellEditTextFieldProps = _tableInstance$option.muiTableBodyCellEditTextFieldProps
|
|
2156
|
+
enableEditing = _tableInstance$option.enableEditing,
|
|
2157
|
+
muiTableBodyCellEditTextFieldProps = _tableInstance$option.muiTableBodyCellEditTextFieldProps,
|
|
2158
|
+
setCurrentEditingRow = _tableInstance$option.setCurrentEditingRow;
|
|
2159
|
+
|
|
2160
|
+
var _useState = React.useState(cell.value),
|
|
2161
|
+
value = _useState[0],
|
|
2162
|
+
setValue = _useState[1];
|
|
2163
|
+
|
|
2157
2164
|
var column = cell.column,
|
|
2158
2165
|
row = cell.row;
|
|
2159
2166
|
|
|
2160
2167
|
var handleChange = function handleChange(event) {
|
|
2168
|
+
setValue(event.target.value);
|
|
2169
|
+
column.onCellEditChange == null ? void 0 : column.onCellEditChange({
|
|
2170
|
+
event: event,
|
|
2171
|
+
cell: cell,
|
|
2172
|
+
tableInstance: tableInstance
|
|
2173
|
+
});
|
|
2174
|
+
};
|
|
2175
|
+
|
|
2176
|
+
var handleBlur = function handleBlur(event) {
|
|
2161
2177
|
if (getState().currentEditingRow) {
|
|
2162
|
-
row.values[column.id] =
|
|
2163
|
-
|
|
2164
|
-
// });
|
|
2178
|
+
row.values[column.id] = value;
|
|
2179
|
+
setCurrentEditingRow(_extends({}, getState().currentEditingRow));
|
|
2165
2180
|
}
|
|
2166
2181
|
|
|
2167
|
-
column.
|
|
2182
|
+
column.onCellEditBlur == null ? void 0 : column.onCellEditBlur({
|
|
2168
2183
|
event: event,
|
|
2169
2184
|
cell: cell,
|
|
2170
2185
|
tableInstance: tableInstance
|
|
@@ -2182,7 +2197,7 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
|
|
|
2182
2197
|
|
|
2183
2198
|
var textFieldProps = _extends({}, mTableBodyCellEditTextFieldProps, mcTableBodyCellEditTextFieldProps);
|
|
2184
2199
|
|
|
2185
|
-
if (
|
|
2200
|
+
if (enableEditing && column.enableEditing !== false && column.Edit) {
|
|
2186
2201
|
return React__default.createElement(React__default.Fragment, null, column.Edit == null ? void 0 : column.Edit({
|
|
2187
2202
|
cell: cell,
|
|
2188
2203
|
tableInstance: tableInstance
|
|
@@ -2191,12 +2206,13 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
|
|
|
2191
2206
|
|
|
2192
2207
|
return React__default.createElement(material.TextField, Object.assign({
|
|
2193
2208
|
margin: "dense",
|
|
2209
|
+
onBlur: handleBlur,
|
|
2194
2210
|
onChange: handleChange,
|
|
2195
2211
|
onClick: function onClick(e) {
|
|
2196
2212
|
return e.stopPropagation();
|
|
2197
2213
|
},
|
|
2198
2214
|
placeholder: column.header,
|
|
2199
|
-
value:
|
|
2215
|
+
value: value,
|
|
2200
2216
|
variant: "standard"
|
|
2201
2217
|
}, textFieldProps));
|
|
2202
2218
|
};
|
|
@@ -2271,6 +2287,7 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
|
|
|
2271
2287
|
_tableInstance$option = tableInstance.options,
|
|
2272
2288
|
enableClickToCopy = _tableInstance$option.enableClickToCopy,
|
|
2273
2289
|
enableColumnPinning = _tableInstance$option.enableColumnPinning,
|
|
2290
|
+
enableEditing = _tableInstance$option.enableEditing,
|
|
2274
2291
|
isLoading = _tableInstance$option.isLoading,
|
|
2275
2292
|
muiTableBodyCellProps = _tableInstance$option.muiTableBodyCellProps,
|
|
2276
2293
|
muiTableBodyCellSkeletonProps = _tableInstance$option.muiTableBodyCellSkeletonProps,
|
|
@@ -2318,7 +2335,7 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
|
|
|
2318
2335
|
}, muiTableBodyCellSkeletonProps)) : column.columnDefType === 'display' ? column.Cell == null ? void 0 : column.Cell({
|
|
2319
2336
|
cell: cell,
|
|
2320
2337
|
tableInstance: tableInstance
|
|
2321
|
-
}) : cell.getIsPlaceholder() || row.getIsGrouped() && column.id !== row.groupingColumnId ? null : cell.getIsAggregated() ? cell.renderAggregatedCell() : column.enableEditing && (currentEditingRow == null ? void 0 : currentEditingRow.id) === row.id ? React__default.createElement(MRT_EditCellTextField, {
|
|
2338
|
+
}) : cell.getIsPlaceholder() || row.getIsGrouped() && column.id !== row.groupingColumnId ? null : cell.getIsAggregated() ? cell.renderAggregatedCell() : enableEditing && column.enableEditing !== false && (currentEditingRow == null ? void 0 : currentEditingRow.id) === row.id ? React__default.createElement(MRT_EditCellTextField, {
|
|
2322
2339
|
cell: cell,
|
|
2323
2340
|
tableInstance: tableInstance
|
|
2324
2341
|
}) : (enableClickToCopy || column.enableClickToCopy) && column.enableClickToCopy !== false ? React__default.createElement(React__default.Fragment, null, React__default.createElement(MRT_CopyButton, {
|
|
@@ -2824,9 +2841,9 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
2824
2841
|
return reactTable.createTable();
|
|
2825
2842
|
}, []);
|
|
2826
2843
|
var displayColumns = React.useMemo(function () {
|
|
2827
|
-
var _props$localization, _props$localization2, _props$localization3, _props$
|
|
2844
|
+
var _props$localization, _props$localization2, _props$localization3, _props$localization5;
|
|
2828
2845
|
|
|
2829
|
-
return [(props.enableRowActions || props.
|
|
2846
|
+
return [(props.enableRowActions || props.enableEditing) && createDisplayColumn(table, {
|
|
2830
2847
|
Cell: function Cell(_ref3) {
|
|
2831
2848
|
var cell = _ref3.cell;
|
|
2832
2849
|
return React__default.createElement(MRT_ToggleRowActionMenuButton, {
|
|
@@ -2879,15 +2896,17 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
2879
2896
|
return cell.row.index + 1;
|
|
2880
2897
|
},
|
|
2881
2898
|
Header: function Header() {
|
|
2882
|
-
|
|
2899
|
+
var _props$localization4;
|
|
2900
|
+
|
|
2901
|
+
return (_props$localization4 = props.localization) == null ? void 0 : _props$localization4.rowNumber;
|
|
2883
2902
|
},
|
|
2884
|
-
header: (_props$
|
|
2903
|
+
header: (_props$localization5 = props.localization) == null ? void 0 : _props$localization5.rowNumbers,
|
|
2885
2904
|
id: 'mrt-row-numbers',
|
|
2886
2905
|
maxWidth: 40,
|
|
2887
2906
|
width: 40,
|
|
2888
2907
|
minWidth: 40
|
|
2889
2908
|
})].filter(Boolean);
|
|
2890
|
-
}, [props.enableExpandAll, props.enableExpanded, props.enableRowActions, props.
|
|
2909
|
+
}, [table, props.enableExpandAll, props.enableExpanded, props.enableRowActions, props.enableGrouping, props.enableEditing, props.enableRowNumbers, props.enableRowSelection, props.enableSelectAll, props.localization]);
|
|
2891
2910
|
var columns = React.useMemo(function () {
|
|
2892
2911
|
return table.createColumns([].concat(displayColumns, props.columns.map(function (column) {
|
|
2893
2912
|
return column.columns ? createGroup(table, column, currentFilterTypes) : createDataColumn(table, column, currentFilterTypes);
|