Download web/src/lib/theme.ts from Anish-g/btc-intel: direct link, hf CLI and curl.
- Browser
- Download file 767 Bytes
-
https://huggingface.co/spaces/Anish-g/btc-intel/resolve/main/web/src/lib/theme.ts
- Command line
-
hf download hf://spaces/Anish-g/btc-intel/web/src/lib/theme.ts
-
curl -L -o theme.ts https://huggingface.co/spaces/Anish-g/btc-intel/resolve/main/web/src/lib/theme.ts
767 Bytes
| import { useCallback, useEffect, useState } from "react"; | |
| export type Theme = "light" | "dark"; | |
| const KEY = "btc-intel.theme"; | |
| /** Light by default, like the reference site. The choice is written to the | |
| * document element so CSS owns every colour and nothing re-renders. */ | |
| export function useTheme(): [Theme, () => void] { | |
| const [theme, setTheme] = useState<Theme>( | |
| () => (document.documentElement.dataset.theme as Theme) || "light", | |
| ); | |
| useEffect(() => { | |
| document.documentElement.dataset.theme = theme; | |
| try { | |
| localStorage.setItem(KEY, theme); | |
| } catch { | |
| /* private window: the choice simply does not persist */ | |
| } | |
| }, [theme]); | |
| return [theme, useCallback(() => setTheme((t) => (t === "dark" ? "light" : "dark")), [])]; | |
| } | |