From 9179cdfb0c7f205b1361adf760d541e49b612246 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 05:54:09 +0000 Subject: [PATCH] feat: Add ThemeContext for dark/light theme toggle --- frontend/src/contexts/ThemeContext.tsx | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 frontend/src/contexts/ThemeContext.tsx diff --git a/frontend/src/contexts/ThemeContext.tsx b/frontend/src/contexts/ThemeContext.tsx new file mode 100644 index 0000000..6d99c08 --- /dev/null +++ b/frontend/src/contexts/ThemeContext.tsx @@ -0,0 +1,34 @@ +import React, { createContext, useContext, useState, ReactNode } from 'react'; + +interface ThemeContextType { + theme: 'light' | 'dark'; + toggleTheme: () => void; +} + +const ThemeContext = createContext(undefined); + +interface ThemeProviderProps { + children: ReactNode; +} + +export const ThemeProvider: React.FC = ({ children }) => { + const [theme, setTheme] = useState<'light' | 'dark'>('dark'); + + const toggleTheme = () => { + setTheme(prevTheme => prevTheme === 'light' ? 'dark' : 'light'); + }; + + return ( + + {children} + + ); +}; + +export const useTheme = (): ThemeContextType => { + const context = useContext(ThemeContext); + if (!context) { + throw new Error('useTheme must be used within a ThemeProvider'); + } + return context; +}; \ No newline at end of file