material-react-table 0.12.2 → 0.13.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.
@@ -1,5 +1,5 @@
1
1
  import React, { useMemo, forwardRef, useState, useCallback, Fragment, useLayoutEffect, useEffect } from 'react';
2
- import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityMedium, DensitySmall, KeyboardDoubleArrowDown, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
2
+ import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityLarge, DensityMedium, DensitySmall, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, KeyboardDoubleArrowDown, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
3
3
  import { createTable, getCoreRowModel, getExpandedRowModel, getFacetedRowModel, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, useTableInstance } from '@tanstack/react-table';
4
4
  import { Tooltip, IconButton, Menu, MenuItem, Box, FormControlLabel, Switch, Button, Divider, ListItemIcon, Checkbox, debounce, Collapse, TextField, InputAdornment, TablePagination, Chip, Alert, LinearProgress, useMediaQuery, Toolbar, lighten, alpha, TableSortLabel, TableCell, TableRow, TableHead, darken, Skeleton, TableBody, TableFooter, Table, TableContainer, Paper, Dialog, Grow } from '@mui/material';
5
5
  import { rankItem, rankings } from '@tanstack/match-sorter-utils';
@@ -101,7 +101,7 @@ var MRT_DefaultLocalization_EN = {
101
101
  sortedByColumnDesc: 'Sorted by {column} descending',
102
102
  thenBy: ', then by ',
103
103
  to: 'to',
104
- toggleDensePadding: 'Toggle dense padding',
104
+ toggleDensity: 'Toggle density',
105
105
  toggleFullScreen: 'Toggle full screen',
106
106
  toggleSelectAll: 'Toggle select all',
107
107
  toggleSelectRow: 'Toggle select row',
@@ -117,9 +117,9 @@ var MRT_Default_Icons = {
117
117
  CheckBoxIcon: CheckBox,
118
118
  ClearAllIcon: ClearAll,
119
119
  CloseIcon: Close,
120
+ DensityLargeIcon: DensityLarge,
120
121
  DensityMediumIcon: DensityMedium,
121
122
  DensitySmallIcon: DensitySmall,
122
- KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
123
123
  DragHandleIcon: DragHandle,
124
124
  DynamicFeedIcon: DynamicFeed,
125
125
  EditIcon: Edit,
@@ -131,6 +131,7 @@ var MRT_Default_Icons = {
131
131
  FilterListOffIcon: FilterListOff,
132
132
  FullscreenExitIcon: FullscreenExit,
133
133
  FullscreenIcon: Fullscreen,
134
+ KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
134
135
  MoreHorizIcon: MoreHoriz,
135
136
  MoreVertIcon: MoreVert,
136
137
  PushPinIcon: PushPin,
@@ -156,7 +157,7 @@ var MRT_ExpandAllButton = function MRT_ExpandAllButton(_ref) {
156
157
  toggleAllRowsExpanded = instance.toggleAllRowsExpanded;
157
158
 
158
159
  var _getState = getState(),
159
- isDensePadding = _getState.isDensePadding;
160
+ density = _getState.density;
160
161
 
161
162
  return React.createElement(Tooltip, {
162
163
  arrow: true,
@@ -170,8 +171,8 @@ var MRT_ExpandAllButton = function MRT_ExpandAllButton(_ref) {
170
171
  return toggleAllRowsExpanded(!getIsAllRowsExpanded());
171
172
  },
172
173
  sx: {
173
- height: isDensePadding ? '1.75rem' : '2.25rem',
174
- width: isDensePadding ? '1.75rem' : '2.25rem'
174
+ height: density === 'compact' ? '1.75rem' : '2.25rem',
175
+ width: density === 'compact' ? '1.75rem' : '2.25rem'
175
176
  }
176
177
  }, React.createElement(KeyboardDoubleArrowDownIcon, {
177
178
  style: {
@@ -192,7 +193,7 @@ var MRT_ExpandButton = function MRT_ExpandButton(_ref) {
192
193
  renderDetailPanel = _instance$options.renderDetailPanel;
193
194
 
194
195
  var _getState = getState(),
195
- isDensePadding = _getState.isDensePadding;
196
+ density = _getState.density;
196
197
 
197
198
  var handleToggleExpand = function handleToggleExpand(event) {
198
199
  row.toggleExpanded();
@@ -213,8 +214,8 @@ var MRT_ExpandButton = function MRT_ExpandButton(_ref) {
213
214
  disabled: !row.getCanExpand() && !renderDetailPanel,
214
215
  onClick: handleToggleExpand,
215
216
  sx: {
216
- height: isDensePadding ? '1.75rem' : '2.25rem',
217
- width: isDensePadding ? '1.75rem' : '2.25rem'
217
+ height: density === 'compact' ? '1.75rem' : '2.25rem',
218
+ width: density === 'compact' ? '1.75rem' : '2.25rem'
218
219
  }
219
220
  }, React.createElement(ExpandMoreIcon, {
220
221
  style: {
@@ -352,7 +353,7 @@ var MRT_FilterOptionMenu = function MRT_FilterOptionMenu(_ref) {
352
353
  setCurrentGlobalFilterFn = instance.setCurrentGlobalFilterFn;
353
354
 
354
355
  var _getState = getState(),
355
- isDensePadding = _getState.isDensePadding,
356
+ density = _getState.density,
356
357
  currentFilterFns = _getState.currentFilterFns,
357
358
  currentGlobalFilterFn = _getState.currentGlobalFilterFn;
358
359
 
@@ -459,7 +460,7 @@ var MRT_FilterOptionMenu = function MRT_FilterOptionMenu(_ref) {
459
460
  },
460
461
  open: !!anchorEl,
461
462
  MenuListProps: {
462
- dense: isDensePadding
463
+ dense: density === 'compact'
463
464
  }
464
465
  }, filterOptions.map(function (_ref4, index) {
465
466
  var option = _ref4.option,
@@ -755,7 +756,7 @@ var MRT_ShowHideColumnsMenu = function MRT_ShowHideColumnsMenu(_ref) {
755
756
  enableColumnOrdering = _instance$options.enableColumnOrdering;
756
757
 
757
758
  var _getState = getState(),
758
- isDensePadding = _getState.isDensePadding,
759
+ density = _getState.density,
759
760
  columnOrder = _getState.columnOrder,
760
761
  columnPinning = _getState.columnPinning;
761
762
 
@@ -789,7 +790,7 @@ var MRT_ShowHideColumnsMenu = function MRT_ShowHideColumnsMenu(_ref) {
789
790
  return setAnchorEl(null);
790
791
  },
791
792
  MenuListProps: {
792
- dense: isDensePadding
793
+ dense: density === 'compact'
793
794
  }
794
795
  }, React.createElement(Box, {
795
796
  sx: {
@@ -873,7 +874,7 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
873
874
  var _getState = getState(),
874
875
  columnSizing = _getState.columnSizing,
875
876
  columnVisibility = _getState.columnVisibility,
876
- isDensePadding = _getState.isDensePadding;
877
+ density = _getState.density;
877
878
 
878
879
  var _useState = useState(null),
879
880
  filterMenuAnchorEl = _useState[0],
@@ -959,7 +960,7 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
959
960
  return setAnchorEl(null);
960
961
  },
961
962
  MenuListProps: {
962
- dense: isDensePadding
963
+ dense: density === 'compact'
963
964
  }
964
965
  }, enableSorting && column.getCanSort() && [React.createElement(MenuItem, {
965
966
  disabled: !column.getIsSorted(),
@@ -1111,7 +1112,7 @@ var MRT_RowActionMenu = function MRT_RowActionMenu(_ref) {
1111
1112
  renderRowActionMenuItems = _instance$options.renderRowActionMenuItems;
1112
1113
 
1113
1114
  var _getState = getState(),
1114
- isDensePadding = _getState.isDensePadding;
1115
+ density = _getState.density;
1115
1116
 
1116
1117
  return React.createElement(Menu, {
1117
1118
  anchorEl: anchorEl,
@@ -1120,7 +1121,7 @@ var MRT_RowActionMenu = function MRT_RowActionMenu(_ref) {
1120
1121
  return setAnchorEl(null);
1121
1122
  },
1122
1123
  MenuListProps: {
1123
- dense: isDensePadding
1124
+ dense: density === 'compact'
1124
1125
  }
1125
1126
  }, enableEditing && React.createElement(MenuItem, {
1126
1127
  onClick: handleEdit,
@@ -1276,7 +1277,7 @@ var MRT_SelectCheckbox = function MRT_SelectCheckbox(_ref) {
1276
1277
  selectAllMode = _instance$options.selectAllMode;
1277
1278
 
1278
1279
  var _getState = getState(),
1279
- isDensePadding = _getState.isDensePadding;
1280
+ density = _getState.density;
1280
1281
 
1281
1282
  var handleSelectChange = function handleSelectChange(event) {
1282
1283
  if (selectAll) {
@@ -1321,11 +1322,11 @@ var MRT_SelectCheckbox = function MRT_SelectCheckbox(_ref) {
1321
1322
  'aria-label': selectAll ? localization.toggleSelectAll : localization.toggleSelectRow
1322
1323
  },
1323
1324
  onChange: handleSelectChange,
1324
- size: isDensePadding ? 'small' : 'medium'
1325
+ size: density === 'compact' ? 'small' : 'medium'
1325
1326
  }, checkboxProps, {
1326
1327
  sx: _extends({
1327
- height: isDensePadding ? '1.75rem' : '2.25rem',
1328
- width: isDensePadding ? '1.75rem' : '2.25rem'
1328
+ height: density === 'compact' ? '1.75rem' : '2.25rem',
1329
+ width: density === 'compact' ? '1.75rem' : '2.25rem'
1329
1330
  }, checkboxProps == null ? void 0 : checkboxProps.sx)
1330
1331
  })));
1331
1332
  };
@@ -1403,31 +1404,33 @@ var MRT_ToggleDensePaddingButton = function MRT_ToggleDensePaddingButton(_ref) {
1403
1404
  var getState = instance.getState,
1404
1405
  _instance$options = instance.options,
1405
1406
  _instance$options$ico = _instance$options.icons,
1407
+ DensityLargeIcon = _instance$options$ico.DensityLargeIcon,
1406
1408
  DensityMediumIcon = _instance$options$ico.DensityMediumIcon,
1407
1409
  DensitySmallIcon = _instance$options$ico.DensitySmallIcon,
1408
1410
  localization = _instance$options.localization,
1409
- onIsDensePaddingChanged = _instance$options.onIsDensePaddingChanged,
1410
- setIsDensePadding = instance.setIsDensePadding;
1411
+ onDensityChanged = _instance$options.onDensityChanged,
1412
+ setDensity = instance.setDensity;
1411
1413
 
1412
1414
  var _getState = getState(),
1413
- isDensePadding = _getState.isDensePadding;
1415
+ density = _getState.density;
1414
1416
 
1415
1417
  var handleToggleDensePadding = function handleToggleDensePadding(event) {
1416
- onIsDensePaddingChanged == null ? void 0 : onIsDensePaddingChanged({
1418
+ var nextDensity = density === 'comfortable' ? 'compact' : density === 'compact' ? 'spacious' : 'comfortable';
1419
+ onDensityChanged == null ? void 0 : onDensityChanged({
1417
1420
  event: event,
1418
- isDensePadding: !isDensePadding,
1421
+ density: nextDensity,
1419
1422
  instance: instance
1420
1423
  });
1421
- setIsDensePadding(!isDensePadding);
1424
+ setDensity(nextDensity);
1422
1425
  };
1423
1426
 
1424
1427
  return React.createElement(Tooltip, {
1425
1428
  arrow: true,
1426
- title: localization.toggleDensePadding
1429
+ title: localization.toggleDensity
1427
1430
  }, React.createElement(IconButton, Object.assign({
1428
- "aria-label": localization.toggleDensePadding,
1431
+ "aria-label": localization.toggleDensity,
1429
1432
  onClick: handleToggleDensePadding
1430
- }, rest), isDensePadding ? React.createElement(DensitySmallIcon, null) : React.createElement(DensityMediumIcon, null)));
1433
+ }, rest), density === 'compact' ? React.createElement(DensitySmallIcon, null) : density === 'comfortable' ? React.createElement(DensityMediumIcon, null) : React.createElement(DensityLargeIcon, null)));
1431
1434
  };
1432
1435
 
1433
1436
  var _excluded$3 = ["instance"];
@@ -2402,7 +2405,7 @@ var MRT_TableHeadCell = function MRT_TableHeadCell(_ref) {
2402
2405
  muiTableHeadCellProps = _instance$options.muiTableHeadCellProps;
2403
2406
 
2404
2407
  var _getState = getState(),
2405
- isDensePadding = _getState.isDensePadding;
2408
+ density = _getState.density;
2406
2409
 
2407
2410
  var column = header.column;
2408
2411
  var columnDef = column.columnDef,
@@ -2451,10 +2454,10 @@ var MRT_TableHeadCell = function MRT_TableHeadCell(_ref) {
2451
2454
  height: '100%',
2452
2455
  left: column.getIsPinned() === 'left' ? column.getStart('left') + "px" : undefined,
2453
2456
  overflow: 'visible',
2454
- p: isDensePadding ? columnDefType === 'display' ? '0 0.5rem' : '0.5rem' : columnDefType === 'display' ? '0.5rem 0.75rem' : '1rem',
2457
+ p: density === 'compact' ? columnDefType === 'display' ? '0 0.5rem' : '0.5rem' : density === 'comfortable' ? columnDefType === 'display' ? '0.5rem 0.75rem' : '1rem' : columnDefType === 'display' ? '1rem 1.25rem' : '1.5rem',
2455
2458
  pb: columnDefType === 'display' ? 0 : undefined,
2456
2459
  position: column.getIsPinned() && columnDefType !== 'group' ? 'sticky' : undefined,
2457
- pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.75rem',
2460
+ pt: columnDefType !== 'data' ? 0 : density === 'compact' ? '0.25' : density === 'comfortable' ? '.75rem' : '1.25rem',
2458
2461
  right: column.getIsPinned() === 'right' ? getTotalRight() + "px" : undefined,
2459
2462
  transition: "all " + (enableColumnResizing ? 0 : '0.2s') + " ease-in-out",
2460
2463
  verticalAlign: 'text-top',
@@ -2781,7 +2784,7 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2781
2784
  columnOrder = _getState.columnOrder,
2782
2785
  currentEditingCell = _getState.currentEditingCell,
2783
2786
  currentEditingRow = _getState.currentEditingRow,
2784
- isDensePadding = _getState.isDensePadding,
2787
+ density = _getState.density,
2785
2788
  isLoading = _getState.isLoading,
2786
2789
  showSkeletons = _getState.showSkeletons;
2787
2790
 
@@ -2861,13 +2864,13 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2861
2864
  cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
2862
2865
  left: column.getIsPinned() === 'left' ? column.getStart('left') + "px" : undefined,
2863
2866
  overflow: 'hidden',
2864
- p: isDensePadding ? columnDefType === 'display' ? '0 0.5rem' : '0.5rem' : columnDefType === 'display' ? '0.5rem 0.75rem' : '1rem',
2865
- pl: column.id === 'mrt-expand' ? row.depth + (isDensePadding ? 0.5 : 0.75) + "rem" : undefined,
2867
+ p: density === 'compact' ? columnDefType === 'display' ? '0 0.5rem' : '0.5rem' : density === 'comfortable' ? columnDefType === 'display' ? '0.5rem 0.75rem' : '1rem' : columnDefType === 'display' ? '1rem 1.25rem' : '1.5rem',
2868
+ pl: column.id === 'mrt-expand' ? row.depth + (density === 'compact' ? 0.5 : density === 'comfortable' ? 0.75 : 1.25) + "rem" : undefined,
2866
2869
  position: column.getIsPinned() ? 'sticky' : 'relative',
2867
2870
  right: column.getIsPinned() === 'right' ? getTotalRight() + "px" : undefined,
2868
2871
  textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
2869
2872
  transition: 'all 0.2s ease-in-out',
2870
- whiteSpace: isDensePadding ? 'nowrap' : 'normal',
2873
+ whiteSpace: density === 'compact' ? 'nowrap' : 'normal',
2871
2874
  zIndex: column.getIsPinned() ? 1 : undefined,
2872
2875
  '&:hover': {
2873
2876
  backgroundColor: enableHover && enableEditing && editingMode !== 'row' ? theme.palette.mode === 'dark' ? lighten(theme.palette.background["default"], 0.13) + " !important" : darken(theme.palette.background["default"], 0.07) + " !important" : undefined
@@ -3005,14 +3008,14 @@ var MRT_TableBody = function MRT_TableBody(_ref) {
3005
3008
  virtualizerProps = _instance$options.virtualizerProps;
3006
3009
 
3007
3010
  var _getState = getState(),
3008
- isDensePadding = _getState.isDensePadding;
3011
+ density = _getState.density;
3009
3012
 
3010
3013
  var tableBodyProps = muiTableBodyProps instanceof Function ? muiTableBodyProps({
3011
3014
  instance: instance
3012
3015
  }) : muiTableBodyProps;
3013
3016
  var rows = enablePagination ? getPaginationRowModel().rows : getPrePaginationRowModel().rows;
3014
3017
  var rowVirtualizer = enableRowVirtualization ? useVirtual(_extends({
3015
- overscan: isDensePadding ? 15 : 5,
3018
+ overscan: density === 'compact' ? 15 : 5,
3016
3019
  size: rows.length,
3017
3020
  parentRef: tableContainerRef
3018
3021
  }, virtualizerProps)) : {};
@@ -3049,7 +3052,7 @@ var MRT_TableFooterCell = function MRT_TableFooterCell(_ref) {
3049
3052
  enableColumnResizing = _instance$options.enableColumnResizing;
3050
3053
 
3051
3054
  var _getState = getState(),
3052
- isDensePadding = _getState.isDensePadding;
3055
+ density = _getState.density;
3053
3056
 
3054
3057
  var column = footer.column;
3055
3058
  var columnDef = column.columnDef,
@@ -3077,7 +3080,7 @@ var MRT_TableFooterCell = function MRT_TableFooterCell(_ref) {
3077
3080
  fontWeight: 'bold',
3078
3081
  maxWidth: column.getSize() + "px",
3079
3082
  minWidth: column.getSize() + "px",
3080
- p: isDensePadding ? '0.5rem' : '1rem',
3083
+ p: density === 'compact' ? '0.5rem' : density === 'comfortable' ? '1rem' : '1.5rem',
3081
3084
  transition: "all " + (enableColumnResizing ? '10ms' : '0.2s') + " ease-in-out",
3082
3085
  width: column.getSize(),
3083
3086
  verticalAlign: 'text-top'
@@ -3254,7 +3257,7 @@ var MRT_TablePaper = function MRT_TablePaper(_ref) {
3254
3257
  };
3255
3258
 
3256
3259
  var MRT_TableRoot = function MRT_TableRoot(props) {
3257
- var _initialState$current, _initialState$current2, _initialState$isDense, _initialState$isFullS, _initialState$showFil, _initialState$showGlo, _props$globalFilterFn, _props$state3, _props$state4, _props$onCurrentEditi, _props$onCurrentEditi2, _props$onCurrentFilte, _props$onCurrentGloba, _props$onIsDensePaddi, _props$onIsFullScreen, _props$onShowFiltersC, _props$onShowGlobalFi;
3260
+ var _initialState$current, _initialState$current2, _initialState$density, _initialState$isFullS, _initialState$showFil, _initialState$showGlo, _props$globalFilterFn, _props$state3, _props$state4, _props$onCurrentEditi, _props$onCurrentEditi2, _props$onCurrentFilte, _props$onCurrentGloba, _props$onDensityChang, _props$onIsFullScreen, _props$onShowFiltersC, _props$onShowGlobalFi;
3258
3261
 
3259
3262
  var _useState = useState(props.tableId),
3260
3263
  tableId = _useState[0],
@@ -3308,9 +3311,9 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
3308
3311
  currentEditingRow = _useState3[0],
3309
3312
  setCurrentEditingRow = _useState3[1];
3310
3313
 
3311
- var _useState4 = useState((_initialState$isDense = initialState == null ? void 0 : initialState.isDensePadding) != null ? _initialState$isDense : false),
3312
- isDensePadding = _useState4[0],
3313
- setIsDensePadding = _useState4[1];
3314
+ var _useState4 = useState((_initialState$density = initialState == null ? void 0 : initialState.density) != null ? _initialState$density : 'comfortable'),
3315
+ density = _useState4[0],
3316
+ setDensity = _useState4[1];
3314
3317
 
3315
3318
  var _useState5 = useState((_initialState$isFullS = initialState == null ? void 0 : initialState.isFullScreen) != null ? _initialState$isFullS : false),
3316
3319
  isFullScreen = _useState5[0],
@@ -3469,7 +3472,7 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
3469
3472
  currentEditingRow: currentEditingRow,
3470
3473
  currentFilterFns: currentFilterFns,
3471
3474
  currentGlobalFilterFn: currentGlobalFilterFn,
3472
- isDensePadding: isDensePadding,
3475
+ density: density,
3473
3476
  isFullScreen: isFullScreen,
3474
3477
  showFilters: showFilters,
3475
3478
  showGlobalFilter: showGlobalFilter
@@ -3479,7 +3482,7 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
3479
3482
  setCurrentEditingRow: (_props$onCurrentEditi2 = props.onCurrentEditingRowChange) != null ? _props$onCurrentEditi2 : setCurrentEditingRow,
3480
3483
  setCurrentFilterFns: (_props$onCurrentFilte = props.onCurrentFilterFnsChange) != null ? _props$onCurrentFilte : setCurrentFilterFns,
3481
3484
  setCurrentGlobalFilterFn: (_props$onCurrentGloba = props.onCurrentGlobalFilterFnChange) != null ? _props$onCurrentGloba : setCurrentGlobalFilterFn,
3482
- setIsDensePadding: (_props$onIsDensePaddi = props.onIsDensePaddingChange) != null ? _props$onIsDensePaddi : setIsDensePadding,
3485
+ setDensity: (_props$onDensityChang = props.onDensityChange) != null ? _props$onDensityChang : setDensity,
3483
3486
  setIsFullScreen: (_props$onIsFullScreen = props.onIsFullScreenChange) != null ? _props$onIsFullScreen : setIsFullScreen,
3484
3487
  setShowFilters: (_props$onShowFiltersC = props.onShowFiltersChange) != null ? _props$onShowFiltersC : setShowFilters,
3485
3488
  setShowGlobalFilter: (_props$onShowGlobalFi = props.onShowGlobalFilterChange) != null ? _props$onShowGlobalFi : setShowGlobalFilter