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.
- package/dist/cjs/MaterialReactTable.d.ts +1 -1
- package/dist/cjs/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/cjs/body/MRT_TableBodyRow.d.ts +1 -0
- package/dist/cjs/index.js +63 -63
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/table/MRT_TableRoot.d.ts +1 -1
- package/dist/esm/MaterialReactTable.d.ts +1 -1
- package/dist/esm/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/esm/body/MRT_TableBodyRow.d.ts +1 -0
- package/dist/esm/material-react-table.esm.js +63 -63
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +1 -1
- package/src/body/MRT_TableBody.tsx +6 -2
- package/src/body/MRT_TableBodyCell.tsx +37 -36
- package/src/body/MRT_TableBodyRow.tsx +15 -9
- package/src/footer/MRT_TableFooterCell.tsx +1 -0
- package/src/head/MRT_TableHeadCell.tsx +19 -16
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +1 -1
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +29 -20
- package/src/inputs/MRT_FilterTextField.tsx +2 -1
|
@@ -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?: '
|
|
457
|
+
memoMode?: 'cells' | 'rows' | 'table-body';
|
|
458
458
|
muiBottomToolbarProps?: ToolbarProps | (({ table }: {
|
|
459
459
|
table: MRT_TableInstance<TData>;
|
|
460
460
|
}) => ToolbarProps);
|
package/dist/cjs/index.js
CHANGED
|
@@ -1364,7 +1364,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
|
|
|
1364
1364
|
const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
|
|
1365
1365
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
1366
1366
|
React__default["default"].createElement(material.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 },
|
|
1367
|
-
React__default["default"].createElement(material.IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem',
|
|
1367
|
+
React__default["default"].createElement(material.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': {
|
|
1368
1368
|
opacity: 1,
|
|
1369
1369
|
} }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
|
|
1370
1370
|
? iconButtonProps.sx(theme)
|
|
@@ -1539,7 +1539,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
|
|
|
1539
1539
|
? '100px'
|
|
1540
1540
|
: !filterChipLabel
|
|
1541
1541
|
? '120px'
|
|
1542
|
-
: 'auto', width: '100%', '& .MuiSelect-icon': {
|
|
1542
|
+
: 'auto', width: 'calc(100% + 4px)', mx: '-2px', '& .MuiSelect-icon': {
|
|
1543
1543
|
mr: '1.5rem',
|
|
1544
1544
|
} }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
|
|
1545
1545
|
? textFieldProps.sx(theme)
|
|
@@ -1698,31 +1698,36 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
|
|
|
1698
1698
|
const { column } = header;
|
|
1699
1699
|
const { columnDef } = column;
|
|
1700
1700
|
const { columnDefType } = columnDef;
|
|
1701
|
-
return (React__default["default"].createElement(material.
|
|
1702
|
-
borderRadius: '2px',
|
|
1703
|
-
borderRightWidth: '2px',
|
|
1701
|
+
return (React__default["default"].createElement(material.Box, { onDoubleClick: () => column.resetSize(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), sx: (theme) => ({
|
|
1704
1702
|
cursor: 'col-resize',
|
|
1705
|
-
height: showColumnFilters && columnDefType === 'data' ? '4rem' : '2rem',
|
|
1706
1703
|
mr: density === 'compact' ? '-0.5rem' : '-1rem',
|
|
1707
|
-
opacity: 0.8,
|
|
1708
1704
|
position: 'absolute',
|
|
1709
1705
|
right: '1px',
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
? undefined
|
|
1713
|
-
: 'all 150ms ease-in-out',
|
|
1714
|
-
userSelect: 'none',
|
|
1715
|
-
zIndex: 4,
|
|
1716
|
-
'&:active': {
|
|
1706
|
+
px: '4px',
|
|
1707
|
+
'&:active > hr': {
|
|
1717
1708
|
backgroundColor: theme.palette.info.main,
|
|
1718
1709
|
opacity: 1,
|
|
1719
1710
|
},
|
|
1720
|
-
}),
|
|
1711
|
+
}), style: {
|
|
1721
1712
|
transform: column.getIsResizing()
|
|
1722
1713
|
? `translateX(${((_a = getState().columnSizingInfo.deltaOffset) !== null && _a !== void 0 ? _a : 0) /
|
|
1723
1714
|
(columnResizeMode === 'onChange' ? 16 : 1)}px)`
|
|
1724
|
-
:
|
|
1725
|
-
} }
|
|
1715
|
+
: undefined,
|
|
1716
|
+
} },
|
|
1717
|
+
React__default["default"].createElement(material.Divider, { flexItem: true, orientation: "vertical", sx: {
|
|
1718
|
+
borderRadius: '2px',
|
|
1719
|
+
borderWidth: '2px',
|
|
1720
|
+
height: showColumnFilters && columnDefType === 'data'
|
|
1721
|
+
? '3.5rem'
|
|
1722
|
+
: '1.75rem',
|
|
1723
|
+
opacity: 0.8,
|
|
1724
|
+
touchAction: 'none',
|
|
1725
|
+
transition: column.getIsResizing()
|
|
1726
|
+
? undefined
|
|
1727
|
+
: 'all 150ms ease-in-out',
|
|
1728
|
+
userSelect: 'none',
|
|
1729
|
+
zIndex: 4,
|
|
1730
|
+
} })));
|
|
1726
1731
|
};
|
|
1727
1732
|
|
|
1728
1733
|
const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
|
|
@@ -1760,19 +1765,11 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
|
1760
1765
|
? columnDef.muiTableHeadCellProps({ column, table })
|
|
1761
1766
|
: columnDef.muiTableHeadCellProps;
|
|
1762
1767
|
const tableCellProps = Object.assign(Object.assign({}, mTableHeadCellProps), mcTableHeadCellProps);
|
|
1763
|
-
const
|
|
1764
|
-
if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1765
|
-
setHoveredColumn(null);
|
|
1766
|
-
}
|
|
1767
|
-
if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
|
|
1768
|
-
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
1769
|
-
}
|
|
1770
|
-
};
|
|
1771
|
-
const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
1768
|
+
const draggingBorder = React.useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
1772
1769
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
1773
1770
|
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
1774
1771
|
? `2px dashed ${theme.palette.primary.main}`
|
|
1775
|
-
: undefined;
|
|
1772
|
+
: undefined, [draggingColumn, hoveredColumn]);
|
|
1776
1773
|
const draggingBorders = draggingBorder
|
|
1777
1774
|
? {
|
|
1778
1775
|
borderLeft: draggingBorder,
|
|
@@ -1780,6 +1777,14 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
|
1780
1777
|
borderTop: draggingBorder,
|
|
1781
1778
|
}
|
|
1782
1779
|
: undefined;
|
|
1780
|
+
const handleDragEnter = (_e) => {
|
|
1781
|
+
if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1782
|
+
setHoveredColumn(null);
|
|
1783
|
+
}
|
|
1784
|
+
if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
|
|
1785
|
+
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1783
1788
|
const headerElement = ((_b = ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
|
|
1784
1789
|
? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
|
|
1785
1790
|
column,
|
|
@@ -2018,10 +2023,10 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
|
2018
2023
|
: (_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()));
|
|
2019
2024
|
};
|
|
2020
2025
|
|
|
2021
|
-
const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
2026
|
+
const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table, }) => {
|
|
2022
2027
|
var _a, _b;
|
|
2023
2028
|
const theme = material.useTheme();
|
|
2024
|
-
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping,
|
|
2029
|
+
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
|
2025
2030
|
const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
|
|
2026
2031
|
const { column, row } = cell;
|
|
2027
2032
|
const { columnDef } = column;
|
|
@@ -2036,6 +2041,25 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2036
2041
|
const skeletonProps = muiTableBodyCellSkeletonProps instanceof Function
|
|
2037
2042
|
? muiTableBodyCellSkeletonProps({ cell, column, row, table })
|
|
2038
2043
|
: muiTableBodyCellSkeletonProps;
|
|
2044
|
+
const [skeletonWidth, setSkeletonWidth] = React.useState(0);
|
|
2045
|
+
React.useEffect(() => setSkeletonWidth(isLoading || showSkeletons
|
|
2046
|
+
? columnDefType === 'display'
|
|
2047
|
+
? column.getSize() / 2
|
|
2048
|
+
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
2049
|
+
column.getSize() / 3)
|
|
2050
|
+
: 100), []);
|
|
2051
|
+
const draggingBorder = React.useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
2052
|
+
? `1px dashed ${theme.palette.text.secondary}`
|
|
2053
|
+
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
2054
|
+
? `2px dashed ${theme.palette.primary.main}`
|
|
2055
|
+
: undefined, [draggingColumn, hoveredColumn]);
|
|
2056
|
+
const draggingBorders = React.useMemo(() => draggingBorder
|
|
2057
|
+
? {
|
|
2058
|
+
borderLeft: draggingBorder,
|
|
2059
|
+
borderRight: draggingBorder,
|
|
2060
|
+
borderBottom: rowIndex === numRows - 1 ? draggingBorder : undefined,
|
|
2061
|
+
}
|
|
2062
|
+
: undefined, [draggingBorder, numRows]);
|
|
2039
2063
|
const isEditable = (enableEditing || columnDef.enableEditing) &&
|
|
2040
2064
|
columnDef.enableEditing !== false;
|
|
2041
2065
|
const isEditing = isEditable &&
|
|
@@ -2043,13 +2067,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2043
2067
|
(editingMode === 'table' ||
|
|
2044
2068
|
(editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
|
|
2045
2069
|
(editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id);
|
|
2046
|
-
const [skeletonWidth, setSkeletonWidth] = React.useState(0);
|
|
2047
|
-
React.useEffect(() => setSkeletonWidth(isLoading || showSkeletons
|
|
2048
|
-
? columnDefType === 'display'
|
|
2049
|
-
? column.getSize() / 2
|
|
2050
|
-
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
2051
|
-
column.getSize() / 3)
|
|
2052
|
-
: 100), [isLoading, showSkeletons]);
|
|
2053
2070
|
const handleDoubleClick = (event) => {
|
|
2054
2071
|
var _a;
|
|
2055
2072
|
(_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onDoubleClick) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
|
|
@@ -2076,24 +2093,6 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
|
|
|
2076
2093
|
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
|
2077
2094
|
}
|
|
2078
2095
|
};
|
|
2079
|
-
const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
|
|
2080
|
-
? `1px dashed ${theme.palette.text.secondary}`
|
|
2081
|
-
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
|
2082
|
-
? `2px dashed ${theme.palette.primary.main}`
|
|
2083
|
-
: undefined;
|
|
2084
|
-
const draggingBorders = draggingBorder
|
|
2085
|
-
? {
|
|
2086
|
-
borderLeft: draggingBorder,
|
|
2087
|
-
borderRight: draggingBorder,
|
|
2088
|
-
borderBottom: row.index ===
|
|
2089
|
-
(enablePagination
|
|
2090
|
-
? table.getRowModel()
|
|
2091
|
-
: table.getPrePaginationRowModel()).rows.length -
|
|
2092
|
-
1
|
|
2093
|
-
? draggingBorder
|
|
2094
|
-
: undefined,
|
|
2095
|
-
}
|
|
2096
|
-
: undefined;
|
|
2097
2096
|
return (React__default["default"].createElement(material.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'
|
|
2098
2097
|
? columnDefType === 'display'
|
|
2099
2098
|
? '0 0.5rem'
|
|
@@ -2150,8 +2149,7 @@ const MRT_TableDetailPanel = ({ row, table }) => {
|
|
|
2150
2149
|
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React__default["default"].createElement(material.Collapse, { in: row.getIsExpanded() }, renderDetailPanel({ row, table }))))));
|
|
2151
2150
|
};
|
|
2152
2151
|
|
|
2153
|
-
const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
2154
|
-
var _a, _b;
|
|
2152
|
+
const MRT_TableBodyRow = ({ numRows, row, rowIndex, table, virtualRow, }) => {
|
|
2155
2153
|
const theme = material.useTheme();
|
|
2156
2154
|
const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
|
2157
2155
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
|
@@ -2164,11 +2162,11 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2164
2162
|
}
|
|
2165
2163
|
};
|
|
2166
2164
|
const rowRef = React.useRef(null);
|
|
2167
|
-
const draggingBorder = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
|
2165
|
+
const draggingBorder = React.useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
|
2168
2166
|
? `1px dashed ${theme.palette.text.secondary}`
|
|
2169
2167
|
: (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
|
|
2170
2168
|
? `2px dashed ${theme.palette.primary.main}`
|
|
2171
|
-
: undefined;
|
|
2169
|
+
: undefined, [draggingRow, hoveredRow]);
|
|
2172
2170
|
const draggingBorders = draggingBorder
|
|
2173
2171
|
? {
|
|
2174
2172
|
border: draggingBorder,
|
|
@@ -2188,16 +2186,17 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2188
2186
|
: undefined,
|
|
2189
2187
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
|
2190
2188
|
? tableRowProps.sx(theme)
|
|
2191
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }),
|
|
2189
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }), row.getVisibleCells().map((cell) => {
|
|
2192
2190
|
const props = {
|
|
2193
2191
|
cell,
|
|
2194
2192
|
enableHover: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false,
|
|
2195
2193
|
key: cell.id,
|
|
2194
|
+
numRows,
|
|
2196
2195
|
rowIndex,
|
|
2197
2196
|
rowRef,
|
|
2198
2197
|
table,
|
|
2199
2198
|
};
|
|
2200
|
-
return memoMode === '
|
|
2199
|
+
return memoMode === 'cells' &&
|
|
2201
2200
|
cell.column.columnDef.columnDefType === 'data' &&
|
|
2202
2201
|
!draggingColumn &&
|
|
2203
2202
|
!draggingRow &&
|
|
@@ -2296,6 +2295,7 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2296
2295
|
: rowOrVirtualRow;
|
|
2297
2296
|
const props = {
|
|
2298
2297
|
key: row.id,
|
|
2298
|
+
numRows: rows.length,
|
|
2299
2299
|
row,
|
|
2300
2300
|
rowIndex: enableRowVirtualization
|
|
2301
2301
|
? rowOrVirtualRow.index
|
|
@@ -2303,12 +2303,12 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2303
2303
|
table,
|
|
2304
2304
|
virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
|
|
2305
2305
|
};
|
|
2306
|
-
return memoMode === '
|
|
2306
|
+
return memoMode === 'rows' ? (React__default["default"].createElement(Memo_MRT_TableBodyRow, Object.assign({}, props))) : (React__default["default"].createElement(MRT_TableBodyRow, Object.assign({}, props)));
|
|
2307
2307
|
}),
|
|
2308
2308
|
enableRowVirtualization && paddingBottom > 0 && (React__default["default"].createElement("tr", null,
|
|
2309
2309
|
React__default["default"].createElement("td", { style: { height: `${paddingBottom}px` } })))))));
|
|
2310
2310
|
};
|
|
2311
|
-
const Memo_MRT_TableBody = React.memo(MRT_TableBody, () =>
|
|
2311
|
+
const Memo_MRT_TableBody = React.memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
|
|
2312
2312
|
|
|
2313
2313
|
const MRT_TableFooterCell = ({ footer, table }) => {
|
|
2314
2314
|
var _a, _b, _c;
|
|
@@ -2328,7 +2328,7 @@ const MRT_TableFooterCell = ({ footer, table }) => {
|
|
|
2328
2328
|
? '0.5rem'
|
|
2329
2329
|
: density === 'comfortable'
|
|
2330
2330
|
? '1rem'
|
|
2331
|
-
: '1.5rem', verticalAlign: 'top' }, getCommonCellStyles({ column, table, theme, tableCellProps }))) }),
|
|
2331
|
+
: '1.5rem', verticalAlign: 'top', zIndex: column.getIsPinned() && columnDefType !== 'group' ? 2 : 1 }, getCommonCellStyles({ column, table, theme, tableCellProps }))) }),
|
|
2332
2332
|
React__default["default"].createElement(React__default["default"].Fragment, null, footer.isPlaceholder
|
|
2333
2333
|
? null
|
|
2334
2334
|
: (_c = (_b = (columnDef.Footer instanceof Function
|