material-react-table 1.0.0-beta.5 → 1.0.0-beta.8

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.
@@ -1,4 +1,4 @@
1
- import { Dispatch, DragEvent, MutableRefObject, ReactNode, SetStateAction } from 'react';
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>;
@@ -471,11 +471,11 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
471
471
  var _a;
472
472
  const { options: { icons: { DragHandleIcon }, localization, }, } = table;
473
473
  return (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.move },
474
- React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { onClick: (e) => {
474
+ React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
475
475
  var _a;
476
476
  e.stopPropagation();
477
477
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
478
- }, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
478
+ }, 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': {
479
479
  backgroundColor: 'transparent',
480
480
  opacity: 1,
481
481
  }, '&:active': {
@@ -1304,7 +1304,11 @@ const MRT_TopToolbar = ({ table }) => {
1304
1304
  width: '100%',
1305
1305
  } },
1306
1306
  enableGlobalFilter && positionGlobalFilter === 'left' && (React.createElement(MRT_GlobalFilterTextField, { table: table })), (_a = renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({ table })) !== null && _a !== void 0 ? _a : React.createElement("span", null),
1307
- enableToolbarInternalActions ? (React.createElement(Box, { sx: { display: 'flex', flexWrap: 'wrap' } },
1307
+ enableToolbarInternalActions ? (React.createElement(Box, { sx: {
1308
+ display: 'flex',
1309
+ flexWrap: 'wrap-reverse',
1310
+ justifyContent: 'flex-end',
1311
+ } },
1308
1312
  enableGlobalFilter && positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })),
1309
1313
  React.createElement(MRT_ToolbarInternalButtons, { table: table }))) : (enableGlobalFilter &&
1310
1314
  positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })))),
@@ -1596,11 +1600,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1596
1600
  const { options: { icons: { FilterAltIcon }, localization, }, } = table;
1597
1601
  const { column } = header;
1598
1602
  const { columnDef } = column;
1599
- const isRangeFilter = [
1600
- 'between',
1601
- 'betweenInclusive',
1602
- 'inNumberRange',
1603
- ].includes(columnDef._filterFn);
1603
+ const isRangeFilter = columnDef.filterVariant === 'range' ||
1604
+ ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
1604
1605
  const currentFilterOption = columnDef._filterFn;
1605
1606
  const filterTooltip = localization.filteringByColumn
1606
1607
  .replace('{column}', String(columnDef.header))
@@ -1612,8 +1613,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1612
1613
  ? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1613
1614
  : column.getFilterValue()}"`)
1614
1615
  .replace('" "', '');
1615
- return (React.createElement(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && isRangeFilter) ||
1616
- (!isRangeFilter && // @ts-ignore
1616
+ return (React.createElement(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
1617
+ (isRangeFilter && // @ts-ignore
1617
1618
  (!!((_b = column.getFilterValue()) === null || _b === void 0 ? void 0 : _b[0]) || !!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[1]))) },
1618
1619
  React.createElement("span", null,
1619
1620
  React.createElement(Tooltip, { arrow: true, placement: "top", title: filterTooltip },
@@ -1630,7 +1631,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1630
1631
  };
1631
1632
 
1632
1633
  const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1633
- const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1634
+ const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1634
1635
  const { columnDef } = column;
1635
1636
  const { hoveredColumn, draggingColumn, columnOrder } = getState();
1636
1637
  const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
@@ -1640,16 +1641,15 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1640
1641
  ? columnDef.muiTableHeadCellDragHandleProps({ column, table })
1641
1642
  : columnDef.muiTableHeadCellDragHandleProps;
1642
1643
  const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
1643
- const handleDragStart = (e) => {
1644
+ const handleDragStart = (event) => {
1645
+ var _a;
1646
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1644
1647
  setDraggingColumn(column);
1645
- e.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1648
+ event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1646
1649
  };
1647
1650
  const handleDragEnd = (event) => {
1648
- onColumnDrop === null || onColumnDrop === void 0 ? void 0 : onColumnDrop({
1649
- event,
1650
- draggedColumn: column,
1651
- targetColumn: hoveredColumn,
1652
- });
1651
+ var _a;
1652
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1653
1653
  if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1654
1654
  column.toggleGrouping();
1655
1655
  }
@@ -1938,21 +1938,20 @@ const MRT_CopyButton = ({ cell, children, table, }) => {
1938
1938
  };
1939
1939
 
1940
1940
  const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1941
- const { options: { muiTableBodyRowDragHandleProps, onRowDrop }, } = table;
1941
+ const { options: { muiTableBodyRowDragHandleProps }, } = table;
1942
1942
  const { row } = cell;
1943
1943
  const iconButtonProps = muiTableBodyRowDragHandleProps instanceof Function
1944
1944
  ? muiTableBodyRowDragHandleProps({ row, table })
1945
1945
  : muiTableBodyRowDragHandleProps;
1946
- const handleDragStart = (e) => {
1947
- e.dataTransfer.setDragImage(rowRef.current, 0, 0);
1946
+ const handleDragStart = (event) => {
1947
+ var _a;
1948
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1949
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1948
1950
  table.setDraggingRow(row);
1949
1951
  };
1950
1952
  const handleDragEnd = (event) => {
1951
- onRowDrop === null || onRowDrop === void 0 ? void 0 : onRowDrop({
1952
- event,
1953
- draggedRow: table.getState().draggingRow,
1954
- targetRow: table.getState().hoveredRow,
1955
- });
1953
+ var _a;
1954
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1956
1955
  table.setDraggingRow(null);
1957
1956
  table.setHoveredRow(null);
1958
1957
  };
@@ -2157,7 +2156,8 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2157
2156
  };
2158
2157
 
2159
2158
  const MRT_TableBody = ({ table }) => {
2160
- const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef }, } = table;
2159
+ var _a;
2160
+ const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
2161
2161
  const { columnFilters, globalFilter, pagination, sorting } = getState();
2162
2162
  const tableBodyProps = muiTableBodyProps instanceof Function
2163
2163
  ? muiTableBodyProps({ table })
@@ -2223,10 +2223,12 @@ const MRT_TableBody = ({ table }) => {
2223
2223
  // ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
2224
2224
  // : 0;
2225
2225
  // }
2226
- return (React.createElement(TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React.createElement(TableRow, null,
2227
- React.createElement(TableCell, { colSpan: table.getVisibleLeafColumns().length },
2228
- React.createElement(Box, { sx: {
2229
- maxWidth: '100vw',
2226
+ return (React.createElement(TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React.createElement("tr", null,
2227
+ React.createElement("td", { colSpan: table.getVisibleLeafColumns().length },
2228
+ React.createElement(Typography, { sx: {
2229
+ color: 'text.secondary',
2230
+ fontStyle: 'italic',
2231
+ maxWidth: `min(100vw, ${(_a = tablePaperRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px)`,
2230
2232
  py: '2rem',
2231
2233
  textAlign: 'center',
2232
2234
  width: '100%',
@@ -2296,11 +2298,11 @@ const MRT_TableFooter = ({ table }) => {
2296
2298
  ? muiTableFooterProps({ table })
2297
2299
  : muiTableFooterProps;
2298
2300
  const stickFooter = (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
2299
- return (React.createElement(TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ position: stickFooter ? 'sticky' : undefined, bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2301
+ return (React.createElement(TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.06), bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2300
2302
  ? theme.palette.mode === 'light'
2301
2303
  ? `1px solid ${theme.palette.grey[300]}`
2302
2304
  : `1px solid ${theme.palette.grey[700]}`
2303
- : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2305
+ : undefined, position: stickFooter ? 'sticky' : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2304
2306
  ? tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx(theme)
2305
2307
  : tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2306
2308
  };
@@ -2354,24 +2356,29 @@ const MRT_TableContainer = ({ table }) => {
2354
2356
  };
2355
2357
 
2356
2358
  const MRT_TablePaper = ({ table }) => {
2357
- const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, } = table;
2359
+ const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, refs: { tablePaperRef }, } = table;
2358
2360
  const { isFullScreen } = getState();
2359
- useEffect(() => {
2360
- if (typeof window !== 'undefined') {
2361
- if (isFullScreen) {
2362
- document.body.style.height = '100vh';
2363
- }
2364
- else {
2365
- document.body.style.height = 'auto';
2366
- }
2367
- }
2368
- }, [isFullScreen]);
2369
2361
  const tablePaperProps = muiTablePaperProps instanceof Function
2370
2362
  ? muiTablePaperProps({ table })
2371
2363
  : muiTablePaperProps;
2372
- return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2364
+ return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { ref: (ref) => {
2365
+ tablePaperRef.current = ref;
2366
+ if (tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.ref) {
2367
+ //@ts-ignore
2368
+ tablePaperProps.ref.current = ref;
2369
+ }
2370
+ }, sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2373
2371
  ? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
2374
- : 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 }) }),
2372
+ : tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx))), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), (isFullScreen
2373
+ ? {
2374
+ height: '100vh',
2375
+ margin: 0,
2376
+ maxHeight: '100vh',
2377
+ maxWidth: '100vw',
2378
+ padding: 0,
2379
+ width: '100vw',
2380
+ }
2381
+ : {})) }),
2375
2382
  enableTopToolbar && React.createElement(MRT_TopToolbar, { table: table }),
2376
2383
  React.createElement(MRT_TableContainer, { table: table }),
2377
2384
  enableBottomToolbar && React.createElement(MRT_BottomToolbar, { table: table })));
@@ -2402,6 +2409,7 @@ const MRT_TableRoot = (props) => {
2402
2409
  const filterInputRefs = useRef({});
2403
2410
  const searchInputRef = useRef(null);
2404
2411
  const tableContainerRef = useRef(null);
2412
+ const tablePaperRef = useRef(null);
2405
2413
  const topToolbarRef = useRef(null);
2406
2414
  const initialState = useMemo(() => {
2407
2415
  var _a, _b;
@@ -2522,11 +2530,28 @@ const MRT_TableRoot = (props) => {
2522
2530
  filterInputRefs,
2523
2531
  searchInputRef,
2524
2532
  tableContainerRef,
2533
+ tablePaperRef,
2525
2534
  topToolbarRef,
2526
2535
  }, 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 });
2527
2536
  if (props.tableInstanceRef) {
2528
2537
  props.tableInstanceRef.current = table;
2529
2538
  }
2539
+ const initialBodyHeight = useRef();
2540
+ useEffect(() => {
2541
+ if (typeof window !== 'undefined') {
2542
+ initialBodyHeight.current = document.body.style.height;
2543
+ }
2544
+ }, []);
2545
+ useEffect(() => {
2546
+ if (typeof window !== 'undefined') {
2547
+ if (table.getState().isFullScreen) {
2548
+ document.body.style.height = '100vh';
2549
+ }
2550
+ else {
2551
+ document.body.style.height = initialBodyHeight.current;
2552
+ }
2553
+ }
2554
+ }, [table.getState().isFullScreen]);
2530
2555
  return (React.createElement(React.Fragment, null,
2531
2556
  React.createElement(Dialog, { PaperComponent: Box, TransitionComponent: Grow, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => table.setIsFullScreen(false), open: table.getState().isFullScreen, transitionDuration: 400 },
2532
2557
  React.createElement(MRT_TablePaper, { table: table })),