material-react-table 1.1.1 → 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);
@@ -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);
@@ -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();
@@ -1709,10 +1709,7 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1709
1709
  React.createElement(Divider, { flexItem: true, orientation: "vertical", sx: {
1710
1710
  borderRadius: '2px',
1711
1711
  borderWidth: '2px',
1712
- height: showColumnFilters && columnDefType === 'data'
1713
- ? '3.5rem'
1714
- : '1.75rem',
1715
- opacity: 0.8,
1712
+ height: showColumnFilters && columnDefType === 'data' ? '3.5rem' : '1.5rem',
1716
1713
  touchAction: 'none',
1717
1714
  transition: column.getIsResizing()
1718
1715
  ? undefined
@@ -1735,6 +1732,7 @@ const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
1735
1732
  React.createElement(TableSortLabel, { "aria-label": sortTooltip, active: !!column.getIsSorted(), direction: column.getIsSorted()
1736
1733
  ? column.getIsSorted()
1737
1734
  : undefined, sx: {
1735
+ flex: '0 0',
1738
1736
  width: '2ch',
1739
1737
  transform: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) !== 'right'
1740
1738
  ? 'translateX(-0.5ch)'
@@ -1745,7 +1743,7 @@ const MRT_TableHeadCellSortLabel = ({ header, table, tableCellProps, }) => {
1745
1743
  const MRT_TableHeadCell = ({ header, table }) => {
1746
1744
  var _a, _b, _c, _d;
1747
1745
  const theme = useTheme();
1748
- 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;
1749
1747
  const { density, draggingColumn, grouping, hoveredColumn, showColumnFilters, } = getState();
1750
1748
  const { column } = header;
1751
1749
  const { columnDef } = column;
@@ -1757,6 +1755,25 @@ const MRT_TableHeadCell = ({ header, table }) => {
1757
1755
  ? columnDef.muiTableHeadCellProps({ column, table })
1758
1756
  : columnDef.muiTableHeadCellProps;
1759
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]);
1760
1777
  const draggingBorder = useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1761
1778
  ? `1px dashed ${theme.palette.text.secondary}`
1762
1779
  : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
@@ -1777,15 +1794,18 @@ const MRT_TableHeadCell = ({ header, table }) => {
1777
1794
  setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1778
1795
  }
1779
1796
  };
1780
- 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
1781
1798
  ? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
1782
1799
  column,
1783
1800
  header,
1784
1801
  table,
1785
1802
  })
1786
- : columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header)) !== null && _b !== void 0 ? _b : columnDef.header);
1787
- const tableHeadCellRef = React.useRef(null);
1788
- 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'
1789
1809
  ? '0.5rem'
1790
1810
  : density === 'comfortable'
1791
1811
  ? columnDefType === 'display'
@@ -1812,47 +1832,42 @@ const MRT_TableHeadCell = ({ header, table }) => {
1812
1832
  tableCellProps,
1813
1833
  theme,
1814
1834
  })), draggingBorders)) }),
1815
- header.isPlaceholder ? null : (React.createElement(Box, { sx: {
1835
+ header.isPlaceholder ? null : (React.createElement(Box, { className: "Mui-TableHeadCell-Content", sx: {
1816
1836
  alignItems: 'flex-start',
1817
1837
  display: 'flex',
1818
1838
  flexDirection: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right' ? 'row-reverse' : 'row',
1819
- justifyContent: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right'
1820
- ? 'flex-start'
1821
- : columnDefType === 'group' ||
1822
- (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
1823
- ? 'center'
1824
- : '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',
1825
1844
  position: 'relative',
1826
1845
  width: '100%',
1827
1846
  } },
1828
- React.createElement(Box, { onClick: column.getToggleSortingHandler(), sx: {
1847
+ React.createElement(Box, { className: "Mui-TableHeadCell-Content-Labels", onClick: column.getToggleSortingHandler(), sx: {
1829
1848
  alignItems: 'center',
1830
1849
  cursor: column.getCanSort() && columnDefType !== 'group'
1831
1850
  ? 'pointer'
1832
1851
  : undefined,
1833
1852
  display: 'flex',
1834
1853
  flexDirection: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right' ? 'row-reverse' : 'row',
1835
- flexWrap: 'nowrap',
1836
- m: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center' ? 'auto' : undefined,
1837
- pl: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center' && column.getCanSort()
1838
- ? '1rem'
1854
+ overflow: 'hidden',
1855
+ pl: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
1856
+ ? `${headerPL}rem`
1839
1857
  : undefined,
1840
- whiteSpace: ((_d = (_c = columnDef.header) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 24 ? 'nowrap' : 'normal',
1841
1858
  } },
1842
- 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),
1843
1864
  column.getCanSort() && (React.createElement(MRT_TableHeadCellSortLabel, { header: header, table: table, tableCellProps: tableCellProps })),
1844
1865
  column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterLabel, { header: header, table: table }))),
1845
- columnDefType !== 'group' && (React.createElement(Box, { sx: { whiteSpace: 'nowrap' } },
1846
- enableColumnDragging !== false &&
1847
- columnDef.enableColumnDragging !== false &&
1848
- (enableColumnDragging ||
1849
- (enableColumnOrdering &&
1850
- columnDef.enableColumnOrdering !== false) ||
1851
- (enableGrouping &&
1852
- columnDef.enableGrouping !== false &&
1853
- !grouping.includes(column.id))) && (React.createElement(MRT_TableHeadCellGrabHandle, { column: column, table: table, tableHeadCellRef: tableHeadCellRef })),
1854
- (enableColumnActions || columnDef.enableColumnActions) &&
1855
- 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 })))),
1856
1871
  column.getCanResize() && (React.createElement(MRT_TableHeadCellResizeHandle, { header: header, table: table })))),
1857
1872
  column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterContainer, { header: header, table: table }))));
1858
1873
  };
@@ -2471,6 +2486,7 @@ const MRT_TableRoot = (props) => {
2471
2486
  const filterInputRefs = useRef({});
2472
2487
  const searchInputRef = useRef(null);
2473
2488
  const tableContainerRef = useRef(null);
2489
+ const tableHeadCellRefs = useRef({});
2474
2490
  const tablePaperRef = useRef(null);
2475
2491
  const topToolbarRef = useRef(null);
2476
2492
  const initialState = useMemo(() => {
@@ -2592,6 +2608,7 @@ const MRT_TableRoot = (props) => {
2592
2608
  filterInputRefs,
2593
2609
  searchInputRef,
2594
2610
  tableContainerRef,
2611
+ tableHeadCellRefs,
2595
2612
  tablePaperRef,
2596
2613
  topToolbarRef,
2597
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 });