material-react-table 1.1.0-beta.1 → 1.1.1

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.
@@ -45,7 +45,7 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
45
45
  icons?: Partial<import("..").MRT_Icons> | undefined;
46
46
  initialState?: Partial<MRT_TableState<TData>> | undefined;
47
47
  localization?: Partial<MRT_Localization> | undefined;
48
- memoMode?: "row" | "cell" | "table-body" | undefined;
48
+ memoMode?: "rows" | "cells" | "table-body" | undefined;
49
49
  muiBottomToolbarProps?: import("@mui/material").ToolbarProps<"div", {}> | (({ table }: {
50
50
  table: MRT_TableInstance<TData>;
51
51
  }) => import("@mui/material").ToolbarProps<"div", {}>) | undefined;
@@ -454,7 +454,7 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
454
454
  * @warning This will break some dynamic rendering features. See the memoization guide for more info:
455
455
  * @link https://www.material-react-table.com/docs/guides/memoize-components
456
456
  */
457
- memoMode?: 'cell' | 'row' | 'table-body';
457
+ memoMode?: 'cells' | 'rows' | 'table-body';
458
458
  muiBottomToolbarProps?: ToolbarProps | (({ table }: {
459
459
  table: MRT_TableInstance<TData>;
460
460
  }) => ToolbarProps);
@@ -3,6 +3,7 @@ import type { MRT_Cell, MRT_TableInstance } from '..';
3
3
  interface Props {
4
4
  cell: MRT_Cell;
5
5
  enableHover?: boolean;
6
+ numRows: number;
6
7
  rowIndex: number;
7
8
  rowRef: RefObject<HTMLTableRowElement>;
8
9
  table: MRT_TableInstance;
@@ -1,6 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import type { MRT_Row, MRT_TableInstance } from '..';
3
3
  interface Props {
4
+ numRows: number;
4
5
  row: MRT_Row;
5
6
  rowIndex: number;
6
7
  table: MRT_TableInstance;
@@ -1356,7 +1356,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
1356
1356
  const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
1357
1357
  return (React.createElement(React.Fragment, null,
1358
1358
  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 },
1359
- React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', mt: '-0.2rem', opacity: 0.5, transition: 'opacity 150ms', width: '2rem', '&:hover': {
1359
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', m: '-0.2rem', opacity: 0.5, transition: 'opacity 150ms', width: '2rem', '&:hover': {
1360
1360
  opacity: 1,
1361
1361
  } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
1362
1362
  ? iconButtonProps.sx(theme)
@@ -1531,7 +1531,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1531
1531
  ? '100px'
1532
1532
  : !filterChipLabel
1533
1533
  ? '120px'
1534
- : 'auto', width: '100%', '& .MuiSelect-icon': {
1534
+ : 'auto', width: 'calc(100% + 4px)', mx: '-2px', '& .MuiSelect-icon': {
1535
1535
  mr: '1.5rem',
1536
1536
  } }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
1537
1537
  ? textFieldProps.sx(theme)
@@ -1690,31 +1690,36 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1690
1690
  const { column } = header;
1691
1691
  const { columnDef } = column;
1692
1692
  const { columnDefType } = columnDef;
1693
- return (React.createElement(Divider, { flexItem: true, orientation: "vertical", onDoubleClick: () => column.resetSize(), sx: (theme) => ({
1694
- borderRadius: '2px',
1695
- borderRightWidth: '2px',
1693
+ return (React.createElement(Box, { onDoubleClick: () => column.resetSize(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), sx: (theme) => ({
1696
1694
  cursor: 'col-resize',
1697
- height: showColumnFilters && columnDefType === 'data' ? '4rem' : '2rem',
1698
1695
  mr: density === 'compact' ? '-0.5rem' : '-1rem',
1699
- opacity: 0.8,
1700
1696
  position: 'absolute',
1701
1697
  right: '1px',
1702
- touchAction: 'none',
1703
- transition: column.getIsResizing()
1704
- ? undefined
1705
- : 'all 150ms ease-in-out',
1706
- userSelect: 'none',
1707
- zIndex: 4,
1708
- '&:active': {
1698
+ px: '4px',
1699
+ '&:active > hr': {
1709
1700
  backgroundColor: theme.palette.info.main,
1710
1701
  opacity: 1,
1711
1702
  },
1712
- }), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), style: {
1703
+ }), style: {
1713
1704
  transform: column.getIsResizing()
1714
1705
  ? `translateX(${((_a = getState().columnSizingInfo.deltaOffset) !== null && _a !== void 0 ? _a : 0) /
1715
1706
  (columnResizeMode === 'onChange' ? 16 : 1)}px)`
1716
- : 'none',
1717
- } }));
1707
+ : undefined,
1708
+ } },
1709
+ React.createElement(Divider, { flexItem: true, orientation: "vertical", sx: {
1710
+ borderRadius: '2px',
1711
+ borderWidth: '2px',
1712
+ height: showColumnFilters && columnDefType === 'data'
1713
+ ? '3.5rem'
1714
+ : '1.75rem',
1715
+ opacity: 0.8,
1716
+ touchAction: 'none',
1717
+ transition: column.getIsResizing()
1718
+ ? undefined
1719
+ : 'all 150ms ease-in-out',
1720
+ userSelect: 'none',
1721
+ zIndex: 4,
1722
+ } })));
1718
1723
  };
1719
1724
 
1720
1725
  const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
@@ -1752,19 +1757,11 @@ const MRT_TableHeadCell = ({ header, table }) => {
1752
1757
  ? columnDef.muiTableHeadCellProps({ column, table })
1753
1758
  : columnDef.muiTableHeadCellProps;
1754
1759
  const tableCellProps = Object.assign(Object.assign({}, mTableHeadCellProps), mcTableHeadCellProps);
1755
- const handleDragEnter = (_e) => {
1756
- if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1757
- setHoveredColumn(null);
1758
- }
1759
- if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
1760
- setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1761
- }
1762
- };
1763
- const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1760
+ const draggingBorder = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1764
1761
  ? `1px dashed ${theme.palette.text.secondary}`
1765
1762
  : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
1766
1763
  ? `2px dashed ${theme.palette.primary.main}`
1767
- : undefined;
1764
+ : undefined, [draggingColumn, hoveredColumn]);
1768
1765
  const draggingBorders = draggingBorder
1769
1766
  ? {
1770
1767
  borderLeft: draggingBorder,
@@ -1772,6 +1769,14 @@ const MRT_TableHeadCell = ({ header, table }) => {
1772
1769
  borderTop: draggingBorder,
1773
1770
  }
1774
1771
  : undefined;
1772
+ const handleDragEnter = (_e) => {
1773
+ if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1774
+ setHoveredColumn(null);
1775
+ }
1776
+ if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
1777
+ setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1778
+ }
1779
+ };
1775
1780
  const headerElement = ((_b = ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
1776
1781
  ? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
1777
1782
  column,
@@ -2010,10 +2015,10 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
2010
2015
  : (_b = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) !== null && _b !== void 0 ? _b : cell.renderValue()));
2011
2016
  };
2012
2017
 
2013
- const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2018
+ const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table, }) => {
2014
2019
  var _a, _b;
2015
2020
  const theme = useTheme();
2016
- const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enablePagination, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
2021
+ const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
2017
2022
  const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
2018
2023
  const { column, row } = cell;
2019
2024
  const { columnDef } = column;
@@ -2028,6 +2033,25 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2028
2033
  const skeletonProps = muiTableBodyCellSkeletonProps instanceof Function
2029
2034
  ? muiTableBodyCellSkeletonProps({ cell, column, row, table })
2030
2035
  : muiTableBodyCellSkeletonProps;
2036
+ const [skeletonWidth, setSkeletonWidth] = useState(0);
2037
+ useEffect(() => setSkeletonWidth(isLoading || showSkeletons
2038
+ ? columnDefType === 'display'
2039
+ ? column.getSize() / 2
2040
+ : Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
2041
+ column.getSize() / 3)
2042
+ : 100), []);
2043
+ const draggingBorder = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
2044
+ ? `1px dashed ${theme.palette.text.secondary}`
2045
+ : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
2046
+ ? `2px dashed ${theme.palette.primary.main}`
2047
+ : undefined, [draggingColumn, hoveredColumn]);
2048
+ const draggingBorders = useMemo(() => draggingBorder
2049
+ ? {
2050
+ borderLeft: draggingBorder,
2051
+ borderRight: draggingBorder,
2052
+ borderBottom: rowIndex === numRows - 1 ? draggingBorder : undefined,
2053
+ }
2054
+ : undefined, [draggingBorder, numRows]);
2031
2055
  const isEditable = (enableEditing || columnDef.enableEditing) &&
2032
2056
  columnDef.enableEditing !== false;
2033
2057
  const isEditing = isEditable &&
@@ -2035,13 +2059,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2035
2059
  (editingMode === 'table' ||
2036
2060
  (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
2037
2061
  (editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id);
2038
- const [skeletonWidth, setSkeletonWidth] = useState(0);
2039
- useEffect(() => setSkeletonWidth(isLoading || showSkeletons
2040
- ? columnDefType === 'display'
2041
- ? column.getSize() / 2
2042
- : Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
2043
- column.getSize() / 3)
2044
- : 100), [isLoading, showSkeletons]);
2045
2062
  const handleDoubleClick = (event) => {
2046
2063
  var _a;
2047
2064
  (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onDoubleClick) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
@@ -2068,24 +2085,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2068
2085
  setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
2069
2086
  }
2070
2087
  };
2071
- const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
2072
- ? `1px dashed ${theme.palette.text.secondary}`
2073
- : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
2074
- ? `2px dashed ${theme.palette.primary.main}`
2075
- : undefined;
2076
- const draggingBorders = draggingBorder
2077
- ? {
2078
- borderLeft: draggingBorder,
2079
- borderRight: draggingBorder,
2080
- borderBottom: row.index ===
2081
- (enablePagination
2082
- ? table.getRowModel()
2083
- : table.getPrePaginationRowModel()).rows.length -
2084
- 1
2085
- ? draggingBorder
2086
- : undefined,
2087
- }
2088
- : undefined;
2089
2088
  return (React.createElement(TableCell, Object.assign({}, tableCellProps, { onDragEnter: handleDragEnter, onDoubleClick: handleDoubleClick, sx: (theme) => (Object.assign(Object.assign({ cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'inherit', overflow: 'hidden', p: density === 'compact'
2090
2089
  ? columnDefType === 'display'
2091
2090
  ? '0 0.5rem'
@@ -2142,8 +2141,7 @@ const MRT_TableDetailPanel = ({ row, table }) => {
2142
2141
  : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React.createElement(Collapse, { in: row.getIsExpanded() }, renderDetailPanel({ row, table }))))));
2143
2142
  };
2144
2143
 
2145
- const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2146
- var _a, _b;
2144
+ const MRT_TableBodyRow = ({ numRows, row, rowIndex, table, virtualRow, }) => {
2147
2145
  const theme = useTheme();
2148
2146
  const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
2149
2147
  const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
@@ -2156,11 +2154,11 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2156
2154
  }
2157
2155
  };
2158
2156
  const rowRef = useRef(null);
2159
- const draggingBorder = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
2157
+ const draggingBorder = useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
2160
2158
  ? `1px dashed ${theme.palette.text.secondary}`
2161
2159
  : (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
2162
2160
  ? `2px dashed ${theme.palette.primary.main}`
2163
- : undefined;
2161
+ : undefined, [draggingRow, hoveredRow]);
2164
2162
  const draggingBorders = draggingBorder
2165
2163
  ? {
2166
2164
  border: draggingBorder,
@@ -2180,16 +2178,17 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2180
2178
  : undefined,
2181
2179
  } }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
2182
2180
  ? tableRowProps.sx(theme)
2183
- : tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }), (_b = (_a = row === null || row === void 0 ? void 0 : row.getVisibleCells()) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (cell) => {
2181
+ : tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }), row.getVisibleCells().map((cell) => {
2184
2182
  const props = {
2185
2183
  cell,
2186
2184
  enableHover: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false,
2187
2185
  key: cell.id,
2186
+ numRows,
2188
2187
  rowIndex,
2189
2188
  rowRef,
2190
2189
  table,
2191
2190
  };
2192
- return memoMode === 'cell' &&
2191
+ return memoMode === 'cells' &&
2193
2192
  cell.column.columnDef.columnDefType === 'data' &&
2194
2193
  !draggingColumn &&
2195
2194
  !draggingRow &&
@@ -2288,6 +2287,7 @@ const MRT_TableBody = ({ table }) => {
2288
2287
  : rowOrVirtualRow;
2289
2288
  const props = {
2290
2289
  key: row.id,
2290
+ numRows: rows.length,
2291
2291
  row,
2292
2292
  rowIndex: enableRowVirtualization
2293
2293
  ? rowOrVirtualRow.index
@@ -2295,12 +2295,12 @@ const MRT_TableBody = ({ table }) => {
2295
2295
  table,
2296
2296
  virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
2297
2297
  };
2298
- return memoMode === 'row' ? (React.createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React.createElement(MRT_TableBodyRow, Object.assign({}, props)));
2298
+ return memoMode === 'rows' ? (React.createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React.createElement(MRT_TableBodyRow, Object.assign({}, props)));
2299
2299
  }),
2300
2300
  enableRowVirtualization && paddingBottom > 0 && (React.createElement("tr", null,
2301
2301
  React.createElement("td", { style: { height: `${paddingBottom}px` } })))))));
2302
2302
  };
2303
- const Memo_MRT_TableBody = memo(MRT_TableBody, () => true);
2303
+ const Memo_MRT_TableBody = memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
2304
2304
 
2305
2305
  const MRT_TableFooterCell = ({ footer, table }) => {
2306
2306
  var _a, _b, _c;
@@ -2320,7 +2320,7 @@ const MRT_TableFooterCell = ({ footer, table }) => {
2320
2320
  ? '0.5rem'
2321
2321
  : density === 'comfortable'
2322
2322
  ? '1rem'
2323
- : '1.5rem', verticalAlign: 'top' }, getCommonCellStyles({ column, table, theme, tableCellProps }))) }),
2323
+ : '1.5rem', verticalAlign: 'top', zIndex: column.getIsPinned() && columnDefType !== 'group' ? 2 : 1 }, getCommonCellStyles({ column, table, theme, tableCellProps }))) }),
2324
2324
  React.createElement(React.Fragment, null, footer.isPlaceholder
2325
2325
  ? null
2326
2326
  : (_c = (_b = (columnDef.Footer instanceof Function