material-react-table 1.0.0-beta.4 → 1.0.0-beta.7

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>;
package/dist/cjs/index.js CHANGED
@@ -208,6 +208,8 @@ const MRT_DefaultLocalization_EN = {
208
208
  max: 'Max',
209
209
  min: 'Min',
210
210
  move: 'Move',
211
+ noRecordsToDisplay: 'No records to display',
212
+ noResultsFound: 'No results found',
211
213
  or: 'or',
212
214
  pinToLeft: 'Pin to left',
213
215
  pinToRight: 'Pin to right',
@@ -477,11 +479,11 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
477
479
  var _a;
478
480
  const { options: { icons: { DragHandleIcon }, localization, }, } = table;
479
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 },
480
- React__default["default"].createElement(material.IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { onClick: (e) => {
482
+ React__default["default"].createElement(material.IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
481
483
  var _a;
482
484
  e.stopPropagation();
483
485
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
484
- }, 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': {
485
487
  backgroundColor: 'transparent',
486
488
  opacity: 1,
487
489
  }, '&:active': {
@@ -1310,7 +1312,11 @@ const MRT_TopToolbar = ({ table }) => {
1310
1312
  width: '100%',
1311
1313
  } },
1312
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),
1313
- enableToolbarInternalActions ? (React__default["default"].createElement(material.Box, { sx: { display: 'flex', flexWrap: 'wrap' } },
1315
+ enableToolbarInternalActions ? (React__default["default"].createElement(material.Box, { sx: {
1316
+ display: 'flex',
1317
+ flexWrap: 'wrap-reverse',
1318
+ justifyContent: 'flex-end',
1319
+ } },
1314
1320
  enableGlobalFilter && positionGlobalFilter === 'right' && (React__default["default"].createElement(MRT_GlobalFilterTextField, { table: table })),
1315
1321
  React__default["default"].createElement(MRT_ToolbarInternalButtons, { table: table }))) : (enableGlobalFilter &&
1316
1322
  positionGlobalFilter === 'right' && (React__default["default"].createElement(MRT_GlobalFilterTextField, { table: table })))),
@@ -1602,11 +1608,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1602
1608
  const { options: { icons: { FilterAltIcon }, localization, }, } = table;
1603
1609
  const { column } = header;
1604
1610
  const { columnDef } = column;
1605
- const isRangeFilter = [
1606
- 'between',
1607
- 'betweenInclusive',
1608
- 'inNumberRange',
1609
- ].includes(columnDef._filterFn);
1611
+ const isRangeFilter = columnDef.filterVariant === 'range' ||
1612
+ ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
1610
1613
  const currentFilterOption = columnDef._filterFn;
1611
1614
  const filterTooltip = localization.filteringByColumn
1612
1615
  .replace('{column}', String(columnDef.header))
@@ -1618,8 +1621,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1618
1621
  ? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1619
1622
  : column.getFilterValue()}"`)
1620
1623
  .replace('" "', '');
1621
- return (React__default["default"].createElement(material.Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && isRangeFilter) ||
1622
- (!isRangeFilter && // @ts-ignore
1624
+ return (React__default["default"].createElement(material.Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
1625
+ (isRangeFilter && // @ts-ignore
1623
1626
  (!!((_b = column.getFilterValue()) === null || _b === void 0 ? void 0 : _b[0]) || !!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[1]))) },
1624
1627
  React__default["default"].createElement("span", null,
1625
1628
  React__default["default"].createElement(material.Tooltip, { arrow: true, placement: "top", title: filterTooltip },
@@ -1636,7 +1639,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1636
1639
  };
1637
1640
 
1638
1641
  const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1639
- const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1642
+ const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1640
1643
  const { columnDef } = column;
1641
1644
  const { hoveredColumn, draggingColumn, columnOrder } = getState();
1642
1645
  const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
@@ -1646,16 +1649,15 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1646
1649
  ? columnDef.muiTableHeadCellDragHandleProps({ column, table })
1647
1650
  : columnDef.muiTableHeadCellDragHandleProps;
1648
1651
  const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
1649
- const handleDragStart = (e) => {
1652
+ const handleDragStart = (event) => {
1653
+ var _a;
1654
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1650
1655
  setDraggingColumn(column);
1651
- e.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1656
+ event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1652
1657
  };
1653
1658
  const handleDragEnd = (event) => {
1654
- onColumnDrop === null || onColumnDrop === void 0 ? void 0 : onColumnDrop({
1655
- event,
1656
- draggedColumn: column,
1657
- targetColumn: hoveredColumn,
1658
- });
1659
+ var _a;
1660
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1659
1661
  if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1660
1662
  column.toggleGrouping();
1661
1663
  }
@@ -1944,21 +1946,20 @@ const MRT_CopyButton = ({ cell, children, table, }) => {
1944
1946
  };
1945
1947
 
1946
1948
  const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1947
- const { options: { muiTableBodyRowDragHandleProps, onRowDrop }, } = table;
1949
+ const { options: { muiTableBodyRowDragHandleProps }, } = table;
1948
1950
  const { row } = cell;
1949
1951
  const iconButtonProps = muiTableBodyRowDragHandleProps instanceof Function
1950
1952
  ? muiTableBodyRowDragHandleProps({ row, table })
1951
1953
  : muiTableBodyRowDragHandleProps;
1952
- const handleDragStart = (e) => {
1953
- e.dataTransfer.setDragImage(rowRef.current, 0, 0);
1954
+ const handleDragStart = (event) => {
1955
+ var _a;
1956
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1957
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1954
1958
  table.setDraggingRow(row);
1955
1959
  };
1956
1960
  const handleDragEnd = (event) => {
1957
- onRowDrop === null || onRowDrop === void 0 ? void 0 : onRowDrop({
1958
- event,
1959
- draggedRow: table.getState().draggingRow,
1960
- targetRow: table.getState().hoveredRow,
1961
- });
1961
+ var _a;
1962
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1962
1963
  table.setDraggingRow(null);
1963
1964
  table.setHoveredRow(null);
1964
1965
  };
@@ -2163,8 +2164,9 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2163
2164
  };
2164
2165
 
2165
2166
  const MRT_TableBody = ({ table }) => {
2166
- const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef }, } = table;
2167
- const { globalFilter, pagination, sorting } = getState();
2167
+ var _a;
2168
+ const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
2169
+ const { columnFilters, globalFilter, pagination, sorting } = getState();
2168
2170
  const tableBodyProps = muiTableBodyProps instanceof Function
2169
2171
  ? muiTableBodyProps({ table })
2170
2172
  : muiTableBodyProps;
@@ -2229,7 +2231,18 @@ const MRT_TableBody = ({ table }) => {
2229
2231
  // ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
2230
2232
  // : 0;
2231
2233
  // }
2232
- return (React__default["default"].createElement(material.TableBody, Object.assign({}, tableBodyProps),
2234
+ return (React__default["default"].createElement(material.TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React__default["default"].createElement("tr", null,
2235
+ React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length },
2236
+ React__default["default"].createElement(material.Typography, { sx: {
2237
+ color: 'text.secondary',
2238
+ fontStyle: 'italic',
2239
+ maxWidth: `min(100vw, ${(_a = tablePaperRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px)`,
2240
+ py: '2rem',
2241
+ textAlign: 'center',
2242
+ width: '100%',
2243
+ } }, globalFilter || columnFilters.length
2244
+ ? localization.noResultsFound
2245
+ : localization.noRecordsToDisplay)))) : (React__default["default"].createElement(React__default["default"].Fragment, null,
2233
2246
  enableRowVirtualization && paddingTop > 0 && (React__default["default"].createElement("tr", null,
2234
2247
  React__default["default"].createElement("td", { style: { height: `${paddingTop}px` } }))),
2235
2248
  (enableRowVirtualization ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
@@ -2239,7 +2252,7 @@ const MRT_TableBody = ({ table }) => {
2239
2252
  return (React__default["default"].createElement(MRT_TableBodyRow, { key: row.id, row: row, rowIndex: enableRowVirtualization ? rowOrVirtualRow.index : rowIndex, table: table, virtualRow: enableRowVirtualization ? rowOrVirtualRow : null }));
2240
2253
  }),
2241
2254
  enableRowVirtualization && paddingBottom > 0 && (React__default["default"].createElement("tr", null,
2242
- React__default["default"].createElement("td", { style: { height: `${paddingBottom}px` } })))));
2255
+ React__default["default"].createElement("td", { style: { height: `${paddingBottom}px` } })))))));
2243
2256
  };
2244
2257
 
2245
2258
  const MRT_TableFooterCell = ({ footer, table }) => {
@@ -2293,11 +2306,11 @@ const MRT_TableFooter = ({ table }) => {
2293
2306
  ? muiTableFooterProps({ table })
2294
2307
  : muiTableFooterProps;
2295
2308
  const stickFooter = (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
2296
- return (React__default["default"].createElement(material.TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ position: stickFooter ? 'sticky' : undefined, bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2309
+ return (React__default["default"].createElement(material.TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ backgroundColor: material.lighten(theme.palette.background.default, 0.06), bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2297
2310
  ? theme.palette.mode === 'light'
2298
2311
  ? `1px solid ${theme.palette.grey[300]}`
2299
2312
  : `1px solid ${theme.palette.grey[700]}`
2300
- : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2313
+ : undefined, position: stickFooter ? 'sticky' : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2301
2314
  ? tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx(theme)
2302
2315
  : tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React__default["default"].createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2303
2316
  };
@@ -2351,7 +2364,7 @@ const MRT_TableContainer = ({ table }) => {
2351
2364
  };
2352
2365
 
2353
2366
  const MRT_TablePaper = ({ table }) => {
2354
- const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, } = table;
2367
+ const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, refs: { tablePaperRef }, } = table;
2355
2368
  const { isFullScreen } = getState();
2356
2369
  React.useEffect(() => {
2357
2370
  if (typeof window !== 'undefined') {
@@ -2366,7 +2379,13 @@ const MRT_TablePaper = ({ table }) => {
2366
2379
  const tablePaperProps = muiTablePaperProps instanceof Function
2367
2380
  ? muiTablePaperProps({ table })
2368
2381
  : muiTablePaperProps;
2369
- return (React__default["default"].createElement(material.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
2382
+ return (React__default["default"].createElement(material.Paper, Object.assign({ elevation: 2 }, tablePaperProps, { ref: (ref) => {
2383
+ tablePaperRef.current = ref;
2384
+ if (tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.ref) {
2385
+ //@ts-ignore
2386
+ tablePaperProps.ref.current = ref;
2387
+ }
2388
+ }, sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2370
2389
  ? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
2371
2390
  : 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
2391
  enableTopToolbar && React__default["default"].createElement(MRT_TopToolbar, { table: table }),
@@ -2399,6 +2418,7 @@ const MRT_TableRoot = (props) => {
2399
2418
  const filterInputRefs = React.useRef({});
2400
2419
  const searchInputRef = React.useRef(null);
2401
2420
  const tableContainerRef = React.useRef(null);
2421
+ const tablePaperRef = React.useRef(null);
2402
2422
  const topToolbarRef = React.useRef(null);
2403
2423
  const initialState = React.useMemo(() => {
2404
2424
  var _a, _b;
@@ -2519,6 +2539,7 @@ const MRT_TableRoot = (props) => {
2519
2539
  filterInputRefs,
2520
2540
  searchInputRef,
2521
2541
  tableContainerRef,
2542
+ tablePaperRef,
2522
2543
  topToolbarRef,
2523
2544
  }, 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 });
2524
2545
  if (props.tableInstanceRef) {