Add light and system themes next to dark
PageHeader.Theme now has three values (ThemeDark, ThemeLight, ThemeSystem). "system" follows prefers-color-scheme. Unset Theme is still the dark palette, but every block now also sets color-scheme, so native controls and scrollbars match it. TestThemeBlocksInSync keeps the duplicated light values and the property lists in step. Persisting the choice stays the consumer's job (README, Theming). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
000bb42240
commit
6b40ff059c
4 files changed
+158
-72
No files matched your search
@@ -66,34 +66,41 @@ forms, buttons, markdown, ...), and anything else specific to that tool.
|
||||
`--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:
|
||||
Three themes ship, selected by `PageHeader.Theme` (see `layout.go`),
|
||||
which renders as `<html data-theme="...">`:
|
||||
|
||||
- `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).
|
||||
| `Theme` | Look |
|
||||
|---|---|
|
||||
| `""` (unset) | dark, the bare `:root` block, i.e. what every consumer had before themes existed |
|
||||
| `layout.ThemeDark` (`"dark"`) | dark, the same values |
|
||||
| `layout.ThemeLight` (`"light"`) | light |
|
||||
| `layout.ThemeSystem` (`"system"`) | follows the browser's `prefers-color-scheme` |
|
||||
|
||||
Every block also sets `color-scheme`, so native controls and scrollbars
|
||||
match the palette.
|
||||
|
||||
- The light values appear twice in `static/style.css` (as
|
||||
`:root[data-theme="light"]` and inside `@media (prefers-color-scheme:
|
||||
light)` for `"system"`). `TestThemeBlocksInSync` fails if the two drift
|
||||
apart or if a theme is missing a property.
|
||||
- `--yw-nav-link` is `#0b82b8` in every theme. It is a cross-project
|
||||
design token (see the meta-repo `AGENTS.md`).
|
||||
- This module does **not** persist a choice (no cookie, localStorage or
|
||||
JS). That is the consuming project's job: keep the preference
|
||||
(e.g. in a cookie set by a POST form), resolve it server-side into
|
||||
`Theme` before rendering, and offer the switch itself (e.g. via
|
||||
`NavbarRightExtra`). Resolving server-side avoids a flash of the wrong
|
||||
theme without an inline script, so it works under a strict
|
||||
`script-src 'self'` CSP. `yareco` is the reference consumer.
|
||||
- A consumer whose own stylesheet needs theme-dependent colors defines
|
||||
its **own** custom properties with the same selector structure
|
||||
(`:root, [data-theme="dark"], [data-theme="system"]` / `[data-theme="light"]`
|
||||
/ the `prefers-color-scheme: light` media query). Don't redefine
|
||||
`--yw-*` in one consumer's stylesheet: that reskins only that
|
||||
project and makes it drift from everyone else sharing this file.
|
||||
- **Adding another theme:** add its own `:root[data-theme="..."]` block
|
||||
with the same property list, a constant in `layout.go`, and a case in
|
||||
`TestThemeAttribute`.
|
||||
|
||||
## Consuming this module
|
||||
|
||||
@@ -140,12 +147,13 @@ concurrent-edit conflict during the initial rollout) and can produce a
|
||||
force-move an existing tag again for any future change — always cut a
|
||||
new one, even for a one-line fix.
|
||||
|
||||
## PageHeader fields (current as of v0.1.5)
|
||||
## PageHeader fields (current as of v0.1.9)
|
||||
|
||||
`Title`, `AppName` (lowercase product name for `<title>`/footer — not
|
||||
`Name`, which collides with a domain type's own `Name` field once
|
||||
embedded in the same struct, as yakwui's viewmodel types do), `Lang`
|
||||
(`<html lang>`, defaults to `"en"`), `Brand`, `BrandInitial`, `Subtitle`,
|
||||
(`<html lang>`, defaults to `"en"`), `Theme` (`<html data-theme>`, see
|
||||
Theming), `Brand`, `BrandInitial`, `Subtitle`,
|
||||
`BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`,
|
||||
`LogoutPath` (a plain GET link — for a POST-form logout or any other
|
||||
markup mismatch, render it yourself into `NavbarRightExtra` instead and
|
||||
|
||||
Reference in new issue
Block a user