Skip to content

Add light/dark theme toggle with persistence#37

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-12-fr347g
Jul 13, 2026
Merged

Add light/dark theme toggle with persistence#37
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-12-fr347g

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

The dashboard's style.css already defined light and dark custom properties, but the UI only followed the OS prefers-color-scheme setting with no manual override. This adds a small header toggle that lets the user flip the theme:

  • style.css — promoted the dark palette from a bare @media (prefers-color-scheme: dark) block to a :root[data-theme="dark"] selector for explicit choices, while keeping an OS-default block scoped to :root:not([data-theme]) so an untouched dashboard still follows the OS. Added styling for the toggle button and a flex header layout.
  • index.html — added the toggle button to the header, plus a tiny pre-paint inline script that applies any stored choice before first paint to avoid a flash of the wrong palette.
  • app.js — theme logic: reads/writes localStorage (pimonitor-theme), toggles the data-theme attribute, updates the button icon/aria-label, and follows live OS changes only while no explicit choice is stored. Toggling repaints the canvas gauges/sparklines immediately, since they read their colors from CSS variables at draw time.

Behavior matches the acceptance criteria: the toggle flips the theme instantly and the choice survives a reload; with no stored choice the theme still follows the OS setting.

Related Issue

Closes #12

Checklist

  • Tests added/updated for the change (go test ./... passes locally) — added TestHandler_ServesThemeToggle guarding that the toggle and storage key ship in the served index.html
  • go vet ./... and golangci-lint run are clean
  • Documentation updated if this changes the REST API, configuration, or installation/packaging — added a feature bullet to README.md; no API/config/packaging changes
  • No breaking change to /api/v1/... response shapes, or a new API version was introduced instead — no API changes

Verification note

Automated coverage is limited to the Go asset-serving test; the interactive behavior (instant flip, reload persistence, OS-default fallback) was reviewed by reading the code but has not been exercised in a real browser as part of this change.

The dashboard previously followed only the OS color-scheme setting with no
way to override it. Promote the dark palette to a data-theme selector and add
a header toggle that persists the choice in localStorage, falling back to
prefers-color-scheme when the user has never toggled.

A pre-paint inline script applies any stored choice before first paint to
avoid a flash of the wrong palette, and toggling repaints the canvas gauges
and sparklines immediately since they read their colors from CSS variables
at draw time.

Closes #12
@LarsLaskowski
LarsLaskowski merged commit 68e52f2 into main Jul 13, 2026
3 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-12-fr347g branch July 13, 2026 17:51
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.

C4: Light/dark theme toggle with persistence

2 participants