material-react-table 1.1.0 → 1.2.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.
@@ -132,6 +132,7 @@ export declare type MRT_TableInstance<TData extends Record<string, any> = {}> =
132
132
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
133
133
  searchInputRef: MutableRefObject<HTMLInputElement>;
134
134
  tableContainerRef: MutableRefObject<HTMLDivElement>;
135
+ tableHeadCellRefs: MutableRefObject<Record<string, HTMLTableCellElement>>;
135
136
  tablePaperRef: MutableRefObject<HTMLDivElement>;
136
137
  topToolbarRef: MutableRefObject<HTMLDivElement>;
137
138
  };
@@ -556,7 +556,7 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
556
556
  var _a;
557
557
  e.stopPropagation();
558
558
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
559
- }, onDragStart: onDragStart, onDragEnd: onDragEnd, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 150ms ease-in-out', '&:hover': {
559
+ }, onDragStart: onDragStart, onDragEnd: onDragEnd, sx: (theme) => (Object.assign({ cursor: 'grab', m: '0 -0.1rem', opacity: 0.5, p: '2px', transition: 'all 150ms ease-in-out', '&:hover': {
560
560
  backgroundColor: 'transparent',
561
561
  opacity: 1,
562
562
  }, '&:active': {
@@ -988,7 +988,7 @@ const MRT_SelectCheckbox = ({ row, selectAll, table }) => {
988
988
 
989
989
  const MRT_GlobalFilterTextField = ({ table, }) => {
990
990
  var _a;
991
- const { getState, setGlobalFilter, options: { enableGlobalFilterModes, icons: { SearchIcon, CloseIcon }, localization, muiSearchTextFieldProps, }, refs: { searchInputRef }, } = table;
991
+ const { getState, setGlobalFilter, options: { enableGlobalFilterModes, icons: { SearchIcon, CloseIcon }, localization, manualFiltering, muiSearchTextFieldProps, }, refs: { searchInputRef }, } = table;
992
992
  const { globalFilter, showGlobalFilter } = getState();
993
993
  const textFieldProps = muiSearchTextFieldProps instanceof Function
994
994
  ? muiSearchTextFieldProps({ table })
@@ -998,7 +998,7 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
998
998
  const handleChangeDebounced = useCallback(debounce((event) => {
999
999
  var _a;
1000
1000
  setGlobalFilter((_a = event.target.value) !== null && _a !== void 0 ? _a : undefined);
1001
- }, 250), []);
1001
+ }, manualFiltering ? 500 : 250), []);
1002
1002
  const handleChange = (event) => {
1003
1003
  setSearchValue(event.target.value);
1004
1004
  handleChangeDebounced(event);
@@ -1356,7 +1356,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
1356
1356
  const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
1357
1357
  return (React.createElement(React.Fragment, null,
1358
1358
  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 },
1359
- React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', mt: '-0.2rem', opacity: 0.5, transition: 'opacity 150ms', width: '2rem', '&:hover': {
1359
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', m: '-0.2rem', opacity: 0.5, transition: 'opacity 150ms', width: '2rem', '&:hover': {
1360
1360
  opacity: 1,
1361
1361
  } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
1362
1362
  ? iconButtonProps.sx(theme)
@@ -1367,7 +1367,7 @@ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
1367
1367
 
1368
1368
  const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1369
1369
  var _a, _b, _c, _d, _e, _f, _g, _h;
1370
- const { options: { enableColumnFilterModes, columnFilterModeOptions, icons: { FilterListIcon, CloseIcon }, localization, muiTableHeadCellFilterTextFieldProps, }, refs: { filterInputRefs }, setColumnFilterFns, } = table;
1370
+ const { options: { enableColumnFilterModes, columnFilterModeOptions, icons: { FilterListIcon, CloseIcon }, localization, manualFiltering, muiTableHeadCellFilterTextFieldProps, }, refs: { filterInputRefs }, setColumnFilterFns, } = table;
1371
1371
  const { column } = header;
1372
1372
  const { columnDef } = column;
1373
1373
  const mTableHeadCellFilterTextFieldProps = muiTableHeadCellFilterTextFieldProps instanceof Function
@@ -1434,7 +1434,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1434
1434
  else {
1435
1435
  column.setFilterValue(value !== null && value !== void 0 ? value : undefined);
1436
1436
  }
1437
- }, isTextboxFilter ? 200 : 1), []);
1437
+ }, isTextboxFilter ? (manualFiltering ? 400 : 200) : 1), []);
1438
1438
  const handleChange = (event) => {
1439
1439
  setFilterValue(event.target.value);
1440
1440
  handleChangeDebounced(event);
@@ -1531,7 +1531,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1531
1531
  ? '100px'
1532
1532
  : !filterChipLabel
1533
1533
  ? '120px'
1534
- : 'auto', width: '100%', '& .MuiSelect-icon': {
1534
+ : 'auto', width: 'calc(100% + 4px)', mx: '-2px', '& .MuiSelect-icon': {
1535
1535
  mr: '1.5rem',
1536
1536
  } }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
1537
1537
  ? textFieldProps.sx(theme)
@@ -1635,7 +1635,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1635
1635
  return (React.createElement(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
1636
1636
  (isRangeFilter && // @ts-ignore
1637
1637
  (!!((_b = column.getFilterValue()) === null || _b === void 0 ? void 0 : _b[0]) || !!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[1]))) },
1638
- React.createElement("span", null,
1638
+ React.createElement(Box, { component: "span", sx: { flex: '0 0' } },
1639
1639
  React.createElement(Tooltip, { arrow: true, placement: "top", title: filterTooltip },
1640
1640
  React.createElement(IconButton, { disableRipple: true, onClick: (event) => {
1641
1641
  event.stopPropagation();
@@ -1690,31 +1690,33 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1690
1690
  const { column } = header;
1691
1691
  const { columnDef } = column;
1692
1692
  const { columnDefType } = columnDef;
1693
- return (React.createElement(Divider, { flexItem: true, orientation: "vertical", onDoubleClick: () => column.resetSize(), sx: (theme) => ({
1694
- borderRadius: '2px',
1695
- borderRightWidth: '2px',
1693
+ return (React.createElement(Box, { onDoubleClick: () => column.resetSize(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), sx: (theme) => ({
1696
1694
  cursor: 'col-resize',
1697
- height: showColumnFilters && columnDefType === 'data' ? '4rem' : '2rem',
1698
1695
  mr: density === 'compact' ? '-0.5rem' : '-1rem',
1699
- opacity: 0.8,
1700
1696
  position: 'absolute',
1701
1697
  right: '1px',
1702
- touchAction: 'none',
1703
- transition: column.getIsResizing()
1704
- ? undefined
1705
- : 'all 150ms ease-in-out',
1706
- userSelect: 'none',
1707
- zIndex: 4,
1708
- '&:active': {
1698
+ px: '4px',
1699
+ '&:active > hr': {
1709
1700
  backgroundColor: theme.palette.info.main,
1710
1701
  opacity: 1,
1711
1702
  },
1712
- }), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), style: {
1703
+ }), style: {
1713
1704
  transform: column.getIsResizing()
1714
1705
  ? `translateX(${((_a = getState().columnSizingInfo.deltaOffset) !== null && _a !== void 0 ? _a : 0) /
1715
1706
  (columnResizeMode === 'onChange' ? 16 : 1)}px)`
1716
- : 'none',
1717
- } }));
1707
+ : undefined,
1708
+ } },
1709
+ React.createElement(Divider, { flexItem: true, orientation: "vertical", sx: {
1710
+ borderRadius: '2px',
1711
+ borderWidth: '2px',
1712
+ height: showColumnFilters && columnDefType === 'data' ? '3.5rem' : '1.5rem',
1713
+ touchAction: 'none',
1714
+ transition: column.getIsResizing()
1715
+ ? undefined
1716
+ : 'all 150ms ease-in-out',
1717
+ userSelect: 'none',
1718
+ zIndex: 4,
1719
+ } })));
1718
1720
  };
1719
1721
 
1720
1722
  const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
@@ -1730,6 +1732,7 @@ const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
1730
1732
  React.createElement(TableSortLabel, { "aria-label": sortTooltip, active: !!column.getIsSorted(), direction: column.getIsSorted()
1731
1733
  ? column.getIsSorted()
1732
1734
  : undefined, sx: {
1735
+ flex: '0 0',
1733
1736
  width: '2ch',
1734
1737
  transform: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) !== 'right'
1735
1738
  ? 'translateX(-0.5ch)'
@@ -1740,7 +1743,7 @@ const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
1740
1743
  const MRT_TableHeadCell = ({ header, table }) => {
1741
1744
  var _a, _b, _c, _d;
1742
1745
  const theme = useTheme();
1743
- const { getState, options: { enableColumnActions, enableColumnDragging, enableColumnOrdering, enableGrouping, enableMultiSort, muiTableHeadCellProps, }, setHoveredColumn, } = table;
1746
+ const { getState, options: { enableColumnActions, enableColumnDragging, enableColumnOrdering, enableGrouping, enableMultiSort, muiTableHeadCellProps, }, refs: { tableHeadCellRefs }, setHoveredColumn, } = table;
1744
1747
  const { density, draggingColumn, grouping, hoveredColumn, showColumnFilters, } = getState();
1745
1748
  const { column } = header;
1746
1749
  const { columnDef } = column;
@@ -1752,6 +1755,25 @@ const MRT_TableHeadCell = ({ header, table }) => {
1752
1755
  ? columnDef.muiTableHeadCellProps({ column, table })
1753
1756
  : columnDef.muiTableHeadCellProps;
1754
1757
  const tableCellProps = Object.assign(Object.assign({}, mTableHeadCellProps), mcTableHeadCellProps);
1758
+ const showColumnActions = (enableColumnActions || columnDef.enableColumnActions) &&
1759
+ columnDef.enableColumnActions !== false;
1760
+ const showDragHandle = enableColumnDragging !== false &&
1761
+ columnDef.enableColumnDragging !== false &&
1762
+ (enableColumnDragging ||
1763
+ (enableColumnOrdering && columnDef.enableColumnOrdering !== false) ||
1764
+ (enableGrouping &&
1765
+ columnDef.enableGrouping !== false &&
1766
+ !grouping.includes(column.id)));
1767
+ const headerPL = useMemo(() => {
1768
+ let pl = 0;
1769
+ if (column.getCanSort())
1770
+ pl++;
1771
+ if (showColumnActions)
1772
+ pl += 1.75;
1773
+ if (showDragHandle)
1774
+ pl += 1.25;
1775
+ return pl;
1776
+ }, [showColumnActions, showDragHandle]);
1755
1777
  const draggingBorder = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1756
1778
  ? `1px dashed ${theme.palette.text.secondary}`
1757
1779
  : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
@@ -1772,15 +1794,18 @@ const MRT_TableHeadCell = ({ header, table }) => {
1772
1794
  setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1773
1795
  }
1774
1796
  };
1775
- const headerElement = ((_b = ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
1797
+ const headerElement = (columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
1776
1798
  ? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
1777
1799
  column,
1778
1800
  header,
1779
1801
  table,
1780
1802
  })
1781
- : columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header)) !== null && _b !== void 0 ? _b : columnDef.header);
1782
- const tableHeadCellRef = React.useRef(null);
1783
- return (React.createElement(TableCell, Object.assign({ align: columnDefType === 'group' ? 'center' : 'left', colSpan: header.colSpan, onDragEnter: handleDragEnter, ref: tableHeadCellRef }, tableCellProps, { sx: (theme) => (Object.assign(Object.assign({ fontWeight: 'bold', overflow: 'visible', p: density === 'compact'
1803
+ : (_b = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) !== null && _b !== void 0 ? _b : columnDef.header;
1804
+ return (React.createElement(TableCell, Object.assign({ align: columnDefType === 'group' ? 'center' : 'left', colSpan: header.colSpan, onDragEnter: handleDragEnter, ref: (node) => {
1805
+ if (node) {
1806
+ tableHeadCellRefs.current[column.id] = node;
1807
+ }
1808
+ } }, tableCellProps, { sx: (theme) => (Object.assign(Object.assign({ fontWeight: 'bold', overflow: 'visible', p: density === 'compact'
1784
1809
  ? '0.5rem'
1785
1810
  : density === 'comfortable'
1786
1811
  ? columnDefType === 'display'
@@ -1807,47 +1832,42 @@ const MRT_TableHeadCell = ({ header, table }) => {
1807
1832
  tableCellProps,
1808
1833
  theme,
1809
1834
  })), draggingBorders)) }),
1810
- header.isPlaceholder ? null : (React.createElement(Box, { sx: {
1835
+ header.isPlaceholder ? null : (React.createElement(Box, { className: "Mui-TableHeadCell-Content", sx: {
1811
1836
  alignItems: 'flex-start',
1812
1837
  display: 'flex',
1813
1838
  flexDirection: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right' ? 'row-reverse' : 'row',
1814
- justifyContent: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right'
1815
- ? 'flex-start'
1816
- : columnDefType === 'group' ||
1817
- (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
1818
- ? 'center'
1819
- : 'space-between',
1839
+ justifyContent: columnDefType === 'group' || (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
1840
+ ? 'center'
1841
+ : column.getCanResize()
1842
+ ? 'space-between'
1843
+ : 'flex-start',
1820
1844
  position: 'relative',
1821
1845
  width: '100%',
1822
1846
  } },
1823
- React.createElement(Box, { onClick: column.getToggleSortingHandler(), sx: {
1847
+ React.createElement(Box, { className: "Mui-TableHeadCell-Content-Labels", onClick: column.getToggleSortingHandler(), sx: {
1824
1848
  alignItems: 'center',
1825
1849
  cursor: column.getCanSort() && columnDefType !== 'group'
1826
1850
  ? 'pointer'
1827
1851
  : undefined,
1828
1852
  display: 'flex',
1829
1853
  flexDirection: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right' ? 'row-reverse' : 'row',
1830
- flexWrap: 'nowrap',
1831
- m: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center' ? 'auto' : undefined,
1832
- pl: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center' && column.getCanSort()
1833
- ? '1rem'
1854
+ overflow: 'hidden',
1855
+ pl: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
1856
+ ? `${headerPL}rem`
1834
1857
  : undefined,
1835
- whiteSpace: ((_d = (_c = columnDef.header) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 24 ? 'nowrap' : 'normal',
1836
1858
  } },
1837
- headerElement,
1859
+ React.createElement(Box, { className: "Mui-TableHeadCell-Content-Wrapper", sx: {
1860
+ overflow: 'hidden',
1861
+ textOverflow: 'ellipsis',
1862
+ whiteSpace: ((_d = (_c = columnDef.header) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 20 ? 'nowrap' : 'normal',
1863
+ }, title: columnDef.header }, headerElement),
1838
1864
  column.getCanSort() && (React.createElement(MRT_TableHeadCellSortLabel, { header: header, table: table, tableCellProps: tableCellProps })),
1839
1865
  column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterLabel, { header: header, table: table }))),
1840
- columnDefType !== 'group' && (React.createElement(Box, { sx: { whiteSpace: 'nowrap' } },
1841
- enableColumnDragging !== false &&
1842
- columnDef.enableColumnDragging !== false &&
1843
- (enableColumnDragging ||
1844
- (enableColumnOrdering &&
1845
- columnDef.enableColumnOrdering !== false) ||
1846
- (enableGrouping &&
1847
- columnDef.enableGrouping !== false &&
1848
- !grouping.includes(column.id))) && (React.createElement(MRT_TableHeadCellGrabHandle, { column: column, table: table, tableHeadCellRef: tableHeadCellRef })),
1849
- (enableColumnActions || columnDef.enableColumnActions) &&
1850
- columnDef.enableColumnActions !== false && (React.createElement(MRT_TableHeadCellColumnActionsButton, { header: header, table: table })))),
1866
+ columnDefType !== 'group' && (React.createElement(Box, { className: "Mui-TableHeadCell-Content-Actions", sx: { whiteSpace: 'nowrap' } },
1867
+ showDragHandle && (React.createElement(MRT_TableHeadCellGrabHandle, { column: column, table: table, tableHeadCellRef: {
1868
+ current: tableHeadCellRefs.current[column.id],
1869
+ } })),
1870
+ showColumnActions && (React.createElement(MRT_TableHeadCellColumnActionsButton, { header: header, table: table })))),
1851
1871
  column.getCanResize() && (React.createElement(MRT_TableHeadCellResizeHandle, { header: header, table: table })))),
1852
1872
  column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterContainer, { header: header, table: table }))));
1853
1873
  };
@@ -2315,7 +2335,7 @@ const MRT_TableFooterCell = ({ footer, table }) => {
2315
2335
  ? '0.5rem'
2316
2336
  : density === 'comfortable'
2317
2337
  ? '1rem'
2318
- : '1.5rem', verticalAlign: 'top' }, getCommonCellStyles({ column, table, theme, tableCellProps }))) }),
2338
+ : '1.5rem', verticalAlign: 'top', zIndex: column.getIsPinned() && columnDefType !== 'group' ? 2 : 1 }, getCommonCellStyles({ column, table, theme, tableCellProps }))) }),
2319
2339
  React.createElement(React.Fragment, null, footer.isPlaceholder
2320
2340
  ? null
2321
2341
  : (_c = (_b = (columnDef.Footer instanceof Function
@@ -2466,6 +2486,7 @@ const MRT_TableRoot = (props) => {
2466
2486
  const filterInputRefs = useRef({});
2467
2487
  const searchInputRef = useRef(null);
2468
2488
  const tableContainerRef = useRef(null);
2489
+ const tableHeadCellRefs = useRef({});
2469
2490
  const tablePaperRef = useRef(null);
2470
2491
  const topToolbarRef = useRef(null);
2471
2492
  const initialState = useMemo(() => {
@@ -2587,6 +2608,7 @@ const MRT_TableRoot = (props) => {
2587
2608
  filterInputRefs,
2588
2609
  searchInputRef,
2589
2610
  tableContainerRef,
2611
+ tableHeadCellRefs,
2590
2612
  tablePaperRef,
2591
2613
  topToolbarRef,
2592
2614
  }, 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 });