2026-01-22 16:23:11 +00:00
|
|
|
import { createContext, useContext, useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
export type Theme = 'dark' | 'light' | 'system';
|
|
|
|
|
|
|
|
|
|
type ThemeProviderProps = {
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
defaultTheme?: Theme;
|
|
|
|
|
storageKey?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ThemeProviderState = {
|
|
|
|
|
theme: Theme;
|
|
|
|
|
setTheme: (theme: Theme) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const initialState: ThemeProviderState = {
|
|
|
|
|
theme: 'system',
|
|
|
|
|
setTheme: () => null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ThemeContext = createContext<ThemeProviderState>(initialState);
|
|
|
|
|
|
|
|
|
|
export function ThemeProvider({
|
|
|
|
|
children,
|
|
|
|
|
defaultTheme = 'system',
|
|
|
|
|
storageKey = 'vite-ui-theme',
|
|
|
|
|
}: ThemeProviderProps) {
|
|
|
|
|
const [theme, setTheme] = useState<Theme>(
|
|
|
|
|
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const root = window.document.documentElement;
|
|
|
|
|
|
refactor: Phase 1 — SUMI token foundation
- Rewrite index.css with complete SUMI token system (dark + light themes)
- All --sumi-* variables: backgrounds, surfaces, borders, text, pigments,
spacing, radius, shadows, glass, scrollbar, motion, z-index, layout
- shadcn/Radix semantic mapping (--background, --foreground, etc.)
- Tailwind @theme mapping with new fonts (Inter, Space Grotesk, JetBrains Mono)
- SUMI keyframe animations (sumi-fade-in, sumi-slide-up, sumi-scale-in, etc.)
- Delete 11 redundant CSS files (design-system.css, design-tokens.css,
button.css, card.css, input.css, badge-avatar.css, header.css,
fix-input-focus.css, fix-login-form.css, visual-enhancements.css,
premium-utilities.css)
- Update main.tsx: single CSS import (index.css only)
- Update ThemeProvider: data-theme attribute instead of .dark class toggle
- Update index.html FOUC script: data-theme attribute
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 00:48:01 +00:00
|
|
|
// SUMI: Use data-theme attribute instead of class toggle
|
2026-01-22 16:23:11 +00:00
|
|
|
if (theme === 'system') {
|
|
|
|
|
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)')
|
|
|
|
|
.matches
|
|
|
|
|
? 'dark'
|
|
|
|
|
: 'light';
|
|
|
|
|
|
refactor: Phase 1 — SUMI token foundation
- Rewrite index.css with complete SUMI token system (dark + light themes)
- All --sumi-* variables: backgrounds, surfaces, borders, text, pigments,
spacing, radius, shadows, glass, scrollbar, motion, z-index, layout
- shadcn/Radix semantic mapping (--background, --foreground, etc.)
- Tailwind @theme mapping with new fonts (Inter, Space Grotesk, JetBrains Mono)
- SUMI keyframe animations (sumi-fade-in, sumi-slide-up, sumi-scale-in, etc.)
- Delete 11 redundant CSS files (design-system.css, design-tokens.css,
button.css, card.css, input.css, badge-avatar.css, header.css,
fix-input-focus.css, fix-login-form.css, visual-enhancements.css,
premium-utilities.css)
- Update main.tsx: single CSS import (index.css only)
- Update ThemeProvider: data-theme attribute instead of .dark class toggle
- Update index.html FOUC script: data-theme attribute
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 00:48:01 +00:00
|
|
|
root.setAttribute('data-theme', systemTheme);
|
2026-01-22 16:23:11 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
refactor: Phase 1 — SUMI token foundation
- Rewrite index.css with complete SUMI token system (dark + light themes)
- All --sumi-* variables: backgrounds, surfaces, borders, text, pigments,
spacing, radius, shadows, glass, scrollbar, motion, z-index, layout
- shadcn/Radix semantic mapping (--background, --foreground, etc.)
- Tailwind @theme mapping with new fonts (Inter, Space Grotesk, JetBrains Mono)
- SUMI keyframe animations (sumi-fade-in, sumi-slide-up, sumi-scale-in, etc.)
- Delete 11 redundant CSS files (design-system.css, design-tokens.css,
button.css, card.css, input.css, badge-avatar.css, header.css,
fix-input-focus.css, fix-login-form.css, visual-enhancements.css,
premium-utilities.css)
- Update main.tsx: single CSS import (index.css only)
- Update ThemeProvider: data-theme attribute instead of .dark class toggle
- Update index.html FOUC script: data-theme attribute
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 00:48:01 +00:00
|
|
|
root.setAttribute('data-theme', theme);
|
2026-01-22 16:23:11 +00:00
|
|
|
}, [theme]);
|
|
|
|
|
|
|
|
|
|
// Listen for system changes when theme is 'system'
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (theme !== 'system') return;
|
|
|
|
|
|
|
|
|
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
|
|
|
|
|
|
const handleChange = () => {
|
|
|
|
|
const root = window.document.documentElement;
|
refactor: Phase 1 — SUMI token foundation
- Rewrite index.css with complete SUMI token system (dark + light themes)
- All --sumi-* variables: backgrounds, surfaces, borders, text, pigments,
spacing, radius, shadows, glass, scrollbar, motion, z-index, layout
- shadcn/Radix semantic mapping (--background, --foreground, etc.)
- Tailwind @theme mapping with new fonts (Inter, Space Grotesk, JetBrains Mono)
- SUMI keyframe animations (sumi-fade-in, sumi-slide-up, sumi-scale-in, etc.)
- Delete 11 redundant CSS files (design-system.css, design-tokens.css,
button.css, card.css, input.css, badge-avatar.css, header.css,
fix-input-focus.css, fix-login-form.css, visual-enhancements.css,
premium-utilities.css)
- Update main.tsx: single CSS import (index.css only)
- Update ThemeProvider: data-theme attribute instead of .dark class toggle
- Update index.html FOUC script: data-theme attribute
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 00:48:01 +00:00
|
|
|
root.setAttribute('data-theme', mediaQuery.matches ? 'dark' : 'light');
|
2026-01-22 16:23:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mediaQuery.addEventListener('change', handleChange);
|
|
|
|
|
return () => mediaQuery.removeEventListener('change', handleChange);
|
|
|
|
|
}, [theme]);
|
|
|
|
|
|
|
|
|
|
const value = {
|
|
|
|
|
theme,
|
|
|
|
|
setTheme: (theme: Theme) => {
|
|
|
|
|
localStorage.setItem(storageKey, theme);
|
|
|
|
|
setTheme(theme);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-12 23:32:08 +00:00
|
|
|
<ThemeContext.Provider value={value}>
|
2026-01-22 16:23:11 +00:00
|
|
|
{children}
|
|
|
|
|
</ThemeContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useTheme = () => {
|
|
|
|
|
const context = useContext(ThemeContext);
|
|
|
|
|
|
|
|
|
|
if (context === undefined)
|
|
|
|
|
throw new Error('useTheme must be used within a ThemeProvider');
|
|
|
|
|
|
|
|
|
|
return context;
|
|
|
|
|
};
|