Skip to content

refactor(ui): unify dark mode across Ladle and components #18

Closed

Description

@Ardnived

Summary

Ladle stories force the preview canvas to light and demonstrate dark mode only via per-section <StorySection theme="dark"> blocks, while Ladle's own theme toggle is enabled (.ladle/config.mjs) but unused. Replace that pattern: let Ladle's toggle drive the entire canvas, remove the hardcoded bg-white/dark-surface sections, and fix the components and the useTheme hook so everything — including the Mapbox basemap — renders correctly in both themes from a single theme signal.

Proposed changes

1. Ladle global decorator — .ladle/components.tsx

  • Stop force-adding light / removing dark. Instead read the active theme from Ladle (useLadleContext().globalState.theme → ThemeState = 'light' | 'dark' | 'auto') and apply the matching class to document.documentElement (resolve auto via matchMedia('(prefers-color-scheme: dark)')).
  • Replace <main className="min-h-screen bg-white p-6 text-gray-900"> with semantic tokens: bg-background text-foreground.
  • Drive our theme system from the same Ladle signal (see change 4) so useTheme consumers follow.

2. StorySection helper — src/components/ladle/StorySection.tsx

  • Remove the theme prop and every theme === 'dark' branch (childrenTextColor, dark backgrounds, dark borders, dark scrollable background).
  • Re-express chrome with NextUI semantic tokens so it's legible in both themes: titles text-foreground, subsection titles text-default-600, descriptions text-default-500, dividers border-divider, scrollable border border-default-200.
  • Keep background="neutral" | "gradient" (context backgrounds that simulate the map surface panels float over) but make them theme-aware: neutral → bg-default-100; gradient → keep the teal gradient (brand, reads on both); scrollable default → bg-background.

3. Stories — remove the dark-surface section (18 files)

  • Delete each <StorySection background="neutral" theme="dark" title="Dark Surface"> … </StorySection> block. Files: atoms/{ThemeSwitch,Panel,Chip,Dropdown,Icons,Fallbacks,LanguageSelector}, molecules/{SearchBar,Navbar,EventImages,EventShare,ListItem,List,EventTime,EventSoon,EventItem}, organisms/{EventPanel,EventsList} — all *.stories.tsx.
  • Remove the now-orphaned text-white override in atoms/Icons/Icons.stories.tsx:71.
  • Update story docstrings that reference "dark surface" (e.g. Chip.stories.tsx's "how chips read on a dark surface").

4. useTheme reactivity (the core gotcha) — src/hooks/use-theme.ts

  • Current state: per-component useState seeded from localStorage, plus a dependency-less useEffect (L41–43) that rewrites the root light/dark class on every render. It is not reactive to externally-set themes and actively fights any class set elsewhere — so the Mapbox basemap (MAP_STYLES[theme], Map.tsx:148) will not follow Ladle's toggle.
  • Make theme a single reactive source of truth that both NextUI (via the root class) and useTheme consumers (Map style) read. Preferred: derive useTheme from the root dark class (observe it) — or back it with a tiny zustand store — and drop the every-render class write. The Ladle decorator then sets that one signal from globalState.theme, and the basemap follows.
  • App behavior unchanged: ThemeSwitch toggles the same signal; the standalone widget still persists to localStorage.

5. Component dark-mode fixes — audit + convert hardcoded light-only colors

  • organisms/EventDetails/EventDetails.tsx: text-background bg-primary-100 (L84), bg-primary-100 (L134), border-primary-100 (L192) are tuned for a light surface — verify in dark and adjust with dark: variants or semantic tokens (bg-content2, border-default-200).
  • molecules/EventItem/EventItem.tsx:42 and molecules/ListItem/ListItem.tsx:16: idle bg is transparent and hover already carries dark:hover:bg-default-100 — verify in dark; adjust only if a problem shows.
  • organisms/Mapbox/layers.ts: white cluster text (L21) and #888 bounds line (L71) — once change 4 makes the basemap follow the toggle, verify legibility on both basemaps and make them theme-aware (read isDark) if needed.
  • Sweep remaining bg-white / text-gray-* / hardcoded hex across src/components/** (excluding the intentional brand colors in atoms/Icons/socials.tsx) and convert to semantic tokens or dark: variants.

Acceptance criteria

  • No theme prop remains on StorySection; no theme="dark" / "Dark Surface" section remains in any *.stories.tsx.
  • .ladle/components.tsx no longer hardcodes light or bg-white; the canvas follows Ladle's theme toggle (light / dark / auto).
  • Toggling Ladle's theme flips every story — including the Mapbox basemap — between light and dark, with legible text and adequate contrast throughout.
  • StorySection chrome (titles, descriptions, dividers, neutral/gradient backgrounds) is legible in both themes.
  • No component renders light-only colors in dark mode; the EventDetails primary-100 usages are verified in both themes.
  • useTheme no longer rewrites the root class on every render and derives from a single reactive source; standalone-widget dark mode via ThemeSwitch still works.
  • pnpm lint, pnpm typecheck, pnpm test:run, pnpm build, and pnpm ladle:build all pass.

Files affected

  • .ladle/components.tsx — decorator reads Ladle theme; drop forced light + bg-white
  • src/components/ladle/StorySection.tsx — drop theme prop, semantic-token chrome
  • 18 *.stories.tsx files — remove dark-surface sections (list above)
  • src/hooks/use-theme.ts — make reactive, drop per-render class write
  • src/components/organisms/EventDetails/EventDetails.tsx — primary-100 dark variants
  • src/components/organisms/Mapbox/{layers.ts,Map.tsx} — theme-aware layer colors / basemap follows toggle
  • src/components/molecules/{EventItem,ListItem}/*.tsx — verify hover/idle in dark

References

  • .claude/rules/components.md, .claude/rules/mapbox.md, .claude/rules/i18n-and-state.md
  • DESIGN_SYSTEM.md, STORYBOOK.md
  • Ladle theme API: @ladle/react useLadleContext() → globalState.theme (ThemeState)
  • tailwind.config.js (darkMode: 'class', NextUI light/dark theme tokens)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions