From c89ccf7185858128b825cbe930f74d97dbb6db0c Mon Sep 17 00:00:00 2001 From: dongchengjie <37543964+dongchengjie@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:10:18 +0800 Subject: [PATCH] refactor: extract tooltip icon as component --- src/components/base/base-tooltip-icon.tsx | 24 ++++++ .../setting/mods/sysproxy-viewer.tsx | 10 +-- src/components/setting/setting-clash.tsx | 62 +++++---------- src/components/setting/setting-system.tsx | 76 ++++--------------- src/locales/en.json | 1 + src/locales/fa.json | 1 + src/locales/ru.json | 1 + src/locales/zh.json | 3 +- 8 files changed, 66 insertions(+), 112 deletions(-) create mode 100644 src/components/base/base-tooltip-icon.tsx diff --git a/src/components/base/base-tooltip-icon.tsx b/src/components/base/base-tooltip-icon.tsx new file mode 100644 index 00000000..99cb15c8 --- /dev/null +++ b/src/components/base/base-tooltip-icon.tsx @@ -0,0 +1,24 @@ +import { + Tooltip, + IconButton, + IconButtonProps, + SvgIconProps, +} from "@mui/material"; +import { InfoRounded } from "@mui/icons-material"; + +interface Props extends IconButtonProps { + title?: string; + icon?: React.ElementType; +} + +export const TooltipIcon: React.FC = (props: Props) => { + const { title = "", icon: Icon = InfoRounded } = props; + + return ( + + + + + + ); +}; diff --git a/src/components/setting/mods/sysproxy-viewer.tsx b/src/components/setting/mods/sysproxy-viewer.tsx index de3c7f0c..c0459c5b 100644 --- a/src/components/setting/mods/sysproxy-viewer.tsx +++ b/src/components/setting/mods/sysproxy-viewer.tsx @@ -20,6 +20,7 @@ import { Edit } from "@mui/icons-material"; import { EditorViewer } from "@/components/profile/editor-viewer"; import { BaseFieldset } from "@/components/base/base-fieldset"; import getSystem from "@/utils/get-system"; +import { TooltipIcon } from "@/components/base/base-tooltip-icon"; const DEFAULT_PAC = `function FindProxyForURL(url, host) { return "PROXY 127.0.0.1:%mixed-port%; SOCKS5 127.0.0.1:%mixed-port%; DIRECT;"; }`; @@ -170,14 +171,7 @@ export const SysproxyViewer = forwardRef((props, ref) => { primary={t("Proxy Guard")} sx={{ maxWidth: "fit-content" }} /> - - - - - + { - { - Notice.success( - t("Restart Application to Apply Modifications"), - 1000 - ); - onChangeVerge({ enable_random_port: !enable_random_port }); - patchVerge({ enable_random_port: !enable_random_port }); - }} - > - - - + { + Notice.success( + t("Restart Application to Apply Modifications"), + 1000 + ); + onChangeVerge({ enable_random_port: !enable_random_port }); + patchVerge({ enable_random_port: !enable_random_port }); + }} + /> } > { coreRef.current?.open()} - > - - + /> } > {version} @@ -179,18 +166,7 @@ const SettingClash = ({ onError }: Props) => { - - - - - - - } + extra={} /> )} diff --git a/src/components/setting/setting-system.tsx b/src/components/setting/setting-system.tsx index 433f3bb8..41546d3d 100644 --- a/src/components/setting/setting-system.tsx +++ b/src/components/setting/setting-system.tsx @@ -1,8 +1,7 @@ import useSWR from "swr"; import { useRef } from "react"; import { useTranslation } from "react-i18next"; -import { IconButton, Tooltip } from "@mui/material"; -import { PrivacyTipRounded, Settings, InfoRounded } from "@mui/icons-material"; +import { PrivacyTipRounded, Settings } from "@mui/icons-material"; import { checkService } from "@/services/cmds"; import { useVerge } from "@/hooks/use-verge"; import { DialogRef, Switch } from "@/components/base"; @@ -11,6 +10,7 @@ import { GuardState } from "./mods/guard-state"; import { ServiceViewer } from "./mods/service-viewer"; import { SysproxyViewer } from "./mods/sysproxy-viewer"; import { TunViewer } from "./mods/tun-viewer"; +import { TooltipIcon } from "@/components/base/base-tooltip-icon"; interface Props { onError?: (err: Error) => void; @@ -54,26 +54,11 @@ const SettingSystem = ({ onError }: Props) => { - - - - - - tunRef.current?.open()} - > - - - + tunRef.current?.open()} + /> } > { serviceRef.current?.open()} - > - - + /> } > { label={t("System Proxy")} extra={ <> - - - - - - sysproxyRef.current?.open()} - > - - + /> } > @@ -172,18 +139,7 @@ const SettingSystem = ({ onError }: Props) => { - - - - - - - } + extra={} >