feat: add dark mode and theme switching support#6766
Open
Ansita20 wants to merge 1 commit into
Open
Conversation
Signed-off-by: ansita20 <ansitasingh20@gmail.com>
66afaa0 to
bc61417
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds dark mode support with centralized theme state management, persistence, and a header toggle, plus a dev proxy tweak for auth endpoints.
Changes:
- Introduces a
ThemeContextprovider/hook to manage light/dark mode with persistence and system preference support. - Splits MUI theme into
lightTheme/darkThemeand adds aThemeTogglein the header. - Updates dev webpack proxy to include
/authroutes.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| web/webpack.config.dev.js | Proxies /auth alongside /api for dev auth routing. |
| web/src/theme.ts | Adds light/dark theme variants and a helper to select by mode. |
| web/src/index.tsx | Switches app wiring to use the custom ThemeProvider (context-managed). |
| web/src/contexts/ThemeContext.tsx | New context/provider implementing theme mode, persistence, and system detection. |
| web/src/components/theme/ThemeToggle.tsx | New header-friendly theme toggle button component. |
| web/src/components/header/index.tsx | Adds the toggle to the header actions area. |
| web/package.json | Adds ajv and ajv-keywords dependencies. |
Comment on lines
+49
to
+67
| // Persist theme mode to localStorage | ||
| useEffect(() => { | ||
| localStorage.setItem(THEME_STORAGE_KEY, mode); | ||
| // Update HTML attribute for CSS-based styling if needed | ||
| if (typeof window !== "undefined") { | ||
| document.documentElement.setAttribute("data-theme", mode); | ||
| } | ||
| }, [mode]); | ||
|
|
||
| // Listen to system theme changes | ||
| useEffect(() => { | ||
| const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); | ||
| const handleChange = (e: MediaQueryListEvent) => { | ||
| const stored = localStorage.getItem(THEME_STORAGE_KEY); | ||
| // Only update if user hasn't explicitly set a preference | ||
| if (!stored) { | ||
| setMode(e.matches ? "dark" : "light"); | ||
| } | ||
| }; |
Comment on lines
+59
to
+71
| useEffect(() => { | ||
| const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); | ||
| const handleChange = (e: MediaQueryListEvent) => { | ||
| const stored = localStorage.getItem(THEME_STORAGE_KEY); | ||
| // Only update if user hasn't explicitly set a preference | ||
| if (!stored) { | ||
| setMode(e.matches ? "dark" : "light"); | ||
| } | ||
| }; | ||
|
|
||
| mediaQuery.addEventListener("change", handleChange); | ||
| return () => mediaQuery.removeEventListener("change", handleChange); | ||
| }, []); |
|
|
||
| return ( | ||
| <Tooltip title={`Switch to ${mode === "light" ? "dark" : "light"} mode`}> | ||
| <IconButton onClick={toggleTheme} size="small" color="inherit"> |
Comment on lines
+99
to
+102
| export const useTheme = (): ThemeContextType => { | ||
| const context = useContext(ThemeContext); | ||
| if (context === undefined) { | ||
| throw new Error("useTheme must be used within a ThemeProvider"); |
Comment on lines
+38
to
+39
| "ajv": "^8.20.0", | ||
| "ajv-keywords": "^5.1.0", |
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.
Pull Request: Implement Dark Mode Theme Switching
Overview
This PR adds comprehensive dark mode support to the PipeCD web application with a centralized theme management system, automatic system preference detection, and localStorage persistence.
Changes Made
New Files Created
1. web/src/contexts/ThemeContext.tsx
ThemeContextwith TypeScript supportThemeProvidercomponent that wraps the appuseTheme()hook for accessing theme stateprefers-color-schemepipecd-theme-mode2. web/src/components/theme/ThemeToggle.tsx
ThemeTogglecomponentModified Files
1. web/src/theme.ts
lightThemeobject with light color palettedarkThemeobject with dark color palettegetTheme()helper function for dynamic theme selectioncommonComponentsconstantthemeexport2. web/src/index.tsx
ThemeProviderwith customThemeProviderfrom ThemeContextCssBaselineimport (now handled by ThemeContext)ThemeProviderfrom contexts3. web/src/components/header/index.tsx
import ThemeToggle from "~/components/theme/ThemeToggle";<ThemeToggle />component in the header's right-side action box4. web/webpack.config.dev.js
/authto proxy context alongside/apiCannot POST /auth/loginerror during local developmentTechnical Details
Theme Architecture
Data Flow
toggleTheme()updates state in ThemeContextgetTheme()returns appropriate MUI themedata-themeattribute updated for CSS hooksBrowser API Usage
localStoragefor persistencewindow.matchMedia('(prefers-color-scheme: dark)')for system detectiondocument.documentElement.setAttribute('data-theme', mode)for CSS integrationTesting Checklist
/authproxy works in dev environmentBrowser Compatibility
Performance Impact
Accessibility
Documentation
Usage for Developers
For End Users
Breaking Changes
None. The
themeexport fromtheme.tsis maintained for backward compatibility.Related Issues
Closes #[Issue Number - Dark Mode Support]
Screenshots
Reviewers
@pipe-cd/maintainers
Deployment Notes
Future Improvements
fixes issue : #6765