Repository navigation
refactor(ui): unify dark mode across Ladle and components - #20
Merged
Merged
Conversation
useTheme now derives the theme by observing the <html> class with useSyncExternalStore (MutationObserver), instead of per-component useState plus a dependency-less effect that rewrote the class on every render. The root class becomes the single source of truth that NextUI, Tailwind, and the Mapbox basemap all read, so a change made anywhere (ThemeSwitch, the Ladle toggle) propagates to every consumer. Add initTheme() to apply the persisted/default theme to the root class once at startup, wired into App's mount effect (standalone + widget). Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The decorator now reads useLadleContext().globalState.theme and maps it onto the root light/dark class (resolving 'auto' against the OS, tracked live). Since useTheme observes that class, flipping Ladle's toggle re-themes every story including the Mapbox basemap. Drop the forced `light` class and the hardcoded `bg-white`/`text-gray-900` canvas in favor of `bg-background text-foreground`. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Dark mode is now driven by Ladle's own theme toggle (whole canvas), so the per-story `<StorySection theme="dark" title="Dark Surface">` blocks are redundant. Remove them from all 18 stories, drop the orphaned `text-white` override and now-unused imports, reword the three docstrings that referenced the dark surface, and swap a stray `text-gray-500` for the semantic `text-default-500` in the EventTime story. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Remove the `theme` prop and all `theme === 'dark'` branches now that the canvas theme comes from Ladle's toggle. Re-express chrome with NextUI semantic tokens (text-foreground / text-default-600 / text-default-500 / border-divider / border-default-200) so it reads in both themes, and make the neutral (bg-default-100) and brand-teal gradient context backgrounds theme-aware. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Visual verification (Ladle, both themes) confirmed the white cluster count and the debug-only #888 bounds line read on both basemaps once the basemap follows the theme toggle, so they're left as-is with a comment explaining why. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Post-review refinements: - use-theme: drop premature useCallback wrappers; export a single shared applyTheme() seam for writing the root class. - Ladle decorator reuses applyTheme() instead of duplicating the class-toggle logic. - Move initTheme() out of App's mount effect to the entry points (main.tsx module scope, Widget.tsx body) so the persisted theme is set before first paint — no flash — matching the existing pre-render setup in those files. - Let the Ladle story canvas fall back to Ladle's own theme background (drop the forced bg-background; keep text-foreground) per feedback. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying atlas-legacy with
|
| Latest commit: |
b847ee5
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bd21b993.syatlas.pages.dev |
| Branch Preview URL: | https://refactor-unify-dark-mode.syatlas.pages.dev |
localStorage can throw (not just be absent) in sandboxed iframes and some privacy modes — relevant since this ships as an embeddable widget. Wrap reads/writes so applyTheme still updates the root class when storage is unavailable (the choice just isn't persisted), and fix initTheme's guard, which previously only handled a missing localStorage, not one that throws on access. Adds a co-located node-only test for applyTheme/initTheme. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The gradient background is a fixed dark teal; without a pinned text color its children inherited text-foreground, which is dark in light mode — dark-on-dark. Pin white text so the (currently unused) gradient surface reads in both themes, matching its comment. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
NextUI's themes.<name>.extend takes a base-theme *name* (a string), so nesting `colors` under `dark.extend` silently dropped the custom dark palette — dark mode fell back to NextUI's default blue/purple instead of the brand orange/teal. Move colors to the theme level (mirroring the light theme) and drop the invalid borderColor/backgroundColor keys (never read by NextUI). This exposes that our `*-100` shades are fixed light tints, so the EventDetails month-label `bg-primary-100` strip would render light-on- light in dark; give it a dark brand surface there (dark:bg-primary-900) so its text stays high-contrast. Verified both themes in Ladle. Refs #18 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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
Unifies dark mode so a single signal — the root
<html>class — drives NextUI, Tailwind, and the Mapbox basemap, and lets Ladle's own theme toggle re-theme the entire story canvas.useThemenow observes the root class (viauseSyncExternalStore+MutationObserver) instead of giving each component its ownuseStateplus a per-render class write. A theme change made anywhere (ThemeSwitch, the Ladle toggle) propagates to every consumer — including the map basemap, which previously could not follow an externally-set theme.<StorySection theme="dark">"Dark Surface" blocks (18 stories) are removed along with thethemeprop onStorySection, whose chrome is now expressed in NextUI semantic tokens so it reads in both themes.Changes
src/hooks/use-theme.ts— reactive, root-class-derived theme; exportsapplyTheme()(the single class-writing seam) andinitTheme()(startup restore). No more dependency-less per-render class write.src/main.tsx,src/Widget.tsx— callinitTheme()before first paint (no flash);App.tsxno longer inits..ladle/components.tsx— decorator mapsuseLadleContext().globalState.themeonto the root class throughapplyTheme()(resolvesautoviamatchMedia, tracked live); canvas defers its background to Ladle's own theme.src/components/ladle/StorySection.tsx— drops thethemeprop and alltheme === 'dark'branches; semantic-token chrome; theme-awareneutral/gradientbackgrounds retained.*.stories.tsx— removed "Dark Surface" sections; reworded 3 docstrings; onetext-gray-500→text-default-500.src/components/organisms/Mapbox/layers.ts— comments documenting why the white cluster count and debug-only#888bounds line need no theming.tailwind.config.js— fix the dark theme so the custom brand palette (orange/teal) actually applies in dark;EventDetailsmonth-label gets a dark brand surface in dark mode so its text stays legible.Verification
pnpm lint)pnpm typecheck)pnpm test:run)pnpm build)pnpm ladle:build)Manual / visual verification
Drove the running Ladle (Playwright MCP), toggling the theme on representative stories in both light and dark:
dark:bg-primary-900), borders, highlighted contact icon, chips, and the "Register" button all read in both themes.dark:hover:bg-default-100hover all legible in dark.StorySectionchrome (titles, grid headers, dividers,inContextrule) legible in both themes.Notes for reviewer
tailwind.config.jsnested the dark theme'scolorsunder NextUI'sextend(which takes a base-theme name string, not an object), so the custom dark palette never applied and dark mode used NextUI's default blue/purple. Moved colors to the theme level (mirroring the light theme); dark now renders the brand orange/teal.*-100shades are fixed light tints, so once the palette applied, the EventDetails month-labelbg-primary-100strip would have rendered light-on-light in dark — given a dark brand surface there (dark:bg-primary-900). EventItem/ListItem hover,border-primary-100, the highlighted contact icon, and the Mapbox layers were all re-verified legible in dark with the brand palette and need no change.bg-background; it defers to Ladle's own theme background./code-review(max effort, with verification) and a 4-angle/simplifypass were run over the branch — no correctness bugs. From the/reviewpass,localStorageaccess inuseThemeis now wrapped so the toggle survives sandboxed-iframe embeds / blocked storage (with a co-located test).Closes #18
🤖 Generated with Claude Code