feat: add global dark mode toggle via URL flag#1108
Open
TaprootFreak wants to merge 3 commits into
Open
Conversation
Switch Tailwind from media-based to class-based dark mode and add a ThemeContextProvider that reads `?dark=1`, `?dark=0`, `?theme=dark` or `?theme=light` from the URL, persists the choice in localStorage, and toggles the `dark` class on `<html>` and `<body>` so the rest of the app picks it up via Tailwind dark variants and the global CSS overrides in index.css. Dashboard screens (which use inline styles) consume the new theme tokens and forward an `isDark` flag to the chart components so Apex charts render with the correct theme. The Financial Overview page continues to render dark by default (admin-internal page) but now integrates cleanly with the global theme. The flag is intended for internal use only — there is no UI toggle. Activate dark mode by appending `?dark=1` or `?theme=dark` to any URL, deactivate with `?dark=0` or `?theme=light`. The param is stripped after consumption.
Replaces a weak cleanup test that only asserted the dark class was present with a proper setDark round-trip test that verifies state, dom classes (html + body), and localStorage all flip in both directions.
Use createContext<ThemeContextInterface | undefined>(undefined) and throw a clear error when consumed outside ThemeContextProvider. Removes the unsafe undefined as any cast and gives developers an actionable failure mode.
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.
Summary
darkMode: 'media'(system-preference) to'class'so dark mode is opt-in via JavaScript instead of OS-driven.ThemeContextProviderreads?dark=1/?dark=0(also?theme=dark/?theme=light) from the URL on mount, persists the choice inlocalStorageunderdfx.srv.darkMode, and toggles adarkclass on<html>and<body>. The flag is stripped from the URL after consumption.html.dark/body.darkflip the background to#072440(dfxBlue.800) so library components (Buy/Sell/Swap/KYC/Compliance/etc.) inherit a dark surface even without per-componentdark:variants.useThemeContext()and forward anisDarkflag to the dashboard chart components so ApexCharts pick up the dark theme. The Financial Overview page keeps its always-dark rendering and now integrates cleanly with the global theme.The flag is intentionally URL-only — no UI toggle is exposed yet (internal/staging use).
Activation
?dark=1?theme=dark?dark=0?theme=lightOnce set, the choice persists across navigations and reloads via
localStorage. The param itself is removed from the URL on consumption.Files
tailwind.config.js—darkMode: 'media'->'class'src/index.css—html.dark/body.darkbackground + dark-aware.scroll-shadowsrc/contexts/theme.context.tsx(new) — provider, hook, light/dark token palettesrc/hooks/store.hook.ts— newdarkModestorage entrysrc/App.tsx— wrap routes inThemeContextProvidersrc/screens/dashboard*.screen.tsx— consume theme tokens, forwardisDarkto chartssrc/components/dashboard/{financial-changes,balance-by-type-area,total-balance-short}-chart.tsx— acceptdarkprop, switch Apex theme + grid colorsrc/__tests__/theme.context.test.tsx(new), extendedstore.hook.test.tsTest plan
npm run lintcleannpm run test— 298/298 passing (incl. new theme.context test suite)npm run build:devsucceeds (only pre-existing source-map warnings from@dfx.swiss/core)https://services.dfx.swiss/?dark=1, verify whole app renders dark and URL param is stripped?dark=0— switches back to light