material-react-table 0.38.0 → 0.38.3

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.
@@ -48,8 +48,8 @@ export declare type MRT_TableInstance<TData extends Record<string, any> = {}> =
48
48
  setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
49
49
  setDraggingColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
50
50
  setDraggingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
51
- setEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
52
- setEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
51
+ setEditingCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
52
+ setEditingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
53
53
  setGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
54
54
  setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | {
55
55
  id: string;
@@ -288,6 +288,7 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
288
288
  enableRowSelection?: boolean | ((row: MRT_Row<TData>) => boolean);
289
289
  enableRowVirtualization?: boolean;
290
290
  enableSelectAll?: boolean;
291
+ enableStickyFooter?: boolean;
291
292
  enableStickyHeader?: boolean;
292
293
  enableTableFooter?: boolean;
293
294
  enableTableHead?: boolean;
@@ -255,7 +255,9 @@ const MRT_ExpandAllButton = ({ table }) => {
255
255
  : muiExpandAllButtonProps;
256
256
  return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.expandAll },
257
257
  React.createElement("span", null,
258
- React.createElement(IconButton, Object.assign({ "aria-label": localization.expandAll, disabled: !getCanSomeRowsExpand() && !renderDetailPanel, onClick: () => toggleAllRowsExpanded(!getIsAllRowsExpanded()) }, iconButtonProps, { sx: Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', width: density === 'compact' ? '1.75rem' : '2.25rem', mt: density !== 'compact' ? '-0.25rem' : undefined }, iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) }),
258
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.expandAll, disabled: !getCanSomeRowsExpand() && !renderDetailPanel, onClick: () => toggleAllRowsExpanded(!getIsAllRowsExpanded()) }, iconButtonProps, { sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', width: density === 'compact' ? '1.75rem' : '2.25rem', mt: density !== 'compact' ? '-0.25rem' : undefined }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
259
+ ? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
260
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))) }),
259
261
  React.createElement(KeyboardDoubleArrowDownIcon, { style: {
260
262
  transform: `rotate(${getIsAllRowsExpanded()
261
263
  ? -180
@@ -445,12 +447,14 @@ const MRT_ColumnPinningButtons = ({ column, table, }) => {
445
447
  const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table, }) => {
446
448
  const { options: { icons: { DragHandleIcon }, localization, }, } = table;
447
449
  return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: localization.move },
448
- React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { sx: Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
450
+ React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
449
451
  backgroundColor: 'transparent',
450
452
  opacity: 1,
451
453
  }, '&:active': {
452
454
  cursor: 'grabbing',
453
- } }, iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) }),
455
+ } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
456
+ ? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
457
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))) }),
454
458
  React.createElement(DragHandleIcon, null))));
455
459
  };
456
460
 
@@ -1444,7 +1448,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1444
1448
  if (textFieldProps.inputRef) {
1445
1449
  textFieldProps.inputRef = inputRef;
1446
1450
  }
1447
- }, sx: (theme) => (Object.assign({ p: 0, minWidth: !filterChipLabel ? '6rem' : 'auto', width: '100%', '& .MuiSelect-icon': {
1451
+ }, sx: (theme) => (Object.assign({ p: 0, minWidth: !filterChipLabel ? '150px' : 'auto', width: '100%', '& .MuiSelect-icon': {
1448
1452
  mr: '1.5rem',
1449
1453
  } }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
1450
1454
  ? textFieldProps.sx(theme)
@@ -1743,7 +1747,9 @@ const MRT_TableHeadRow = ({ headerGroup, table }) => {
1743
1747
  const tableRowProps = muiTableHeadRowProps instanceof Function
1744
1748
  ? muiTableHeadRowProps({ headerGroup, table })
1745
1749
  : muiTableHeadRowProps;
1746
- return (React.createElement(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`, backgroundColor: lighten(theme.palette.background.default, 0.04) }, tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)) }), headerGroup.headers.map((header, index) => (React.createElement(MRT_TableHeadCell, { header: header, key: header.id || index, table: table })))));
1750
+ return (React.createElement(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`, backgroundColor: lighten(theme.palette.background.default, 0.04) }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
1751
+ ? tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx(theme)
1752
+ : tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }), headerGroup.headers.map((header, index) => (React.createElement(MRT_TableHeadCell, { header: header, key: header.id || index, table: table })))));
1747
1753
  };
1748
1754
 
1749
1755
  const MRT_TableHead = ({ table }) => {
@@ -1773,30 +1779,43 @@ const MRT_EditCellTextField = ({ cell, showLabel, table, }) => {
1773
1779
  })
1774
1780
  : columnDef.muiTableBodyCellEditTextFieldProps;
1775
1781
  const textFieldProps = Object.assign(Object.assign({}, mTableBodyCellEditTextFieldProps), mcTableBodyCellEditTextFieldProps);
1782
+ const saveRow = (newValue) => {
1783
+ if (editingRow) {
1784
+ setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: newValue }) }));
1785
+ }
1786
+ };
1776
1787
  const handleChange = (event) => {
1777
1788
  var _a;
1778
1789
  (_a = textFieldProps.onChange) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1779
1790
  setValue(event.target.value);
1791
+ if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.select) {
1792
+ saveRow(event.target.value);
1793
+ }
1780
1794
  };
1781
1795
  const handleBlur = (event) => {
1782
1796
  var _a;
1783
1797
  (_a = textFieldProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1784
- if (editingRow) {
1785
- setEditingRow(Object.assign(Object.assign({}, editingRow), { _valuesCache: Object.assign(Object.assign({}, editingRow._valuesCache), { [column.id]: value }) }));
1786
- }
1798
+ saveRow(value);
1787
1799
  setEditingCell(null);
1788
1800
  };
1801
+ const handleEnterKeyDown = (event) => {
1802
+ var _a, _b;
1803
+ (_a = textFieldProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
1804
+ if (event.key === 'Enter') {
1805
+ (_b = editInputRefs.current[column.id]) === null || _b === void 0 ? void 0 : _b.blur();
1806
+ }
1807
+ };
1789
1808
  if (columnDef.Edit) {
1790
1809
  return React.createElement(React.Fragment, null, (_a = columnDef.Edit) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table }));
1791
1810
  }
1792
- return (React.createElement(TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, label: showLabel ? column.columnDef.header : undefined, margin: "none", name: cell.id, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { inputRef: (inputRef) => {
1811
+ return (React.createElement(TextField, Object.assign({ disabled: columnDef.enableEditing === false, fullWidth: true, inputRef: (inputRef) => {
1793
1812
  if (inputRef) {
1794
1813
  editInputRefs.current[column.id] = inputRef;
1795
1814
  if (textFieldProps.inputRef) {
1796
1815
  textFieldProps.inputRef = inputRef;
1797
1816
  }
1798
1817
  }
1799
- }, onBlur: handleBlur, onChange: handleChange })));
1818
+ }, label: showLabel ? column.columnDef.header : undefined, margin: "none", name: column.id, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps, { onBlur: handleBlur, onChange: handleChange, onKeyDown: handleEnterKeyDown })));
1800
1819
  };
1801
1820
 
1802
1821
  const MRT_CopyButton = ({ cell, children, table, }) => {
@@ -2181,11 +2200,19 @@ const MRT_TableFooterRow = ({ footerGroup, table }) => {
2181
2200
  };
2182
2201
 
2183
2202
  const MRT_TableFooter = ({ table }) => {
2184
- const { getFooterGroups, options: { muiTableFooterProps }, } = table;
2203
+ const { getFooterGroups, getState, options: { enableStickyFooter, muiTableFooterProps }, } = table;
2204
+ const { isFullScreen } = getState();
2185
2205
  const tableFooterProps = muiTableFooterProps instanceof Function
2186
2206
  ? muiTableFooterProps({ table })
2187
2207
  : muiTableFooterProps;
2188
- return (React.createElement(TableFooter, Object.assign({}, tableFooterProps), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2208
+ const stickFooter = (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
2209
+ 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
2210
+ ? theme.palette.mode === 'light'
2211
+ ? `1px solid ${theme.palette.grey[300]}`
2212
+ : `1px solid ${theme.palette.grey[700]}`
2213
+ : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2214
+ ? tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx(theme)
2215
+ : tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2189
2216
  };
2190
2217
 
2191
2218
  const MRT_Table = ({ tableContainerRef, table }) => {
@@ -2252,7 +2279,9 @@ const MRT_TablePaper = ({ table }) => {
2252
2279
  const tablePaperProps = muiTablePaperProps instanceof Function
2253
2280
  ? muiTablePaperProps({ table })
2254
2281
  : muiTablePaperProps;
2255
- return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { sx: Object.assign({ transition: 'all 0.2s ease-in-out' }, 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 }) }),
2282
+ 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
2283
+ ? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
2284
+ : 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 }) }),
2256
2285
  enableTopToolbar && React.createElement(MRT_TopToolbar, { table: table }),
2257
2286
  React.createElement(MRT_TableContainer, { table: table }),
2258
2287
  enableBottomToolbar && React.createElement(MRT_BottomToolbar, { table: table })));