mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-22 05:23:10 +08:00
refactor(theme): drop unused MouseEvent param from setTheme
Now that the view transition animation is gone, setTheme no longer needs click coordinates. Reduce the API surface to (theme: Theme) => void and simplify the call sites in mode-toggle and ThemeSettings.
This commit is contained in:
@@ -7,13 +7,11 @@ export function ModeToggle() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const toggleTheme = (event: React.MouseEvent) => {
|
||||
// 如果当前是 dark 或 system(且系统是暗色),切换到 light
|
||||
// 否则切换到 dark
|
||||
const toggleTheme = () => {
|
||||
if (theme === "dark") {
|
||||
setTheme("light", event);
|
||||
setTheme("light");
|
||||
} else {
|
||||
setTheme("dark", event);
|
||||
setTheme("dark");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,21 +19,21 @@ export function ThemeSettings() {
|
||||
<div className="inline-flex gap-1 rounded-md border border-border-default bg-background p-1">
|
||||
<ThemeButton
|
||||
active={theme === "light"}
|
||||
onClick={(e) => setTheme("light", e)}
|
||||
onClick={() => setTheme("light")}
|
||||
icon={Sun}
|
||||
>
|
||||
{t("settings.themeLight")}
|
||||
</ThemeButton>
|
||||
<ThemeButton
|
||||
active={theme === "dark"}
|
||||
onClick={(e) => setTheme("dark", e)}
|
||||
onClick={() => setTheme("dark")}
|
||||
icon={Moon}
|
||||
>
|
||||
{t("settings.themeDark")}
|
||||
</ThemeButton>
|
||||
<ThemeButton
|
||||
active={theme === "system"}
|
||||
onClick={(e) => setTheme("system", e)}
|
||||
onClick={() => setTheme("system")}
|
||||
icon={Monitor}
|
||||
>
|
||||
{t("settings.themeSystem")}
|
||||
|
||||
@@ -17,7 +17,7 @@ interface ThemeProviderProps {
|
||||
|
||||
interface ThemeContextValue {
|
||||
theme: Theme;
|
||||
setTheme: (theme: Theme, event?: React.MouseEvent) => void;
|
||||
setTheme: (theme: Theme) => void;
|
||||
}
|
||||
|
||||
const ThemeProviderContext = createContext<ThemeContextValue | undefined>(
|
||||
|
||||
Reference in New Issue
Block a user