Prepare theming: PageHeader.Theme -> <html data-theme>, explicit dark block

Zero behavior change for every current consumer (Theme defaults to "",
which resolves to the unchanged bare :root block). Adds the seam a
future second theme slots into: its own :root[data-theme="..."] block
in static/style.css, nothing else in this module changes. See
README.md's expanded Theming section for the concrete mechanism.
This commit is contained in:
terminar committed 2026-09-01 22:24:58 +02:00
1 parent adea139888
commit 8875062fc5
5 files changed
+123 -34

No files matched your search

+32 -15
View File
@@ -62,21 +62,38 @@ forms, buttons, markdown, ...), and anything else specific to that tool.
## Theming
`static/style.css`'s palette is exposed as `--yw-*` CSS custom properties
on `:root` (`--yw-bg`, `--yw-text`, `--yw-chrome-bg`, `--yw-accent`,
`--yw-nav-link`, `--yw-success-*`/`--yw-danger-*`, ...) rather than baked
directly into each rule — it's a documented, reusable theme, not just an
implementation detail. This is the *only* theme the module ships: fixed
dark, no `prefers-color-scheme`, no light mode. Don't add one here on a
per-project basis (redefining `--yw-*` globally in one consumer would
silently reskin every future consumer sharing this CSS file); a project
that genuinely needs a different look — e.g. a light/dark toggle, like
`yaais` has — should own that itself rather than pushing multi-theme
complexity into this module, since `yaais` shows that need doesn't
actually require *this* module either (it's a client-rendered SPA, not a
server-rendered Go-template dashboard). If a real case for a second theme
*in* this module shows up later, the `--yw-*` tokens are exactly the
seam to add one through — redefine them under a `[data-theme="..."]`
selector the way `yaais`'s own stylesheet does.
(`--yw-bg`, `--yw-text`, `--yw-chrome-bg`, `--yw-accent`, `--yw-nav-link`,
`--yw-success-*`/`--yw-danger-*`, ...) rather than baked directly into
each rule — a documented, reusable theme, not an implementation detail.
The mechanism is prepared but only one theme ("dark") is actually
defined today:
- `PageHeader.Theme` (see `layout.go`) renders as `<html data-theme="...">`.
`""` (every current consumer) omits the attribute, which resolves to
the bare `:root` block — today's exact look, unchanged.
- `static/style.css` also declares `:root[data-theme="dark"]`, byte-
identical to the bare `:root` block — `Theme: "dark"` is an explicit,
equivalent opt-in, and the template a second theme copies.
- **Adding a second theme** (e.g. "light"): add its own
`:root[data-theme="light"] { --yw-*: ...; }` block to
`static/style.css` with the same property list and new values. Nothing
else in this module changes. A consuming project opts in per-request
or per-user by setting `Theme: "light"` on the `PageHeader`s it
builds; projects that never set `Theme` are completely unaffected.
- This module does **not** read `prefers-color-scheme` or persist a
choice itself (no cookie/localStorage/JS) — that's each consuming
project's own concern (e.g. a cookie/session-backed preference,
resolved server-side into `Theme` before rendering), same as any other
`PageHeader` field.
- Don't redefine `--yw-*` globally in one consumer's own stylesheet to
get a per-project look — that silently reskins every other consumer
sharing this CSS file too. A project that genuinely needs a
self-contained different look — e.g. a light/dark toggle with its own
JS/localStorage, like `yaais` has — should own that itself rather than
pushing multi-theme complexity into this module, since `yaais` shows
that need doesn't actually require *this* module either (it's a
client-rendered SPA, not a server-rendered Go-template dashboard).
## Consuming this module