1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
| import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react'
export type ThemeMode = 'light' | 'dark';
export interface ThemeContextType { theme: ThemeMode; setTheme: (theme: ThemeMode) => void; toggleTheme: () => void; }
const ThemeContext = createContext<ThemeContextType>({ theme: 'light', setTheme: () => { }, toggleTheme: () => { }, });
const lightThemeVars = { '--color-background': '#ffffff', '--color-background-secondary': '#f8f9fa', '--color-text': '#333333', '--color-text-secondary': '#666666', '--color-text-tertiary': '#999999',
'--color-primary': '#3498db', '--color-primary-rgb': '52, 152, 219', '--color-secondary': '#2ecc71', '--color-secondary-rgb': '46, 204, 113', '--color-accent': '#e74c3c', '--color-accent-rgb': '231, 76, 60',
'--color-success': '#2ecc71', '--color-success-rgb': '46, 204, 113', '--color-info': '#3498db', '--color-info-rgb': '52, 152, 219', '--color-warning': '#f39c12', '--color-warning-rgb': '243, 156, 18', '--color-error': '#e74c3c', '--color-error-rgb': '231, 76, 60', '--color-grey': '#7f8c8d', '--color-grey-rgb': '127, 140, 141',
'--color-border': '#e0e0e0', '--shadow-default': '0 2px 5px rgba(0, 0, 0, 0.1)', '--shadow-medium': '0 4px 12px rgba(0, 0, 0, 0.08)', '--shadow-large': '0 8px 20px rgba(0, 0, 0, 0.12)',
'--radius-small': '4px', '--radius-medium': '8px', '--radius-large': '12px', '--radius-pill': '999px',
'--z-index-dropdown': '1000', '--z-index-modal': '1050', '--z-index-tooltip': '1100', };
const darkThemeVars = { '--color-background': '#1e1e1e', '--color-background-secondary': '#2d2d2d', '--color-text': '#f5f5f5', '--color-text-secondary': '#c2c2c2', '--color-text-tertiary': '#999999',
'--color-primary': '#61dafb', '--color-primary-rgb': '97, 218, 251', '--color-secondary': '#4ecca3', '--color-secondary-rgb': '78, 204, 163', '--color-accent': '#ff6b6b', '--color-accent-rgb': '255, 107, 107',
'--color-success': '#4ecca3', '--color-success-rgb': '78, 204, 163', '--color-info': '#61dafb', '--color-info-rgb': '97, 218, 251', '--color-warning': '#ffbe76', '--color-warning-rgb': '255, 190, 118', '--color-error': '#ff6b6b', '--color-error-rgb': '255, 107, 107', '--color-grey': '#a4b0be', '--color-grey-rgb': '164, 176, 190',
'--color-border': '#444444', '--shadow-default': '0 2px 5px rgba(0, 0, 0, 0.3)', '--shadow-medium': '0 4px 12px rgba(0, 0, 0, 0.4)', '--shadow-large': '0 8px 20px rgba(0, 0, 0, 0.5)',
'--radius-small': '4px', '--radius-medium': '8px', '--radius-large': '12px', '--radius-pill': '999px',
'--z-index-dropdown': '1000', '--z-index-modal': '1050', '--z-index-tooltip': '1100', };
interface ThemeProviderProps { initialTheme?: ThemeMode; children: ReactNode; }
export const ThemeProvider: React.FC<ThemeProviderProps> = ({ initialTheme = 'light', children }) => { const [theme, setTheme] = useState<ThemeMode>(() => { if (typeof window !== 'undefined') { const savedTheme = localStorage.getItem('harydhu-theme') as ThemeMode; return savedTheme || initialTheme; } return initialTheme; })
useEffect(() => { if (typeof window != 'undefined') { const themeVars = theme === 'light' ? lightThemeVars : darkThemeVars;
Object.entries(themeVars).forEach(([property, value]) => { document.documentElement.style.setProperty(property, value) });
localStorage.setItem('hardyhu-theme', theme) } }, [theme]);
useEffect(() => { setTheme(initialTheme); }, [initialTheme]);
const toggleTheme = () => { setTheme(prevTheme => (prevTheme === 'light' ? 'dark' : 'light')) };
return ( <ThemeContext.Provider value={{ theme, setTheme, toggleTheme }}> {children} </ThemeContext.Provider> ) }
export const useTheme = (): ThemeContextType => useContext(ThemeContext);
|