material-react-table 1.9.3 → 1.10.0
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 +44 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +4 -0
- package/dist/cjs/types/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/cjs/types/column.utils.d.ts +1 -1
- package/dist/esm/material-react-table.esm.js +44 -31
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +4 -0
- package/dist/esm/types/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/esm/types/column.utils.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/package.json +20 -15
- package/src/MaterialReactTable.tsx +4 -0
- package/src/body/MRT_TableBody.tsx +22 -17
- package/src/body/MRT_TableBodyRow.tsx +2 -1
- package/src/body/MRT_TableDetailPanel.tsx +3 -1
- package/src/column.utils.ts +95 -83
- package/src/table/MRT_TableRoot.tsx +2 -0
- package/src/toolbar/MRT_ToolbarDropZone.tsx +1 -0
package/dist/cjs/index.js
CHANGED
@@ -278,13 +278,17 @@ const getTrailingDisplayColumnIds = (props) => {
|
|
278
278
|
props.positionExpandColumn === 'last' &&
|
279
279
|
showExpandColumn(props) &&
|
280
280
|
'mrt-row-expand',
|
281
|
-
];
|
281
|
+
].filter(Boolean);
|
282
|
+
};
|
283
|
+
const getDefaultColumnOrderIds = (props) => {
|
284
|
+
const leadingDisplayCols = getLeadingDisplayColumnIds(props);
|
285
|
+
const trailingDisplayCols = getTrailingDisplayColumnIds(props);
|
286
|
+
const allLeafColumnDefs = getAllLeafColumnDefs(props.columns)
|
287
|
+
.map((columnDef) => getColumnId(columnDef))
|
288
|
+
.filter((columnId) => !leadingDisplayCols.includes(columnId) &&
|
289
|
+
!trailingDisplayCols.includes(columnId));
|
290
|
+
return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
|
282
291
|
};
|
283
|
-
const getDefaultColumnOrderIds = (props) => [
|
284
|
-
...getLeadingDisplayColumnIds(props),
|
285
|
-
...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
|
286
|
-
...getTrailingDisplayColumnIds(props),
|
287
|
-
].filter(Boolean);
|
288
292
|
const getDefaultColumnFilterFn = (columnDef) => {
|
289
293
|
if (columnDef.filterVariant === 'multi-select')
|
290
294
|
return 'arrIncludesSome';
|
@@ -314,28 +318,33 @@ const getTotalRight = (table, column) => {
|
|
314
318
|
};
|
315
319
|
const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
|
316
320
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
317
|
-
|
321
|
+
const widthStyles = {
|
322
|
+
minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) * 1px), ${(_b = column.columnDef.minSize) !== null && _b !== void 0 ? _b : 30}px)`,
|
323
|
+
width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_c = header === null || header === void 0 ? void 0 : header.id) !== null && _c !== void 0 ? _c : column.id)}-size) * 1px)`,
|
324
|
+
};
|
325
|
+
return Object.assign(Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
318
326
|
? styles.alpha(styles.lighten(theme.palette.background.default, 0.04), 0.97)
|
319
327
|
: 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
|
320
328
|
? `-4px 0 8px -6px ${styles.alpha(theme.palette.common.black, 0.2)} inset`
|
321
329
|
: getIsFirstRightPinnedColumn(column)
|
322
330
|
? `4px 0 8px -6px ${styles.alpha(theme.palette.common.black, 0.2)} inset`
|
323
331
|
: undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', flex: table.options.layoutMode === 'grid'
|
324
|
-
? `var(--${header ? 'header' : 'col'}-${parseCSSVarId((
|
332
|
+
? `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_d = header === null || header === void 0 ? void 0 : header.id) !== null && _d !== void 0 ? _d : column.id)}-size) 0 auto`
|
325
333
|
: undefined, left: column.getIsPinned() === 'left'
|
326
334
|
? `${column.getStart('left')}px`
|
327
335
|
: undefined, ml: table.options.enableColumnVirtualization &&
|
328
336
|
column.getIsPinned() === 'left' &&
|
329
337
|
column.getPinnedIndex() === 0
|
330
|
-
? `-${column.getSize() *
|
338
|
+
? `-${column.getSize() *
|
339
|
+
((_f = (_e = table.getState().columnPinning.left) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 1)}px`
|
331
340
|
: undefined, mr: table.options.enableColumnVirtualization &&
|
332
341
|
column.getIsPinned() === 'right' &&
|
333
342
|
column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
|
334
343
|
? `-${column.getSize() *
|
335
|
-
((
|
344
|
+
((_h = (_g = table.getState().columnPinning.right) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 1) *
|
336
345
|
1.2}px`
|
337
|
-
: undefined, opacity: ((
|
338
|
-
((
|
346
|
+
: undefined, opacity: ((_j = table.getState().draggingColumn) === null || _j === void 0 ? void 0 : _j.id) === column.id ||
|
347
|
+
((_k = table.getState().hoveredColumn) === null || _k === void 0 ? void 0 : _k.id) === column.id
|
339
348
|
? 0.5
|
340
349
|
: 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
341
350
|
? 'sticky'
|
@@ -343,9 +352,9 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
|
|
343
352
|
? `${getTotalRight(table, column)}px`
|
344
353
|
: undefined, transition: table.options.enableColumnVirtualization
|
345
354
|
? 'none'
|
346
|
-
: `padding 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
|
355
|
+
: `padding 150ms ease-in-out` }, (!table.options.enableColumnResizing && widthStyles)), ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
|
347
356
|
? tableCellProps.sx(theme)
|
348
|
-
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)),
|
357
|
+
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), (table.options.enableColumnResizing && widthStyles));
|
349
358
|
};
|
350
359
|
const MRT_DefaultColumn = {
|
351
360
|
filterVariant: 'text',
|
@@ -1448,6 +1457,7 @@ const MRT_ToolbarDropZone = ({ table, }) => {
|
|
1448
1457
|
if (((_a = table.options.state) === null || _a === void 0 ? void 0 : _a.showToolbarDropZone) !== undefined) {
|
1449
1458
|
setShowToolbarDropZone(!!enableGrouping &&
|
1450
1459
|
!!draggingColumn &&
|
1460
|
+
draggingColumn.columnDef.enableGrouping !== false &&
|
1451
1461
|
!grouping.includes(draggingColumn.id));
|
1452
1462
|
}
|
1453
1463
|
}, [enableGrouping, draggingColumn, grouping]);
|
@@ -2514,11 +2524,11 @@ const MRT_TableBodyCell = ({ cell, measureElement, numRows, rowIndex, rowRef, ta
|
|
2514
2524
|
};
|
2515
2525
|
const Memo_MRT_TableBodyCell = React.memo(MRT_TableBodyCell, (prev, next) => next.cell === prev.cell);
|
2516
2526
|
|
2517
|
-
const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
|
2527
|
+
const MRT_TableDetailPanel = ({ parentRowRef, row, rowIndex, table, virtualRow, }) => {
|
2518
2528
|
const { getVisibleLeafColumns, getState, options: { layoutMode, muiTableBodyRowProps, muiTableDetailPanelProps, renderDetailPanel, }, } = table;
|
2519
2529
|
const { isLoading } = getState();
|
2520
2530
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
2521
|
-
? muiTableBodyRowProps({ isDetailPanel: true, row, table })
|
2531
|
+
? muiTableBodyRowProps({ isDetailPanel: true, row, staticRowIndex: rowIndex, table })
|
2522
2532
|
: muiTableBodyRowProps;
|
2523
2533
|
const tableCellProps = muiTableDetailPanelProps instanceof Function
|
2524
2534
|
? muiTableDetailPanelProps({ row, table })
|
@@ -2544,7 +2554,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2544
2554
|
const { getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
2545
2555
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
2546
2556
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
2547
|
-
? muiTableBodyRowProps({ row, table })
|
2557
|
+
? muiTableBodyRowProps({ row, staticRowIndex: rowIndex, table })
|
2548
2558
|
: muiTableBodyRowProps;
|
2549
2559
|
const handleDragEnter = (_e) => {
|
2550
2560
|
if (enableRowOrdering && draggingRow) {
|
@@ -2596,13 +2606,13 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2596
2606
|
(editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) !== row.id ? (React__default["default"].createElement(Memo_MRT_TableBodyCell, Object.assign({}, props))) : (React__default["default"].createElement(MRT_TableBodyCell, Object.assign({}, props)));
|
2597
2607
|
}),
|
2598
2608
|
virtualPaddingRight ? (React__default["default"].createElement("td", { style: { display: 'flex', width: virtualPaddingRight } })) : null),
|
2599
|
-
renderDetailPanel && !row.getIsGrouped() && (React__default["default"].createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, table: table, virtualRow: virtualRow }))));
|
2609
|
+
renderDetailPanel && !row.getIsGrouped() && (React__default["default"].createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, rowIndex: rowIndex, table: table, virtualRow: virtualRow }))));
|
2600
2610
|
};
|
2601
2611
|
const Memo_MRT_TableBodyRow = React.memo(MRT_TableBodyRow, (prev, next) => prev.row === next.row && prev.rowIndex === next.rowIndex);
|
2602
2612
|
|
2603
2613
|
const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2604
|
-
var _a, _b, _c;
|
2605
|
-
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2614
|
+
var _a, _b, _c, _d;
|
2615
|
+
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, renderEmptyRowsFallback, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2606
2616
|
const { columnFilters, density, expanded, globalFilter, globalFilterFn, pagination, sorting, } = getState();
|
2607
2617
|
const tableBodyProps = muiTableBodyProps instanceof Function
|
2608
2618
|
? muiTableBodyProps({ table })
|
@@ -2665,17 +2675,18 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
2665
2675
|
: 'inherit', minHeight: !rows.length ? '100px' : undefined, position: 'relative' }, ((tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx) instanceof Function
|
2666
2676
|
? tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx(theme)
|
2667
2677
|
: tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx))) }), (_a = tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.children) !== null && _a !== void 0 ? _a : (!rows.length ? (React__default["default"].createElement("tr", { style: { display: layoutMode === 'grid' ? 'grid' : 'table-row' } },
|
2668
|
-
React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: {
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2674
|
-
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2678
|
+
React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: {
|
2679
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-cell',
|
2680
|
+
} }, (_b = renderEmptyRowsFallback === null || renderEmptyRowsFallback === void 0 ? void 0 : renderEmptyRowsFallback({ table })) !== null && _b !== void 0 ? _b : (React__default["default"].createElement(Typography__default["default"], { sx: {
|
2681
|
+
color: 'text.secondary',
|
2682
|
+
fontStyle: 'italic',
|
2683
|
+
maxWidth: `min(100vw, ${(_d = (_c = tablePaperRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 360}px)`,
|
2684
|
+
py: '2rem',
|
2685
|
+
textAlign: 'center',
|
2686
|
+
width: '100%',
|
2687
|
+
} }, globalFilter || columnFilters.length
|
2688
|
+
? localization.noResultsFound
|
2689
|
+
: localization.noRecordsToDisplay))))) : (React__default["default"].createElement(React__default["default"].Fragment, null, (virtualRows !== null && virtualRows !== void 0 ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
|
2679
2690
|
const row = rowVirtualizer
|
2680
2691
|
? rows[rowOrVirtualRow.index]
|
2681
2692
|
: rowOrVirtualRow;
|
@@ -3016,6 +3027,8 @@ const MRT_TableRoot = (props) => {
|
|
3016
3027
|
props.localization,
|
3017
3028
|
props.positionActionsColumn,
|
3018
3029
|
props.renderDetailPanel,
|
3030
|
+
props.renderRowActionMenuItems,
|
3031
|
+
props.renderRowActions,
|
3019
3032
|
(_s = props.state) === null || _s === void 0 ? void 0 : _s.columnOrder,
|
3020
3033
|
(_t = props.state) === null || _t === void 0 ? void 0 : _t.grouping,
|
3021
3034
|
]);
|