Download studio/src/context/ThemeContext.jsx from shak3008/DiffWeave: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/context/ThemeContext.jsx
- Command line
-
hf download hf://spaces/shak3008/DiffWeave/studio/src/context/ThemeContext.jsx
-
curl -L -o ThemeContext.jsx https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/context/ThemeContext.jsx
1.03 kB
| import React, { createContext, useContext, useEffect, useState } from 'react'; | |
| const ThemeContext = createContext(); | |
| export function ThemeProvider({ children }) { | |
| const [theme, setTheme] = useState(() => { | |
| return localStorage.getItem('diffweave_theme') || 'dark'; | |
| }); | |
| useEffect(() => { | |
| const root = document.documentElement; | |
| if (theme === 'light') { | |
| root.classList.remove('dark'); | |
| root.classList.add('light'); | |
| } else { | |
| root.classList.add('dark'); | |
| root.classList.remove('light'); | |
| } | |
| localStorage.setItem('diffweave_theme', theme); | |
| }, [theme]); | |
| const toggleTheme = () => { | |
| setTheme((prev) => (prev === 'dark' ? 'light' : 'dark')); | |
| }; | |
| return ( | |
| <ThemeContext.Provider value={{ theme, setTheme, toggleTheme }}> | |
| {children} | |
| </ThemeContext.Provider> | |
| ); | |
| } | |
| export const useTheme = () => { | |
| const context = useContext(ThemeContext); | |
| if (!context) { | |
| return { theme: 'dark', setTheme: () => {}, toggleTheme: () => {} }; | |
| } | |
| return context; | |
| }; | |