feat: dark mode with system preference detection (#104)#375
Open
i010542 wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: dark mode with system preference detection (#104)#375i010542 wants to merge 1 commit intorohitdash08:mainfrom
i010542 wants to merge 1 commit intorohitdash08:mainfrom
Conversation
- Add ThemeProvider context with light/dark/system modes - Persist preference to localStorage with validation - Add FOUC-prevention inline script to index.html - Add ThemeToggle button to Navbar (cycles light->dark->system) - Override all CSS variables for dark theme in index.css - Fix hardcoded bg-white references to use semantic tokens - Add 11 unit tests for useTheme hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Summary
The app lacked a dark mode, making it uncomfortable for users in low-light environments and failing accessibility contrast requirements.
Solution Approach
src/hooks/use-theme.tsx): manageslight | dark | systemmodes, persists tolocalStoragewith validation, listens toprefers-color-schemechangesindex.htmlapplies theme class before React hydration — no flash on page load.dark { ... }override inindex.cssusing a WCAG AA-compliant navy palettearia-labelandfocus-visibleringbg-white/hsl(0 0% 100%)references to use semantic tokensKey Design Decisions
createContext<ThemeContextType | undefined>(undefined)useThemethrows if used outside ProviderparseTheme()validation<body>useMemoon context valueFiles Changed
app/src/hooks/use-theme.tsxapp/src/App.tsxapp/src/index.css.dark { ... }CSS variable overridesapp/src/components/layout/Navbar.tsxapp/index.htmlapp/src/__tests__/useTheme.test.tsxapp/src/__tests__/Navbar.test.tsxTest Evidence
New tests include:
systemdark→ appliesdarkclasslight→ removesdarkclassuseThemeoutside Provider → throws descriptive errorResolves: #104