material-react-table 0.37.2 → 0.38.0

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';
@@ -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;
@@ -1845,7 +1848,7 @@ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1845
1848
  };
1846
1849
 
1847
1850
  const MRT_TableBodyCellValue = ({ cell, table }) => {
1848
- var _a, _b, _c;
1851
+ var _a, _b, _c, _d;
1849
1852
  const { column, row } = cell;
1850
1853
  const { columnDef } = column;
1851
1854
  return (React.createElement(React.Fragment, null, cell.getIsAggregated() && column.columnDef.aggregationFn
@@ -1857,7 +1860,14 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
1857
1860
  })
1858
1861
  : row.getIsGrouped() && !cell.getIsGrouped()
1859
1862
  ? 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()));
1863
+ : (cell.getIsGrouped() &&
1864
+ ((_b = columnDef.GroupedCell) === null || _b === void 0 ? void 0 : _b.call(columnDef, {
1865
+ cell,
1866
+ column,
1867
+ row,
1868
+ table,
1869
+ }))) ||
1870
+ ((_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
1871
  };
1862
1872
 
1863
1873
  const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
@@ -1993,10 +2003,10 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
1993
2003
  !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
2004
  columnDef.enableClickToCopy !== false ? (React.createElement(MRT_CopyButton, { cell: cell, table: table },
1995
2005
  React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))) : (React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))),
1996
- cell.getIsGrouped() && React.createElement(React.Fragment, null,
2006
+ cell.getIsGrouped() && !columnDef.GroupedCell && (React.createElement(React.Fragment, null,
1997
2007
  " (", (_b = row.subRows) === null || _b === void 0 ? void 0 :
1998
2008
  _b.length,
1999
- ")")));
2009
+ ")"))));
2000
2010
  };
2001
2011
 
2002
2012
  const MRT_TableDetailPanel = ({ row, table }) => {