material-react-table 1.7.2 → 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 +33 -42
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +6 -0
- package/dist/cjs/types/column.utils.d.ts +4 -2
- package/dist/cjs/types/icons.d.ts +0 -1
- package/dist/esm/material-react-table.esm.js +33 -41
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +6 -0
- package/dist/esm/types/column.utils.d.ts +4 -2
- package/dist/esm/types/icons.d.ts +0 -1
- package/dist/index.d.ts +6 -1
- package/package.json +12 -13
- package/src/MaterialReactTable.tsx +6 -0
- package/src/body/MRT_TableBodyCell.tsx +3 -1
- package/src/buttons/MRT_ExpandAllButton.tsx +10 -8
- package/src/buttons/MRT_ExpandButton.tsx +10 -8
- package/src/column.utils.ts +16 -13
- package/src/head/MRT_TableHeadCell.tsx +1 -0
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +1 -1
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +2 -5
- package/src/icons.ts +0 -3
- package/src/table/MRT_Table.tsx +5 -4
@@ -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;
|
@@ -137,3 +138,4 @@ export declare const MRT_DefaultDisplayColumn: {
|
|
137
138
|
readonly enableResizing: false;
|
138
139
|
readonly enableSorting: false;
|
139
140
|
};
|
141
|
+
export declare const parseCSSVarId: (id: string) => string;
|
@@ -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,37 +242,31 @@ 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-${column.id
|
247
|
-
.replaceAll('.', '_')
|
248
|
-
.replaceAll(' ', '_')}-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`
|
249
246
|
: undefined, left: column.getIsPinned() === 'left'
|
250
247
|
? `${column.getStart('left')}px`
|
251
248
|
: undefined, ml: table.options.enableColumnVirtualization &&
|
252
249
|
column.getIsPinned() === 'left' &&
|
253
250
|
column.getPinnedIndex() === 0
|
254
|
-
? `-${column.getSize() * ((
|
251
|
+
? `-${column.getSize() * ((_c = (_b = table.getState().columnPinning.left) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 1)}px`
|
255
252
|
: undefined, mr: table.options.enableColumnVirtualization &&
|
256
253
|
column.getIsPinned() === 'right' &&
|
257
254
|
column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
|
258
255
|
? `-${column.getSize() *
|
259
|
-
((
|
256
|
+
((_e = (_d = table.getState().columnPinning.right) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 1) *
|
260
257
|
1.2}px`
|
261
|
-
: undefined, opacity: ((
|
262
|
-
((
|
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
|
263
260
|
? 0.5
|
264
261
|
: 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
265
262
|
? 'sticky'
|
266
263
|
: undefined, right: column.getIsPinned() === 'right'
|
267
264
|
? `${getTotalRight(table, column)}px`
|
268
|
-
: undefined, transition: table.options.enableColumnVirtualization
|
265
|
+
: undefined, transition: table.options.enableColumnVirtualization
|
269
266
|
? 'none'
|
270
267
|
: `padding 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
|
271
268
|
? tableCellProps.sx(theme)
|
272
|
-
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { minWidth: `max(calc(var(--col-${column.id
|
273
|
-
.replaceAll('.', '_')
|
274
|
-
.replaceAll(' ', '_')}-size) * 1px), ${(_g = column.columnDef.minSize) !== null && _g !== void 0 ? _g : 30}px)`, width: `calc(var(--col-${column.id
|
275
|
-
.replaceAll('.', '_')
|
276
|
-
.replaceAll(' ', '_')}-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)` }));
|
277
270
|
};
|
278
271
|
const MRT_DefaultColumn = {
|
279
272
|
filterVariant: 'text',
|
@@ -295,6 +288,7 @@ const MRT_DefaultDisplayColumn = {
|
|
295
288
|
enableResizing: false,
|
296
289
|
enableSorting: false,
|
297
290
|
};
|
291
|
+
const parseCSSVarId = (id) => id.replaceAll('.', '_').replaceAll(' ', '_').replaceAll('+', '_');
|
298
292
|
|
299
293
|
const fuzzy$1 = (row, columnId, filterValue, addMeta) => {
|
300
294
|
const itemRank = rankItem(row.getValue(columnId), filterValue, {
|
@@ -392,7 +386,6 @@ const MRT_Default_Icons = {
|
|
392
386
|
DragHandleIcon,
|
393
387
|
DynamicFeedIcon,
|
394
388
|
EditIcon,
|
395
|
-
ExpandLessIcon,
|
396
389
|
ExpandMoreIcon,
|
397
390
|
FilterAltIcon,
|
398
391
|
FilterListIcon,
|
@@ -427,7 +420,7 @@ const rankGlobalFuzzy = (rowA, rowB) => Math.max(...Object.values(rowB.columnFil
|
|
427
420
|
Math.max(...Object.values(rowA.columnFiltersMeta).map((v) => v.rank));
|
428
421
|
|
429
422
|
const MRT_ExpandAllButton = ({ table }) => {
|
430
|
-
var _a;
|
423
|
+
var _a, _b;
|
431
424
|
const { getIsAllRowsExpanded, getIsSomeRowsExpanded, getCanSomeRowsExpand, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
|
432
425
|
const { density, isLoading } = getState();
|
433
426
|
const iconButtonProps = muiExpandAllButtonProps instanceof Function
|
@@ -440,15 +433,14 @@ const MRT_ExpandAllButton = ({ table }) => {
|
|
440
433
|
React.createElement("span", null,
|
441
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
|
442
435
|
? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
|
443
|
-
: iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
} })))));
|
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
|
+
} }))))));
|
448
440
|
};
|
449
441
|
|
450
442
|
const MRT_ExpandButton = ({ row, table }) => {
|
451
|
-
var _a;
|
443
|
+
var _a, _b;
|
452
444
|
const { getState, options: { icons: { ExpandMoreIcon }, localization, muiExpandButtonProps, renderDetailPanel, }, } = table;
|
453
445
|
const { density } = getState();
|
454
446
|
const iconButtonProps = muiExpandButtonProps instanceof Function
|
@@ -468,11 +460,10 @@ const MRT_ExpandButton = ({ row, table }) => {
|
|
468
460
|
React.createElement("span", null,
|
469
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
|
470
462
|
? iconButtonProps.sx(theme)
|
471
|
-
: iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
} })))));
|
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
|
+
} }))))));
|
476
467
|
};
|
477
468
|
|
478
469
|
const mrtFilterOptions = (localization) => [
|
@@ -1469,7 +1460,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
|
|
1469
1460
|
const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
|
1470
1461
|
return (React.createElement(React.Fragment, null,
|
1471
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 },
|
1472
|
-
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': {
|
1473
1464
|
opacity: 1,
|
1474
1465
|
} }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
|
1475
1466
|
? iconButtonProps.sx(theme)
|
@@ -1820,10 +1811,8 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
|
|
1820
1811
|
const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
|
1821
1812
|
var _a;
|
1822
1813
|
const { getState, options: { columnResizeMode }, setColumnSizingInfo, } = table;
|
1823
|
-
const { density
|
1814
|
+
const { density } = getState();
|
1824
1815
|
const { column } = header;
|
1825
|
-
const { columnDef } = column;
|
1826
|
-
const { columnDefType } = columnDef;
|
1827
1816
|
return (React.createElement(Box, { onDoubleClick: () => {
|
1828
1817
|
setColumnSizingInfo((old) => (Object.assign(Object.assign({}, old), { isResizingColumn: false })));
|
1829
1818
|
column.resetSize();
|
@@ -1845,7 +1834,7 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
|
|
1845
1834
|
React.createElement(Divider, { flexItem: true, orientation: "vertical", sx: {
|
1846
1835
|
borderRadius: '2px',
|
1847
1836
|
borderWidth: '2px',
|
1848
|
-
height:
|
1837
|
+
height: '24px',
|
1849
1838
|
touchAction: 'none',
|
1850
1839
|
transition: column.getIsResizing()
|
1851
1840
|
? undefined
|
@@ -1963,6 +1952,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
1963
1952
|
? 2
|
1964
1953
|
: 1 }, getCommonCellStyles({
|
1965
1954
|
column,
|
1955
|
+
header,
|
1966
1956
|
table,
|
1967
1957
|
tableCellProps,
|
1968
1958
|
theme,
|
@@ -2216,7 +2206,7 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
2216
2206
|
};
|
2217
2207
|
|
2218
2208
|
const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowIndex, rowRef, table, virtualCell, }) => {
|
2219
|
-
var _a, _b;
|
2209
|
+
var _a, _b, _c, _d;
|
2220
2210
|
const theme = useTheme();
|
2221
2211
|
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
2222
2212
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, density, isLoading, showSkeletons, } = getState();
|
@@ -2343,12 +2333,12 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
|
|
2343
2333
|
theme,
|
2344
2334
|
tableCellProps,
|
2345
2335
|
})), draggingBorders)) }),
|
2346
|
-
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 &&
|
2347
2337
|
rowNumberMode === 'static' &&
|
2348
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' &&
|
2349
2339
|
(column.id === 'mrt-row-select' ||
|
2350
2340
|
column.id === 'mrt-row-expand' ||
|
2351
|
-
!row.getIsGrouped()) ? ((
|
2341
|
+
!row.getIsGrouped()) ? ((_c = columnDef.Cell) === null || _c === void 0 ? void 0 : _c.call(columnDef, {
|
2352
2342
|
cell,
|
2353
2343
|
renderedCellValue: cell.renderValue(),
|
2354
2344
|
column,
|
@@ -2358,8 +2348,8 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
|
|
2358
2348
|
columnDef.enableClickToCopy !== false ? (React.createElement(MRT_CopyButton, { cell: cell, table: table },
|
2359
2349
|
React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))) : (React.createElement(MRT_TableBodyCellValue, { cell: cell, table: table }))),
|
2360
2350
|
cell.getIsGrouped() && !columnDef.GroupedCell && (React.createElement(React.Fragment, null,
|
2361
|
-
" (", (
|
2362
|
-
|
2351
|
+
" (", (_d = row.subRows) === null || _d === void 0 ? void 0 :
|
2352
|
+
_d.length,
|
2363
2353
|
")"))));
|
2364
2354
|
};
|
2365
2355
|
const Memo_MRT_TableBodyCell = memo(MRT_TableBodyCell, (prev, next) => next.cell === prev.cell);
|
@@ -2637,8 +2627,10 @@ const MRT_Table = ({ table }) => {
|
|
2637
2627
|
const headers = getFlatHeaders();
|
2638
2628
|
const colSizes = {};
|
2639
2629
|
for (let i = 0; i < headers.length; i++) {
|
2640
|
-
const
|
2641
|
-
|
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;
|
2642
2634
|
}
|
2643
2635
|
return colSizes;
|
2644
2636
|
}, [columns, columnSizing, columnSizingInfo]);
|