material-react-table 1.7.3 → 1.7.4

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.
@@ -243,6 +243,12 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnD
243
243
  header: MRT_Header<TData>;
244
244
  table: MRT_TableInstance<TData>;
245
245
  }) => ReactNode);
246
+ PlaceholderCell?: (props: {
247
+ cell: MRT_Cell<TData>;
248
+ column: MRT_Column<TData>;
249
+ row: MRT_Row<TData>;
250
+ table: MRT_TableInstance<TData>;
251
+ }) => ReactNode;
246
252
  /**
247
253
  * Either an `accessorKey` or a combination of an `accessorFn` and `id` are required for a data column definition.
248
254
  * Specify a function here to point to the correct property in the data object.
@@ -4,7 +4,7 @@ import { MRT_FilterFns } from './filterFns';
4
4
  import { MRT_SortingFns } from './sortingFns';
5
5
  import type { TableCellProps } from '@mui/material/TableCell';
6
6
  import type { Theme } from '@mui/material/styles';
7
- import type { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterOption, MRT_TableInstance } from '.';
7
+ import type { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterOption, MRT_Header, MRT_TableInstance } from '.';
8
8
  export declare const getColumnId: <TData extends Record<string, any> = {}>(columnDef: MRT_ColumnDef<TData>) => string;
9
9
  export declare const getAllLeafColumnDefs: <TData extends Record<string, any> = {}>(columns: MRT_ColumnDef<TData>[]) => MRT_ColumnDef<TData>[];
10
10
  export declare const prepareColumns: <TData extends Record<string, any> = {}>({ aggregationFns, columnDefs, columnFilterFns, defaultDisplayColumn, filterFns, sortingFns, }: {
@@ -111,8 +111,9 @@ export declare const getIsLastColumn: (column: MRT_Column, table: MRT_TableInsta
111
111
  export declare const getIsLastLeftPinnedColumn: (table: MRT_TableInstance, column: MRT_Column) => boolean;
112
112
  export declare const getIsFirstRightPinnedColumn: (column: MRT_Column) => boolean;
113
113
  export declare const getTotalRight: (table: MRT_TableInstance, column: MRT_Column) => number;
114
- export declare const getCommonCellStyles: ({ column, table, tableCellProps, theme, }: {
114
+ export declare const getCommonCellStyles: ({ column, header, table, tableCellProps, theme, }: {
115
115
  column: MRT_Column;
116
+ header?: MRT_Header<{}> | undefined;
116
117
  table: MRT_TableInstance;
117
118
  tableCellProps: TableCellProps;
118
119
  theme: Theme;
@@ -11,7 +11,6 @@ export interface MRT_Icons {
11
11
  DragHandleIcon: any;
12
12
  DynamicFeedIcon: any;
13
13
  EditIcon: any;
14
- ExpandLessIcon: any;
15
14
  ExpandMoreIcon: any;
16
15
  FilterAltIcon: any;
17
16
  FilterListIcon: any;
@@ -13,7 +13,6 @@ import DensitySmallIcon from '@mui/icons-material/DensitySmall';
13
13
  import DragHandleIcon from '@mui/icons-material/DragHandle';
14
14
  import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
15
15
  import EditIcon from '@mui/icons-material/Edit';
16
- import ExpandLessIcon from '@mui/icons-material/ExpandLess';
17
16
  import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
18
17
  import FilterAltIcon from '@mui/icons-material/FilterAlt';
19
18
  import FilterListIcon from '@mui/icons-material/FilterList';
@@ -234,8 +233,8 @@ const getIsFirstRightPinnedColumn = (column) => {
234
233
  const getTotalRight = (table, column) => {
235
234
  return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 200);
236
235
  };
237
- const getCommonCellStyles = ({ column, table, tableCellProps, theme, }) => {
238
- var _a, _b, _c, _d, _e, _f, _g;
236
+ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
237
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
239
238
  return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
240
239
  ? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
241
240
  : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
@@ -243,21 +242,21 @@ const getCommonCellStyles = ({ column, table, tableCellProps, theme, }) => {
243
242
  : getIsFirstRightPinnedColumn(column)
244
243
  ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
245
244
  : undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', flex: table.options.layoutMode === 'grid'
246
- ? `var(--col-${parseCSSVarId(column.id)}-size) 0 auto`
245
+ ? `var(--col-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) 0 auto`
247
246
  : undefined, left: column.getIsPinned() === 'left'
248
247
  ? `${column.getStart('left')}px`
249
248
  : undefined, ml: table.options.enableColumnVirtualization &&
250
249
  column.getIsPinned() === 'left' &&
251
250
  column.getPinnedIndex() === 0
252
- ? `-${column.getSize() * ((_b = (_a = table.getState().columnPinning.left) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1)}px`
251
+ ? `-${column.getSize() * ((_c = (_b = table.getState().columnPinning.left) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 1)}px`
253
252
  : undefined, mr: table.options.enableColumnVirtualization &&
254
253
  column.getIsPinned() === 'right' &&
255
254
  column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
256
255
  ? `-${column.getSize() *
257
- ((_d = (_c = table.getState().columnPinning.right) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 1) *
256
+ ((_e = (_d = table.getState().columnPinning.right) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 1) *
258
257
  1.2}px`
259
- : undefined, opacity: ((_e = table.getState().draggingColumn) === null || _e === void 0 ? void 0 : _e.id) === column.id ||
260
- ((_f = table.getState().hoveredColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id
258
+ : undefined, opacity: ((_f = table.getState().draggingColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id ||
259
+ ((_g = table.getState().hoveredColumn) === null || _g === void 0 ? void 0 : _g.id) === column.id
261
260
  ? 0.5
262
261
  : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
263
262
  ? 'sticky'
@@ -267,7 +266,7 @@ const getCommonCellStyles = ({ column, table, tableCellProps, theme, }) => {
267
266
  ? 'none'
268
267
  : `padding 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
269
268
  ? tableCellProps.sx(theme)
270
- : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { minWidth: `max(calc(var(--col-${parseCSSVarId(column.id)}-size) * 1px), ${(_g = column.columnDef.minSize) !== null && _g !== void 0 ? _g : 30}px)`, width: `calc(var(--col-${parseCSSVarId(column.id)}-size) * 1px)` }));
269
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { minWidth: `max(calc(var(--col-${parseCSSVarId((_h = header === null || header === void 0 ? void 0 : header.id) !== null && _h !== void 0 ? _h : column.id)}-size) * 1px), ${(_j = column.columnDef.minSize) !== null && _j !== void 0 ? _j : 30}px)`, width: `calc(var(--col-${parseCSSVarId((_k = header === null || header === void 0 ? void 0 : header.id) !== null && _k !== void 0 ? _k : column.id)}-size) * 1px)` }));
271
270
  };
272
271
  const MRT_DefaultColumn = {
273
272
  filterVariant: 'text',
@@ -387,7 +386,6 @@ const MRT_Default_Icons = {
387
386
  DragHandleIcon,
388
387
  DynamicFeedIcon,
389
388
  EditIcon,
390
- ExpandLessIcon,
391
389
  ExpandMoreIcon,
392
390
  FilterAltIcon,
393
391
  FilterListIcon,
@@ -422,7 +420,7 @@ const rankGlobalFuzzy = (rowA, rowB) => Math.max(...Object.values(rowB.columnFil
422
420
  Math.max(...Object.values(rowA.columnFiltersMeta).map((v) => v.rank));
423
421
 
424
422
  const MRT_ExpandAllButton = ({ table }) => {
425
- var _a;
423
+ var _a, _b;
426
424
  const { getIsAllRowsExpanded, getIsSomeRowsExpanded, getCanSomeRowsExpand, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
427
425
  const { density, isLoading } = getState();
428
426
  const iconButtonProps = muiExpandAllButtonProps instanceof Function
@@ -435,15 +433,14 @@ const MRT_ExpandAllButton = ({ table }) => {
435
433
  React.createElement("span", null,
436
434
  React.createElement(IconButton, Object.assign({ "aria-label": localization.expandAll, disabled: isLoading || (!renderDetailPanel && !getCanSomeRowsExpand()), onClick: () => toggleAllRowsExpanded(!isAllRowsExpanded) }, iconButtonProps, { sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', width: density === 'compact' ? '1.75rem' : '2.25rem', mt: density !== 'compact' ? '-0.25rem' : undefined }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
437
435
  ? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
438
- : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
439
- React.createElement(KeyboardDoubleArrowDownIcon, { style: {
440
- transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
441
- transition: 'transform 150ms',
442
- } })))));
436
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }), (_b = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.children) !== null && _b !== void 0 ? _b : (React.createElement(KeyboardDoubleArrowDownIcon, { style: {
437
+ transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
438
+ transition: 'transform 150ms',
439
+ } }))))));
443
440
  };
444
441
 
445
442
  const MRT_ExpandButton = ({ row, table }) => {
446
- var _a;
443
+ var _a, _b;
447
444
  const { getState, options: { icons: { ExpandMoreIcon }, localization, muiExpandButtonProps, renderDetailPanel, }, } = table;
448
445
  const { density } = getState();
449
446
  const iconButtonProps = muiExpandButtonProps instanceof Function
@@ -463,11 +460,10 @@ const MRT_ExpandButton = ({ row, table }) => {
463
460
  React.createElement("span", null,
464
461
  React.createElement(IconButton, Object.assign({ "aria-label": localization.expand, disabled: !canExpand && !renderDetailPanel }, iconButtonProps, { onClick: handleToggleExpand, sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', width: density === 'compact' ? '1.75rem' : '2.25rem' }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
465
462
  ? iconButtonProps.sx(theme)
466
- : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
467
- React.createElement(ExpandMoreIcon, { style: {
468
- transform: `rotate(${!canExpand && !renderDetailPanel ? -90 : isExpanded ? -180 : 0}deg)`,
469
- transition: 'transform 150ms',
470
- } })))));
463
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }), (_b = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.children) !== null && _b !== void 0 ? _b : (React.createElement(ExpandMoreIcon, { style: {
464
+ transform: `rotate(${!canExpand && !renderDetailPanel ? -90 : isExpanded ? -180 : 0}deg)`,
465
+ transition: 'transform 150ms',
466
+ } }))))));
471
467
  };
472
468
 
473
469
  const mrtFilterOptions = (localization) => [
@@ -1464,7 +1460,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
1464
1460
  const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
1465
1461
  return (React.createElement(React.Fragment, null,
1466
1462
  React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : localization.columnActions },
1467
- React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', m: '-8px -4px', opacity: 0.5, transform: 'scale(0.85)', transition: 'opacity 150ms', width: '2rem', '&:hover': {
1463
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', m: '-8px -4px', opacity: 0.5, transform: 'scale(0.85) translateX(-4px)', transition: 'opacity 150ms', width: '2rem', '&:hover': {
1468
1464
  opacity: 1,
1469
1465
  } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
1470
1466
  ? iconButtonProps.sx(theme)
@@ -1815,10 +1811,8 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1815
1811
  const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1816
1812
  var _a;
1817
1813
  const { getState, options: { columnResizeMode }, setColumnSizingInfo, } = table;
1818
- const { density, showColumnFilters } = getState();
1814
+ const { density } = getState();
1819
1815
  const { column } = header;
1820
- const { columnDef } = column;
1821
- const { columnDefType } = columnDef;
1822
1816
  return (React.createElement(Box, { onDoubleClick: () => {
1823
1817
  setColumnSizingInfo((old) => (Object.assign(Object.assign({}, old), { isResizingColumn: false })));
1824
1818
  column.resetSize();
@@ -1840,7 +1834,7 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1840
1834
  React.createElement(Divider, { flexItem: true, orientation: "vertical", sx: {
1841
1835
  borderRadius: '2px',
1842
1836
  borderWidth: '2px',
1843
- height: showColumnFilters && columnDefType === 'data' ? '3.5rem' : '1.5rem',
1837
+ height: '24px',
1844
1838
  touchAction: 'none',
1845
1839
  transition: column.getIsResizing()
1846
1840
  ? undefined
@@ -1958,6 +1952,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
1958
1952
  ? 2
1959
1953
  : 1 }, getCommonCellStyles({
1960
1954
  column,
1955
+ header,
1961
1956
  table,
1962
1957
  tableCellProps,
1963
1958
  theme,
@@ -2211,7 +2206,7 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
2211
2206
  };
2212
2207
 
2213
2208
  const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowIndex, rowRef, table, virtualCell, }) => {
2214
- var _a, _b;
2209
+ var _a, _b, _c, _d;
2215
2210
  const theme = useTheme();
2216
2211
  const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
2217
2212
  const { draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, density, isLoading, showSkeletons, } = getState();
@@ -2338,12 +2333,12 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
2338
2333
  theme,
2339
2334
  tableCellProps,
2340
2335
  })), draggingBorders)) }),
2341
- React.createElement(React.Fragment, null, cell.getIsPlaceholder() ? null : isLoading || showSkeletons ? (React.createElement(Skeleton, Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
2336
+ React.createElement(React.Fragment, null, cell.getIsPlaceholder() ? ((_b = (_a = columnDef.PlaceholderCell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) !== null && _b !== void 0 ? _b : null) : isLoading || showSkeletons ? (React.createElement(Skeleton, Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
2342
2337
  rowNumberMode === 'static' &&
2343
2338
  column.id === 'mrt-row-numbers' ? (rowIndex + 1) : column.id === 'mrt-row-drag' ? (React.createElement(MRT_TableBodyRowGrabHandle, { cell: cell, rowRef: rowRef, table: table })) : columnDefType === 'display' &&
2344
2339
  (column.id === 'mrt-row-select' ||
2345
2340
  column.id === 'mrt-row-expand' ||
2346
- !row.getIsGrouped()) ? ((_a = columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
2341
+ !row.getIsGrouped()) ? ((_c = columnDef.Cell) === null || _c === void 0 ? void 0 : _c.call(columnDef, {
2347
2342
  cell,
2348
2343
  renderedCellValue: cell.renderValue(),
2349
2344
  column,
@@ -2353,8 +2348,8 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
2353
2348
  columnDef.enableClickToCopy !== false ? (React.createElement(MRT_CopyButton, { cell: cell, table: table },
2354
2349
  React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))) : (React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))),
2355
2350
  cell.getIsGrouped() && !columnDef.GroupedCell && (React.createElement(React.Fragment, null,
2356
- " (", (_b = row.subRows) === null || _b === void 0 ? void 0 :
2357
- _b.length,
2351
+ " (", (_d = row.subRows) === null || _d === void 0 ? void 0 :
2352
+ _d.length,
2358
2353
  ")"))));
2359
2354
  };
2360
2355
  const Memo_MRT_TableBodyCell = memo(MRT_TableBodyCell, (prev, next) => next.cell === prev.cell);
@@ -2632,8 +2627,10 @@ const MRT_Table = ({ table }) => {
2632
2627
  const headers = getFlatHeaders();
2633
2628
  const colSizes = {};
2634
2629
  for (let i = 0; i < headers.length; i++) {
2635
- const h = headers[i];
2636
- colSizes[`--col-${parseCSSVarId(h.column.id)}-size`] = h.getSize();
2630
+ const header = headers[i];
2631
+ const colSize = header.getSize();
2632
+ colSizes[`--header-${parseCSSVarId(header.id)}-size`] = colSize;
2633
+ colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
2637
2634
  }
2638
2635
  return colSizes;
2639
2636
  }, [columns, columnSizing, columnSizingInfo]);