refactor: extract tooltip icon as component

This commit is contained in:
dongchengjie
2024-06-26 08:10:18 +08:00
parent 753395965a
commit c89ccf7185
8 changed files with 66 additions and 112 deletions

View File

@@ -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) => {
<SettingItem
label={t("Tun Mode")}
extra={
<>
<Tooltip title={t("Tun Mode Info")} placement="top">
<IconButton color="inherit" size="small">
<InfoRounded
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
</Tooltip>
<IconButton
color="inherit"
size="small"
onClick={() => tunRef.current?.open()}
>
<Settings
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
</>
<TooltipIcon
title={t("Tun Mode Info")}
icon={Settings}
onClick={() => tunRef.current?.open()}
/>
}
>
<GuardState
@@ -91,16 +76,11 @@ const SettingSystem = ({ onError }: Props) => {
<SettingItem
label={t("Service Mode")}
extra={
<IconButton
color="inherit"
size="small"
<TooltipIcon
title={t("Service Mode Info")}
icon={PrivacyTipRounded}
onClick={() => serviceRef.current?.open()}
>
<PrivacyTipRounded
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
/>
}
>
<GuardState
@@ -124,24 +104,11 @@ const SettingSystem = ({ onError }: Props) => {
label={t("System Proxy")}
extra={
<>
<Tooltip title={t("System Proxy Info")} placement="top">
<IconButton color="inherit" size="small">
<InfoRounded
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
</Tooltip>
<IconButton
color="inherit"
size="small"
<TooltipIcon
title={t("System Proxy Info")}
icon={Settings}
onClick={() => sysproxyRef.current?.open()}
>
<Settings
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
/>
</>
}
>
@@ -172,18 +139,7 @@ const SettingSystem = ({ onError }: Props) => {
<SettingItem
label={t("Silent Start")}
extra={
<>
<Tooltip title={t("Silent Start Info")} placement="top">
<IconButton color="inherit" size="small">
<InfoRounded
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
</Tooltip>
</>
}
extra={<TooltipIcon title={t("Silent Start Info")} />}
>
<GuardState
value={enable_silent_start ?? false}