Download src/ThemeToggle.tsx from fffiloni/SimReady-assets-explorer: direct link, hf CLI and curl.
- Browser
- Download file 875 Bytes
-
https://huggingface.co/spaces/fffiloni/SimReady-assets-explorer/resolve/main/src/ThemeToggle.tsx
- Command line
-
hf download hf://spaces/fffiloni/SimReady-assets-explorer/src/ThemeToggle.tsx
-
curl -L -o ThemeToggle.tsx https://huggingface.co/spaces/fffiloni/SimReady-assets-explorer/resolve/main/src/ThemeToggle.tsx
875 Bytes
| import {useLayoutEffect,useState} from 'react'; | |
| import {Moon,Sun} from 'lucide-react'; | |
| export default function ThemeToggle(){ | |
| const [night,setNight]=useState(()=>document.documentElement.dataset.theme==='dark'); | |
| useLayoutEffect(()=>{ | |
| const theme=night?'dark':'light'; | |
| document.documentElement.dataset.theme=theme; | |
| document.querySelector('meta[name="theme-color"]')?.setAttribute('content',night?'#181b24':'#f7f8fc'); | |
| try{localStorage.setItem('openusd-explorer:theme:v1',theme);}catch{/* The switch also works when storage is unavailable. */} | |
| },[night]); | |
| return <button className="icon-button theme-button" aria-label="Night mode" aria-pressed={night} title={night?'Switch to light mode':'Switch to night mode'} onClick={()=>setNight(value=>!value)}> | |
| {night?<Sun size={17} aria-hidden="true"/>:<Moon size={17} aria-hidden="true"/>} | |
| </button>; | |
| } | |