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
@@ -0,0 +1,105 @@
|
||||
// Command webui-demo serves a sample page on the shared layout, for
|
||||
// looking at themes, palettes and styles in a browser:
|
||||
//
|
||||
// go run ./cmd/webui-demo -addr 127.0.0.1:8097
|
||||
//
|
||||
// The appearance menu (top right) switches mode, palette and style;
|
||||
// ?style=, ?palette= and ?theme= set the same cookies (handy for links
|
||||
// and screenshots). It has no state and serves nothing but the sample.
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
layout "teruna.dev/yetano/yetano-webui-template"
|
||||
)
|
||||
|
||||
//go:embed pages
|
||||
var pagesFS embed.FS
|
||||
|
||||
type page struct {
|
||||
layout.PageHeader
|
||||
Section string
|
||||
}
|
||||
|
||||
var nav = []layout.NavItem{
|
||||
{ID: "overview", Label: "Overview", Href: "/", Icon: "dashboard"},
|
||||
{ID: "services", Label: "Services", Href: "/services", Group: "Node", Icon: "box"},
|
||||
{ID: "hosts", Label: "Hosts", Href: "/hosts", Group: "Node", Icon: "server"},
|
||||
{ID: "network", Label: "Network", Href: "/network", Group: "Node", Icon: "network"},
|
||||
{ID: "logs", Label: "Logs", Href: "/logs", Group: "Node", Icon: "terminal"},
|
||||
{ID: "users", Label: "Users", Href: "/users", Group: "Access", Icon: "users"},
|
||||
{ID: "keys", Label: "Keys", Href: "/keys", Group: "Access", Icon: "key"},
|
||||
{ID: "security", Label: "Security", Href: "/security", Group: "Access", Icon: "shield"},
|
||||
{ID: "metrics", Label: "Metrics", Href: "/metrics", Group: "Data", Icon: "chart"},
|
||||
{ID: "storage", Label: "Storage", Href: "/storage", Group: "Data", Icon: "database"},
|
||||
{ID: "settings", Label: "Settings", Href: "/settings", Icon: "settings"},
|
||||
}
|
||||
|
||||
func main() {
|
||||
addr := flag.String("addr", "127.0.0.1:8097", "listen address")
|
||||
flag.Parse()
|
||||
|
||||
r, err := layout.NewRenderer(pagesFS, "pages", []string{"demo"}, ".html.tmpl", template.FuncMap{
|
||||
"buildInfo": func() string { return "demo" },
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("GET /webui-static/", layout.StaticHandler("/webui-static/"))
|
||||
mux.Handle("POST /appearance", layout.AppearanceHandler(""))
|
||||
mux.HandleFunc("GET /", func(w http.ResponseWriter, req *http.Request) {
|
||||
active := "overview"
|
||||
for _, n := range nav {
|
||||
if n.Href == req.URL.Path {
|
||||
active = n.ID
|
||||
}
|
||||
}
|
||||
p := page{PageHeader: layout.PageHeader{
|
||||
Title: "Overview", AppName: "demo", Brand: "YETANO", BrandInitial: "y",
|
||||
Subtitle: "night.local", NavItems: nav, ActiveNav: active,
|
||||
AppearancePath: "/appearance", Username: "admin", LogoutPath: "/logout",
|
||||
}}
|
||||
p.ApplyAppearance(req)
|
||||
// ?theme=/?palette=/?style= also go into the menu's cookies, so
|
||||
// the choice stays when you follow a sidebar link.
|
||||
q := req.URL.Query()
|
||||
for _, o := range []struct {
|
||||
key, cookie string
|
||||
choices []layout.Choice
|
||||
field *string
|
||||
}{
|
||||
{"theme", layout.ThemeCookie, layout.Themes, &p.Theme},
|
||||
{"palette", layout.PaletteCookie, layout.Palettes, &p.Palette},
|
||||
{"style", layout.StyleCookie, layout.Styles, &p.Style},
|
||||
} {
|
||||
v := q.Get(o.key)
|
||||
for _, c := range o.choices {
|
||||
if c.ID == v {
|
||||
*o.field = v
|
||||
http.SetCookie(w, &http.Cookie{Name: o.cookie, Value: v, Path: "/",
|
||||
MaxAge: 365 * 24 * 3600, HttpOnly: true, SameSite: http.SameSiteLaxMode})
|
||||
}
|
||||
}
|
||||
}
|
||||
if v := q.Get("flash"); v != "" {
|
||||
p.Flash, p.FlashKind = v, layout.FlashOK
|
||||
}
|
||||
for _, n := range nav {
|
||||
if n.ID == active {
|
||||
p.Section, p.Title = n.Group, n.Label
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := r.Page(w, "demo", p); err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
})
|
||||
log.Printf("webui-demo on http://%s/", *addr)
|
||||
log.Fatal(http.ListenAndServe(*addr, mux))
|
||||
}
|
||||
Reference in new issue
Block a user