diff --git a/eslint.config.mjs b/eslint.config.mjs index 097a32f..bcb5fbc 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -17,6 +17,8 @@ export default [ // Base configuration with ignores { ignores: [ + ".media/**", + "coverage/**", ".next/**", "node_modules/**", "out/**", diff --git a/src/components/ThemeToggle.tsx b/src/components/ThemeToggle.tsx index 00c7333..d7b9f2e 100644 --- a/src/components/ThemeToggle.tsx +++ b/src/components/ThemeToggle.tsx @@ -3,7 +3,21 @@ import { useTheme } from "next-themes"; import { IconButton } from "@radix-ui/themes"; import { MoonIcon, SunIcon, DesktopIcon } from "@radix-ui/react-icons"; -import { useEffect, useState } from "react"; +import { useEffect, useState, type ReactElement } from "react"; + +type Theme = "light" | "dark" | "system"; + +const ICON_SIZE = 22; + +const THEME_CONFIG: Record = { + light: { icon: , next: "dark" }, + dark: { icon: , next: "system" }, + system: { icon: , next: "light" }, +}; + +const isTheme = (value: string | undefined): value is Theme => { + return value === "light" || value === "dark" || value === "system"; +}; export const ThemeToggle = () => { const { theme, setTheme } = useTheme(); @@ -18,44 +32,16 @@ export const ThemeToggle = () => { return null; } + const currentTheme: Theme = isTheme(theme) ? theme : "system"; + const { icon, next } = THEME_CONFIG[currentTheme]; + const toggleTheme = () => { - if (theme === "light") { - setTheme("dark"); - } else if (theme === "dark") { - setTheme("system"); - } else { - setTheme("light"); - } + setTheme(next); }; - const getNextTheme = () => { - if (theme === "light") return "dark"; - if (theme === "dark") return "system"; - return "light"; - }; - - const getIcon = () => { - if (theme === "light") { - return ; - } else if (theme === "dark") { - return ; - } else { - return ; - } - }; - - const nextTheme = getNextTheme(); - const themeLabel = theme === "system" ? "system" : theme === "light" ? "light" : "dark"; - return ( - - {getIcon()} + + {icon} ); };