material-react-table 0.6.4 → 0.6.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,11 +1,13 @@
1
1
  import React, { useState, useCallback, useMemo, useContext, createContext, Fragment, useEffect } from 'react';
2
2
  import { useTable, useFilters, useGlobalFilter, useGroupBy, useSortBy, useExpanded, usePagination, useRowSelect, useResizeColumns, useFlexLayout, useAsyncDebounce } from 'react-table';
3
- import { Menu, MenuItem, TextField, InputAdornment, Tooltip, IconButton, Chip, FormControlLabel, Switch, Box, Button, Divider, TableCell, TableSortLabel, Collapse, Skeleton, Checkbox, TableRow, TableHead, alpha, TableBody, TableFooter, Table, TablePagination, useMediaQuery, Alert, LinearProgress, Toolbar, TableContainer, Paper } from '@mui/material';
3
+ import { Menu, MenuItem, TextField, InputAdornment, Tooltip, IconButton, Chip, FormControlLabel, Switch, Box, Button, Divider, ListItemIcon, TableCell, TableSortLabel, Collapse, Skeleton, Checkbox, TableRow, TableHead, TableBody, TableFooter, Table, TablePagination, useMediaQuery, Alert, LinearProgress, Toolbar, alpha, TableContainer, Paper } from '@mui/material';
4
4
  import { matchSorter } from 'match-sorter';
5
5
  import ArrowRightIcon from '@mui/icons-material/ArrowRight';
6
6
  import CancelIcon from '@mui/icons-material/Cancel';
7
+ import CheckBoxIcon from '@mui/icons-material/CheckBox';
7
8
  import ClearAllIcon from '@mui/icons-material/ClearAll';
8
9
  import CloseIcon from '@mui/icons-material/Close';
10
+ import ContentCopyIcon from '@mui/icons-material/ContentCopy';
9
11
  import DensityMediumIcon from '@mui/icons-material/DensityMedium';
10
12
  import DensitySmallIcon from '@mui/icons-material/DensitySmall';
11
13
  import DoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
@@ -445,7 +447,9 @@ var MRT_FilterTypeMenu = function MRT_FilterTypeMenu(_ref) {
445
447
  label: localization.filterNotEmpty,
446
448
  divider: false,
447
449
  fn: notEmpty
448
- }];
450
+ }].filter(function (filterType) {
451
+ return !column.filterTypes || column.filterTypes.includes(filterType.type);
452
+ });
449
453
  }, []);
450
454
 
451
455
  var handleSelectFilterType = function handleSelectFilterType(value) {
@@ -683,6 +687,11 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
683
687
 
684
688
  var column = _ref.column,
685
689
  isSubMenu = _ref.isSubMenu;
690
+
691
+ var _useMRT = useMRT(),
692
+ onColumnHide = _useMRT.onColumnHide,
693
+ tableInstance = _useMRT.tableInstance;
694
+
686
695
  var isParentHeader = !!(column != null && (_column$columns = column.columns) != null && _column$columns.length);
687
696
  var allChildColumnsVisible = isParentHeader && !!((_column$columns2 = column.columns) != null && _column$columns2.every(function (childColumn) {
688
697
  return childColumn.isVisible;
@@ -699,6 +708,8 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
699
708
  } else {
700
709
  column.toggleHidden();
701
710
  }
711
+
712
+ onColumnHide == null ? void 0 : onColumnHide(column, tableInstance.state.hiddenColumns);
702
713
  };
703
714
 
704
715
  return React.createElement(React.Fragment, null, React.createElement(MenuItem, {
@@ -781,7 +792,6 @@ var commonMenuItemStyles$1 = {
781
792
  };
782
793
  var commonListItemStyles = {
783
794
  display: 'flex',
784
- gap: '0.75rem',
785
795
  alignItems: 'center'
786
796
  };
787
797
  var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
@@ -890,14 +900,14 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
890
900
  sx: commonMenuItemStyles$1
891
901
  }, React.createElement(Box, {
892
902
  sx: commonListItemStyles
893
- }, React.createElement(ClearAllIcon, null), localization.clearSort)), React.createElement(MenuItem, {
903
+ }, React.createElement(ListItemIcon, null, React.createElement(ClearAllIcon, null)), localization.clearSort)), React.createElement(MenuItem, {
894
904
  disabled: column.isSorted && !column.isSortedDesc,
895
905
  key: 1,
896
906
  onClick: handleSortAsc,
897
907
  sx: commonMenuItemStyles$1
898
908
  }, React.createElement(Box, {
899
909
  sx: commonListItemStyles
900
- }, React.createElement(SortIcon, null), (_localization$sortByC = localization.sortByColumnAsc) == null ? void 0 : _localization$sortByC.replace('{column}', String(column.Header)))), React.createElement(MenuItem, {
910
+ }, React.createElement(ListItemIcon, null, React.createElement(SortIcon, null)), (_localization$sortByC = localization.sortByColumnAsc) == null ? void 0 : _localization$sortByC.replace('{column}', String(column.Header)))), React.createElement(MenuItem, {
901
911
  divider: !disableFilters || enableColumnGrouping || !disableColumnHiding,
902
912
  key: 2,
903
913
  disabled: column.isSorted && column.isSortedDesc,
@@ -905,25 +915,25 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
905
915
  sx: commonMenuItemStyles$1
906
916
  }, React.createElement(Box, {
907
917
  sx: commonListItemStyles
908
- }, React.createElement(SortIcon, {
918
+ }, React.createElement(ListItemIcon, null, React.createElement(SortIcon, {
909
919
  style: {
910
920
  transform: 'rotate(180deg) scaleX(-1)'
911
921
  }
912
- }), (_localization$sortByC2 = localization.sortByColumnDesc) == null ? void 0 : _localization$sortByC2.replace('{column}', String(column.Header))))], !disableFilters && column.canFilter && [React.createElement(MenuItem, {
922
+ })), (_localization$sortByC2 = localization.sortByColumnDesc) == null ? void 0 : _localization$sortByC2.replace('{column}', String(column.Header))))], !disableFilters && column.canFilter && [React.createElement(MenuItem, {
913
923
  disabled: !column.filterValue,
914
924
  key: 0,
915
925
  onClick: handleClearFilter,
916
926
  sx: commonMenuItemStyles$1
917
927
  }, React.createElement(Box, {
918
928
  sx: commonListItemStyles
919
- }, React.createElement(FilterListOffIcon, null), localization.clearFilter)), React.createElement(MenuItem, {
929
+ }, React.createElement(ListItemIcon, null, React.createElement(FilterListOffIcon, null)), localization.clearFilter)), React.createElement(MenuItem, {
920
930
  divider: enableColumnGrouping || !disableColumnHiding,
921
931
  key: 1,
922
932
  onClick: handleFilterByColumn,
923
933
  sx: commonMenuItemStyles$1
924
934
  }, React.createElement(Box, {
925
935
  sx: commonListItemStyles
926
- }, React.createElement(FilterListIcon, null), (_localization$filterB = localization.filterByColumn) == null ? void 0 : _localization$filterB.replace('{column}', String(column.Header))), !column.filterSelectOptions && React.createElement(IconButton, {
936
+ }, React.createElement(ListItemIcon, null, React.createElement(FilterListIcon, null)), (_localization$filterB = localization.filterByColumn) == null ? void 0 : _localization$filterB.replace('{column}', String(column.Header))), !column.filterSelectOptions && React.createElement(IconButton, {
927
937
  onClick: handleOpenFilterModeMenu,
928
938
  onMouseEnter: handleOpenFilterModeMenu,
929
939
  size: "small",
@@ -943,20 +953,20 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
943
953
  sx: commonMenuItemStyles$1
944
954
  }, React.createElement(Box, {
945
955
  sx: commonListItemStyles
946
- }, React.createElement(DynamicFeedIcon, null), (_localization = localization[column.isGrouped ? 'ungroupByColumn' : 'groupByColumn']) == null ? void 0 : _localization.replace('{column}', String(column.Header))))], !disableColumnHiding && [React.createElement(MenuItem, {
956
+ }, React.createElement(ListItemIcon, null, React.createElement(DynamicFeedIcon, null)), (_localization = localization[column.isGrouped ? 'ungroupByColumn' : 'groupByColumn']) == null ? void 0 : _localization.replace('{column}', String(column.Header))))], !disableColumnHiding && [React.createElement(MenuItem, {
947
957
  key: 0,
948
958
  onClick: handleHideColumn,
949
959
  sx: commonMenuItemStyles$1
950
960
  }, React.createElement(Box, {
951
961
  sx: commonListItemStyles
952
- }, React.createElement(VisibilityOffIcon, null), (_localization$hideCol = localization.hideColumn) == null ? void 0 : _localization$hideCol.replace('{column}', String(column.Header)))), React.createElement(MenuItem, {
962
+ }, React.createElement(ListItemIcon, null, React.createElement(VisibilityOffIcon, null)), (_localization$hideCol = localization.hideColumn) == null ? void 0 : _localization$hideCol.replace('{column}', String(column.Header)))), React.createElement(MenuItem, {
953
963
  disabled: !((_tableInstance$state$ = tableInstance.state.hiddenColumns) != null && _tableInstance$state$.length),
954
964
  key: 1,
955
965
  onClick: handleShowAllColumns,
956
966
  sx: commonMenuItemStyles$1
957
967
  }, React.createElement(Box, {
958
968
  sx: commonListItemStyles
959
- }, React.createElement(ViewColumnIcon, null), (_localization$showAll = localization.showAllColumns) == null ? void 0 : _localization$showAll.replace('{column}', String(column.Header))), !column.filterSelectOptions && React.createElement(IconButton, {
969
+ }, React.createElement(ListItemIcon, null, React.createElement(ViewColumnIcon, null)), (_localization$showAll = localization.showAllColumns) == null ? void 0 : _localization$showAll.replace('{column}', String(column.Header))), !column.filterSelectOptions && React.createElement(IconButton, {
960
970
  onClick: handleOpenShowHideColumnsMenu,
961
971
  onMouseEnter: handleOpenShowHideColumnsMenu,
962
972
  size: "small",
@@ -1016,15 +1026,15 @@ var MRT_ToggleColumnActionMenuButton = function MRT_ToggleColumnActionMenuButton
1016
1026
  }));
1017
1027
  };
1018
1028
 
1019
- var commonTableHeadCellStyles = function commonTableHeadCellStyles(densePadding, enableColumnResizing) {
1020
- return {
1029
+ var commonTableHeadCellStyles = function commonTableHeadCellStyles(densePadding, enableColumnResizing, widths) {
1030
+ return _extends({
1021
1031
  fontWeight: 'bold',
1022
1032
  height: '100%',
1023
1033
  p: densePadding ? '0.5rem' : '1rem',
1024
1034
  pt: densePadding ? '0.75rem' : '1.25rem',
1025
1035
  transition: "all " + (enableColumnResizing ? '10ms' : '0.2s') + " ease-in-out",
1026
1036
  verticalAlign: 'text-top'
1027
- };
1037
+ }, widths);
1028
1038
  };
1029
1039
  var MRT_TableHeadCell = function MRT_TableHeadCell(_ref) {
1030
1040
  var _column$columns, _localization$sortByC, _localization$sortByC2;
@@ -1059,7 +1069,11 @@ var MRT_TableHeadCell = function MRT_TableHeadCell(_ref) {
1059
1069
  return React.createElement(TableCell, Object.assign({
1060
1070
  align: isParentHeader ? 'center' : 'left'
1061
1071
  }, tableCellProps, {
1062
- sx: _extends({}, commonTableHeadCellStyles(tableInstance.state.densePadding, enableColumnResizing), tableCellProps == null ? void 0 : tableCellProps.sx)
1072
+ sx: _extends({}, commonTableHeadCellStyles(tableInstance.state.densePadding, enableColumnResizing, {
1073
+ maxWidth: column.maxWidth,
1074
+ minWidth: column.minWidth,
1075
+ width: column.width
1076
+ }), tableCellProps == null ? void 0 : tableCellProps.sx)
1063
1077
  }), React.createElement(Box, {
1064
1078
  sx: {
1065
1079
  alignItems: 'flex-start',
@@ -1161,7 +1175,7 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
1161
1175
  style: _extends({}, muiTableBodyCellEditTextFieldProps == null ? void 0 : muiTableBodyCellEditTextFieldProps.style, (_cell$column$muiTable = cell.column.muiTableBodyCellEditTextFieldProps) == null ? void 0 : _cell$column$muiTable.style)
1162
1176
  });
1163
1177
 
1164
- if (cell.column.editable && cell.column.Edit) {
1178
+ if (!cell.column.disableEditing && cell.column.Edit) {
1165
1179
  return React.createElement(React.Fragment, null, cell.column.Edit(_extends({}, textFieldProps, {
1166
1180
  cell: cell
1167
1181
  })));
@@ -1179,6 +1193,51 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
1179
1193
  }, textFieldProps));
1180
1194
  };
1181
1195
 
1196
+ var MRT_CopyButton = function MRT_CopyButton(_ref) {
1197
+ var cell = _ref.cell;
1198
+
1199
+ var _useMRT = useMRT(),
1200
+ localization = _useMRT.localization;
1201
+
1202
+ var _useState = useState(false),
1203
+ copied = _useState[0],
1204
+ setCopied = _useState[1];
1205
+
1206
+ var handleCopy = function handleCopy(text) {
1207
+ navigator.clipboard.writeText(text);
1208
+ setCopied(true);
1209
+ setTimeout(function () {
1210
+ return setCopied(false);
1211
+ }, 4000);
1212
+ };
1213
+
1214
+ return React.createElement(Tooltip, {
1215
+ arrow: true,
1216
+ enterDelay: 1000,
1217
+ enterNextDelay: 1000,
1218
+ placement: "top",
1219
+ title: copied ? localization.copiedToClipboard : localization.clickToCopy
1220
+ }, React.createElement(Button, {
1221
+ "aria-label": localization.clickToCopy,
1222
+ onClick: function onClick() {
1223
+ return handleCopy(cell.value);
1224
+ },
1225
+ size: "small",
1226
+ sx: {
1227
+ backgroundColor: 'transparent',
1228
+ color: 'inherit',
1229
+ letterSpacing: 'inherit',
1230
+ fontFamily: 'inherit',
1231
+ fontSize: 'inherit',
1232
+ m: '-0.25rem',
1233
+ textTransform: 'inherit',
1234
+ textAlign: 'inherit',
1235
+ minWidth: 'unset'
1236
+ },
1237
+ variant: "text"
1238
+ }, cell.render('Cell')));
1239
+ };
1240
+
1182
1241
  var commonTableBodyCellStyles = function commonTableBodyCellStyles(densePadding) {
1183
1242
  return {
1184
1243
  p: densePadding ? '0.5rem' : '1rem',
@@ -1197,6 +1256,7 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
1197
1256
  var cell = _ref.cell;
1198
1257
 
1199
1258
  var _useMRT = useMRT(),
1259
+ enableClickToCopy = _useMRT.enableClickToCopy,
1200
1260
  isLoading = _useMRT.isLoading,
1201
1261
  muiTableBodyCellProps = _useMRT.muiTableBodyCellProps,
1202
1262
  muiTableBodyCellSkeletonProps = _useMRT.muiTableBodyCellSkeletonProps,
@@ -1222,9 +1282,11 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
1222
1282
  animation: "wave",
1223
1283
  height: 20,
1224
1284
  width: Math.random() * (120 - 60) + 60
1225
- }, muiTableBodyCellSkeletonProps)) : (currentEditingRow == null ? void 0 : currentEditingRow.id) === cell.row.id ? React.createElement(MRT_EditCellTextField, {
1285
+ }, muiTableBodyCellSkeletonProps)) : !cell.column.disableEditing && (currentEditingRow == null ? void 0 : currentEditingRow.id) === cell.row.id ? React.createElement(MRT_EditCellTextField, {
1286
+ cell: cell
1287
+ }) : cell.isPlaceholder ? null : cell.isAggregated ? cell.render('Aggregated') : cell.isGrouped ? React.createElement("span", null, cell.render('Cell'), " (", cell.row.subRows.length, ")") : enableClickToCopy && !cell.column.disableClickToCopy ? React.createElement(MRT_CopyButton, {
1226
1288
  cell: cell
1227
- }) : cell.isPlaceholder ? null : cell.isAggregated ? cell.render('Aggregated') : cell.isGrouped ? React.createElement("span", null, cell.render('Cell'), " (", cell.row.subRows.length, ")") : cell.render('Cell'));
1289
+ }) : cell.render('Cell'));
1228
1290
  };
1229
1291
 
1230
1292
  var MRT_SelectCheckbox = function MRT_SelectCheckbox(_ref) {
@@ -1320,7 +1382,9 @@ var MRT_TableHeadCellActions = function MRT_TableHeadCellActions() {
1320
1382
  textAlign: 'center'
1321
1383
  },
1322
1384
  sx: _extends({}, commonTableHeadCellStyles(densePadding), {
1323
- textAlign: 'center'
1385
+ textAlign: 'center',
1386
+ maxWidth: '4rem',
1387
+ width: '4rem'
1324
1388
  })
1325
1389
  }, localization.actions);
1326
1390
  };
@@ -1418,9 +1482,18 @@ var MRT_ExpandButton = function MRT_ExpandButton(_ref) {
1418
1482
  var _useMRT = useMRT(),
1419
1483
  ExpandMoreIcon = _useMRT.icons.ExpandMoreIcon,
1420
1484
  localization = _useMRT.localization,
1485
+ onRowExpandChange = _useMRT.onRowExpandChange,
1421
1486
  renderDetailPanel = _useMRT.renderDetailPanel,
1422
1487
  densePadding = _useMRT.tableInstance.state.densePadding;
1423
1488
 
1489
+ var handleToggleExpand = function handleToggleExpand(event) {
1490
+ var _row$getToggleRowExpa;
1491
+
1492
+ // @ts-ignore
1493
+ (_row$getToggleRowExpa = row.getToggleRowExpandedProps()) == null ? void 0 : _row$getToggleRowExpa.onClick(event);
1494
+ onRowExpandChange == null ? void 0 : onRowExpandChange(event, row);
1495
+ };
1496
+
1424
1497
  return React.createElement(TableCell, {
1425
1498
  size: "small",
1426
1499
  sx: _extends({}, commonTableBodyButtonCellStyles(densePadding), {
@@ -1431,7 +1504,9 @@ var MRT_ExpandButton = function MRT_ExpandButton(_ref) {
1431
1504
  "aria-label": localization.expand,
1432
1505
  disabled: !row.canExpand && !renderDetailPanel,
1433
1506
  title: localization.expand
1434
- }, row.getToggleRowExpandedProps()), React.createElement(ExpandMoreIcon, {
1507
+ }, row.getToggleRowExpandedProps(), {
1508
+ onClick: handleToggleExpand
1509
+ }), React.createElement(ExpandMoreIcon, {
1435
1510
  style: {
1436
1511
  transform: "rotate(" + (!row.canExpand && !renderDetailPanel ? -90 : row.isExpanded ? -180 : 0) + "deg)",
1437
1512
  transition: 'transform 0.2s'
@@ -1466,7 +1541,9 @@ var MRT_RowActionMenu = function MRT_RowActionMenu(_ref) {
1466
1541
  }, enableRowEditing && React.createElement(MenuItem, {
1467
1542
  onClick: handleEdit,
1468
1543
  sx: commonMenuItemStyles$1
1469
- }, React.createElement(EditIcon, null), localization.edit), (_renderRowActionMenuI = renderRowActionMenuItems == null ? void 0 : renderRowActionMenuItems(row, tableInstance, function () {
1544
+ }, React.createElement(Box, {
1545
+ sx: commonListItemStyles
1546
+ }, React.createElement(ListItemIcon, null, React.createElement(EditIcon, null)), localization.edit)), (_renderRowActionMenuI = renderRowActionMenuItems == null ? void 0 : renderRowActionMenuItems(row, tableInstance, function () {
1470
1547
  return setAnchorEl(null);
1471
1548
  })) != null ? _renderRowActionMenuI : null);
1472
1549
  };
@@ -2389,14 +2466,9 @@ var MRT_TableBodyRow = function MRT_TableBodyRow(_ref) {
2389
2466
  hover: true,
2390
2467
  onClick: function onClick(event) {
2391
2468
  return onRowClick == null ? void 0 : onRowClick(event, row);
2392
- }
2393
- }, tableRowProps, {
2394
- sx: function sx(theme) {
2395
- return _extends({
2396
- backgroundColor: row.isSelected ? alpha(theme.palette.primary.light, 0.1) : 'transparent'
2397
- }, tableRowProps == null ? void 0 : tableRowProps.sx);
2398
- }
2399
- }), enableRowNumbers && React.createElement(TableCell, {
2469
+ },
2470
+ selected: row.isSelected
2471
+ }, tableRowProps), enableRowNumbers && React.createElement(TableCell, {
2400
2472
  sx: _extends({}, commonTableBodyCellStyles(densePadding))
2401
2473
  }, row.index + 1), (enableRowActions || enableRowEditing) && positionActionsColumn === 'first' && React.createElement(MRT_ToggleRowActionMenuButton, {
2402
2474
  row: row
@@ -2998,7 +3070,9 @@ var MRT_DefaultLocalization_EN = {
2998
3070
  clearFilter: 'Clear filter',
2999
3071
  clearSearch: 'Clear search',
3000
3072
  clearSort: 'Clear sort',
3073
+ clickToCopy: 'Click to copy',
3001
3074
  columnActions: 'Column Actions',
3075
+ copiedToClipboard: 'Copied to clipboard',
3002
3076
  edit: 'Edit',
3003
3077
  expand: 'Expand',
3004
3078
  expandAll: 'Expand all',
@@ -3041,8 +3115,10 @@ var MRT_DefaultLocalization_EN = {
3041
3115
  var MRT_Default_Icons = {
3042
3116
  ArrowRightIcon: ArrowRightIcon,
3043
3117
  CancelIcon: CancelIcon,
3118
+ CheckBoxIcon: CheckBoxIcon,
3044
3119
  ClearAllIcon: ClearAllIcon,
3045
3120
  CloseIcon: CloseIcon,
3121
+ ContentCopyIcon: ContentCopyIcon,
3046
3122
  DensityMediumIcon: DensityMediumIcon,
3047
3123
  DensitySmallIcon: DensitySmallIcon,
3048
3124
  DoubleArrowDownIcon: DoubleArrowDownIcon,