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
+43
-1
@@ -97,7 +97,9 @@ func TestThemeAttribute(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"unset resolves to the bare :root theme", "", `<html lang="en">`},
|
||||
{"explicit dark", "dark", `<html lang="en" data-theme="dark">`},
|
||||
{"explicit dark", ThemeDark, `<html lang="en" data-theme="dark">`},
|
||||
{"light", ThemeLight, `<html lang="en" data-theme="light">`},
|
||||
{"system", ThemeSystem, `<html lang="en" data-theme="system">`},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
@@ -136,3 +138,43 @@ func TestPageUnknown(t *testing.T) {
|
||||
t.Fatal("expected error for unknown page")
|
||||
}
|
||||
}
|
||||
|
||||
// TestThemeBlocksInSync guards the hand-kept duplication in
|
||||
// static/style.css: every theme declares the same --yw-* properties, and
|
||||
// the "system" media-query block is identical to "light".
|
||||
func TestThemeBlocksInSync(t *testing.T) {
|
||||
css, err := staticFS.ReadFile("static/style.css")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := func(selector string) string {
|
||||
s := string(css)
|
||||
i := strings.Index(s, selector+" {")
|
||||
if i < 0 {
|
||||
t.Fatalf("style.css: no block %q", selector)
|
||||
}
|
||||
s = s[i+len(selector)+2:]
|
||||
return s[:strings.Index(s, "}")]
|
||||
}
|
||||
decls := func(b string) (names, full []string) {
|
||||
for _, line := range strings.Split(b, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
full = append(full, line)
|
||||
names = append(names, strings.SplitN(line, ":", 2)[0])
|
||||
}
|
||||
return names, full
|
||||
}
|
||||
|
||||
darkNames, _ := decls(block(`:root[data-theme="system"]`))
|
||||
lightNames, light := decls(block(`:root[data-theme="light"]`))
|
||||
_, system := decls(block(` :root[data-theme="system"]`))
|
||||
if strings.Join(darkNames, ",") != strings.Join(lightNames, ",") {
|
||||
t.Errorf("dark and light declare different properties:\ndark: %v\nlight: %v", darkNames, lightNames)
|
||||
}
|
||||
if strings.Join(light, "\n") != strings.Join(system, "\n") {
|
||||
t.Errorf("light and prefers-color-scheme: light blocks differ:\nlight: %v\nsystem: %v", light, system)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user