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.
package/dist/index.d.ts CHANGED
@@ -440,7 +440,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
440
440
  displayColumnDefOptions?: Partial<{
441
441
  [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
442
442
  }>;
443
- editingMode?: 'table' | 'row' | 'cell';
443
+ editingMode?: 'table' | 'modal' | 'row' | 'cell';
444
444
  enableBottomToolbar?: boolean;
445
445
  enableClickToCopy?: boolean;
446
446
  enableColumnActions?: boolean;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.36.1",
2
+ "version": "0.36.2",
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.",
@@ -432,7 +432,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
432
432
  displayColumnDefOptions?: Partial<{
433
433
  [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
434
434
  }>;
435
- editingMode?: 'table' | 'row' | 'cell';
435
+ editingMode?: 'table' | 'modal' | 'row' | 'cell';
436
436
  enableBottomToolbar?: boolean;
437
437
  enableClickToCopy?: boolean;
438
438
  enableColumnActions?: boolean;
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import {
3
+ Dialog,
4
+ DialogActions,
5
+ DialogContent,
6
+ DialogTitle,
7
+ Stack,
8
+ } from '@mui/material';
9
+ import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
10
+ import type { MRT_Row, MRT_TableInstance } from '..';
11
+ import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
12
+
13
+ interface Props<TData extends Record<string, any> = {}> {
14
+ open: boolean;
15
+ row: MRT_Row<TData>;
16
+ table: MRT_TableInstance<TData>;
17
+ }
18
+
19
+ export const MRT_EditRowModal = <TData extends Record<string, any> = {}>({
20
+ open,
21
+ row,
22
+ table,
23
+ }: Props<TData>) => {
24
+ const {
25
+ options: { localization },
26
+ } = table;
27
+
28
+ return (
29
+ <Dialog open={open}>
30
+ <DialogTitle textAlign="center">{localization.edit}</DialogTitle>
31
+ <DialogContent>
32
+ <Stack
33
+ sx={{
34
+ width: '100%',
35
+ minWidth: { xs: '300px', sm: '360px', md: '400px' },
36
+ gap: '1.5rem',
37
+ }}
38
+ >
39
+ {row
40
+ .getVisibleCells()
41
+ .filter((cell) => cell.column.columnDef.columnDefType === 'data')
42
+ .map((cell) => (
43
+ <MRT_EditCellTextField
44
+ cell={cell}
45
+ key={cell.id}
46
+ showLabel
47
+ table={table}
48
+ />
49
+ ))}
50
+ </Stack>
51
+ </DialogContent>
52
+ <DialogActions sx={{ p: '1.25rem' }}>
53
+ <MRT_EditActionButtons row={row} table={table} variant="text" />
54
+ </DialogActions>
55
+ </Dialog>
56
+ );
57
+ };
@@ -87,6 +87,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
87
87
 
88
88
  const isEditing =
89
89
  isEditable &&
90
+ editingMode !== 'modal' &&
90
91
  (editingMode === 'table' ||
91
92
  editingRow?.id === row.id ||
92
93
  editingCell?.id === cell.id);
@@ -241,13 +242,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
241
242
  enableHover &&
242
243
  enableEditing &&
243
244
  columnDef.enableEditing !== false &&
244
- editingMode !== 'row'
245
+ ['table', 'cell'].includes(editingMode ?? '')
245
246
  ? theme.palette.mode === 'dark'
246
- ? `${lighten(
247
- theme.palette.background.default,
248
- 0.13,
249
- )} !important`
250
- : `${darken(theme.palette.background.default, 0.07)} !important`
247
+ ? `${lighten(theme.palette.background.default, 0.2)} !important`
248
+ : `${darken(theme.palette.background.default, 0.1)} !important`
251
249
  : undefined,
252
250
  },
253
251
  ...(tableCellProps?.sx instanceof Function
@@ -1,13 +1,18 @@
1
- import React, { FC } from 'react';
2
- import { Box, IconButton, Tooltip } from '@mui/material';
1
+ import React from 'react';
2
+ import { Box, Button, IconButton, Tooltip } from '@mui/material';
3
3
  import type { MRT_Row, MRT_TableInstance } from '..';
4
4
 
5
- interface Props {
6
- row: MRT_Row;
7
- table: MRT_TableInstance;
5
+ interface Props<TData extends Record<string, any> = {}> {
6
+ row: MRT_Row<TData>;
7
+ table: MRT_TableInstance<TData>;
8
+ variant?: 'icon' | 'text';
8
9
  }
9
10
 
10
- export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
11
+ export const MRT_EditActionButtons = <TData extends Record<string, any> = {}>({
12
+ row,
13
+ table,
14
+ variant = 'icon',
15
+ }: Props<TData>) => {
11
16
  const {
12
17
  getState,
13
18
  options: {
@@ -20,7 +25,6 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
20
25
  const { editingRow } = getState();
21
26
 
22
27
  const handleCancel = () => {
23
- row._valuesCache = { ...row.original };
24
28
  setEditingRow(null);
25
29
  };
26
30
 
@@ -35,20 +39,31 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
35
39
 
36
40
  return (
37
41
  <Box sx={{ display: 'flex', gap: '0.75rem' }}>
38
- <Tooltip arrow title={localization.cancel}>
39
- <IconButton aria-label={localization.cancel} onClick={handleCancel}>
40
- <CancelIcon />
41
- </IconButton>
42
- </Tooltip>
43
- <Tooltip arrow title={localization.save}>
44
- <IconButton
45
- aria-label={localization.save}
46
- color="info"
47
- onClick={handleSave}
48
- >
49
- <SaveIcon />
50
- </IconButton>
51
- </Tooltip>
42
+ {variant === 'icon' ? (
43
+ <>
44
+ <Tooltip arrow title={localization.cancel}>
45
+ <IconButton aria-label={localization.cancel} onClick={handleCancel}>
46
+ <CancelIcon />
47
+ </IconButton>
48
+ </Tooltip>
49
+ <Tooltip arrow title={localization.save}>
50
+ <IconButton
51
+ aria-label={localization.save}
52
+ color="info"
53
+ onClick={handleSave}
54
+ >
55
+ <SaveIcon />
56
+ </IconButton>
57
+ </Tooltip>
58
+ </>
59
+ ) : (
60
+ <>
61
+ <Button onClick={handleCancel}>{localization.cancel}</Button>
62
+ <Button onClick={handleSave} variant="contained">
63
+ {localization.save}
64
+ </Button>
65
+ </>
66
+ )}
52
67
  </Box>
53
68
  );
54
69
  };
@@ -24,6 +24,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
24
24
  const {
25
25
  getState,
26
26
  options: {
27
+ editingMode,
27
28
  enableEditing,
28
29
  icons: { EditIcon, MoreHorizIcon },
29
30
  localization,
@@ -52,7 +53,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
52
53
  <>
53
54
  {renderRowActions ? (
54
55
  <>{renderRowActions({ row, table })}</>
55
- ) : row.id === editingRow?.id ? (
56
+ ) : row.id === editingRow?.id && editingMode === 'row' ? (
56
57
  <MRT_EditActionButtons row={row} table={table} />
57
58
  ) : !renderRowActionMenuItems && enableEditing ? (
58
59
  <Tooltip placement="right" arrow title={localization.edit}>
@@ -116,7 +116,8 @@ export const getLeadingDisplayColumnIds = <
116
116
  [
117
117
  (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
118
118
  ((props.positionActionsColumn === 'first' && props.enableRowActions) ||
119
- (props.enableEditing && props.editingMode === 'row')) &&
119
+ (props.enableEditing &&
120
+ ['row', 'modal'].includes(props.editingMode ?? ''))) &&
120
121
  'mrt-row-actions',
121
122
  props.positionExpandColumn === 'first' &&
122
123
  (props.enableExpanding ||
@@ -133,7 +134,8 @@ export const getTrailingDisplayColumnIds = <
133
134
  props: MaterialReactTableProps<TData>,
134
135
  ) => [
135
136
  ((props.positionActionsColumn === 'last' && props.enableRowActions) ||
136
- (props.enableEditing && props.editingMode === 'row')) &&
137
+ (props.enableEditing &&
138
+ ['row', 'modal'].includes(props.editingMode ?? ''))) &&
137
139
  'mrt-row-actions',
138
140
  props.positionExpandColumn === 'last' &&
139
141
  (props.enableExpanding ||
@@ -1,26 +1,25 @@
1
- import React, {
2
- ChangeEvent,
3
- FC,
4
- FocusEvent,
5
- MouseEvent,
6
- useState,
7
- } from 'react';
1
+ import React, { ChangeEvent, FocusEvent, MouseEvent, useState } from 'react';
8
2
  import { TextField, TextFieldProps } from '@mui/material';
9
- import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
3
+ import type { MRT_Cell, MRT_TableInstance } from '..';
10
4
 
11
- interface Props {
12
- cell: MRT_Cell;
13
- table: MRT_TableInstance;
5
+ interface Props<TData extends Record<string, any> = {}> {
6
+ cell: MRT_Cell<TData>;
7
+ table: MRT_TableInstance<TData>;
8
+ showLabel?: boolean;
14
9
  }
15
10
 
16
- export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
11
+ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
12
+ cell,
13
+ showLabel,
14
+ table,
15
+ }: Props<TData>) => {
17
16
  const {
18
17
  getState,
19
18
  options: { tableId, muiTableBodyCellEditTextFieldProps },
20
19
  setEditingCell,
21
20
  setEditingRow,
22
21
  } = table;
23
- const { column, row } = cell;
22
+ const { column } = cell;
24
23
  const { columnDef } = column;
25
24
  const { editingRow } = getState();
26
25
 
@@ -52,9 +51,10 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
52
51
  const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
53
52
  textFieldProps.onBlur?.(event);
54
53
  if (editingRow) {
55
- if (!row._valuesCache) row._valuesCache = {};
56
- (row._valuesCache as Record<string, any>)[column.id] = value;
57
- setEditingRow({ ...editingRow } as MRT_Row);
54
+ setEditingRow({
55
+ ...editingRow,
56
+ _valuesCache: { ...editingRow._valuesCache, [column.id]: value },
57
+ } as any);
58
58
  }
59
59
  setEditingCell(null);
60
60
  };
@@ -65,7 +65,10 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
65
65
 
66
66
  return (
67
67
  <TextField
68
+ disabled={columnDef.enableEditing === false}
69
+ fullWidth
68
70
  id={`mrt-${tableId}-edit-cell-text-field-${cell.id}`}
71
+ label={showLabel ? column.columnDef.header : undefined}
69
72
  margin="none"
70
73
  onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
71
74
  placeholder={columnDef.header}
@@ -33,6 +33,7 @@ import type {
33
33
  MRT_TableState,
34
34
  MaterialReactTableProps,
35
35
  } from '..';
36
+ import { MRT_EditRowModal } from '../body/MRT_EditRowModal';
36
37
 
37
38
  export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
38
39
  props: MaterialReactTableProps<TData>,
@@ -300,6 +301,9 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
300
301
  <MRT_TablePaper table={table} />
301
302
  </Dialog>
302
303
  {!isFullScreen && <MRT_TablePaper table={table} />}
304
+ {editingRow && props.editingMode === 'modal' && (
305
+ <MRT_EditRowModal row={editingRow as any} table={table} open />
306
+ )}
303
307
  </>
304
308
  );
305
309
  };