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.
package/dist/cjs/index.js CHANGED
@@ -17,7 +17,6 @@ var DensitySmallIcon = require('@mui/icons-material/DensitySmall');
17
17
  var DragHandleIcon = require('@mui/icons-material/DragHandle');
18
18
  var DynamicFeedIcon = require('@mui/icons-material/DynamicFeed');
19
19
  var EditIcon = require('@mui/icons-material/Edit');
20
- var ExpandLessIcon = require('@mui/icons-material/ExpandLess');
21
20
  var ExpandMoreIcon = require('@mui/icons-material/ExpandMore');
22
21
  var FilterAltIcon = require('@mui/icons-material/FilterAlt');
23
22
  var FilterListIcon = require('@mui/icons-material/FilterList');
@@ -93,7 +92,6 @@ var DensitySmallIcon__default = /*#__PURE__*/_interopDefaultLegacy(DensitySmallI
93
92
  var DragHandleIcon__default = /*#__PURE__*/_interopDefaultLegacy(DragHandleIcon);
94
93
  var DynamicFeedIcon__default = /*#__PURE__*/_interopDefaultLegacy(DynamicFeedIcon);
95
94
  var EditIcon__default = /*#__PURE__*/_interopDefaultLegacy(EditIcon);
96
- var ExpandLessIcon__default = /*#__PURE__*/_interopDefaultLegacy(ExpandLessIcon);
97
95
  var ExpandMoreIcon__default = /*#__PURE__*/_interopDefaultLegacy(ExpandMoreIcon);
98
96
  var FilterAltIcon__default = /*#__PURE__*/_interopDefaultLegacy(FilterAltIcon);
99
97
  var FilterListIcon__default = /*#__PURE__*/_interopDefaultLegacy(FilterListIcon);
@@ -312,8 +310,8 @@ const getIsFirstRightPinnedColumn = (column) => {
312
310
  const getTotalRight = (table, column) => {
313
311
  return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 200);
314
312
  };
315
- const getCommonCellStyles = ({ column, table, tableCellProps, theme, }) => {
316
- var _a, _b, _c, _d, _e, _f, _g;
313
+ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
314
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
317
315
  return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
318
316
  ? styles.alpha(styles.lighten(theme.palette.background.default, 0.04), 0.97)
319
317
  : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
@@ -321,21 +319,21 @@ const getCommonCellStyles = ({ column, table, tableCellProps, theme, }) => {
321
319
  : getIsFirstRightPinnedColumn(column)
322
320
  ? `4px 0 8px -6px ${styles.alpha(theme.palette.common.black, 0.2)} inset`
323
321
  : undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', flex: table.options.layoutMode === 'grid'
324
- ? `var(--col-${parseCSSVarId(column.id)}-size) 0 auto`
322
+ ? `var(--col-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) 0 auto`
325
323
  : undefined, left: column.getIsPinned() === 'left'
326
324
  ? `${column.getStart('left')}px`
327
325
  : undefined, ml: table.options.enableColumnVirtualization &&
328
326
  column.getIsPinned() === 'left' &&
329
327
  column.getPinnedIndex() === 0
330
- ? `-${column.getSize() * ((_b = (_a = table.getState().columnPinning.left) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1)}px`
328
+ ? `-${column.getSize() * ((_c = (_b = table.getState().columnPinning.left) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 1)}px`
331
329
  : undefined, mr: table.options.enableColumnVirtualization &&
332
330
  column.getIsPinned() === 'right' &&
333
331
  column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
334
332
  ? `-${column.getSize() *
335
- ((_d = (_c = table.getState().columnPinning.right) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 1) *
333
+ ((_e = (_d = table.getState().columnPinning.right) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 1) *
336
334
  1.2}px`
337
- : undefined, opacity: ((_e = table.getState().draggingColumn) === null || _e === void 0 ? void 0 : _e.id) === column.id ||
338
- ((_f = table.getState().hoveredColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id
335
+ : undefined, opacity: ((_f = table.getState().draggingColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id ||
336
+ ((_g = table.getState().hoveredColumn) === null || _g === void 0 ? void 0 : _g.id) === column.id
339
337
  ? 0.5
340
338
  : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
341
339
  ? 'sticky'
@@ -345,7 +343,7 @@ const getCommonCellStyles = ({ column, table, tableCellProps, theme, }) => {
345
343
  ? 'none'
346
344
  : `padding 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
347
345
  ? tableCellProps.sx(theme)
348
- : 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)` }));
346
+ : 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)` }));
349
347
  };
350
348
  const MRT_DefaultColumn = {
351
349
  filterVariant: 'text',
@@ -465,7 +463,6 @@ const MRT_Default_Icons = {
465
463
  DragHandleIcon: DragHandleIcon__default["default"],
466
464
  DynamicFeedIcon: DynamicFeedIcon__default["default"],
467
465
  EditIcon: EditIcon__default["default"],
468
- ExpandLessIcon: ExpandLessIcon__default["default"],
469
466
  ExpandMoreIcon: ExpandMoreIcon__default["default"],
470
467
  FilterAltIcon: FilterAltIcon__default["default"],
471
468
  FilterListIcon: FilterListIcon__default["default"],
@@ -500,7 +497,7 @@ const rankGlobalFuzzy = (rowA, rowB) => Math.max(...Object.values(rowB.columnFil
500
497
  Math.max(...Object.values(rowA.columnFiltersMeta).map((v) => v.rank));
501
498
 
502
499
  const MRT_ExpandAllButton = ({ table }) => {
503
- var _a;
500
+ var _a, _b;
504
501
  const { getIsAllRowsExpanded, getIsSomeRowsExpanded, getCanSomeRowsExpand, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
505
502
  const { density, isLoading } = getState();
506
503
  const iconButtonProps = muiExpandAllButtonProps instanceof Function
@@ -513,15 +510,14 @@ const MRT_ExpandAllButton = ({ table }) => {
513
510
  React__default["default"].createElement("span", null,
514
511
  React__default["default"].createElement(IconButton__default["default"], 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
515
512
  ? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
516
- : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
517
- React__default["default"].createElement(KeyboardDoubleArrowDownIcon, { style: {
518
- transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
519
- transition: 'transform 150ms',
520
- } })))));
513
+ : 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__default["default"].createElement(KeyboardDoubleArrowDownIcon, { style: {
514
+ transform: `rotate(${isAllRowsExpanded ? -180 : getIsSomeRowsExpanded() ? -90 : 0}deg)`,
515
+ transition: 'transform 150ms',
516
+ } }))))));
521
517
  };
522
518
 
523
519
  const MRT_ExpandButton = ({ row, table }) => {
524
- var _a;
520
+ var _a, _b;
525
521
  const { getState, options: { icons: { ExpandMoreIcon }, localization, muiExpandButtonProps, renderDetailPanel, }, } = table;
526
522
  const { density } = getState();
527
523
  const iconButtonProps = muiExpandButtonProps instanceof Function
@@ -541,11 +537,10 @@ const MRT_ExpandButton = ({ row, table }) => {
541
537
  React__default["default"].createElement("span", null,
542
538
  React__default["default"].createElement(IconButton__default["default"], 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
543
539
  ? iconButtonProps.sx(theme)
544
- : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
545
- React__default["default"].createElement(ExpandMoreIcon, { style: {
546
- transform: `rotate(${!canExpand && !renderDetailPanel ? -90 : isExpanded ? -180 : 0}deg)`,
547
- transition: 'transform 150ms',
548
- } })))));
540
+ : 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__default["default"].createElement(ExpandMoreIcon, { style: {
541
+ transform: `rotate(${!canExpand && !renderDetailPanel ? -90 : isExpanded ? -180 : 0}deg)`,
542
+ transition: 'transform 150ms',
543
+ } }))))));
549
544
  };
550
545
 
551
546
  const mrtFilterOptions = (localization) => [
@@ -1542,7 +1537,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
1542
1537
  const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
1543
1538
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
1544
1539
  React__default["default"].createElement(Tooltip__default["default"], { 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 },
1545
- React__default["default"].createElement(IconButton__default["default"], 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': {
1540
+ React__default["default"].createElement(IconButton__default["default"], 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': {
1546
1541
  opacity: 1,
1547
1542
  } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
1548
1543
  ? iconButtonProps.sx(theme)
@@ -1893,10 +1888,8 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1893
1888
  const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1894
1889
  var _a;
1895
1890
  const { getState, options: { columnResizeMode }, setColumnSizingInfo, } = table;
1896
- const { density, showColumnFilters } = getState();
1891
+ const { density } = getState();
1897
1892
  const { column } = header;
1898
- const { columnDef } = column;
1899
- const { columnDefType } = columnDef;
1900
1893
  return (React__default["default"].createElement(Box__default["default"], { onDoubleClick: () => {
1901
1894
  setColumnSizingInfo((old) => (Object.assign(Object.assign({}, old), { isResizingColumn: false })));
1902
1895
  column.resetSize();
@@ -1918,7 +1911,7 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1918
1911
  React__default["default"].createElement(Divider__default["default"], { flexItem: true, orientation: "vertical", sx: {
1919
1912
  borderRadius: '2px',
1920
1913
  borderWidth: '2px',
1921
- height: showColumnFilters && columnDefType === 'data' ? '3.5rem' : '1.5rem',
1914
+ height: '24px',
1922
1915
  touchAction: 'none',
1923
1916
  transition: column.getIsResizing()
1924
1917
  ? undefined
@@ -2036,6 +2029,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
2036
2029
  ? 2
2037
2030
  : 1 }, getCommonCellStyles({
2038
2031
  column,
2032
+ header,
2039
2033
  table,
2040
2034
  tableCellProps,
2041
2035
  theme,
@@ -2289,7 +2283,7 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
2289
2283
  };
2290
2284
 
2291
2285
  const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowIndex, rowRef, table, virtualCell, }) => {
2292
- var _a, _b;
2286
+ var _a, _b, _c, _d;
2293
2287
  const theme = styles.useTheme();
2294
2288
  const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
2295
2289
  const { draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, density, isLoading, showSkeletons, } = getState();
@@ -2416,12 +2410,12 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
2416
2410
  theme,
2417
2411
  tableCellProps,
2418
2412
  })), draggingBorders)) }),
2419
- React__default["default"].createElement(React__default["default"].Fragment, null, cell.getIsPlaceholder() ? null : isLoading || showSkeletons ? (React__default["default"].createElement(Skeleton__default["default"], Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
2413
+ React__default["default"].createElement(React__default["default"].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__default["default"].createElement(Skeleton__default["default"], Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
2420
2414
  rowNumberMode === 'static' &&
2421
2415
  column.id === 'mrt-row-numbers' ? (rowIndex + 1) : column.id === 'mrt-row-drag' ? (React__default["default"].createElement(MRT_TableBodyRowGrabHandle, { cell: cell, rowRef: rowRef, table: table })) : columnDefType === 'display' &&
2422
2416
  (column.id === 'mrt-row-select' ||
2423
2417
  column.id === 'mrt-row-expand' ||
2424
- !row.getIsGrouped()) ? ((_a = columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
2418
+ !row.getIsGrouped()) ? ((_c = columnDef.Cell) === null || _c === void 0 ? void 0 : _c.call(columnDef, {
2425
2419
  cell,
2426
2420
  renderedCellValue: cell.renderValue(),
2427
2421
  column,
@@ -2431,8 +2425,8 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
2431
2425
  columnDef.enableClickToCopy !== false ? (React__default["default"].createElement(MRT_CopyButton, { cell: cell, table: table },
2432
2426
  React__default["default"].createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))) : (React__default["default"].createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))),
2433
2427
  cell.getIsGrouped() && !columnDef.GroupedCell && (React__default["default"].createElement(React__default["default"].Fragment, null,
2434
- " (", (_b = row.subRows) === null || _b === void 0 ? void 0 :
2435
- _b.length,
2428
+ " (", (_d = row.subRows) === null || _d === void 0 ? void 0 :
2429
+ _d.length,
2436
2430
  ")"))));
2437
2431
  };
2438
2432
  const Memo_MRT_TableBodyCell = React.memo(MRT_TableBodyCell, (prev, next) => next.cell === prev.cell);
@@ -2710,8 +2704,10 @@ const MRT_Table = ({ table }) => {
2710
2704
  const headers = getFlatHeaders();
2711
2705
  const colSizes = {};
2712
2706
  for (let i = 0; i < headers.length; i++) {
2713
- const h = headers[i];
2714
- colSizes[`--col-${parseCSSVarId(h.column.id)}-size`] = h.getSize();
2707
+ const header = headers[i];
2708
+ const colSize = header.getSize();
2709
+ colSizes[`--header-${parseCSSVarId(header.id)}-size`] = colSize;
2710
+ colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
2715
2711
  }
2716
2712
  return colSizes;
2717
2713
  }, [columns, columnSizing, columnSizingInfo]);