material-react-table 1.10.0 → 1.11.1
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.
- package/dist/cjs/index.js +182 -185
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/_locales/fi.d.ts +2 -0
- package/dist/cjs/types/_locales/id.d.ts +2 -0
- package/dist/cjs/types/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
- package/dist/cjs/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -2
- package/dist/esm/material-react-table.esm.js +179 -182
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/_locales/fi.d.ts +2 -0
- package/dist/esm/types/_locales/id.d.ts +2 -0
- package/dist/esm/types/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
- package/dist/esm/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -2
- package/locales/fi.d.ts +2 -0
- package/locales/fi.esm.d.ts +2 -0
- package/locales/fi.esm.js +94 -0
- package/locales/fi.esm.js.map +1 -0
- package/locales/fi.js +98 -0
- package/locales/fi.js.map +1 -0
- package/locales/id.d.ts +2 -0
- package/locales/id.esm.d.ts +2 -0
- package/locales/id.esm.js +94 -0
- package/locales/id.esm.js.map +1 -0
- package/locales/id.js +98 -0
- package/locales/id.js.map +1 -0
- package/locales/it.esm.js +5 -5
- package/locales/it.esm.js.map +1 -1
- package/locales/it.js +5 -5
- package/locales/it.js.map +1 -1
- package/locales/nl.esm.js +25 -25
- package/locales/nl.esm.js.map +1 -1
- package/locales/nl.js +25 -25
- package/locales/nl.js.map +1 -1
- package/package.json +7 -7
- package/src/_locales/fi.ts +95 -0
- package/src/_locales/id.ts +95 -0
- package/src/_locales/it.ts +5 -5
- package/src/_locales/nl.ts +25 -25
- package/src/body/MRT_TableDetailPanel.tsx +6 -1
- package/src/head/MRT_TableHeadCell.tsx +2 -2
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +1 -1
- package/src/menus/MRT_ColumnActionMenu.tsx +8 -27
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +4 -6
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +3 -8
@@ -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,
|
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,
|
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,
|
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,9 @@ 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:
|
779
|
+
React.createElement(MenuItem, { disabled: showColumnFilters && !enableColumnFilterModes, divider: enableGrouping || enableHiding, key: 1, onClick: showColumnFilters
|
780
|
+
? handleOpenFilterModeMenu
|
781
|
+
: handleFilterByColumn, sx: commonMenuItemStyles },
|
947
782
|
React.createElement(Box, { sx: commonListItemStyles },
|
948
783
|
React.createElement(ListItemIcon, null,
|
949
784
|
React.createElement(FilterListIcon, null)), (_g = localization.filterByColumn) === null || _g === void 0 ? void 0 :
|
@@ -997,10 +832,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
997
832
|
React.createElement(Box, { sx: commonListItemStyles },
|
998
833
|
React.createElement(ListItemIcon, null,
|
999
834
|
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 }),
|
835
|
+
_k.replace('{column}', String(columnDef.header)))),
|
1004
836
|
]));
|
1005
837
|
};
|
1006
838
|
|
@@ -1291,6 +1123,166 @@ const MRT_FullScreenToggleButton = (_a) => {
|
|
1291
1123
|
React.createElement(IconButton, Object.assign({ "aria-label": localization.showHideFilters, onClick: handleToggleFullScreen }, rest, { title: undefined }), isFullScreen ? React.createElement(FullscreenExitIcon, null) : React.createElement(FullscreenIcon, null))));
|
1292
1124
|
};
|
1293
1125
|
|
1126
|
+
const MRT_ColumnPinningButtons = ({ column, table, }) => {
|
1127
|
+
const { options: { icons: { PushPinIcon }, localization, }, } = table;
|
1128
|
+
const handlePinColumn = (pinDirection) => {
|
1129
|
+
column.pin(pinDirection);
|
1130
|
+
};
|
1131
|
+
return (React.createElement(Box, { sx: { minWidth: '70px', textAlign: 'center' } }, column.getIsPinned() ? (React.createElement(Tooltip, { arrow: true, title: localization.unpin },
|
1132
|
+
React.createElement(IconButton, { onClick: () => handlePinColumn(false), size: "small" },
|
1133
|
+
React.createElement(PushPinIcon, null)))) : (React.createElement(React.Fragment, null,
|
1134
|
+
React.createElement(Tooltip, { arrow: true, title: localization.pinToLeft },
|
1135
|
+
React.createElement(IconButton, { onClick: () => handlePinColumn('left'), size: "small" },
|
1136
|
+
React.createElement(PushPinIcon, { style: {
|
1137
|
+
transform: 'rotate(90deg)',
|
1138
|
+
} }))),
|
1139
|
+
React.createElement(Tooltip, { arrow: true, title: localization.pinToRight },
|
1140
|
+
React.createElement(IconButton, { onClick: () => handlePinColumn('right'), size: "small" },
|
1141
|
+
React.createElement(PushPinIcon, { style: {
|
1142
|
+
transform: 'rotate(-90deg)',
|
1143
|
+
} })))))));
|
1144
|
+
};
|
1145
|
+
|
1146
|
+
const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table, }) => {
|
1147
|
+
var _a;
|
1148
|
+
const { options: { icons: { DragHandleIcon }, localization, }, } = table;
|
1149
|
+
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 },
|
1150
|
+
React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
|
1151
|
+
var _a;
|
1152
|
+
e.stopPropagation();
|
1153
|
+
(_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
|
1154
|
+
}, 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': {
|
1155
|
+
backgroundColor: 'transparent',
|
1156
|
+
opacity: 1,
|
1157
|
+
}, '&:active': {
|
1158
|
+
cursor: 'grabbing',
|
1159
|
+
} }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
|
1160
|
+
? iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx(theme)
|
1161
|
+
: iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))), title: undefined }),
|
1162
|
+
React.createElement(DragHandleIcon, null))));
|
1163
|
+
};
|
1164
|
+
|
1165
|
+
const MRT_ShowHideColumnsMenuItems = ({ allColumns, hoveredColumn, setHoveredColumn, column, table, }) => {
|
1166
|
+
var _a;
|
1167
|
+
const { getState, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, setColumnOrder, } = table;
|
1168
|
+
const { columnOrder } = getState();
|
1169
|
+
const { columnDef } = column;
|
1170
|
+
const { columnDefType } = columnDef;
|
1171
|
+
const switchChecked = (columnDefType !== 'group' && column.getIsVisible()) ||
|
1172
|
+
(columnDefType === 'group' &&
|
1173
|
+
column.getLeafColumns().some((col) => col.getIsVisible()));
|
1174
|
+
const handleToggleColumnHidden = (column) => {
|
1175
|
+
var _a, _b;
|
1176
|
+
if (columnDefType === 'group') {
|
1177
|
+
(_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) => {
|
1178
|
+
childColumn.toggleVisibility(!switchChecked);
|
1179
|
+
});
|
1180
|
+
}
|
1181
|
+
else {
|
1182
|
+
column.toggleVisibility();
|
1183
|
+
}
|
1184
|
+
};
|
1185
|
+
const menuItemRef = useRef(null);
|
1186
|
+
const [isDragging, setIsDragging] = useState(false);
|
1187
|
+
const handleDragStart = (e) => {
|
1188
|
+
setIsDragging(true);
|
1189
|
+
e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
|
1190
|
+
};
|
1191
|
+
const handleDragEnd = (_e) => {
|
1192
|
+
setIsDragging(false);
|
1193
|
+
setHoveredColumn(null);
|
1194
|
+
if (hoveredColumn) {
|
1195
|
+
setColumnOrder(reorderColumn(column, hoveredColumn, columnOrder));
|
1196
|
+
}
|
1197
|
+
};
|
1198
|
+
const handleDragEnter = (_e) => {
|
1199
|
+
if (!isDragging && columnDef.enableColumnOrdering !== false) {
|
1200
|
+
setHoveredColumn(column);
|
1201
|
+
}
|
1202
|
+
};
|
1203
|
+
return (React.createElement(React.Fragment, null,
|
1204
|
+
React.createElement(MenuItem, { disableRipple: true, ref: menuItemRef, onDragEnter: handleDragEnter, sx: (theme) => ({
|
1205
|
+
alignItems: 'center',
|
1206
|
+
justifyContent: 'flex-start',
|
1207
|
+
my: 0,
|
1208
|
+
opacity: isDragging ? 0.5 : 1,
|
1209
|
+
outlineOffset: '-2px',
|
1210
|
+
outline: isDragging
|
1211
|
+
? `2px dashed ${theme.palette.divider}`
|
1212
|
+
: (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
|
1213
|
+
? `2px dashed ${theme.palette.primary.main}`
|
1214
|
+
: 'none',
|
1215
|
+
pl: `${(column.depth + 0.5) * 2}rem`,
|
1216
|
+
py: '6px',
|
1217
|
+
}) },
|
1218
|
+
React.createElement(Box, { sx: {
|
1219
|
+
display: 'flex',
|
1220
|
+
flexWrap: 'nowrap',
|
1221
|
+
gap: '8px',
|
1222
|
+
} },
|
1223
|
+
columnDefType !== 'group' &&
|
1224
|
+
enableColumnOrdering &&
|
1225
|
+
!allColumns.some((col) => col.columnDef.columnDefType === 'group') &&
|
1226
|
+
(columnDef.enableColumnOrdering !== false ? (React.createElement(MRT_GrabHandleButton, { onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })) : (React.createElement(Box, { sx: { width: '28px' } }))),
|
1227
|
+
enablePinning &&
|
1228
|
+
(column.getCanPin() ? (React.createElement(MRT_ColumnPinningButtons, { column: column, table: table })) : (React.createElement(Box, { sx: { width: '70px' } }))),
|
1229
|
+
enableHiding ? (React.createElement(FormControlLabel, { componentsProps: {
|
1230
|
+
typography: {
|
1231
|
+
sx: {
|
1232
|
+
mb: 0,
|
1233
|
+
opacity: columnDefType !== 'display' ? 1 : 0.5,
|
1234
|
+
},
|
1235
|
+
},
|
1236
|
+
}, checked: switchChecked, control: React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.toggleVisibility },
|
1237
|
+
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 :
|
1238
|
+
_a.map((c, i) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, hoveredColumn: hoveredColumn, key: `${i}-${c.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
|
1239
|
+
};
|
1240
|
+
|
1241
|
+
const MRT_ShowHideColumnsMenu = ({ anchorEl, setAnchorEl, table, }) => {
|
1242
|
+
const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, toggleAllColumnsVisible, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, } = table;
|
1243
|
+
const { density, columnOrder, columnPinning } = getState();
|
1244
|
+
const hideAllColumns = () => {
|
1245
|
+
getAllLeafColumns()
|
1246
|
+
.filter((col) => col.columnDef.enableHiding !== false)
|
1247
|
+
.forEach((col) => col.toggleVisibility(false));
|
1248
|
+
};
|
1249
|
+
const allColumns = useMemo(() => {
|
1250
|
+
const columns = getAllColumns();
|
1251
|
+
if (columnOrder.length > 0 &&
|
1252
|
+
!columns.some((col) => col.columnDef.columnDefType === 'group')) {
|
1253
|
+
return [
|
1254
|
+
...getLeftLeafColumns(),
|
1255
|
+
...Array.from(new Set(columnOrder)).map((colId) => getCenterLeafColumns().find((col) => (col === null || col === void 0 ? void 0 : col.id) === colId)),
|
1256
|
+
...getRightLeafColumns(),
|
1257
|
+
].filter(Boolean);
|
1258
|
+
}
|
1259
|
+
return columns;
|
1260
|
+
}, [
|
1261
|
+
columnOrder,
|
1262
|
+
columnPinning,
|
1263
|
+
getAllColumns(),
|
1264
|
+
getCenterLeafColumns(),
|
1265
|
+
getLeftLeafColumns(),
|
1266
|
+
getRightLeafColumns(),
|
1267
|
+
]);
|
1268
|
+
const [hoveredColumn, setHoveredColumn] = useState(null);
|
1269
|
+
return (React.createElement(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
|
1270
|
+
dense: density === 'compact',
|
1271
|
+
} },
|
1272
|
+
React.createElement(Box, { sx: {
|
1273
|
+
display: 'flex',
|
1274
|
+
justifyContent: 'space-between',
|
1275
|
+
p: '0.5rem',
|
1276
|
+
pt: 0,
|
1277
|
+
} },
|
1278
|
+
enableHiding && (React.createElement(Button, { disabled: !getIsSomeColumnsVisible(), onClick: hideAllColumns }, localization.hideAll)),
|
1279
|
+
enableColumnOrdering && (React.createElement(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options)) }, localization.resetOrder)),
|
1280
|
+
enablePinning && (React.createElement(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true) }, localization.unpinAll)),
|
1281
|
+
enableHiding && (React.createElement(Button, { disabled: getIsAllColumnsVisible(), onClick: () => toggleAllColumnsVisible(true) }, localization.showAll))),
|
1282
|
+
React.createElement(Divider, null),
|
1283
|
+
allColumns.map((column, index) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, key: `${index}-${column.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
|
1284
|
+
};
|
1285
|
+
|
1294
1286
|
const MRT_ShowHideColumnsButton = (_a) => {
|
1295
1287
|
var _b;
|
1296
1288
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
@@ -1880,7 +1872,7 @@ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
|
|
1880
1872
|
cursor: 'col-resize',
|
1881
1873
|
mr: density === 'compact' ? '-0.75rem' : '-1rem',
|
1882
1874
|
position: 'absolute',
|
1883
|
-
right: '
|
1875
|
+
right: '4px',
|
1884
1876
|
px: '4px',
|
1885
1877
|
'&:active > hr': {
|
1886
1878
|
backgroundColor: theme.palette.info.main,
|
@@ -2024,7 +2016,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
2024
2016
|
theme,
|
2025
2017
|
})), draggingBorders)) }),
|
2026
2018
|
header.isPlaceholder ? null : (React.createElement(Box, { className: "Mui-TableHeadCell-Content", sx: {
|
2027
|
-
alignItems: '
|
2019
|
+
alignItems: 'center',
|
2028
2020
|
display: 'flex',
|
2029
2021
|
flexDirection: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right' ? 'row-reverse' : 'row',
|
2030
2022
|
justifyContent: columnDefType === 'group' || (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
|
@@ -2048,7 +2040,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
2048
2040
|
: undefined,
|
2049
2041
|
} },
|
2050
2042
|
React.createElement(Box, { className: "Mui-TableHeadCell-Content-Wrapper", sx: {
|
2051
|
-
minWidth:
|
2043
|
+
minWidth: `${Math.min(columnDef.header.length, 5)}ch`,
|
2052
2044
|
overflow: columnDefType === 'data' ? 'hidden' : undefined,
|
2053
2045
|
textOverflow: 'ellipsis',
|
2054
2046
|
whiteSpace: ((_d = (_c = columnDef.header) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 20 ? 'nowrap' : 'normal',
|
@@ -2450,7 +2442,12 @@ const MRT_TableDetailPanel = ({ parentRowRef, row, rowIndex, table, virtualRow,
|
|
2450
2442
|
const { getVisibleLeafColumns, getState, options: { layoutMode, muiTableBodyRowProps, muiTableDetailPanelProps, renderDetailPanel, }, } = table;
|
2451
2443
|
const { isLoading } = getState();
|
2452
2444
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
2453
|
-
? muiTableBodyRowProps({
|
2445
|
+
? muiTableBodyRowProps({
|
2446
|
+
isDetailPanel: true,
|
2447
|
+
row,
|
2448
|
+
staticRowIndex: rowIndex,
|
2449
|
+
table,
|
2450
|
+
})
|
2454
2451
|
: muiTableBodyRowProps;
|
2455
2452
|
const tableCellProps = muiTableDetailPanelProps instanceof Function
|
2456
2453
|
? muiTableDetailPanelProps({ row, table })
|