material-react-table 1.10.0 → 1.11.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.
@@ -0,0 +1,2 @@
1
+ import type { MRT_Localization } from '../MaterialReactTable';
2
+ export declare const MRT_Localization_FI: MRT_Localization;
@@ -0,0 +1,2 @@
1
+ import type { MRT_Localization } from '../MaterialReactTable';
2
+ export declare const MRT_Localization_ID: MRT_Localization;
@@ -6,5 +6,5 @@ interface Props<TData extends Record<string, any> = {}> {
6
6
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
7
7
  table: MRT_TableInstance<TData>;
8
8
  }
9
- export declare const MRT_ShowHideColumnsMenu: <TData extends Record<string, any> = {}>({ anchorEl, isSubMenu, setAnchorEl, table, }: Props<TData>) => JSX.Element;
9
+ export declare const MRT_ShowHideColumnsMenu: <TData extends Record<string, any> = {}>({ anchorEl, setAnchorEl, table, }: Props<TData>) => JSX.Element;
10
10
  export {};
@@ -4,9 +4,8 @@ interface Props<TData extends Record<string, any> = {}> {
4
4
  allColumns: MRT_Column<TData>[];
5
5
  column: MRT_Column<TData>;
6
6
  hoveredColumn: MRT_Column<TData> | null;
7
- isSubMenu?: boolean;
8
7
  setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
9
8
  table: MRT_TableInstance<TData>;
10
9
  }
11
- export declare const MRT_ShowHideColumnsMenuItems: <TData extends Record<string, any> = {}>({ allColumns, hoveredColumn, setHoveredColumn, column, isSubMenu, table, }: Props<TData>) => JSX.Element;
10
+ export declare const MRT_ShowHideColumnsMenuItems: <TData extends Record<string, any> = {}>({ allColumns, hoveredColumn, setHoveredColumn, column, table, }: Props<TData>) => JSX.Element;
12
11
  export {};
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useRef, useState, useCallback, useEffect, Fragment, memo, useLayoutEffect } from 'react';
1
+ import React, { useMemo, useState, useRef, useCallback, useEffect, Fragment, memo, useLayoutEffect } from 'react';
2
2
  import { aggregationFns, filterFns, sortingFns, useReactTable, getCoreRowModel, getExpandedRowModel, getFacetedRowModel, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel } from '@tanstack/react-table';
3
3
  import { alpha, lighten, useTheme, darken } from '@mui/material/styles';
4
4
  import { rankItem, rankings, compareItems } from '@tanstack/match-sorter-utils';
@@ -39,10 +39,6 @@ import ListItemIcon from '@mui/material/ListItemIcon';
39
39
  import Menu from '@mui/material/Menu';
40
40
  import MenuItem from '@mui/material/MenuItem';
41
41
  import Button from '@mui/material/Button';
42
- import Divider from '@mui/material/Divider';
43
- import FormControlLabel from '@mui/material/FormControlLabel';
44
- import Switch from '@mui/material/Switch';
45
- import Typography from '@mui/material/Typography';
46
42
  import Checkbox from '@mui/material/Checkbox';
47
43
  import Radio from '@mui/material/Radio';
48
44
  import Paper from '@mui/material/Paper';
@@ -57,6 +53,10 @@ import TablePagination from '@mui/material/TablePagination';
57
53
  import Alert from '@mui/material/Alert';
58
54
  import AlertTitle from '@mui/material/AlertTitle';
59
55
  import Chip from '@mui/material/Chip';
56
+ import Divider from '@mui/material/Divider';
57
+ import FormControlLabel from '@mui/material/FormControlLabel';
58
+ import Switch from '@mui/material/Switch';
59
+ import Typography from '@mui/material/Typography';
60
60
  import Fade from '@mui/material/Fade';
61
61
  import TableContainer from '@mui/material/TableContainer';
62
62
  import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
@@ -669,168 +669,6 @@ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilt
669
669
  label)))));
670
670
  };
671
671
 
672
- const MRT_ColumnPinningButtons = ({ column, table, }) => {
673
- const { options: { icons: { PushPinIcon }, localization, }, } = table;
674
- const handlePinColumn = (pinDirection) => {
675
- column.pin(pinDirection);
676
- };
677
- return (React.createElement(Box, { sx: { minWidth: '70px', textAlign: 'center' } }, column.getIsPinned() ? (React.createElement(Tooltip, { arrow: true, title: localization.unpin },
678
- React.createElement(IconButton, { onClick: () => handlePinColumn(false), size: "small" },
679
- React.createElement(PushPinIcon, null)))) : (React.createElement(React.Fragment, null,
680
- React.createElement(Tooltip, { arrow: true, title: localization.pinToLeft },
681
- React.createElement(IconButton, { onClick: () => handlePinColumn('left'), size: "small" },
682
- React.createElement(PushPinIcon, { style: {
683
- transform: 'rotate(90deg)',
684
- } }))),
685
- React.createElement(Tooltip, { arrow: true, title: localization.pinToRight },
686
- React.createElement(IconButton, { onClick: () => handlePinColumn('right'), size: "small" },
687
- React.createElement(PushPinIcon, { style: {
688
- transform: 'rotate(-90deg)',
689
- } })))))));
690
- };
691
-
692
- const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table, }) => {
693
- var _a;
694
- const { options: { icons: { DragHandleIcon }, localization, }, } = table;
695
- return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : localization.move },
696
- React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
697
- var _a;
698
- e.stopPropagation();
699
- (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
700
- }, 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': {
701
- backgroundColor: 'transparent',
702
- opacity: 1,
703
- }, '&:active': {
704
- cursor: 'grabbing',
705
- } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
706
- ? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
707
- : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
708
- React.createElement(DragHandleIcon, null))));
709
- };
710
-
711
- const MRT_ShowHideColumnsMenuItems = ({ allColumns, hoveredColumn, setHoveredColumn, column, isSubMenu, table, }) => {
712
- var _a;
713
- const { getState, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, setColumnOrder, } = table;
714
- const { columnOrder } = getState();
715
- const { columnDef } = column;
716
- const { columnDefType } = columnDef;
717
- const switchChecked = (columnDefType !== 'group' && column.getIsVisible()) ||
718
- (columnDefType === 'group' &&
719
- column.getLeafColumns().some((col) => col.getIsVisible()));
720
- const handleToggleColumnHidden = (column) => {
721
- var _a, _b;
722
- if (columnDefType === 'group') {
723
- (_b = (_a = column === null || column === void 0 ? void 0 : column.columns) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (childColumn) => {
724
- childColumn.toggleVisibility(!switchChecked);
725
- });
726
- }
727
- else {
728
- column.toggleVisibility();
729
- }
730
- };
731
- const menuItemRef = useRef(null);
732
- const [isDragging, setIsDragging] = useState(false);
733
- const handleDragStart = (e) => {
734
- setIsDragging(true);
735
- e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
736
- };
737
- const handleDragEnd = (_e) => {
738
- setIsDragging(false);
739
- setHoveredColumn(null);
740
- if (hoveredColumn) {
741
- setColumnOrder(reorderColumn(column, hoveredColumn, columnOrder));
742
- }
743
- };
744
- const handleDragEnter = (_e) => {
745
- if (!isDragging && columnDef.enableColumnOrdering !== false) {
746
- setHoveredColumn(column);
747
- }
748
- };
749
- return (React.createElement(React.Fragment, null,
750
- React.createElement(MenuItem, { disableRipple: true, ref: menuItemRef, onDragEnter: handleDragEnter, sx: (theme) => ({
751
- alignItems: 'center',
752
- justifyContent: 'flex-start',
753
- my: 0,
754
- opacity: isDragging ? 0.5 : 1,
755
- outlineOffset: '-2px',
756
- outline: isDragging
757
- ? `2px dashed ${theme.palette.divider}`
758
- : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
759
- ? `2px dashed ${theme.palette.primary.main}`
760
- : 'none',
761
- pl: `${(column.depth + 0.5) * 2}rem`,
762
- py: '6px',
763
- }) },
764
- React.createElement(Box, { sx: {
765
- display: 'flex',
766
- flexWrap: 'nowrap',
767
- gap: '8px',
768
- } },
769
- !isSubMenu &&
770
- columnDefType !== 'group' &&
771
- enableColumnOrdering &&
772
- !allColumns.some((col) => col.columnDef.columnDefType === 'group') &&
773
- (columnDef.enableColumnOrdering !== false ? (React.createElement(MRT_GrabHandleButton, { onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })) : (React.createElement(Box, { sx: { width: '28px' } }))),
774
- !isSubMenu &&
775
- enablePinning &&
776
- (column.getCanPin() ? (React.createElement(MRT_ColumnPinningButtons, { column: column, table: table })) : (React.createElement(Box, { sx: { width: '70px' } }))),
777
- enableHiding ? (React.createElement(FormControlLabel, { componentsProps: {
778
- typography: {
779
- sx: {
780
- mb: 0,
781
- opacity: columnDefType !== 'display' ? 1 : 0.5,
782
- },
783
- },
784
- }, checked: switchChecked, control: React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.toggleVisibility },
785
- React.createElement(Switch, null)), disabled: (isSubMenu && switchChecked) || !column.getCanHide(), label: columnDef.header, onChange: () => handleToggleColumnHidden(column) })) : (React.createElement(Typography, { sx: { alignSelf: 'center' } }, columnDef.header)))), (_a = column.columns) === null || _a === void 0 ? void 0 :
786
- _a.map((c, i) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, hoveredColumn: hoveredColumn, isSubMenu: isSubMenu, key: `${i}-${c.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
787
- };
788
-
789
- const MRT_ShowHideColumnsMenu = ({ anchorEl, isSubMenu, setAnchorEl, table, }) => {
790
- const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, toggleAllColumnsVisible, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, } = table;
791
- const { density, columnOrder, columnPinning } = getState();
792
- const hideAllColumns = () => {
793
- getAllLeafColumns()
794
- .filter((col) => col.columnDef.enableHiding !== false)
795
- .forEach((col) => col.toggleVisibility(false));
796
- };
797
- const allColumns = useMemo(() => {
798
- const columns = getAllColumns();
799
- if (columnOrder.length > 0 &&
800
- !columns.some((col) => col.columnDef.columnDefType === 'group')) {
801
- return [
802
- ...getLeftLeafColumns(),
803
- ...Array.from(new Set(columnOrder)).map((colId) => getCenterLeafColumns().find((col) => (col === null || col === void 0 ? void 0 : col.id) === colId)),
804
- ...getRightLeafColumns(),
805
- ].filter(Boolean);
806
- }
807
- return columns;
808
- }, [
809
- columnOrder,
810
- columnPinning,
811
- getAllColumns(),
812
- getCenterLeafColumns(),
813
- getLeftLeafColumns(),
814
- getRightLeafColumns(),
815
- ]);
816
- const [hoveredColumn, setHoveredColumn] = useState(null);
817
- return (React.createElement(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
818
- dense: density === 'compact',
819
- } },
820
- React.createElement(Box, { sx: {
821
- display: 'flex',
822
- justifyContent: isSubMenu ? 'center' : 'space-between',
823
- p: '0.5rem',
824
- pt: 0,
825
- } },
826
- !isSubMenu && enableHiding && (React.createElement(Button, { disabled: !getIsSomeColumnsVisible(), onClick: hideAllColumns }, localization.hideAll)),
827
- !isSubMenu && enableColumnOrdering && (React.createElement(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options)) }, localization.resetOrder)),
828
- !isSubMenu && enablePinning && (React.createElement(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true) }, localization.unpinAll)),
829
- enableHiding && (React.createElement(Button, { disabled: getIsAllColumnsVisible(), onClick: () => toggleAllColumnsVisible(true) }, localization.showAll))),
830
- React.createElement(Divider, null),
831
- allColumns.map((column, index) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, isSubMenu: isSubMenu, key: `${index}-${column.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
832
- };
833
-
834
672
  const commonMenuItemStyles = {
835
673
  py: '6px',
836
674
  my: 0,
@@ -846,9 +684,8 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
846
684
  const { getState, toggleAllColumnsVisible, setColumnOrder, options: { columnFilterModeOptions, enableColumnFilterModes, enableColumnFilters, enableColumnResizing, enableGrouping, enableHiding, enablePinning, enableSorting, icons: { ArrowRightIcon, ClearAllIcon, ViewColumnIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, SortIcon, RestartAltIcon, VisibilityOffIcon, }, localization, renderColumnActionsMenuItems, }, refs: { filterInputRefs }, setColumnSizingInfo, setShowColumnFilters, } = table;
847
685
  const { column } = header;
848
686
  const { columnDef } = column;
849
- const { columnSizing, columnVisibility, density } = getState();
687
+ const { columnSizing, columnVisibility, density, showColumnFilters } = getState();
850
688
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] = useState(null);
851
- const [showHideColumnsMenuAnchorEl, setShowHideColumnsMenuAnchorEl] = useState(null);
852
689
  const handleClearSort = () => {
853
690
  column.clearSorting();
854
691
  setAnchorEl(null);
@@ -896,10 +733,6 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
896
733
  event.stopPropagation();
897
734
  setFilterMenuAnchorEl(event.currentTarget);
898
735
  };
899
- const handleOpenShowHideColumnsMenu = (event) => {
900
- event.stopPropagation();
901
- setShowHideColumnsMenuAnchorEl(event.currentTarget);
902
- };
903
736
  const isSelectFilter = !!columnDef.filterSelectOptions;
904
737
  const allowedColumnFilterOptions = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.columnFilterModeOptions) !== null && _a !== void 0 ? _a : columnFilterModeOptions;
905
738
  const showFilterModeSubMenu = enableColumnFilterModes &&
@@ -943,7 +776,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
943
776
  React.createElement(ListItemIcon, null,
944
777
  React.createElement(FilterListOffIcon, null)),
945
778
  localization.clearFilter)),
946
- React.createElement(MenuItem, { divider: enableGrouping || enableHiding, key: 1, onClick: handleFilterByColumn, sx: commonMenuItemStyles },
779
+ React.createElement(MenuItem, { disabled: showColumnFilters && !enableColumnFilterModes, divider: enableGrouping || enableHiding, key: 1, onClick: handleFilterByColumn, sx: commonMenuItemStyles },
947
780
  React.createElement(Box, { sx: commonListItemStyles },
948
781
  React.createElement(ListItemIcon, null,
949
782
  React.createElement(FilterListIcon, null)), (_g = localization.filterByColumn) === null || _g === void 0 ? void 0 :
@@ -997,10 +830,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
997
830
  React.createElement(Box, { sx: commonListItemStyles },
998
831
  React.createElement(ListItemIcon, null,
999
832
  React.createElement(ViewColumnIcon, null)), (_k = localization.showAllColumns) === null || _k === void 0 ? void 0 :
1000
- _k.replace('{column}', String(columnDef.header))),
1001
- React.createElement(IconButton, { onClick: handleOpenShowHideColumnsMenu, onMouseEnter: handleOpenShowHideColumnsMenu, size: "small", sx: { p: 0 } },
1002
- React.createElement(ArrowRightIcon, null))),
1003
- React.createElement(MRT_ShowHideColumnsMenu, { anchorEl: showHideColumnsMenuAnchorEl, isSubMenu: true, key: 2, setAnchorEl: setShowHideColumnsMenuAnchorEl, table: table }),
833
+ _k.replace('{column}', String(columnDef.header)))),
1004
834
  ]));
1005
835
  };
1006
836
 
@@ -1291,6 +1121,166 @@ const MRT_FullScreenToggleButton = (_a) => {
1291
1121
  React.createElement(IconButton, Object.assign({ "aria-label": localization.showHideFilters, onClick: handleToggleFullScreen }, rest, { title: undefined }), isFullScreen ? React.createElement(FullscreenExitIcon, null) : React.createElement(FullscreenIcon, null))));
1292
1122
  };
1293
1123
 
1124
+ const MRT_ColumnPinningButtons = ({ column, table, }) => {
1125
+ const { options: { icons: { PushPinIcon }, localization, }, } = table;
1126
+ const handlePinColumn = (pinDirection) => {
1127
+ column.pin(pinDirection);
1128
+ };
1129
+ return (React.createElement(Box, { sx: { minWidth: '70px', textAlign: 'center' } }, column.getIsPinned() ? (React.createElement(Tooltip, { arrow: true, title: localization.unpin },
1130
+ React.createElement(IconButton, { onClick: () => handlePinColumn(false), size: "small" },
1131
+ React.createElement(PushPinIcon, null)))) : (React.createElement(React.Fragment, null,
1132
+ React.createElement(Tooltip, { arrow: true, title: localization.pinToLeft },
1133
+ React.createElement(IconButton, { onClick: () => handlePinColumn('left'), size: "small" },
1134
+ React.createElement(PushPinIcon, { style: {
1135
+ transform: 'rotate(90deg)',
1136
+ } }))),
1137
+ React.createElement(Tooltip, { arrow: true, title: localization.pinToRight },
1138
+ React.createElement(IconButton, { onClick: () => handlePinColumn('right'), size: "small" },
1139
+ React.createElement(PushPinIcon, { style: {
1140
+ transform: 'rotate(-90deg)',
1141
+ } })))))));
1142
+ };
1143
+
1144
+ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table, }) => {
1145
+ var _a;
1146
+ const { options: { icons: { DragHandleIcon }, localization, }, } = table;
1147
+ return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : localization.move },
1148
+ React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
1149
+ var _a;
1150
+ e.stopPropagation();
1151
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
1152
+ }, 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': {
1153
+ backgroundColor: 'transparent',
1154
+ opacity: 1,
1155
+ }, '&:active': {
1156
+ cursor: 'grabbing',
1157
+ } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
1158
+ ? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
1159
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
1160
+ React.createElement(DragHandleIcon, null))));
1161
+ };
1162
+
1163
+ const MRT_ShowHideColumnsMenuItems = ({ allColumns, hoveredColumn, setHoveredColumn, column, table, }) => {
1164
+ var _a;
1165
+ const { getState, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, setColumnOrder, } = table;
1166
+ const { columnOrder } = getState();
1167
+ const { columnDef } = column;
1168
+ const { columnDefType } = columnDef;
1169
+ const switchChecked = (columnDefType !== 'group' && column.getIsVisible()) ||
1170
+ (columnDefType === 'group' &&
1171
+ column.getLeafColumns().some((col) => col.getIsVisible()));
1172
+ const handleToggleColumnHidden = (column) => {
1173
+ var _a, _b;
1174
+ if (columnDefType === 'group') {
1175
+ (_b = (_a = column === null || column === void 0 ? void 0 : column.columns) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (childColumn) => {
1176
+ childColumn.toggleVisibility(!switchChecked);
1177
+ });
1178
+ }
1179
+ else {
1180
+ column.toggleVisibility();
1181
+ }
1182
+ };
1183
+ const menuItemRef = useRef(null);
1184
+ const [isDragging, setIsDragging] = useState(false);
1185
+ const handleDragStart = (e) => {
1186
+ setIsDragging(true);
1187
+ e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
1188
+ };
1189
+ const handleDragEnd = (_e) => {
1190
+ setIsDragging(false);
1191
+ setHoveredColumn(null);
1192
+ if (hoveredColumn) {
1193
+ setColumnOrder(reorderColumn(column, hoveredColumn, columnOrder));
1194
+ }
1195
+ };
1196
+ const handleDragEnter = (_e) => {
1197
+ if (!isDragging && columnDef.enableColumnOrdering !== false) {
1198
+ setHoveredColumn(column);
1199
+ }
1200
+ };
1201
+ return (React.createElement(React.Fragment, null,
1202
+ React.createElement(MenuItem, { disableRipple: true, ref: menuItemRef, onDragEnter: handleDragEnter, sx: (theme) => ({
1203
+ alignItems: 'center',
1204
+ justifyContent: 'flex-start',
1205
+ my: 0,
1206
+ opacity: isDragging ? 0.5 : 1,
1207
+ outlineOffset: '-2px',
1208
+ outline: isDragging
1209
+ ? `2px dashed ${theme.palette.divider}`
1210
+ : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
1211
+ ? `2px dashed ${theme.palette.primary.main}`
1212
+ : 'none',
1213
+ pl: `${(column.depth + 0.5) * 2}rem`,
1214
+ py: '6px',
1215
+ }) },
1216
+ React.createElement(Box, { sx: {
1217
+ display: 'flex',
1218
+ flexWrap: 'nowrap',
1219
+ gap: '8px',
1220
+ } },
1221
+ columnDefType !== 'group' &&
1222
+ enableColumnOrdering &&
1223
+ !allColumns.some((col) => col.columnDef.columnDefType === 'group') &&
1224
+ (columnDef.enableColumnOrdering !== false ? (React.createElement(MRT_GrabHandleButton, { onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })) : (React.createElement(Box, { sx: { width: '28px' } }))),
1225
+ enablePinning &&
1226
+ (column.getCanPin() ? (React.createElement(MRT_ColumnPinningButtons, { column: column, table: table })) : (React.createElement(Box, { sx: { width: '70px' } }))),
1227
+ enableHiding ? (React.createElement(FormControlLabel, { componentsProps: {
1228
+ typography: {
1229
+ sx: {
1230
+ mb: 0,
1231
+ opacity: columnDefType !== 'display' ? 1 : 0.5,
1232
+ },
1233
+ },
1234
+ }, checked: switchChecked, control: React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.toggleVisibility },
1235
+ React.createElement(Switch, null)), disabled: !column.getCanHide(), label: columnDef.header, onChange: () => handleToggleColumnHidden(column) })) : (React.createElement(Typography, { sx: { alignSelf: 'center' } }, columnDef.header)))), (_a = column.columns) === null || _a === void 0 ? void 0 :
1236
+ _a.map((c, i) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, hoveredColumn: hoveredColumn, key: `${i}-${c.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
1237
+ };
1238
+
1239
+ const MRT_ShowHideColumnsMenu = ({ anchorEl, setAnchorEl, table, }) => {
1240
+ const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, toggleAllColumnsVisible, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, } = table;
1241
+ const { density, columnOrder, columnPinning } = getState();
1242
+ const hideAllColumns = () => {
1243
+ getAllLeafColumns()
1244
+ .filter((col) => col.columnDef.enableHiding !== false)
1245
+ .forEach((col) => col.toggleVisibility(false));
1246
+ };
1247
+ const allColumns = useMemo(() => {
1248
+ const columns = getAllColumns();
1249
+ if (columnOrder.length > 0 &&
1250
+ !columns.some((col) => col.columnDef.columnDefType === 'group')) {
1251
+ return [
1252
+ ...getLeftLeafColumns(),
1253
+ ...Array.from(new Set(columnOrder)).map((colId) => getCenterLeafColumns().find((col) => (col === null || col === void 0 ? void 0 : col.id) === colId)),
1254
+ ...getRightLeafColumns(),
1255
+ ].filter(Boolean);
1256
+ }
1257
+ return columns;
1258
+ }, [
1259
+ columnOrder,
1260
+ columnPinning,
1261
+ getAllColumns(),
1262
+ getCenterLeafColumns(),
1263
+ getLeftLeafColumns(),
1264
+ getRightLeafColumns(),
1265
+ ]);
1266
+ const [hoveredColumn, setHoveredColumn] = useState(null);
1267
+ return (React.createElement(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
1268
+ dense: density === 'compact',
1269
+ } },
1270
+ React.createElement(Box, { sx: {
1271
+ display: 'flex',
1272
+ justifyContent: 'space-between',
1273
+ p: '0.5rem',
1274
+ pt: 0,
1275
+ } },
1276
+ enableHiding && (React.createElement(Button, { disabled: !getIsSomeColumnsVisible(), onClick: hideAllColumns }, localization.hideAll)),
1277
+ enableColumnOrdering && (React.createElement(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options)) }, localization.resetOrder)),
1278
+ enablePinning && (React.createElement(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true) }, localization.unpinAll)),
1279
+ enableHiding && (React.createElement(Button, { disabled: getIsAllColumnsVisible(), onClick: () => toggleAllColumnsVisible(true) }, localization.showAll))),
1280
+ React.createElement(Divider, null),
1281
+ allColumns.map((column, index) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, key: `${index}-${column.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
1282
+ };
1283
+
1294
1284
  const MRT_ShowHideColumnsButton = (_a) => {
1295
1285
  var _b;
1296
1286
  var { table } = _a, rest = __rest(_a, ["table"]);
@@ -1880,7 +1870,7 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1880
1870
  cursor: 'col-resize',
1881
1871
  mr: density === 'compact' ? '-0.75rem' : '-1rem',
1882
1872
  position: 'absolute',
1883
- right: '1px',
1873
+ right: '4px',
1884
1874
  px: '4px',
1885
1875
  '&:active > hr': {
1886
1876
  backgroundColor: theme.palette.info.main,
@@ -2024,7 +2014,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
2024
2014
  theme,
2025
2015
  })), draggingBorders)) }),
2026
2016
  header.isPlaceholder ? null : (React.createElement(Box, { className: "Mui-TableHeadCell-Content", sx: {
2027
- alignItems: 'flex-start',
2017
+ alignItems: 'center',
2028
2018
  display: 'flex',
2029
2019
  flexDirection: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right' ? 'row-reverse' : 'row',
2030
2020
  justifyContent: columnDefType === 'group' || (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
@@ -2048,7 +2038,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
2048
2038
  : undefined,
2049
2039
  } },
2050
2040
  React.createElement(Box, { className: "Mui-TableHeadCell-Content-Wrapper", sx: {
2051
- minWidth: '5ch',
2041
+ minWidth: `${Math.min(columnDef.header.length, 5)}ch`,
2052
2042
  overflow: columnDefType === 'data' ? 'hidden' : undefined,
2053
2043
  textOverflow: 'ellipsis',
2054
2044
  whiteSpace: ((_d = (_c = columnDef.header) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 20 ? 'nowrap' : 'normal',