Modern style as the new default; style axis, slate palette, nav groups and icons
A third appearance axis, PageHeader.Style (<html data-style>), with StyleModern -- the default when Style is empty -- and StyleClassic, the look up to v0.4.x. The modern style is one [data-style="modern"] block at the end of style.css over the classic rules: navbar without a rule, the sidebar as a floating rounded card with group headings, icons and a pill for the active entry, rounder and quieter Bootstrap components. In it inactive sidebar links use the text color; #0b82b8 now only colors them in the classic style (owner decision 2026-11-28). - appearance menu: "Style"/"Stil" section, cookie yw_style - palette slate (dark slate and lavender) - NavItem.Group (sidebar group headings) and NavItem.Icon (names from the new NavIcons set, shown only in the modern style) - cmd/webui-demo: a sample page for comparing styles, palettes and modes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7afb6a022a
commit
33dfebab9e
13 files changed
+771
-28
No files matched your search
+105
@@ -0,0 +1,105 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStyleAttributeAndMenu(t *testing.T) {
|
||||
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
|
||||
if err != nil {
|
||||
t.Fatalf("NewRenderer: %v", err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := r.Page(&buf, "dashboard", PageHeader{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(buf.String(), `<html lang="en" data-style="modern">`) {
|
||||
t.Errorf("unset Style does not render the modern default\n---\n%s", buf.String())
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
data := PageHeader{Lang: "de", Style: StyleClassic, AppearancePath: "/appearance"}
|
||||
if err := r.Page(&buf, "dashboard", data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out := buf.String()
|
||||
for _, want := range []string{
|
||||
`<html lang="de" data-style="classic">`,
|
||||
`<h6>Stil</h6>`,
|
||||
`name="style" value="modern" aria-pressed="false">Modern</button>`,
|
||||
`name="style" value="classic" aria-pressed="true">Klassisch</button>`,
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("rendered output missing %q\n---\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStyleCookie(t *testing.T) {
|
||||
h := AppearanceHandler("/ui")
|
||||
form := url.Values{"style": {StyleModern}, "back": {"/x"}}
|
||||
req := httptest.NewRequest(http.MethodPost, "/ui/appearance", strings.NewReader(form.Encode()))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, req)
|
||||
cookies := rec.Result().Cookies()
|
||||
if rec.Code != http.StatusSeeOther || len(cookies) != 1 || cookies[0].Name != StyleCookie || cookies[0].Value != StyleModern {
|
||||
t.Fatalf("got %d, cookies %+v", rec.Code, cookies)
|
||||
}
|
||||
|
||||
bad := httptest.NewRequest(http.MethodPost, "/ui/appearance", strings.NewReader("style=fancy"))
|
||||
bad.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
rec = httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, bad)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Errorf("unknown style: got %d, want 400", rec.Code)
|
||||
}
|
||||
|
||||
get := httptest.NewRequest(http.MethodGet, "/ui/x", nil)
|
||||
get.AddCookie(cookies[0])
|
||||
hdr := PageHeader{BasePath: "/ui"}
|
||||
hdr.ApplyAppearance(get)
|
||||
if hdr.Style != StyleModern {
|
||||
t.Errorf("Style = %q, want %q from the cookie", hdr.Style, StyleModern)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSidebarGroupsAndIcons(t *testing.T) {
|
||||
r, err := NewRenderer(testPagesFS(), "pages", []string{"dashboard"}, ".html.tmpl", testFuncs())
|
||||
if err != nil {
|
||||
t.Fatalf("NewRenderer: %v", err)
|
||||
}
|
||||
data := PageHeader{
|
||||
BasePath: "/ui",
|
||||
ActiveNav: "b",
|
||||
NavItems: []NavItem{
|
||||
{ID: "o", Label: "Overview", Href: "/"},
|
||||
{ID: "a", Label: "Account", Href: "/a", Group: "Account", Icon: "user"},
|
||||
{ID: "b", Label: "Security", Href: "/b", Group: "Account", Icon: "shield"},
|
||||
{ID: "c", Label: "Hosts", Href: "/c", Group: "Infra", Icon: "no-such-icon"},
|
||||
},
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := r.Page(&buf, "dashboard", data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out := buf.String()
|
||||
if n := strings.Count(out, `<div class="yw-nav-group">Account</div>`); n != 1 {
|
||||
t.Errorf("group heading Account rendered %d times, want 1\n---\n%s", n, out)
|
||||
}
|
||||
for _, want := range []string{
|
||||
`<div class="yw-nav-group">Infra</div>`,
|
||||
`<a class="nav-link active" href="/ui/b" aria-current="page"><span class="yw-nav-icon" aria-hidden="true"><svg`,
|
||||
`<a class="nav-link" href="/ui/c">Hosts</a>`,
|
||||
`<a class="nav-link" href="/ui/">Overview</a>`,
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("rendered output missing %q\n---\n%s", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user