material-react-table 0.6.4 → 0.6.5

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.
@@ -31,8 +31,8 @@ export declare type MRT_ColumnInterface<D extends {} = {}> = ColumnInterface<D>
31
31
  Header?: string;
32
32
  accessor?: string;
33
33
  columns?: MRT_ColumnInterface<D>[];
34
+ disableEditing?: boolean;
34
35
  disableFilters?: boolean;
35
- editable?: boolean;
36
36
  filter?: MRT_FilterType | string | FilterType<D>;
37
37
  filterSelectOptions?: (string | {
38
38
  text: string;
@@ -119,7 +119,7 @@ export declare type MaterialReactTableProps<D extends {} = {}> = UseTableOptions
119
119
  muiTableToolbarBottomProps?: ToolbarProps | ((tableInstance: MRT_TableInstance<D>) => ToolbarProps);
120
120
  muiTableToolbarTopProps?: ToolbarProps | ((tableInstance: MRT_TableInstance<D>) => ToolbarProps);
121
121
  onCellClick?: (event: MouseEvent<HTMLTableCellElement>, cell: MRT_Cell<D>) => void;
122
- onColumnHide?: (column: Column<D>, visibleColumns: Column<D>[]) => void;
122
+ onColumnHide?: (column: Column<D>, hiddenColumns?: string[]) => void;
123
123
  onDetailPanelClick?: (event: MouseEvent<HTMLTableCellElement>, row: Row<D>) => void;
124
124
  onGlobalFilterChange?: (event: ChangeEvent<HTMLInputElement>) => void;
125
125
  onRowClick?: (event: MouseEvent<HTMLTableRowElement>, row: Row<D>) => void;
@@ -690,6 +690,11 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
690
690
 
691
691
  var column = _ref.column,
692
692
  isSubMenu = _ref.isSubMenu;
693
+
694
+ var _useMRT = useMRT(),
695
+ onColumnHide = _useMRT.onColumnHide,
696
+ tableInstance = _useMRT.tableInstance;
697
+
693
698
  var isParentHeader = !!(column != null && (_column$columns = column.columns) != null && _column$columns.length);
694
699
  var allChildColumnsVisible = isParentHeader && !!((_column$columns2 = column.columns) != null && _column$columns2.every(function (childColumn) {
695
700
  return childColumn.isVisible;
@@ -706,6 +711,8 @@ var MRT_ShowHideColumnsMenuItems = function MRT_ShowHideColumnsMenuItems(_ref) {
706
711
  } else {
707
712
  column.toggleHidden();
708
713
  }
714
+
715
+ onColumnHide == null ? void 0 : onColumnHide(column, tableInstance.state.hiddenColumns);
709
716
  };
710
717
 
711
718
  return React__default.createElement(React__default.Fragment, null, React__default.createElement(material.MenuItem, {
@@ -788,7 +795,6 @@ var commonMenuItemStyles$1 = {
788
795
  };
789
796
  var commonListItemStyles = {
790
797
  display: 'flex',
791
- gap: '0.75rem',
792
798
  alignItems: 'center'
793
799
  };
794
800
  var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
@@ -897,14 +903,14 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
897
903
  sx: commonMenuItemStyles$1
898
904
  }, React__default.createElement(material.Box, {
899
905
  sx: commonListItemStyles
900
- }, React__default.createElement(ClearAllIcon, null), localization.clearSort)), React__default.createElement(material.MenuItem, {
906
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(ClearAllIcon, null)), localization.clearSort)), React__default.createElement(material.MenuItem, {
901
907
  disabled: column.isSorted && !column.isSortedDesc,
902
908
  key: 1,
903
909
  onClick: handleSortAsc,
904
910
  sx: commonMenuItemStyles$1
905
911
  }, React__default.createElement(material.Box, {
906
912
  sx: commonListItemStyles
907
- }, React__default.createElement(SortIcon, null), (_localization$sortByC = localization.sortByColumnAsc) == null ? void 0 : _localization$sortByC.replace('{column}', String(column.Header)))), React__default.createElement(material.MenuItem, {
913
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(SortIcon, null)), (_localization$sortByC = localization.sortByColumnAsc) == null ? void 0 : _localization$sortByC.replace('{column}', String(column.Header)))), React__default.createElement(material.MenuItem, {
908
914
  divider: !disableFilters || enableColumnGrouping || !disableColumnHiding,
909
915
  key: 2,
910
916
  disabled: column.isSorted && column.isSortedDesc,
@@ -912,25 +918,25 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
912
918
  sx: commonMenuItemStyles$1
913
919
  }, React__default.createElement(material.Box, {
914
920
  sx: commonListItemStyles
915
- }, React__default.createElement(SortIcon, {
921
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(SortIcon, {
916
922
  style: {
917
923
  transform: 'rotate(180deg) scaleX(-1)'
918
924
  }
919
- }), (_localization$sortByC2 = localization.sortByColumnDesc) == null ? void 0 : _localization$sortByC2.replace('{column}', String(column.Header))))], !disableFilters && column.canFilter && [React__default.createElement(material.MenuItem, {
925
+ })), (_localization$sortByC2 = localization.sortByColumnDesc) == null ? void 0 : _localization$sortByC2.replace('{column}', String(column.Header))))], !disableFilters && column.canFilter && [React__default.createElement(material.MenuItem, {
920
926
  disabled: !column.filterValue,
921
927
  key: 0,
922
928
  onClick: handleClearFilter,
923
929
  sx: commonMenuItemStyles$1
924
930
  }, React__default.createElement(material.Box, {
925
931
  sx: commonListItemStyles
926
- }, React__default.createElement(FilterListOffIcon, null), localization.clearFilter)), React__default.createElement(material.MenuItem, {
932
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(FilterListOffIcon, null)), localization.clearFilter)), React__default.createElement(material.MenuItem, {
927
933
  divider: enableColumnGrouping || !disableColumnHiding,
928
934
  key: 1,
929
935
  onClick: handleFilterByColumn,
930
936
  sx: commonMenuItemStyles$1
931
937
  }, React__default.createElement(material.Box, {
932
938
  sx: commonListItemStyles
933
- }, React__default.createElement(FilterListIcon, null), (_localization$filterB = localization.filterByColumn) == null ? void 0 : _localization$filterB.replace('{column}', String(column.Header))), !column.filterSelectOptions && React__default.createElement(material.IconButton, {
939
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(FilterListIcon, null)), (_localization$filterB = localization.filterByColumn) == null ? void 0 : _localization$filterB.replace('{column}', String(column.Header))), !column.filterSelectOptions && React__default.createElement(material.IconButton, {
934
940
  onClick: handleOpenFilterModeMenu,
935
941
  onMouseEnter: handleOpenFilterModeMenu,
936
942
  size: "small",
@@ -950,20 +956,20 @@ var MRT_ColumnActionMenu = function MRT_ColumnActionMenu(_ref) {
950
956
  sx: commonMenuItemStyles$1
951
957
  }, React__default.createElement(material.Box, {
952
958
  sx: commonListItemStyles
953
- }, React__default.createElement(DynamicFeedIcon, null), (_localization = localization[column.isGrouped ? 'ungroupByColumn' : 'groupByColumn']) == null ? void 0 : _localization.replace('{column}', String(column.Header))))], !disableColumnHiding && [React__default.createElement(material.MenuItem, {
959
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(DynamicFeedIcon, null)), (_localization = localization[column.isGrouped ? 'ungroupByColumn' : 'groupByColumn']) == null ? void 0 : _localization.replace('{column}', String(column.Header))))], !disableColumnHiding && [React__default.createElement(material.MenuItem, {
954
960
  key: 0,
955
961
  onClick: handleHideColumn,
956
962
  sx: commonMenuItemStyles$1
957
963
  }, React__default.createElement(material.Box, {
958
964
  sx: commonListItemStyles
959
- }, React__default.createElement(VisibilityOffIcon, null), (_localization$hideCol = localization.hideColumn) == null ? void 0 : _localization$hideCol.replace('{column}', String(column.Header)))), React__default.createElement(material.MenuItem, {
965
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(VisibilityOffIcon, null)), (_localization$hideCol = localization.hideColumn) == null ? void 0 : _localization$hideCol.replace('{column}', String(column.Header)))), React__default.createElement(material.MenuItem, {
960
966
  disabled: !((_tableInstance$state$ = tableInstance.state.hiddenColumns) != null && _tableInstance$state$.length),
961
967
  key: 1,
962
968
  onClick: handleShowAllColumns,
963
969
  sx: commonMenuItemStyles$1
964
970
  }, React__default.createElement(material.Box, {
965
971
  sx: commonListItemStyles
966
- }, React__default.createElement(ViewColumnIcon, null), (_localization$showAll = localization.showAllColumns) == null ? void 0 : _localization$showAll.replace('{column}', String(column.Header))), !column.filterSelectOptions && React__default.createElement(material.IconButton, {
972
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(ViewColumnIcon, null)), (_localization$showAll = localization.showAllColumns) == null ? void 0 : _localization$showAll.replace('{column}', String(column.Header))), !column.filterSelectOptions && React__default.createElement(material.IconButton, {
967
973
  onClick: handleOpenShowHideColumnsMenu,
968
974
  onMouseEnter: handleOpenShowHideColumnsMenu,
969
975
  size: "small",
@@ -1168,7 +1174,7 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
1168
1174
  style: _extends({}, muiTableBodyCellEditTextFieldProps == null ? void 0 : muiTableBodyCellEditTextFieldProps.style, (_cell$column$muiTable = cell.column.muiTableBodyCellEditTextFieldProps) == null ? void 0 : _cell$column$muiTable.style)
1169
1175
  });
1170
1176
 
1171
- if (cell.column.editable && cell.column.Edit) {
1177
+ if (!cell.column.disableEditing && cell.column.Edit) {
1172
1178
  return React__default.createElement(React__default.Fragment, null, cell.column.Edit(_extends({}, textFieldProps, {
1173
1179
  cell: cell
1174
1180
  })));
@@ -1229,7 +1235,7 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
1229
1235
  animation: "wave",
1230
1236
  height: 20,
1231
1237
  width: Math.random() * (120 - 60) + 60
1232
- }, muiTableBodyCellSkeletonProps)) : (currentEditingRow == null ? void 0 : currentEditingRow.id) === cell.row.id ? React__default.createElement(MRT_EditCellTextField, {
1238
+ }, muiTableBodyCellSkeletonProps)) : !cell.column.disableEditing && (currentEditingRow == null ? void 0 : currentEditingRow.id) === cell.row.id ? React__default.createElement(MRT_EditCellTextField, {
1233
1239
  cell: cell
1234
1240
  }) : cell.isPlaceholder ? null : cell.isAggregated ? cell.render('Aggregated') : cell.isGrouped ? React__default.createElement("span", null, cell.render('Cell'), " (", cell.row.subRows.length, ")") : cell.render('Cell'));
1235
1241
  };
@@ -1425,9 +1431,18 @@ var MRT_ExpandButton = function MRT_ExpandButton(_ref) {
1425
1431
  var _useMRT = useMRT(),
1426
1432
  ExpandMoreIcon = _useMRT.icons.ExpandMoreIcon,
1427
1433
  localization = _useMRT.localization,
1434
+ onRowExpandChange = _useMRT.onRowExpandChange,
1428
1435
  renderDetailPanel = _useMRT.renderDetailPanel,
1429
1436
  densePadding = _useMRT.tableInstance.state.densePadding;
1430
1437
 
1438
+ var handleToggleExpand = function handleToggleExpand(event) {
1439
+ var _row$getToggleRowExpa;
1440
+
1441
+ // @ts-ignore
1442
+ (_row$getToggleRowExpa = row.getToggleRowExpandedProps()) == null ? void 0 : _row$getToggleRowExpa.onClick(event);
1443
+ onRowExpandChange == null ? void 0 : onRowExpandChange(event, row);
1444
+ };
1445
+
1431
1446
  return React__default.createElement(material.TableCell, {
1432
1447
  size: "small",
1433
1448
  sx: _extends({}, commonTableBodyButtonCellStyles(densePadding), {
@@ -1438,7 +1453,9 @@ var MRT_ExpandButton = function MRT_ExpandButton(_ref) {
1438
1453
  "aria-label": localization.expand,
1439
1454
  disabled: !row.canExpand && !renderDetailPanel,
1440
1455
  title: localization.expand
1441
- }, row.getToggleRowExpandedProps()), React__default.createElement(ExpandMoreIcon, {
1456
+ }, row.getToggleRowExpandedProps(), {
1457
+ onClick: handleToggleExpand
1458
+ }), React__default.createElement(ExpandMoreIcon, {
1442
1459
  style: {
1443
1460
  transform: "rotate(" + (!row.canExpand && !renderDetailPanel ? -90 : row.isExpanded ? -180 : 0) + "deg)",
1444
1461
  transition: 'transform 0.2s'
@@ -1473,7 +1490,9 @@ var MRT_RowActionMenu = function MRT_RowActionMenu(_ref) {
1473
1490
  }, enableRowEditing && React__default.createElement(material.MenuItem, {
1474
1491
  onClick: handleEdit,
1475
1492
  sx: commonMenuItemStyles$1
1476
- }, React__default.createElement(EditIcon, null), localization.edit), (_renderRowActionMenuI = renderRowActionMenuItems == null ? void 0 : renderRowActionMenuItems(row, tableInstance, function () {
1493
+ }, React__default.createElement(material.Box, {
1494
+ sx: commonListItemStyles
1495
+ }, React__default.createElement(material.ListItemIcon, null, React__default.createElement(EditIcon, null)), localization.edit)), (_renderRowActionMenuI = renderRowActionMenuItems == null ? void 0 : renderRowActionMenuItems(row, tableInstance, function () {
1477
1496
  return setAnchorEl(null);
1478
1497
  })) != null ? _renderRowActionMenuI : null);
1479
1498
  };
@@ -2396,14 +2415,9 @@ var MRT_TableBodyRow = function MRT_TableBodyRow(_ref) {
2396
2415
  hover: true,
2397
2416
  onClick: function onClick(event) {
2398
2417
  return onRowClick == null ? void 0 : onRowClick(event, row);
2399
- }
2400
- }, tableRowProps, {
2401
- sx: function sx(theme) {
2402
- return _extends({
2403
- backgroundColor: row.isSelected ? material.alpha(theme.palette.primary.light, 0.1) : 'transparent'
2404
- }, tableRowProps == null ? void 0 : tableRowProps.sx);
2405
- }
2406
- }), enableRowNumbers && React__default.createElement(material.TableCell, {
2418
+ },
2419
+ selected: row.isSelected
2420
+ }, tableRowProps), enableRowNumbers && React__default.createElement(material.TableCell, {
2407
2421
  sx: _extends({}, commonTableBodyCellStyles(densePadding))
2408
2422
  }, row.index + 1), (enableRowActions || enableRowEditing) && positionActionsColumn === 'first' && React__default.createElement(MRT_ToggleRowActionMenuButton, {
2409
2423
  row: row