()
| 3 | import { applyTheme, getCurrentTheme } from "~/utils/theme" |
| 4 | |
| 5 | export function ThemeToggle() { |
| 6 | const [theme, setTheme] = useState<"light" | "dark" | null>(null) |
| 7 | |
| 8 | useLayoutEffect(() => { |
| 9 | setTheme(getCurrentTheme()) |
| 10 | }, []) |
| 11 | |
| 12 | const toggle = () => { |
| 13 | if (!theme) return |
| 14 | const next = theme === "dark" ? "light" : "dark" |
| 15 | applyTheme(next) |
| 16 | setTheme(next) |
| 17 | } |
| 18 | |
| 19 | if (theme === null) { |
| 20 | return <IconButton aria-label="Loading theme..." name="SunMoon" /> |
| 21 | } |
| 22 | |
| 23 | const isDarkTheme = theme === "dark" |
| 24 | return ( |
| 25 | <IconButton |
| 26 | aria-label={`Switch to ${isDarkTheme ? "light" : "dark"} mode`} |
| 27 | name={isDarkTheme ? "Moon" : "Sun"} |
| 28 | onClick={toggle} |
| 29 | /> |
| 30 | ) |
| 31 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…