material-react-table 0.36.1 → 0.36.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.
@@ -249,7 +249,7 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
249
249
  displayColumnDefOptions?: Partial<{
250
250
  [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
251
251
  }>;
252
- editingMode?: 'table' | 'row' | 'cell';
252
+ editingMode?: 'table' | 'modal' | 'row' | 'cell';
253
253
  enableBottomToolbar?: boolean;
254
254
  enableClickToCopy?: boolean;
255
255
  enableColumnActions?: boolean;
@@ -0,0 +1,8 @@
1
+ import type { MRT_Row, MRT_TableInstance } from '..';
2
+ interface Props<TData extends Record<string, any> = {}> {
3
+ open: boolean;
4
+ row: MRT_Row<TData>;
5
+ table: MRT_TableInstance<TData>;
6
+ }
7
+ export declare const MRT_EditRowModal: <TData extends Record<string, any> = {}>({ open, row, table, }: Props<TData>) => JSX.Element;
8
+ export {};
@@ -1,8 +1,8 @@
1
- import { FC } from 'react';
2
1
  import type { MRT_Row, MRT_TableInstance } from '..';
3
- interface Props {
4
- row: MRT_Row;
5
- table: MRT_TableInstance;
2
+ interface Props<TData extends Record<string, any> = {}> {
3
+ row: MRT_Row<TData>;
4
+ table: MRT_TableInstance<TData>;
5
+ variant?: 'icon' | 'text';
6
6
  }
7
- export declare const MRT_EditActionButtons: FC<Props>;
7
+ export declare const MRT_EditActionButtons: <TData extends Record<string, any> = {}>({ row, table, variant, }: Props<TData>) => JSX.Element;
8
8
  export {};
package/dist/cjs/index.js CHANGED
@@ -530,29 +530,37 @@ const reorderColumn = (draggedColumn, targetColumn, columnOrder) => {
530
530
  columnOrder.splice(columnOrder.indexOf(targetColumn.id), 0, columnOrder.splice(columnOrder.indexOf(draggedColumn.id), 1)[0]);
531
531
  return [...columnOrder];
532
532
  };
533
- const getLeadingDisplayColumnIds = (props) => [
534
- (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
535
- ((props.positionActionsColumn === 'first' && props.enableRowActions) ||
536
- (props.enableEditing && props.editingMode === 'row')) &&
537
- 'mrt-row-actions',
538
- props.positionExpandColumn === 'first' &&
539
- (props.enableExpanding ||
540
- props.enableGrouping ||
541
- props.renderDetailPanel) &&
542
- 'mrt-row-expand',
543
- props.enableRowSelection && 'mrt-row-select',
544
- props.enableRowNumbers && 'mrt-row-numbers',
545
- ].filter(Boolean);
546
- const getTrailingDisplayColumnIds = (props) => [
547
- ((props.positionActionsColumn === 'last' && props.enableRowActions) ||
548
- (props.enableEditing && props.editingMode === 'row')) &&
549
- 'mrt-row-actions',
550
- props.positionExpandColumn === 'last' &&
551
- (props.enableExpanding ||
552
- props.enableGrouping ||
553
- props.renderDetailPanel) &&
554
- 'mrt-row-expand',
555
- ];
533
+ const getLeadingDisplayColumnIds = (props) => {
534
+ var _a;
535
+ return [
536
+ (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
537
+ ((props.positionActionsColumn === 'first' && props.enableRowActions) ||
538
+ (props.enableEditing &&
539
+ ['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
540
+ 'mrt-row-actions',
541
+ props.positionExpandColumn === 'first' &&
542
+ (props.enableExpanding ||
543
+ props.enableGrouping ||
544
+ props.renderDetailPanel) &&
545
+ 'mrt-row-expand',
546
+ props.enableRowSelection && 'mrt-row-select',
547
+ props.enableRowNumbers && 'mrt-row-numbers',
548
+ ].filter(Boolean);
549
+ };
550
+ const getTrailingDisplayColumnIds = (props) => {
551
+ var _a;
552
+ return [
553
+ ((props.positionActionsColumn === 'last' && props.enableRowActions) ||
554
+ (props.enableEditing &&
555
+ ['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
556
+ 'mrt-row-actions',
557
+ props.positionExpandColumn === 'last' &&
558
+ (props.enableExpanding ||
559
+ props.enableGrouping ||
560
+ props.renderDetailPanel) &&
561
+ 'mrt-row-expand',
562
+ ];
563
+ };
556
564
  const getDefaultColumnOrderIds = (props) => [
557
565
  ...getLeadingDisplayColumnIds(props),
558
566
  ...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
@@ -881,11 +889,10 @@ const MRT_RowActionMenu = ({ anchorEl, handleEdit, row, setAnchorEl, table, }) =
881
889
  })));
882
890
  };
883
891
 
884
- const MRT_EditActionButtons = ({ row, table }) => {
892
+ const MRT_EditActionButtons = ({ row, table, variant = 'icon', }) => {
885
893
  const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onEditingRowSave, }, setEditingRow, } = table;
886
894
  const { editingRow } = getState();
887
895
  const handleCancel = () => {
888
- row._valuesCache = Object.assign({}, row.original);
889
896
  setEditingRow(null);
890
897
  };
891
898
  const handleSave = () => {
@@ -897,13 +904,15 @@ const MRT_EditActionButtons = ({ row, table }) => {
897
904
  });
898
905
  setEditingRow(null);
899
906
  };
900
- return (React__default["default"].createElement(material.Box, { sx: { display: 'flex', gap: '0.75rem' } },
907
+ return (React__default["default"].createElement(material.Box, { sx: { display: 'flex', gap: '0.75rem' } }, variant === 'icon' ? (React__default["default"].createElement(React__default["default"].Fragment, null,
901
908
  React__default["default"].createElement(material.Tooltip, { arrow: true, title: localization.cancel },
902
909
  React__default["default"].createElement(material.IconButton, { "aria-label": localization.cancel, onClick: handleCancel },
903
910
  React__default["default"].createElement(CancelIcon, null))),
904
911
  React__default["default"].createElement(material.Tooltip, { arrow: true, title: localization.save },
905
912
  React__default["default"].createElement(material.IconButton, { "aria-label": localization.save, color: "info", onClick: handleSave },
906
- React__default["default"].createElement(SaveIcon, null)))));
913
+ React__default["default"].createElement(SaveIcon, null))))) : (React__default["default"].createElement(React__default["default"].Fragment, null,
914
+ React__default["default"].createElement(material.Button, { onClick: handleCancel }, localization.cancel),
915
+ React__default["default"].createElement(material.Button, { onClick: handleSave, variant: "contained" }, localization.save)))));
907
916
  };
908
917
 
909
918
  const commonIconButtonStyles = {
@@ -917,7 +926,7 @@ const commonIconButtonStyles = {
917
926
  },
918
927
  };
919
928
  const MRT_ToggleRowActionMenuButton = ({ row, table }) => {
920
- const { getState, options: { enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
929
+ const { getState, options: { editingMode, enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
921
930
  const { editingRow } = getState();
922
931
  const [anchorEl, setAnchorEl] = React.useState(null);
923
932
  const handleOpenRowActionMenu = (event) => {
@@ -929,7 +938,7 @@ const MRT_ToggleRowActionMenuButton = ({ row, table }) => {
929
938
  setEditingRow(Object.assign({}, row));
930
939
  setAnchorEl(null);
931
940
  };
932
- return (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions ? (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions({ row, table }))) : row.id === (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) ? (React__default["default"].createElement(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems && enableEditing ? (React__default["default"].createElement(material.Tooltip, { placement: "right", arrow: true, title: localization.edit },
941
+ return (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions ? (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions({ row, table }))) : row.id === (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) && editingMode === 'row' ? (React__default["default"].createElement(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems && enableEditing ? (React__default["default"].createElement(material.Tooltip, { placement: "right", arrow: true, title: localization.edit },
933
942
  React__default["default"].createElement(material.IconButton, { sx: commonIconButtonStyles, onClick: handleStartEditMode },
934
943
  React__default["default"].createElement(EditIcon, null)))) : renderRowActionMenuItems ? (React__default["default"].createElement(React__default["default"].Fragment, null,
935
944
  React__default["default"].createElement(material.Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.rowActions },
@@ -1739,10 +1748,10 @@ const MRT_TableHead = ({ table }) => {
1739
1748
  return (React__default["default"].createElement(material.TableHead, Object.assign({}, tableHeadProps), getHeaderGroups().map((headerGroup) => (React__default["default"].createElement(MRT_TableHeadRow, { headerGroup: headerGroup, key: headerGroup.id, table: table })))));
1740
1749
  };
1741
1750
 
1742
- const MRT_EditCellTextField = ({ cell, table }) => {
1751
+ const MRT_EditCellTextField = ({ cell, showLabel, table, }) => {
1743
1752
  var _a;
1744
1753
  const { getState, options: { tableId, muiTableBodyCellEditTextFieldProps }, setEditingCell, setEditingRow, } = table;
1745
- const { column, row } = cell;
1754
+ const { column } = cell;
1746
1755
  const { columnDef } = column;
1747
1756
  const { editingRow } = getState();
1748
1757
  const [value, setValue] = React.useState(() => cell.getValue());
@@ -1765,17 +1774,14 @@ const MRT_EditCellTextField = ({ cell, table }) => {
1765
1774
  var _a;
1766
1775
  (_a = textFieldProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1767
1776
  if (editingRow) {
1768
- if (!row._valuesCache)
1769
- row._valuesCache = {};
1770
- row._valuesCache[column.id] = value;
1771
- setEditingRow(Object.assign({}, editingRow));
1777
+ setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: value }) }));
1772
1778
  }
1773
1779
  setEditingCell(null);
1774
1780
  };
1775
1781
  if (columnDef.Edit) {
1776
1782
  return React__default["default"].createElement(React__default["default"].Fragment, null, (_a = columnDef.Edit) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, table }));
1777
1783
  }
1778
- return (React__default["default"].createElement(material.TextField, Object.assign({ id: `mrt-${tableId}-edit-cell-text-field-${cell.id}`, margin: "none", onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { onBlur: handleBlur, onChange: handleChange })));
1784
+ return (React__default["default"].createElement(material.TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, id: `mrt-${tableId}-edit-cell-text-field-${cell.id}`, label: showLabel ? column.columnDef.header : undefined, margin: "none", onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { onBlur: handleBlur, onChange: handleChange })));
1779
1785
  };
1780
1786
 
1781
1787
  const MRT_CopyButton = ({ cell, children, table }) => {
@@ -1843,6 +1849,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
1843
1849
  const isEditable = (enableEditing || columnDef.enableEditing) &&
1844
1850
  columnDef.enableEditing !== false;
1845
1851
  const isEditing = isEditable &&
1852
+ editingMode !== 'modal' &&
1846
1853
  (editingMode === 'table' ||
1847
1854
  (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
1848
1855
  (editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id);
@@ -1940,10 +1947,10 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
1940
1947
  backgroundColor: enableHover &&
1941
1948
  enableEditing &&
1942
1949
  columnDef.enableEditing !== false &&
1943
- editingMode !== 'row'
1950
+ ['table', 'cell'].includes(editingMode !== null && editingMode !== void 0 ? editingMode : '')
1944
1951
  ? theme.palette.mode === 'dark'
1945
- ? `${material.lighten(theme.palette.background.default, 0.13)} !important`
1946
- : `${material.darken(theme.palette.background.default, 0.07)} !important`
1952
+ ? `${material.lighten(theme.palette.background.default, 0.2)} !important`
1953
+ : `${material.darken(theme.palette.background.default, 0.1)} !important`
1947
1954
  : undefined,
1948
1955
  } }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
1949
1956
  ? tableCellProps.sx(theme)
@@ -2217,6 +2224,23 @@ const MRT_TablePaper = ({ table }) => {
2217
2224
  enableBottomToolbar && React__default["default"].createElement(MRT_BottomToolbar, { table: table })));
2218
2225
  };
2219
2226
 
2227
+ const MRT_EditRowModal = ({ open, row, table, }) => {
2228
+ const { options: { localization }, } = table;
2229
+ return (React__default["default"].createElement(material.Dialog, { open: open },
2230
+ React__default["default"].createElement(material.DialogTitle, { textAlign: "center" }, localization.edit),
2231
+ React__default["default"].createElement(material.DialogContent, null,
2232
+ React__default["default"].createElement(material.Stack, { sx: {
2233
+ width: '100%',
2234
+ minWidth: { xs: '300px', sm: '360px', md: '400px' },
2235
+ gap: '1.5rem',
2236
+ } }, row
2237
+ .getVisibleCells()
2238
+ .filter((cell) => cell.column.columnDef.columnDefType === 'data')
2239
+ .map((cell) => (React__default["default"].createElement(MRT_EditCellTextField, { cell: cell, key: cell.id, showLabel: true, table: table }))))),
2240
+ React__default["default"].createElement(material.DialogActions, { sx: { p: '1.25rem' } },
2241
+ React__default["default"].createElement(MRT_EditActionButtons, { row: row, table: table, variant: "text" }))));
2242
+ };
2243
+
2220
2244
  const MRT_TableRoot = (props) => {
2221
2245
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
2222
2246
  const [tableId, setIdPrefix] = React.useState(props.tableId);
@@ -2318,7 +2342,8 @@ const MRT_TableRoot = (props) => {
2318
2342
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2319
2343
  React__default["default"].createElement(material.Dialog, { PaperComponent: material.Box, TransitionComponent: material.Grow, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => setIsFullScreen(false), open: isFullScreen, transitionDuration: 400 },
2320
2344
  React__default["default"].createElement(MRT_TablePaper, { table: table })),
2321
- !isFullScreen && React__default["default"].createElement(MRT_TablePaper, { table: table })));
2345
+ !isFullScreen && React__default["default"].createElement(MRT_TablePaper, { table: table }),
2346
+ editingRow && props.editingMode === 'modal' && (React__default["default"].createElement(MRT_EditRowModal, { row: editingRow, table: table, open: true }))));
2322
2347
  };
2323
2348
 
2324
2349
  var MaterialReactTable = (_a) => {