material-react-table 1.0.0-beta.5 → 1.0.0-beta.6
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 +2 -15
- package/dist/cjs/index.js +39 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/MaterialReactTable.d.ts +2 -15
- package/dist/esm/material-react-table.esm.js +39 -26
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/index.d.ts +2 -15
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +1 -19
- package/src/body/MRT_TableBody.tsx +11 -9
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +5 -8
- package/src/buttons/MRT_GrabHandleButton.tsx +2 -2
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +5 -12
- package/src/table/MRT_TablePaper.tsx +8 -0
- package/src/table/MRT_TableRoot.tsx +2 -0
- package/src/toolbar/MRT_TopToolbar.tsx +7 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dispatch,
|
|
1
|
+
import { Dispatch, MutableRefObject, ReactNode, SetStateAction } from 'react';
|
|
2
2
|
import type { AlertProps, ButtonProps, CheckboxProps, ChipProps, IconButtonProps, LinearProgressProps, PaperProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
|
|
3
3
|
import type { Cell, Column, ColumnDef, DeepKeys, FilterFn, Header, HeaderGroup, OnChangeFn, Row, SortingFn, Table, TableOptions, TableState } from '@tanstack/react-table';
|
|
4
4
|
import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
|
|
@@ -40,6 +40,7 @@ export declare type MRT_TableInstance<TData extends Record<string, any> = {}> =
|
|
|
40
40
|
filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
41
41
|
searchInputRef: MutableRefObject<HTMLInputElement>;
|
|
42
42
|
tableContainerRef: MutableRefObject<HTMLDivElement>;
|
|
43
|
+
tablePaperRef: MutableRefObject<HTMLDivElement>;
|
|
43
44
|
topToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
44
45
|
};
|
|
45
46
|
setColumnFilterFns: Dispatch<SetStateAction<{
|
|
@@ -439,13 +440,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
|
|
|
439
440
|
muiTopToolbarProps?: ToolbarProps | (({ table }: {
|
|
440
441
|
table: MRT_TableInstance<TData>;
|
|
441
442
|
}) => ToolbarProps);
|
|
442
|
-
onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
|
|
443
|
-
event: DragEvent<HTMLButtonElement>;
|
|
444
|
-
draggedColumn: MRT_Column<TData>;
|
|
445
|
-
targetColumn: MRT_Column<TData> | {
|
|
446
|
-
id: string;
|
|
447
|
-
} | null;
|
|
448
|
-
}) => void;
|
|
449
443
|
onDensityChange?: OnChangeFn<boolean>;
|
|
450
444
|
onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
|
451
445
|
onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
@@ -464,13 +458,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
|
|
|
464
458
|
onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
|
465
459
|
onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
466
460
|
onIsFullScreenChange?: OnChangeFn<boolean>;
|
|
467
|
-
onRowDrop?: ({ event, draggedRow, targetRow, }: {
|
|
468
|
-
event: DragEvent<HTMLButtonElement>;
|
|
469
|
-
draggedRow: MRT_Row<TData>;
|
|
470
|
-
targetRow: MRT_Row<TData> | {
|
|
471
|
-
id: string;
|
|
472
|
-
} | null;
|
|
473
|
-
}) => void;
|
|
474
461
|
onShowAlertBannerChange?: OnChangeFn<boolean>;
|
|
475
462
|
onShowFiltersChange?: OnChangeFn<boolean>;
|
|
476
463
|
onShowGlobalFilterChange?: OnChangeFn<boolean>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -479,11 +479,11 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
|
|
|
479
479
|
var _a;
|
|
480
480
|
const { options: { icons: { DragHandleIcon }, localization, }, } = table;
|
|
481
481
|
return (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.move },
|
|
482
|
-
React__default["default"].createElement(material.IconButton, Object.assign({ disableRipple: true, draggable: "true",
|
|
482
|
+
React__default["default"].createElement(material.IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
|
|
483
483
|
var _a;
|
|
484
484
|
e.stopPropagation();
|
|
485
485
|
(_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
|
|
486
|
-
}, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
|
|
486
|
+
}, onDragStart: onDragStart, onDragEnd: onDragEnd, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
|
|
487
487
|
backgroundColor: 'transparent',
|
|
488
488
|
opacity: 1,
|
|
489
489
|
}, '&:active': {
|
|
@@ -1312,7 +1312,11 @@ const MRT_TopToolbar = ({ table }) => {
|
|
|
1312
1312
|
width: '100%',
|
|
1313
1313
|
} },
|
|
1314
1314
|
enableGlobalFilter && positionGlobalFilter === 'left' && (React__default["default"].createElement(MRT_GlobalFilterTextField, { table: table })), (_a = renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({ table })) !== null && _a !== void 0 ? _a : React__default["default"].createElement("span", null),
|
|
1315
|
-
enableToolbarInternalActions ? (React__default["default"].createElement(material.Box, { sx: {
|
|
1315
|
+
enableToolbarInternalActions ? (React__default["default"].createElement(material.Box, { sx: {
|
|
1316
|
+
display: 'flex',
|
|
1317
|
+
flexWrap: 'wrap-reverse',
|
|
1318
|
+
justifyContent: 'flex-end',
|
|
1319
|
+
} },
|
|
1316
1320
|
enableGlobalFilter && positionGlobalFilter === 'right' && (React__default["default"].createElement(MRT_GlobalFilterTextField, { table: table })),
|
|
1317
1321
|
React__default["default"].createElement(MRT_ToolbarInternalButtons, { table: table }))) : (enableGlobalFilter &&
|
|
1318
1322
|
positionGlobalFilter === 'right' && (React__default["default"].createElement(MRT_GlobalFilterTextField, { table: table })))),
|
|
@@ -1638,7 +1642,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
|
|
1638
1642
|
};
|
|
1639
1643
|
|
|
1640
1644
|
const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
|
|
1641
|
-
const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps
|
|
1645
|
+
const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
|
|
1642
1646
|
const { columnDef } = column;
|
|
1643
1647
|
const { hoveredColumn, draggingColumn, columnOrder } = getState();
|
|
1644
1648
|
const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
|
|
@@ -1648,16 +1652,15 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
|
|
|
1648
1652
|
? columnDef.muiTableHeadCellDragHandleProps({ column, table })
|
|
1649
1653
|
: columnDef.muiTableHeadCellDragHandleProps;
|
|
1650
1654
|
const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
|
|
1651
|
-
const handleDragStart = (
|
|
1655
|
+
const handleDragStart = (event) => {
|
|
1656
|
+
var _a;
|
|
1657
|
+
(_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
|
|
1652
1658
|
setDraggingColumn(column);
|
|
1653
|
-
|
|
1659
|
+
event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
|
|
1654
1660
|
};
|
|
1655
1661
|
const handleDragEnd = (event) => {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
draggedColumn: column,
|
|
1659
|
-
targetColumn: hoveredColumn,
|
|
1660
|
-
});
|
|
1662
|
+
var _a;
|
|
1663
|
+
(_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
|
|
1661
1664
|
if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
|
|
1662
1665
|
column.toggleGrouping();
|
|
1663
1666
|
}
|
|
@@ -1946,21 +1949,20 @@ const MRT_CopyButton = ({ cell, children, table, }) => {
|
|
|
1946
1949
|
};
|
|
1947
1950
|
|
|
1948
1951
|
const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
|
|
1949
|
-
const { options: { muiTableBodyRowDragHandleProps
|
|
1952
|
+
const { options: { muiTableBodyRowDragHandleProps }, } = table;
|
|
1950
1953
|
const { row } = cell;
|
|
1951
1954
|
const iconButtonProps = muiTableBodyRowDragHandleProps instanceof Function
|
|
1952
1955
|
? muiTableBodyRowDragHandleProps({ row, table })
|
|
1953
1956
|
: muiTableBodyRowDragHandleProps;
|
|
1954
|
-
const handleDragStart = (
|
|
1955
|
-
|
|
1957
|
+
const handleDragStart = (event) => {
|
|
1958
|
+
var _a;
|
|
1959
|
+
(_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
|
|
1960
|
+
event.dataTransfer.setDragImage(rowRef.current, 0, 0);
|
|
1956
1961
|
table.setDraggingRow(row);
|
|
1957
1962
|
};
|
|
1958
1963
|
const handleDragEnd = (event) => {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
draggedRow: table.getState().draggingRow,
|
|
1962
|
-
targetRow: table.getState().hoveredRow,
|
|
1963
|
-
});
|
|
1964
|
+
var _a;
|
|
1965
|
+
(_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
|
|
1964
1966
|
table.setDraggingRow(null);
|
|
1965
1967
|
table.setHoveredRow(null);
|
|
1966
1968
|
};
|
|
@@ -2165,7 +2167,8 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
|
|
|
2165
2167
|
};
|
|
2166
2168
|
|
|
2167
2169
|
const MRT_TableBody = ({ table }) => {
|
|
2168
|
-
|
|
2170
|
+
var _a;
|
|
2171
|
+
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
|
2169
2172
|
const { columnFilters, globalFilter, pagination, sorting } = getState();
|
|
2170
2173
|
const tableBodyProps = muiTableBodyProps instanceof Function
|
|
2171
2174
|
? muiTableBodyProps({ table })
|
|
@@ -2231,10 +2234,12 @@ const MRT_TableBody = ({ table }) => {
|
|
|
2231
2234
|
// ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
|
|
2232
2235
|
// : 0;
|
|
2233
2236
|
// }
|
|
2234
|
-
return (React__default["default"].createElement(material.TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React__default["default"].createElement(
|
|
2235
|
-
React__default["default"].createElement(
|
|
2236
|
-
React__default["default"].createElement(material.
|
|
2237
|
-
|
|
2237
|
+
return (React__default["default"].createElement(material.TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React__default["default"].createElement("tr", null,
|
|
2238
|
+
React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length },
|
|
2239
|
+
React__default["default"].createElement(material.Typography, { sx: {
|
|
2240
|
+
color: 'text.secondary',
|
|
2241
|
+
fontStyle: 'italic',
|
|
2242
|
+
maxWidth: `min(100vw, ${(_a = tablePaperRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px)`,
|
|
2238
2243
|
py: '2rem',
|
|
2239
2244
|
textAlign: 'center',
|
|
2240
2245
|
width: '100%',
|
|
@@ -2362,7 +2367,7 @@ const MRT_TableContainer = ({ table }) => {
|
|
|
2362
2367
|
};
|
|
2363
2368
|
|
|
2364
2369
|
const MRT_TablePaper = ({ table }) => {
|
|
2365
|
-
const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, } = table;
|
|
2370
|
+
const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, refs: { tablePaperRef }, } = table;
|
|
2366
2371
|
const { isFullScreen } = getState();
|
|
2367
2372
|
React.useEffect(() => {
|
|
2368
2373
|
if (typeof window !== 'undefined') {
|
|
@@ -2377,7 +2382,13 @@ const MRT_TablePaper = ({ table }) => {
|
|
|
2377
2382
|
const tablePaperProps = muiTablePaperProps instanceof Function
|
|
2378
2383
|
? muiTablePaperProps({ table })
|
|
2379
2384
|
: muiTablePaperProps;
|
|
2380
|
-
return (React__default["default"].createElement(material.Paper, Object.assign({ elevation: 2 }, tablePaperProps, {
|
|
2385
|
+
return (React__default["default"].createElement(material.Paper, Object.assign({ elevation: 2 }, tablePaperProps, { ref: (ref) => {
|
|
2386
|
+
tablePaperRef.current = ref;
|
|
2387
|
+
if (tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.ref) {
|
|
2388
|
+
//@ts-ignore
|
|
2389
|
+
tablePaperProps.ref.current = ref;
|
|
2390
|
+
}
|
|
2391
|
+
}, sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
|
|
2381
2392
|
? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
|
|
2382
2393
|
: tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx))), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), { height: isFullScreen ? '100vh' : undefined, margin: isFullScreen ? '0' : undefined, maxHeight: isFullScreen ? '100vh' : undefined, maxWidth: isFullScreen ? '100vw' : undefined, padding: isFullScreen ? '0' : undefined, width: isFullScreen ? '100vw' : undefined }) }),
|
|
2383
2394
|
enableTopToolbar && React__default["default"].createElement(MRT_TopToolbar, { table: table }),
|
|
@@ -2410,6 +2421,7 @@ const MRT_TableRoot = (props) => {
|
|
|
2410
2421
|
const filterInputRefs = React.useRef({});
|
|
2411
2422
|
const searchInputRef = React.useRef(null);
|
|
2412
2423
|
const tableContainerRef = React.useRef(null);
|
|
2424
|
+
const tablePaperRef = React.useRef(null);
|
|
2413
2425
|
const topToolbarRef = React.useRef(null);
|
|
2414
2426
|
const initialState = React.useMemo(() => {
|
|
2415
2427
|
var _a, _b;
|
|
@@ -2530,6 +2542,7 @@ const MRT_TableRoot = (props) => {
|
|
|
2530
2542
|
filterInputRefs,
|
|
2531
2543
|
searchInputRef,
|
|
2532
2544
|
tableContainerRef,
|
|
2545
|
+
tablePaperRef,
|
|
2533
2546
|
topToolbarRef,
|
|
2534
2547
|
}, setColumnFilterFns: (_x = props.onFilterFnsChange) !== null && _x !== void 0 ? _x : setColumnFilterFns, setDensity: (_y = props.onDensityChange) !== null && _y !== void 0 ? _y : setDensity, setDraggingColumn: (_z = props.onDraggingColumnChange) !== null && _z !== void 0 ? _z : setDraggingColumn, setDraggingRow: (_0 = props.onDraggingRowChange) !== null && _0 !== void 0 ? _0 : setDraggingRow, setEditingCell: (_1 = props.onEditingCellChange) !== null && _1 !== void 0 ? _1 : setEditingCell, setEditingRow: (_2 = props.onEditingRowChange) !== null && _2 !== void 0 ? _2 : setEditingRow, setGlobalFilterFn: (_3 = props.onGlobalFilterFnChange) !== null && _3 !== void 0 ? _3 : setGlobalFilterFn, setHoveredColumn: (_4 = props.onHoveredColumnChange) !== null && _4 !== void 0 ? _4 : setHoveredColumn, setHoveredRow: (_5 = props.onHoveredRowChange) !== null && _5 !== void 0 ? _5 : setHoveredRow, setIsFullScreen: (_6 = props.onIsFullScreenChange) !== null && _6 !== void 0 ? _6 : setIsFullScreen, setShowAlertBanner: (_7 = props.onShowAlertBannerChange) !== null && _7 !== void 0 ? _7 : setShowAlertBanner, setShowFilters: (_8 = props.onShowFiltersChange) !== null && _8 !== void 0 ? _8 : setShowFilters, setShowGlobalFilter: (_9 = props.onShowGlobalFilterChange) !== null && _9 !== void 0 ? _9 : setShowGlobalFilter });
|
|
2535
2548
|
if (props.tableInstanceRef) {
|