You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement a comprehensive dark mode theme toggle to provide users with a comfortable viewing experience in low-light conditions. The feature will include a theme switcher in the navbar, persist user preferences in localStorage, respect system settings, and ensure all UI components are properly styled for both light and dark themes.
Current State
The application currently supports only a light theme with hardcoded colors throughout 30+ CSS files. There is no theme management system, and users cannot switch between light and dark modes. This affects:
All page components (Home, Games, Activities, Favorites)
13 game components
9 activity components
Card components and common UI elements
Layout and navigation components
Proposed Solution
Implement a theme system using React Context API combined with CSS custom properties (variables) for scalable and maintainable theme management.
Automatic detection of system preference (prefers-color-scheme)
Persist user preference in localStorage
Smooth transitions between themes (0.3s ease)
WCAG AA compliant color contrasts
No additional npm packages required
Technical Implementation
Step 1: Create Theme Context
Create src/context/ThemeContext.js:
importReact,{createContext,useContext,useEffect,useState}from'react';constThemeContext=createContext();exportconstuseTheme=()=>{constcontext=useContext(ThemeContext);if(!context)thrownewError('useTheme must be used within ThemeProvider');returncontext;};exportconstThemeProvider=({ children })=>{const[theme,setTheme]=useState(()=>{constsavedTheme=localStorage.getItem('acm-fun-theme');if(savedTheme)returnsavedTheme;if(window.matchMedia('(prefers-color-scheme: dark)').matches){return'dark';}return'light';});useEffect(()=>{document.documentElement.setAttribute('data-theme',theme);localStorage.setItem('acm-fun-theme',theme);},[theme]);useEffect(()=>{constmediaQuery=window.matchMedia('(prefers-color-scheme: dark)');consthandleChange=(e)=>{if(!localStorage.getItem('acm-fun-theme')){setTheme(e.matches ? 'dark' : 'light');}};mediaQuery.addEventListener('change',handleChange);return()=>mediaQuery.removeEventListener('change',handleChange);},[]);consttoggleTheme=()=>{setTheme(prevTheme=>prevTheme==='light' ? 'dark' : 'light');};return(<ThemeContext.Providervalue={{ theme, toggleTheme }}>{children}</ThemeContext.Provider>);};
Respects system dark mode preference on first visit
All text readable in both modes
No color contrast issues
Works on Chrome, Firefox, Safari, Edge
Keyboard accessible (Tab + Enter/Space)
Mobile-friendly toggle button
Automated Tests
describe('ThemeContext',()=>{test('toggles theme from light to dark',()=>{const{ result }=renderHook(()=>useTheme(),{wrapper: ThemeProvider});act(()=>result.current.toggleTheme());expect(result.current.theme).toBe('dark');});test('persists theme to localStorage',()=>{const{ result }=renderHook(()=>useTheme(),{wrapper: ThemeProvider});act(()=>result.current.toggleTheme());expect(localStorage.getItem('acm-fun-theme')).toBe('dark');});});
Implement a comprehensive dark mode theme toggle to provide users with a comfortable viewing experience in low-light conditions. The feature will include a theme switcher in the navbar, persist user preferences in localStorage, respect system settings, and ensure all UI components are properly styled for both light and dark themes.
Current State
The application currently supports only a light theme with hardcoded colors throughout 30+ CSS files. There is no theme management system, and users cannot switch between light and dark modes. This affects:
Proposed Solution
Implement a theme system using React Context API combined with CSS custom properties (variables) for scalable and maintainable theme management.
Architecture:
Key Features:
Technical Implementation
Step 1: Create Theme Context
Create
src/context/ThemeContext.js:Step 2: Define CSS Variables
Create
src/styles/themes.css:Step 3: Create Theme Toggle Component
Create
src/components/common/ThemeToggle.jsandThemeToggle.css:Step 4: Integrate into App
Update
src/App.js:Update
src/components/common/Navbar.jsto include<ThemeToggle />.Step 5: Migrate CSS Files
Replace all hardcoded colors with CSS variables. Example:
Before:
After:
Component Migration Checklist
Layout (Priority 1):
src/App.csssrc/components/common/Navbar.js+ CSSPages (Priority 2):
Cards (Priority 3):
Games (Priority 4):
Activities (Priority 5):
Testing Requirements
Manual Testing
Automated Tests
Accessibility Requirements (WCAG 2.1 AA)
Success Criteria
Must Have:
Should Have:
Browser Support
Minimum Requirements:
Fallback: For browsers without CSS Variables support (< 1% users), display in light mode only.
Performance Considerations
Targets:
Color Palette
Light Theme:
Dark Theme:
All color combinations meet WCAG AA standards (contrast ratios 4.5:1+).
Known Limitations
References
Need Help Implementing This?
I can assist with the implementation in the following ways:
Option 1: Full Implementation Support
I can help you implement the entire feature step-by-step:
Option 2: Guided Implementation
I can guide you through the implementation:
Option 3: Specific Component Help
Need help with specific parts:
Getting Started
If you'd like assistance, I can:
Just let me know which approach works best for you, or if you'd like me to start with creating the foundation files!
Related Issues