Skip to content

feat(web): system theme option — follow the OS prefers-color-scheme (stretch of #67)#90

Open
dchaudhari7177 wants to merge 2 commits into
burakgon:mainfrom
dchaudhari7177:feat/system-theme
Open

feat(web): system theme option — follow the OS prefers-color-scheme (stretch of #67)#90
dchaudhari7177 wants to merge 2 commits into
burakgon:mainfrom
dchaudhari7177:feat/system-theme

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

The stretch item from #67 ("a fourth system option that follows prefers-color-scheme"), as the separate PR the issue invited.

Builds on #89 — the light-theme PR. This branch contains #89's commit; the net new diff is the last commit (feat(web): system theme option). Happy to rebase once #89 lands.

pwa/theme.ts — the stored preference and the rendered palette are now distinct types: ThemeName (dark | oled | light, what tokens.css/xterm can render) vs ThemePreference (ThemeName | "system"). resolveTheme() maps "system" to light/dark via (prefers-color-scheme: light), using the same defensive matchMedia guard as AppLayout.useIsDesktop (jsdom/SSR → dark). watchSystemTheme() re-applies and re-announces rc-theme-change when the OS scheme flips — but only while the preference is "system", so a concrete choice never gets overridden.

main.tsx — starts the watcher immediately after the boot applyTheme, so a daylight/night OS switch restyles the app (and an open terminal, which re-reads its palette on rc-theme-change) live, no reload.

SettingsPanel.tsx — a fourth System option in the Theme select; still applies instantly.

Tests — extends theme.test.ts (8 passing): "system" round-trips and resolves per a stubbed prefers-color-scheme; without matchMedia it falls back to dark instead of crashing; the OS-flip watcher announces only while the preference is system (vi.stubGlobal matchMedia stub with a change-listener registry, the repo's existing idiom).

Verificationpnpm typecheck clean; theme tests 8/8. End-to-end in a real browser: with the stored preference "system", booting under an OS light scheme paints paper (data-theme="light", --bg #f6f6f7) and under an OS dark scheme paints near-black with the theme-color meta mirrored (#0a0a0b, attribute removed).

…xterm palette

- theme.ts: ThemeName gains "light"; TERMINAL_BG/THEME_COLOR entries; loadTheme
  keeps the stored-value validation (unknown values fall back to dark); applyTheme
  sets data-theme="light" (dark still removes the attribute).
- tokens.css: [data-theme="light"] ink→paper surface palette. Text 15.9:1 /
  6.2:1 / 4.7:1 on the paper bg; coral used AS text/status darkens to #c2481d
  (4.6:1, WCAG AA) while coral FILLS (primary buttons, brand glyph) keep brand
  coral with dark ink (7:1). color-scheme: light flips form controls.
- SettingsPanel: the OLED checkbox becomes a three-way Theme select (Dark /
  True black / Light) using the existing rc-settings__field + select idiom;
  still applies instantly via setTheme.
- TerminalView: a full LIGHT_THEME xterm palette (ink-on-paper defaults, ANSI
  hues darkened to >= 4.5:1); terminalTheme() picks the palette at mount and on
  rc-theme-change, so an open terminal restyles live without a remount.
- Tests: light round-trip + unknown-value fallback, theme-color meta for light,
  TERMINAL_BG covers all three themes.

Closes burakgon#67
- theme.ts: ThemePreference = ThemeName | "system"; resolveTheme() maps
  "system" to light/dark via (prefers-color-scheme: light) with the AppLayout
  matchMedia guard idiom (jsdom/SSR falls back to dark); watchSystemTheme()
  re-applies + re-announces rc-theme-change on OS flips only while the
  preference is "system".
- main.tsx: start the watcher right after the boot applyTheme.
- SettingsPanel: fourth "System" option in the Theme select.
- TerminalView: terminalTheme() resolves the preference, so an open terminal
  follows an OS scheme flip live via the re-fired rc-theme-change.
- Tests: system round-trip + no-matchMedia fallback, OS-flip announce gating
  (vi.stubGlobal matchMedia stub with a change-listener registry).

Stretch item from burakgon#67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant