material-react-table 0.37.2 → 0.38.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.
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, DragEvent, MutableRefObject, ReactNode, SetStateAction } from 'react';
2
- import type { AlertProps, ButtonProps, CheckboxProps, IconButtonProps, LinearProgressProps, PaperProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
2
+ import type { AlertProps, ButtonProps, CheckboxProps, ChipProps, IconButtonProps, LinearProgressProps, PaperProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
3
3
  import type { Cell, Column, ColumnDef, DeepKeys, FilterFn, Header, HeaderGroup, OnChangeFn, Row, SortingFn, Table, TableOptions, TableState } from '@tanstack/react-table';
4
4
  import type { Options as VirtualizerOptions } from 'react-virtual';
5
5
  import { MRT_Icons } from './icons';
@@ -48,8 +48,8 @@ export declare type MRT_TableInstance<TData extends Record<string, any> = {}> =
48
48
  setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
49
49
  setDraggingColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
50
50
  setDraggingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
51
- setEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
52
- setEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
51
+ setEditingCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
52
+ setEditingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
53
53
  setGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
54
54
  setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | {
55
55
  id: string;
@@ -113,6 +113,12 @@ export declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit
113
113
  footer: MRT_Header<TData>;
114
114
  table: MRT_TableInstance<TData>;
115
115
  }) => ReactNode);
116
+ GroupedCell?: ({ cell, column, row, table, }: {
117
+ cell: MRT_Cell<TData>;
118
+ column: MRT_Column<TData>;
119
+ row: MRT_Row<TData>;
120
+ table: MRT_TableInstance<TData>;
121
+ }) => ReactNode;
116
122
  Header?: ReactNode | (({ column, header, table, }: {
117
123
  column: MRT_Column<TData>;
118
124
  header: MRT_Header<TData>;
@@ -292,6 +298,9 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
292
298
  icons?: Partial<MRT_Icons>;
293
299
  initialState?: Partial<MRT_TableState<TData>>;
294
300
  localization?: Partial<MRT_Localization>;
301
+ muiBottomToolbarProps?: ToolbarProps | (({ table }: {
302
+ table: MRT_TableInstance<TData>;
303
+ }) => ToolbarProps);
295
304
  muiExpandAllButtonProps?: IconButtonProps | (({ table }: {
296
305
  table: MRT_TableInstance<TData>;
297
306
  }) => IconButtonProps);
@@ -346,9 +355,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
346
355
  table: MRT_TableInstance<TData>;
347
356
  row: MRT_Row<TData>;
348
357
  }) => TableRowProps);
349
- muiTableBottomToolbarProps?: ToolbarProps | (({ table }: {
350
- table: MRT_TableInstance<TData>;
351
- }) => ToolbarProps);
352
358
  muiTableContainerProps?: TableContainerProps | (({ table, }: {
353
359
  table: MRT_TableInstance<TData>;
354
360
  }) => TableContainerProps);
@@ -400,10 +406,13 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
400
406
  muiTableProps?: TableProps | (({ table }: {
401
407
  table: MRT_TableInstance<TData>;
402
408
  }) => TableProps);
403
- muiTableToolbarAlertBannerProps?: AlertProps | (({ table }: {
409
+ muiToolbarAlertBannerChipProps?: ChipProps | (({ table }: {
410
+ table: MRT_TableInstance<TData>;
411
+ }) => ChipProps);
412
+ muiToolbarAlertBannerProps?: AlertProps | (({ table }: {
404
413
  table: MRT_TableInstance<TData>;
405
414
  }) => AlertProps);
406
- muiTableTopToolbarProps?: ToolbarProps | (({ table }: {
415
+ muiTopToolbarProps?: ToolbarProps | (({ table }: {
407
416
  table: MRT_TableInstance<TData>;
408
417
  }) => ToolbarProps);
409
418
  onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
@@ -416,13 +425,13 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
416
425
  onDensityChange?: OnChangeFn<boolean>;
417
426
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
418
427
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
428
+ onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
419
429
  onEditingRowSave?: ({ exitEditingMode, row, table, values, }: {
420
430
  exitEditingMode: () => void;
421
431
  row: MRT_Row<TData>;
422
432
  table: MRT_TableInstance<TData>;
423
433
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
424
434
  }) => Promise<void> | void;
425
- onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
426
435
  onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
427
436
  onFilterFnsChange?: OnChangeFn<{
428
437
  [key: string]: MRT_FilterOption;
@@ -1045,11 +1045,14 @@ const MRT_TablePagination = ({ table, position }) => {
1045
1045
 
1046
1046
  const MRT_ToolbarAlertBanner = ({ stackAlertBanner, table, }) => {
1047
1047
  var _a, _b;
1048
- const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { localization, muiTableToolbarAlertBannerProps }, } = table;
1048
+ const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { localization, muiToolbarAlertBannerProps, muiToolbarAlertBannerChipProps, }, } = table;
1049
1049
  const { grouping, showAlertBanner } = getState();
1050
- const alertProps = muiTableToolbarAlertBannerProps instanceof Function
1051
- ? muiTableToolbarAlertBannerProps({ table })
1052
- : muiTableToolbarAlertBannerProps;
1050
+ const alertProps = muiToolbarAlertBannerProps instanceof Function
1051
+ ? muiToolbarAlertBannerProps({ table })
1052
+ : muiToolbarAlertBannerProps;
1053
+ const chipProps = muiToolbarAlertBannerChipProps instanceof Function
1054
+ ? muiToolbarAlertBannerChipProps({ table })
1055
+ : muiToolbarAlertBannerChipProps;
1053
1056
  const selectMessage = getSelectedRowModel().rows.length > 0
1054
1057
  ? (_b = (_a = localization.selectedCountOfRowCountRowsSelected) === null || _a === void 0 ? void 0 : _a.replace('{selectedCount}', getSelectedRowModel().rows.length.toString())) === null || _b === void 0 ? void 0 : _b.replace('{rowCount}', getPrePaginationRowModel().rows.length.toString())
1055
1058
  : null;
@@ -1058,7 +1061,7 @@ const MRT_ToolbarAlertBanner = ({ stackAlertBanner, table, }) => {
1058
1061
  ' ',
1059
1062
  grouping.map((columnId, index) => (React.createElement(Fragment, { key: `${index}-${columnId}` },
1060
1063
  index > 0 ? localization.thenBy : '',
1061
- React.createElement(Chip, { color: "secondary", label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() })))))) : null;
1064
+ React.createElement(Chip, Object.assign({ label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() }, chipProps))))))) : null;
1062
1065
  return (React.createElement(Collapse, { in: showAlertBanner || !!selectMessage || !!groupedByMessage, timeout: stackAlertBanner ? 200 : 0 },
1063
1066
  React.createElement(Alert, Object.assign({ color: "info", icon: false }, alertProps, { sx: (theme) => (Object.assign({ borderRadius: 0, fontSize: '1rem', left: 0, p: 0, position: 'relative', right: 0, top: 0, width: '100%', zIndex: 2 }, ((alertProps === null || alertProps === void 0 ? void 0 : alertProps.sx) instanceof Function
1064
1067
  ? alertProps.sx(theme)
@@ -1189,12 +1192,12 @@ const commonToolbarStyles = ({ theme }) => ({
1189
1192
  });
1190
1193
  const MRT_TopToolbar = ({ table }) => {
1191
1194
  var _a;
1192
- const { getState, options: { enableGlobalFilter, enablePagination, enableToolbarInternalActions, muiTableTopToolbarProps, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderTopToolbarCustomActions, }, refs: { topToolbarRef }, } = table;
1195
+ const { getState, options: { enableGlobalFilter, enablePagination, enableToolbarInternalActions, muiTopToolbarProps, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderTopToolbarCustomActions, }, refs: { topToolbarRef }, } = table;
1193
1196
  const { isFullScreen, showGlobalFilter } = getState();
1194
1197
  const isMobile = useMediaQuery('(max-width:720px)');
1195
- const toolbarProps = muiTableTopToolbarProps instanceof Function
1196
- ? muiTableTopToolbarProps({ table })
1197
- : muiTableTopToolbarProps;
1198
+ const toolbarProps = muiTopToolbarProps instanceof Function
1199
+ ? muiTopToolbarProps({ table })
1200
+ : muiTopToolbarProps;
1198
1201
  const stackAlertBanner = isMobile || !!renderTopToolbarCustomActions || showGlobalFilter;
1199
1202
  return (React.createElement(Toolbar, Object.assign({ variant: "dense" }, toolbarProps, { ref: (ref) => {
1200
1203
  topToolbarRef.current = ref;
@@ -1227,12 +1230,12 @@ const MRT_TopToolbar = ({ table }) => {
1227
1230
  };
1228
1231
 
1229
1232
  const MRT_BottomToolbar = ({ table }) => {
1230
- const { getState, options: { enablePagination, muiTableBottomToolbarProps, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderBottomToolbarCustomActions, }, refs: { bottomToolbarRef }, } = table;
1233
+ const { getState, options: { enablePagination, muiBottomToolbarProps, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderBottomToolbarCustomActions, }, refs: { bottomToolbarRef }, } = table;
1231
1234
  const { isFullScreen } = getState();
1232
1235
  const isMobile = useMediaQuery('(max-width:720px)');
1233
- const toolbarProps = muiTableBottomToolbarProps instanceof Function
1234
- ? muiTableBottomToolbarProps({ table })
1235
- : muiTableBottomToolbarProps;
1236
+ const toolbarProps = muiBottomToolbarProps instanceof Function
1237
+ ? muiBottomToolbarProps({ table })
1238
+ : muiBottomToolbarProps;
1236
1239
  const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
1237
1240
  return (React.createElement(Toolbar, Object.assign({ variant: "dense" }, toolbarProps, { ref: (ref) => {
1238
1241
  bottomToolbarRef.current = ref;
@@ -1441,7 +1444,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1441
1444
  if (textFieldProps.inputRef) {
1442
1445
  textFieldProps.inputRef = inputRef;
1443
1446
  }
1444
- }, sx: (theme) => (Object.assign({ p: 0, minWidth: !filterChipLabel ? '6rem' : 'auto', width: '100%', '& .MuiSelect-icon': {
1447
+ }, sx: (theme) => (Object.assign({ p: 0, minWidth: !filterChipLabel ? '150px' : 'auto', width: '100%', '& .MuiSelect-icon': {
1445
1448
  mr: '1.5rem',
1446
1449
  } }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
1447
1450
  ? textFieldProps.sx(theme)
@@ -1770,30 +1773,43 @@ const MRT_EditCellTextField = ({ cell, showLabel, table, }) => {
1770
1773
  })
1771
1774
  : columnDef.muiTableBodyCellEditTextFieldProps;
1772
1775
  const textFieldProps = Object.assign(Object.assign({}, mTableBodyCellEditTextFieldProps), mcTableBodyCellEditTextFieldProps);
1776
+ const saveRow = (newValue) => {
1777
+ if (editingRow) {
1778
+ setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: newValue }) }));
1779
+ }
1780
+ };
1773
1781
  const handleChange = (event) => {
1774
1782
  var _a;
1775
1783
  (_a = textFieldProps.onChange) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1776
1784
  setValue(event.target.value);
1785
+ if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.select) {
1786
+ saveRow(event.target.value);
1787
+ }
1777
1788
  };
1778
1789
  const handleBlur = (event) => {
1779
1790
  var _a;
1780
1791
  (_a = textFieldProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1781
- if (editingRow) {
1782
- setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: value }) }));
1783
- }
1792
+ saveRow(value);
1784
1793
  setEditingCell(null);
1785
1794
  };
1795
+ const handleEnterKeyDown = (event) => {
1796
+ var _a, _b;
1797
+ (_a = textFieldProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1798
+ if (event.key === 'Enter') {
1799
+ (_b = editInputRefs.current[column.id]) === null || _b === void 0 ? void 0 : _b.blur();
1800
+ }
1801
+ };
1786
1802
  if (columnDef.Edit) {
1787
1803
  return React.createElement(React.Fragment, null, (_a = columnDef.Edit) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table }));
1788
1804
  }
1789
- return (React.createElement(TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, label: showLabel ? column.columnDef.header : undefined, margin: "none", name: cell.id, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { inputRef: (inputRef) => {
1805
+ return (React.createElement(TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, inputRef: (inputRef) => {
1790
1806
  if (inputRef) {
1791
1807
  editInputRefs.current[column.id] = inputRef;
1792
1808
  if (textFieldProps.inputRef) {
1793
1809
  textFieldProps.inputRef = inputRef;
1794
1810
  }
1795
1811
  }
1796
- }, onBlur: handleBlur, onChange: handleChange })));
1812
+ }, label: showLabel ? column.columnDef.header : undefined, margin: "none", name: column.id, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { onBlur: handleBlur, onChange: handleChange, onKeyDown: handleEnterKeyDown })));
1797
1813
  };
1798
1814
 
1799
1815
  const MRT_CopyButton = ({ cell, children, table, }) => {
@@ -1845,7 +1861,7 @@ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1845
1861
  };
1846
1862
 
1847
1863
  const MRT_TableBodyCellValue = ({ cell, table }) => {
1848
- var _a, _b, _c;
1864
+ var _a, _b, _c, _d;
1849
1865
  const { column, row } = cell;
1850
1866
  const { columnDef } = column;
1851
1867
  return (React.createElement(React.Fragment, null, cell.getIsAggregated() && column.columnDef.aggregationFn
@@ -1857,7 +1873,14 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
1857
1873
  })
1858
1874
  : row.getIsGrouped() && !cell.getIsGrouped()
1859
1875
  ? null
1860
- : (_c = (_b = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _b === void 0 ? void 0 : _b.call(columnDef, { cell, column, row, table })) !== null && _c !== void 0 ? _c : cell.renderValue()));
1876
+ : (cell.getIsGrouped() &&
1877
+ ((_b = columnDef.GroupedCell) === null || _b === void 0 ? void 0 : _b.call(columnDef, {
1878
+ cell,
1879
+ column,
1880
+ row,
1881
+ table,
1882
+ }))) ||
1883
+ ((_d = (_c = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _c === void 0 ? void 0 : _c.call(columnDef, { cell, column, row, table })) !== null && _d !== void 0 ? _d : cell.renderValue())));
1861
1884
  };
1862
1885
 
1863
1886
  const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
@@ -1993,10 +2016,10 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
1993
2016
  !row.getIsGrouped()) ? ((_a = columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) : isEditing ? (React.createElement(MRT_EditCellTextField, { cell: cell, table: table })) : (enableClickToCopy || columnDef.enableClickToCopy) &&
1994
2017
  columnDef.enableClickToCopy !== false ? (React.createElement(MRT_CopyButton, { cell: cell, table: table },
1995
2018
  React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))) : (React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))),
1996
- cell.getIsGrouped() && React.createElement(React.Fragment, null,
2019
+ cell.getIsGrouped() && !columnDef.GroupedCell && (React.createElement(React.Fragment, null,
1997
2020
  " (", (_b = row.subRows) === null || _b === void 0 ? void 0 :
1998
2021
  _b.length,
1999
- ")")));
2022
+ ")"))));
2000
2023
  };
2001
2024
 
2002
2025
  const MRT_TableDetailPanel = ({ row, table }) => {