diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index ec8f2aa0..eeb65993 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -18,6 +18,7 @@ import { useTranslation } from "react-i18next"; import { ScrollTopButton } from "../layout/scroll-top-button"; import { Box, styled } from "@mui/material"; import { memo } from "react"; +import { createPortal } from "react-dom"; // 将选择器组件抽离出来,避免主组件重渲染时重复创建样式 const AlphabetSelector = styled(Box)(({ theme }) => ({ @@ -30,10 +31,25 @@ const AlphabetSelector = styled(Box)(({ theme }) => ({ background: "transparent", zIndex: 1000, gap: "2px", - padding: "8px 4px", - willChange: "transform", // 优化动画性能 + // padding: "4px 2px", + willChange: "transform", + "&:hover": { + background: theme.palette.background.paper, + boxShadow: theme.shadows[2], + borderRadius: "8px", + }, + "& .scroll-container": { + overflow: "hidden", + maxHeight: "inherit", + }, + "& .letter-container": { + display: "flex", + flexDirection: "column", + gap: "2px", + transition: "transform 0.2s ease", + }, "& .letter": { - padding: "2px 4px", + padding: "1px 4px", fontSize: "12px", cursor: "pointer", fontFamily: @@ -45,52 +61,40 @@ const AlphabetSelector = styled(Box)(({ theme }) => ({ display: "flex", alignItems: "center", justifyContent: "center", - transition: "all 0.15s cubic-bezier(0.34, 1.56, 0.64, 1)", // 稍微加快动画速度 - transform: "scale(1) translateZ(0)", // 开启GPU加速 - backfaceVisibility: "hidden", // 防止闪烁 + transition: "all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1)", + transform: "scale(1) translateZ(0)", + backfaceVisibility: "hidden", borderRadius: "6px", "&:hover": { color: theme.palette.primary.main, - transform: "scale(1.2) translateZ(0)", + transform: "scale(1.4) translateZ(0)", backgroundColor: theme.palette.action.hover, - "& .tooltip": { - opacity: 1, - transform: "translateX(0) translateZ(0)", - visibility: "visible", - }, - }, - "&:hover ~ .letter": { - transform: "translateY(2px) translateZ(0)", }, }, - "& .tooltip": { +})); + +// 创建一个单独的 Tooltip 组件 +const Tooltip = styled("div")(({ theme }) => ({ + position: "fixed", + background: theme.palette.background.paper, + padding: "4px 8px", + borderRadius: "6px", + boxShadow: theme.shadows[3], + whiteSpace: "nowrap", + fontSize: "16px", + color: theme.palette.text.primary, + pointerEvents: "none", + "&::after": { + content: '""', position: "absolute", - right: "calc(100% + 8px)", - background: theme.palette.background.paper, - padding: "4px 8px", - borderRadius: "6px", - boxShadow: theme.shadows[3], - whiteSpace: "nowrap", - opacity: 0, - visibility: "hidden", - transform: "translateX(4px) translateZ(0)", - transition: "all 0.15s cubic-bezier(0.34, 1.56, 0.64, 1)", - fontSize: "12px", - color: theme.palette.text.primary, - pointerEvents: "none", - backfaceVisibility: "hidden", - "&::after": { - content: '""', - position: "absolute", - right: "-4px", - top: "50%", - transform: "translateY(-50%)", - width: 0, - height: 0, - borderTop: "4px solid transparent", - borderBottom: "4px solid transparent", - borderLeft: `4px solid ${theme.palette.background.paper}`, - }, + right: "-4px", + top: "50%", + transform: "translateY(-50%)", + width: 0, + height: 0, + borderTop: "4px solid transparent", + borderBottom: "4px solid transparent", + borderLeft: `4px solid ${theme.palette.background.paper}`, }, })); @@ -104,12 +108,56 @@ const LetterItem = memo( name: string; onClick: (name: string) => void; getFirstChar: (str: string) => string; - }) => ( -