Add light mode

merged…
osebo50d ago

See the title

2 repliesoldestnewest
Osebotfable-5-150d ago

Today the app has no way to pick a theme: app/globals.css is light by default and flips to the black dark palette purely via @media (prefers-color-scheme: dark), so anyone on a dark OS is stuck in dark mode. I read "Add light mode" as: let the user choose.

Plan:

  1. Theme switcher — a small System / Light / Dark control (components/theme-toggle.tsx, reusing the existing .seg segmented-control styles) rendered in the header next to the user menu, so it's reachable in all three header layouts (sidebar / top bar / ☰ phone).
  2. Persistence without flash — choice saved in localStorage("theme"); a tiny inline script in <head> (app/layout.tsx) sets data-theme on <html> before first paint, so there's no light→dark flicker. "System" removes the attribute and falls back to the media query.
  3. CSS — move the dark token block into a shared selector so both html[data-theme="dark"] and @media (prefers-color-scheme: dark) html:not([data-theme="light"]) apply it, plus color-scheme: light|dark so native form controls match.
  4. Screenshot the header in forced light and dark, push, open a PR.
Osebotfable-5-150d agothreadide@01b7b41

Done — PR #52 adds a theme switcher. Before, the palette was chosen only by prefers-color-scheme, so a dark OS meant dark app, full stop.

What changed

  • components/theme-toggle.tsx (new): a compact System / Light / Dark control with inline-SVG icons (no font glyphs — see the ☰ gotcha). It's the last item inside the header nav, so it appears in all three header layouts: under the links in the desktop sidebar, inline in the 561–900px top bar, and at the bottom of the phone ☰ panel. The choice is kept in localStorage("theme") and applied as html[data-theme="light"|"dark"]; System removes the attribute and the OS media query takes over. Follows changes made in another tab via the storage event.
  • app/layout.tsx: a tiny inline <head> script applies the saved choice before first paint, so there's no flash of the OS palette on load; <html suppressHydrationWarning> because of that attribute.
  • app/globals.css: dark tokens now apply via html[data-theme="dark"] plus, as the OS fallback, @media (prefers-color-scheme: dark) html:not([data-theme="light"]). The two token blocks must stay identical (plain duplication; Next's default PostCSS doesn't flatten nested @media). color-scheme: light|dark is set alongside so native selects/scrollbars match. Which segment looks selected is pure CSS keyed on html[data-theme], so the server-rendered markup needs no knowledge of the user's choice and nothing flickers during hydration.

Verified with static mockups of the real stylesheet under emulated OS colour schemes (screenshot attached): forced Light on a dark OS, forced Dark on a light OS, and System on a phone. tsc --noEmit is clean. The app itself can't run in the sandbox (Postgres + OAuth), so please give the toggle a quick click on the preview deploy — the preference is per browser, not per account (no DB change).

Theme switcher in the three header layouts: forced Light on a dark OS (sidebar), forced Dark on a light OS (top bar), System in the phone ☰ panel
Theme switcher in the three header layouts: forced Light on a dark OS (sidebar), forced Dark on a light OS (top bar), System in the phone ☰ panel