Repository navigation
Add dark mode that follows the system theme #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51d16b0
Respect system dark mode while retaining the current design.
euxaristia 069d0e0
theme: class-based dark default with an animated toggle, light behind it
Vasanthdev2004 9b542e9
theme: light stays the shipped Clear Sky palette and the default; dar…
kevincodex1 f6bccea
chart: volume bar colours as rgba, not color-mix()
kevincodex1 1a5b3bc
chart: light gridlines and initial fit restored
kevincodex1 e39d1f6
theme: pre-CSS colour hints stay light as on main; theme-color follow…
kevincodex1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect } from "react"; | ||
| import { ThemeProvider as NextThemes, useTheme } from "next-themes"; | ||
|
|
||
| const THEME_COLOR = { light: "#FAFAF8", dark: "#000000" } as const; | ||
|
|
||
| /** Keeps the browser chrome (mobile address bar, PWA title bar) in step with the toggled theme. */ | ||
| function ThemeColorSync() { | ||
| const { resolvedTheme } = useTheme(); | ||
| useEffect(() => { | ||
| const meta = document.querySelector<HTMLMetaElement>('meta[name="theme-color"]'); | ||
| if (meta) meta.content = resolvedTheme === "dark" ? THEME_COLOR.dark : THEME_COLOR.light; | ||
| }, [resolvedTheme]); | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Light by default (the shipped design) with an explicit dark option behind the | ||
| * header toggle. Two states, stored as "light" | "dark"; the OS preference is | ||
| * not consulted so the first paint matches what everyone has seen so far. | ||
| * | ||
| * Class-based: Tailwind's dark variant resolves against `.dark` on <html> | ||
| * (see @custom-variant at the top of globals.css). | ||
| * | ||
| * Deliberately NO `value` mapping. next-themes writes `light` or `dark`, while | ||
| * the animated toggler flips only `dark` — so mid-toggle you briefly get | ||
| * `class="light dark"`. That renders correctly because light is the UNCLASSED | ||
| * base and there is no `.light` rule: `dark` present wins, `dark` absent falls | ||
| * back to light, and the stray `light` class is inert. (Mapping light to "" | ||
| * would be the tidier model, but next-themes calls classList.remove(value) and | ||
| * throws on an empty token.) | ||
| */ | ||
| export default function ThemeProvider({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <NextThemes attribute="class" defaultTheme="light" enableSystem={false} disableTransitionOnChange> | ||
| <ThemeColorSync /> | ||
| {children} | ||
| </NextThemes> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Enable system theme resolution in
NextThemesNextThemesinjects a pre-hydration script, butenableSystem={false}disables system resolution. WithdefaultTheme="light", dark-preference users render light on first load, and later OS changes do not update the class. SetdefaultTheme="system"andenableSystem={true}. KeepThemeColorSyncso browser metadata follows the resolved theme after hydration.🤖 Prompt for AI Agents