Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33dfebab9e |
No files matched your search
@@ -30,14 +30,41 @@ forms, buttons, markdown, ...), and anything else specific to that tool.
|
||||
|
||||
## Theming
|
||||
|
||||
Two independent axes, both set on `<html>` and resolved on the server:
|
||||
Three independent axes, all set on `<html>` and resolved on the server:
|
||||
|
||||
| Axis | `PageHeader` field | Attribute | Values |
|
||||
|---|---|---|---|
|
||||
| Mode | `Theme` | `data-theme` | `layout.ThemeDark` (also `""`, unset), `ThemeLight`, `ThemeSystem` (follows `prefers-color-scheme`) |
|
||||
| Colors | `Palette` | `data-palette` | `layout.PaletteDefault` (also `""`), `PaletteGraphite` (grey/violet, after nessajina.tv), `PaletteContrast` (high contrast) |
|
||||
| Colors | `Palette` | `data-palette` | `layout.PaletteDefault` (also `""`), `PaletteGraphite` (grey/violet, after nessajina.tv), `PaletteContrast` (high contrast), `PaletteSlate` (slate/lavender) |
|
||||
| Shape | `Style` | `data-style` | `layout.StyleModern` (also `""`, the default since v0.5.0), `StyleClassic` (the look up to v0.4.x) |
|
||||
|
||||
A consumer that sets neither keeps the original dark look.
|
||||
A consumer that sets none gets the modern style, dark, palette Yetano.
|
||||
|
||||
### Styles: modern (default) and classic
|
||||
|
||||
Since v0.5.0 the default is the modern style: navbar without a rule,
|
||||
the sidebar as a floating rounded card with small group headings,
|
||||
icons and a pill for the active entry, and rounder, quieter Bootstrap
|
||||
components (cards, buttons, form fields, tables, list groups, tinted
|
||||
status badges). It is one block of `[data-style="modern"]` rules at
|
||||
the end of `static/style.css` over the classic rules; the template
|
||||
always sets `data-style` (`modern` when `Style` is empty), so
|
||||
`data-style="classic"` still gives exactly the old look. Visitors pick
|
||||
either in the appearance menu ("Style"/"Stil", cookie `yw_style`); a
|
||||
consumer that wants the old look by default sets `Style: StyleClassic`
|
||||
before `ApplyAppearance`.
|
||||
|
||||
Two optional `NavItem` fields feed it: `Group` (a heading above the
|
||||
first item of each run of equal groups, shown in both styles) and
|
||||
`Icon`, a name from `layout.NavIcons` (`dashboard`, `server`, `box`,
|
||||
`users`, `key`, `shield`, `settings`, ...; shown only in the modern
|
||||
style). In the modern style inactive sidebar links use the text color;
|
||||
the cross-project `#0b82b8` (`--yw-nav-link` of the default palette)
|
||||
now only colors them in the classic style (owner decision 2026-11-28).
|
||||
|
||||
`go run ./cmd/webui-demo` serves a sample page (http://127.0.0.1:8097/)
|
||||
for comparing styles, palettes and modes; `?style=`, `?palette=` and
|
||||
`?theme=` set the same cookies as the menu.
|
||||
|
||||
How `static/style.css` does it:
|
||||
|
||||
|
||||
+41
-12
@@ -14,6 +14,17 @@ const (
|
||||
PaletteDefault = "default"
|
||||
PaletteGraphite = "graphite" // grey and violet, after nessajina.tv
|
||||
PaletteContrast = "contrast" // high contrast
|
||||
PaletteSlate = "slate" // dark slate and lavender, made for StyleModern
|
||||
)
|
||||
|
||||
// Values for PageHeader.Style, the shape of the chrome, rendered as
|
||||
// <html data-style="...">. "" is StyleModern, the default since v0.5.0
|
||||
// (floating sidebar card with group headings and icons, rounded
|
||||
// components); StyleClassic is the original look, still selectable
|
||||
// from the appearance menu.
|
||||
const (
|
||||
StyleClassic = "classic"
|
||||
StyleModern = "modern"
|
||||
)
|
||||
|
||||
// Cookies AppearanceHandler sets and ApplyAppearance reads. Scoped to
|
||||
@@ -22,6 +33,7 @@ const (
|
||||
const (
|
||||
ThemeCookie = "yw_theme"
|
||||
PaletteCookie = "yw_palette"
|
||||
StyleCookie = "yw_style"
|
||||
)
|
||||
|
||||
// Choice is one entry of the appearance menu.
|
||||
@@ -32,7 +44,7 @@ type Choice struct {
|
||||
Symbol string
|
||||
}
|
||||
|
||||
// Themes and Palettes are the choices ApplyAppearance and
|
||||
// Themes, Palettes and Styles are the choices ApplyAppearance and
|
||||
// AppearanceHandler accept, in menu order.
|
||||
var (
|
||||
Themes = []Choice{
|
||||
@@ -44,6 +56,11 @@ var (
|
||||
{PaletteDefault, "Yetano", "Yetano", ""},
|
||||
{PaletteGraphite, "Graphite", "Graphit", ""},
|
||||
{PaletteContrast, "High contrast", "Hoher Kontrast", ""},
|
||||
{PaletteSlate, "Slate", "Schiefer", ""},
|
||||
}
|
||||
Styles = []Choice{
|
||||
{StyleModern, "Modern", "Modern", ""},
|
||||
{StyleClassic, "Classic", "Klassisch", ""},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -56,7 +73,7 @@ func known(choices []Choice, id string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ApplyAppearance overrides h.Theme and h.Palette with the visitor's
|
||||
// ApplyAppearance overrides h.Theme, h.Palette and h.Style with the visitor's
|
||||
// choice from the cookies AppearanceHandler sets (unknown values are
|
||||
// ignored, so the consumer's own defaults stay), and records the
|
||||
// current page as AppearanceBack for the menu's return trip. Call it
|
||||
@@ -69,6 +86,9 @@ func (h *PageHeader) ApplyAppearance(r *http.Request) {
|
||||
if c, err := r.Cookie(PaletteCookie); err == nil && known(Palettes, c.Value) {
|
||||
h.Palette = c.Value
|
||||
}
|
||||
if c, err := r.Cookie(StyleCookie); err == nil && known(Styles, c.Value) {
|
||||
h.Style = c.Value
|
||||
}
|
||||
path := r.URL.Path
|
||||
if h.BasePath != "" && !strippedPath(r) &&
|
||||
(path == h.BasePath || strings.HasPrefix(path, h.BasePath+"/")) {
|
||||
@@ -100,8 +120,8 @@ func strippedPath(r *http.Request) bool {
|
||||
return u.Path != r.URL.Path
|
||||
}
|
||||
|
||||
// AppearanceHandler stores a theme and/or palette choice from a POST
|
||||
// form (fields "theme", "palette", "back") in cookies and redirects to
|
||||
// AppearanceHandler stores a theme, palette and/or style choice from a
|
||||
// POST form (fields "theme", "palette", "style", "back") in cookies and redirects to
|
||||
// back, a BasePath-relative path inside this UI (anything else goes to
|
||||
// the start page, so it is no open redirect). Register it for POST only
|
||||
// at BasePath + PageHeader.AppearancePath; other methods get 405.
|
||||
@@ -114,11 +134,12 @@ func AppearanceHandler(basePath string) http.Handler {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
theme, palette := r.FormValue("theme"), r.FormValue("palette")
|
||||
if (theme == "" && palette == "") ||
|
||||
theme, palette, style := r.FormValue("theme"), r.FormValue("palette"), r.FormValue("style")
|
||||
if (theme == "" && palette == "" && style == "") ||
|
||||
(theme != "" && !known(Themes, theme)) ||
|
||||
(palette != "" && !known(Palettes, palette)) {
|
||||
http.Error(w, "unknown theme or palette", http.StatusBadRequest)
|
||||
(palette != "" && !known(Palettes, palette)) ||
|
||||
(style != "" && !known(Styles, style)) {
|
||||
http.Error(w, "unknown theme, palette or style", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
set := func(name, value string) {
|
||||
@@ -131,6 +152,9 @@ func AppearanceHandler(basePath string) http.Handler {
|
||||
if palette != "" {
|
||||
set(PaletteCookie, palette)
|
||||
}
|
||||
if style != "" {
|
||||
set(StyleCookie, style)
|
||||
}
|
||||
http.Redirect(w, r, basePath+httpsec.SafeNext(r.FormValue("back"), ""), http.StatusSeeOther)
|
||||
})
|
||||
}
|
||||
@@ -144,8 +168,8 @@ type AppearanceItem struct {
|
||||
// AppearanceMenuData is what the navbar template renders the menu from.
|
||||
type AppearanceMenuData struct {
|
||||
Current AppearanceItem // the active theme, shown on the closed menu
|
||||
ThemeHeading, PaletteHeading string
|
||||
Themes, Palettes []AppearanceItem
|
||||
ThemeHeading, PaletteHeading, StyleHeading string
|
||||
Themes, Palettes, Styles []AppearanceItem
|
||||
}
|
||||
|
||||
// AppearanceMenu builds the menu's data, labeled in German when Lang
|
||||
@@ -163,21 +187,26 @@ func (h PageHeader) AppearanceMenu() AppearanceMenuData {
|
||||
}
|
||||
return out
|
||||
}
|
||||
theme, palette := h.Theme, h.Palette
|
||||
theme, palette, style := h.Theme, h.Palette, h.Style
|
||||
if theme == "" {
|
||||
theme = ThemeDark
|
||||
}
|
||||
if palette == "" {
|
||||
palette = PaletteDefault
|
||||
}
|
||||
if style == "" {
|
||||
style = StyleModern
|
||||
}
|
||||
m := AppearanceMenuData{
|
||||
Themes: items(Themes, theme),
|
||||
Palettes: items(Palettes, palette),
|
||||
Styles: items(Styles, style),
|
||||
ThemeHeading: "Theme",
|
||||
PaletteHeading: "Palette",
|
||||
StyleHeading: "Style",
|
||||
}
|
||||
if de {
|
||||
m.ThemeHeading, m.PaletteHeading = "Modus", "Farben"
|
||||
m.ThemeHeading, m.PaletteHeading, m.StyleHeading = "Modus", "Farben", "Stil"
|
||||
}
|
||||
for _, t := range m.Themes {
|
||||
if t.Current {
|
||||
|
||||
+2
-2
@@ -114,8 +114,8 @@ func TestPaletteAttribute(t *testing.T) {
|
||||
t.Fatalf("NewRenderer: %v", err)
|
||||
}
|
||||
for palette, want := range map[string]string{
|
||||
"": `<html lang="en" data-theme="light">`,
|
||||
PaletteGraphite: `<html lang="en" data-theme="light" data-palette="graphite">`,
|
||||
"": `<html lang="en" data-theme="light" data-style="modern">`,
|
||||
PaletteGraphite: `<html lang="en" data-theme="light" data-palette="graphite" data-style="modern">`,
|
||||
} {
|
||||
var buf bytes.Buffer
|
||||
if err := r.Page(&buf, "dashboard", PageHeader{Theme: ThemeLight, Palette: palette}); err != nil {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{{define "content"}}
|
||||
<nav aria-label="breadcrumb"><ol class="breadcrumb small mb-1"><li class="breadcrumb-item">{{if .Section}}{{.Section}}{{else}}Node{{end}}</li><li class="breadcrumb-item active">{{.Title}}</li></ol></nav>
|
||||
<h1 class="h3 mb-1">{{.Title}}</h1>
|
||||
<p class="text-body-secondary mb-3">Status of this node and the services it runs.</p>
|
||||
<hr class="mb-4">
|
||||
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-sm-6 col-xl-3"><div class="card"><div class="card-body"><div class="text-body-secondary small">Services</div><div class="fs-4 fw-bold">12</div><span class="badge text-bg-success">all running</span></div></div></div>
|
||||
<div class="col-sm-6 col-xl-3"><div class="card"><div class="card-body"><div class="text-body-secondary small">Peers</div><div class="fs-4 fw-bold">3</div><span class="badge text-bg-secondary">kilrathi, yetano1, …</span></div></div></div>
|
||||
<div class="col-sm-6 col-xl-3"><div class="card"><div class="card-body"><div class="text-body-secondary small">Uptime</div><div class="fs-4 fw-bold">4d 7h</div><span class="badge text-bg-info">since restart</span></div></div></div>
|
||||
<div class="col-sm-6 col-xl-3"><div class="card"><div class="card-body"><div class="text-body-secondary small">Warnings</div><div class="fs-4 fw-bold">1</div><span class="badge text-bg-warning">certificate expires</span></div></div></div>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-7">
|
||||
<h2 class="h6 text-uppercase text-body-secondary mb-2">Services</h2>
|
||||
<div class="card mb-4">
|
||||
<table class="table table-hover mb-0 align-middle">
|
||||
<thead><tr><th>Name</th><th>Version</th><th>State</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><a href="#">yasl</a></td><td>0.9.2</td><td><span class="badge text-bg-success">running</span></td><td class="text-end"><button class="btn btn-sm btn-outline-primary">Restart</button></td></tr>
|
||||
<tr><td><a href="#">yaiam</a></td><td>1.4.0</td><td><span class="badge text-bg-success">running</span></td><td class="text-end"><button class="btn btn-sm btn-outline-primary">Restart</button></td></tr>
|
||||
<tr><td><a href="#">yamocir</a></td><td>0.7.1</td><td><span class="badge text-bg-danger">failed</span></td><td class="text-end"><button class="btn btn-sm btn-primary">Start</button></td></tr>
|
||||
<tr><td><a href="#">yareco</a></td><td>0.3.0</td><td><span class="badge text-bg-secondary">stopped</span></td><td class="text-end"><button class="btn btn-sm btn-primary">Start</button></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h2 class="h6 text-uppercase text-body-secondary mb-2">Settings</h2>
|
||||
<div class="list-group">
|
||||
<a href="#" class="list-group-item list-group-item-action py-2"><div class="fw-semibold text-body-emphasis">Account</div><small class="text-body-secondary">Change your email or delete your account.</small></a>
|
||||
<a href="#" class="list-group-item list-group-item-action py-2"><div class="fw-semibold text-body-emphasis">Security</div><small class="text-body-secondary">Change your password or sign out all devices.</small></a>
|
||||
<a href="#" class="list-group-item list-group-item-action py-2"><div class="fw-semibold text-body-emphasis">Keys</div><small class="text-body-secondary">Manage API tokens and SSH keys.</small></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-5">
|
||||
<h2 class="h6 text-uppercase text-body-secondary mb-2">Add a peer</h2>
|
||||
<div class="card"><div class="card-body">
|
||||
<form>
|
||||
<div class="mb-3"><label class="form-label" for="h">Host</label><input class="form-control" id="h" placeholder="kilrathi.local"></div>
|
||||
<div class="mb-3"><label class="form-label" for="r">Role</label><select class="form-select" id="r"><option>member</option><option>relay</option></select></div>
|
||||
<div class="form-check form-switch mb-3"><input class="form-check-input" type="checkbox" id="s" checked><label class="form-check-label" for="s">Trust on first use</label></div>
|
||||
<button type="button" class="btn btn-primary">Add peer</button>
|
||||
<button type="button" class="btn btn-outline-danger ms-1">Cancel</button>
|
||||
</form>
|
||||
</div></div>
|
||||
<div class="alert alert-info mt-3 mb-0">Peers join over the YAPL bus; a relay forwards for nodes behind NAT.</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
@@ -0,0 +1,47 @@
|
||||
package layout
|
||||
|
||||
import "html/template"
|
||||
|
||||
// NavIcons are the sidebar icons NavItem.Icon can name: simple 24x24
|
||||
// stroke icons drawn for this module, colored by currentColor. A
|
||||
// consumer may add its own (an <svg> with the same attributes) at
|
||||
// program start, before the first page is rendered; the map is not
|
||||
// safe for writes while pages render.
|
||||
var NavIcons = map[string]template.HTML{
|
||||
"dashboard": icon(`<rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/>`),
|
||||
"home": icon(`<path d="M3 11 12 4l9 7"/><path d="M5 10v10h14V10"/><path d="M10 20v-6h4v6"/>`),
|
||||
"list": icon(`<path d="M9 6h12M9 12h12M9 18h12"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>`),
|
||||
"settings": icon(`<path d="M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12"/><circle cx="16" cy="6" r="2"/><circle cx="10" cy="12" r="2"/><circle cx="18" cy="18" r="2"/>`),
|
||||
"server": icon(`<rect x="3" y="4" width="18" height="7" rx="1.5"/><rect x="3" y="13" width="18" height="7" rx="1.5"/><path d="M7 7.5h.01M7 16.5h.01"/>`),
|
||||
"database": icon(`<ellipse cx="12" cy="5.5" rx="8" ry="2.5"/><path d="M4 5.5v13c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5v-13"/><path d="M4 12c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5"/>`),
|
||||
"box": icon(`<path d="M3 7.5 12 3l9 4.5v9L12 21l-9-4.5z"/><path d="M3 7.5 12 12l9-4.5M12 12v9"/>`),
|
||||
"user": icon(`<circle cx="12" cy="8" r="4"/><path d="M4 21c1-4 4.5-6 8-6s7 2 8 6"/>`),
|
||||
"users": icon(`<circle cx="9" cy="8" r="3.5"/><path d="M2.5 20c.8-3.5 3.5-5.5 6.5-5.5s5.7 2 6.5 5.5"/><path d="M15.5 4.8a3.5 3.5 0 0 1 0 6.4M18 14.8c1.8.8 3 2.6 3.5 5.2"/>`),
|
||||
"key": icon(`<circle cx="8" cy="15" r="4"/><path d="m11 12 9-9M16 7l3 3M14 9l2 2"/>`),
|
||||
"shield": icon(`<path d="M12 3 4.5 6v6c0 4.5 3.2 7.8 7.5 9 4.3-1.2 7.5-4.5 7.5-9V6z"/><path d="m9 12 2 2 4-4"/>`),
|
||||
"activity": icon(`<path d="M3 12h4l3-8 4 16 3-8h4"/>`),
|
||||
"chart": icon(`<path d="M4 20V4"/><path d="M4 20h16"/><path d="M8 16v-5M12 16V8M16 16v-3"/>`),
|
||||
"terminal": icon(`<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/>`),
|
||||
"globe": icon(`<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.5 3.8 5.5 3.8 9s-1.3 6.5-3.8 9c-2.5-2.5-3.8-5.5-3.8-9S9.5 5.5 12 3z"/>`),
|
||||
"cloud": icon(`<path d="M7 19a4.5 4.5 0 0 1-.6-9A6 6 0 0 1 18 9.5a4.8 4.8 0 0 1-.5 9.5z"/>`),
|
||||
"file": icon(`<path d="M6 3h8l5 5v13H6z"/><path d="M14 3v5h5M9 13h7M9 17h7"/>`),
|
||||
"folder": icon(`<path d="M3 6.5A1.5 1.5 0 0 1 4.5 5H9l2 2.5h8.5A1.5 1.5 0 0 1 21 9v9.5a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18.5z"/>`),
|
||||
"bell": icon(`<path d="M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z"/><path d="M10 21h4"/>`),
|
||||
"compass": icon(`<circle cx="12" cy="12" r="9"/><path d="m15.5 8.5-2 5-5 2 2-5z"/>`),
|
||||
"search": icon(`<circle cx="11" cy="11" r="6.5"/><path d="m16 16 4.5 4.5"/>`),
|
||||
"lock": icon(`<rect x="4.5" y="10.5" width="15" height="10" rx="2"/><path d="M8 10.5V7.5a4 4 0 0 1 8 0v3"/>`),
|
||||
"network": icon(`<rect x="9.5" y="3" width="5" height="5" rx="1"/><rect x="3" y="16" width="5" height="5" rx="1"/><rect x="16" y="16" width="5" height="5" rx="1"/><path d="M12 8v4M5.5 16v-4h13v4"/>`),
|
||||
"download": icon(`<path d="M12 4v11M7 10.5l5 5 5-5"/><path d="M4 19.5h16"/>`),
|
||||
"info": icon(`<circle cx="12" cy="12" r="9"/><path d="M12 11v5.5M12 7.5h.01"/>`),
|
||||
}
|
||||
|
||||
func icon(body string) template.HTML {
|
||||
return template.HTML(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">` + body + `</svg>`)
|
||||
}
|
||||
|
||||
func navIcon(name string) template.HTML {
|
||||
if name == "" {
|
||||
return ""
|
||||
}
|
||||
return NavIcons[name]
|
||||
}
|
||||
@@ -41,6 +41,37 @@ type NavItem struct {
|
||||
ID string // matches PageHeader.ActiveNav to mark this item active
|
||||
Label string
|
||||
Href string // BasePath-relative, e.g. "/tasks"
|
||||
// Group, when set, puts a small heading above the first item of a
|
||||
// run of items with the same Group ("Account", "Downloads", ...).
|
||||
Group string
|
||||
// Icon names one of NavIcons ("dashboard", "settings", ...); unknown
|
||||
// names render nothing. Only StyleModern shows icons, so setting it
|
||||
// leaves the classic look unchanged.
|
||||
Icon string
|
||||
}
|
||||
|
||||
// SidebarEntry is one NavItem as the sidebar template renders it.
|
||||
type SidebarEntry struct {
|
||||
NavItem
|
||||
Active bool
|
||||
GroupHead string // the group heading to render before this item, if any
|
||||
IconSVG template.HTML // NavIcons[Icon]
|
||||
}
|
||||
|
||||
// SidebarEntries resolves NavItems for the sidebar template: active
|
||||
// state, group headings (once per run of equal Group values) and icons.
|
||||
func (h PageHeader) SidebarEntries() []SidebarEntry {
|
||||
out := make([]SidebarEntry, len(h.NavItems))
|
||||
prev := ""
|
||||
for i, n := range h.NavItems {
|
||||
e := SidebarEntry{NavItem: n, Active: n.ID == h.ActiveNav, IconSVG: navIcon(n.Icon)}
|
||||
if n.Group != "" && n.Group != prev {
|
||||
e.GroupHead = n.Group
|
||||
}
|
||||
prev = n.Group
|
||||
out[i] = e
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PageHeader holds the fields every page's own data struct should embed
|
||||
@@ -69,6 +100,10 @@ type PageHeader struct {
|
||||
// PaletteDefault. ApplyAppearance fills Theme and Palette from the
|
||||
// visitor's cookies (see README.md's Theming section).
|
||||
Palette string
|
||||
// Style is the shape of the chrome, rendered as <html
|
||||
// data-style="...">: StyleModern (also "") or StyleClassic.
|
||||
// ApplyAppearance fills it from the visitor's cookie.
|
||||
Style string
|
||||
// AppearancePath is the BasePath-relative POST route of
|
||||
// AppearanceHandler, e.g. "/appearance"; set, the navbar shows the
|
||||
// theme/palette menu. AppearanceBack is the BasePath-relative page
|
||||
|
||||
+6
-6
@@ -47,7 +47,7 @@ func TestNewRendererAndPage(t *testing.T) {
|
||||
`class="nav-link active"`,
|
||||
"test-build",
|
||||
"<title>Dashboard · example</title>",
|
||||
`<html lang="en">`,
|
||||
`<html lang="en" data-style="modern">`,
|
||||
"<body>",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
@@ -75,7 +75,7 @@ func TestPageHeaderOverrides(t *testing.T) {
|
||||
out := buf.String()
|
||||
|
||||
for _, want := range []string{
|
||||
`<html lang="de">`,
|
||||
`<html lang="de" data-style="modern">`,
|
||||
`<body x-data="{ open: true }">`,
|
||||
`sidebar d-md-block" :class="{ hidden: !open }">`,
|
||||
} {
|
||||
@@ -96,10 +96,10 @@ func TestThemeAttribute(t *testing.T) {
|
||||
theme string
|
||||
want string
|
||||
}{
|
||||
{"unset resolves to the bare :root theme", "", `<html lang="en">`},
|
||||
{"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">`},
|
||||
{"unset resolves to the bare :root theme", "", `<html lang="en" data-style="modern">`},
|
||||
{"explicit dark", ThemeDark, `<html lang="en" data-theme="dark" data-style="modern">`},
|
||||
{"light", ThemeLight, `<html lang="en" data-theme="light" data-style="modern">`},
|
||||
{"system", ThemeSystem, `<html lang="en" data-theme="system" data-style="modern">`},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
|
||||
+343
-1
@@ -12,7 +12,11 @@
|
||||
dark, the look every consumer had before themes existed. The mode
|
||||
only sets color-scheme and the --yw-if-* switches below.
|
||||
- data-palette (PageHeader.Palette): the colors -- "default",
|
||||
"graphite" or "contrast". Unset is "default".
|
||||
"graphite", "contrast" or "slate". Unset is "default".
|
||||
- data-style (PageHeader.Style): the shape -- "modern" (the
|
||||
default; the template always sets the attribute) or "classic".
|
||||
The rules without a data-style selector are the classic look;
|
||||
the modern section at the end of this file overrides them.
|
||||
|
||||
Every color token is written once, as light-dark(<light>, <dark>), so
|
||||
a palette is one block and no mode duplicates another's values. The
|
||||
@@ -181,6 +185,44 @@
|
||||
--yw-info-text: light-dark(#003f5c, #a0dcff);
|
||||
}
|
||||
|
||||
/* slate: dark slate blue-grey with a soft lavender accent, made to go
|
||||
with data-style="modern" (but works with either style). The primary
|
||||
is light enough in dark mode that buttons carry dark text. */
|
||||
:root[data-palette="slate"] {
|
||||
--yw-bg: light-dark(#f5f5fa, #11131a);
|
||||
--yw-bg-rgb: var(--yw-if-light, 245, 245, 250) var(--yw-if-dark, 17, 19, 26);
|
||||
--yw-surface: light-dark(#ffffff, #1a1d27);
|
||||
--yw-surface-rgb: var(--yw-if-light, 255, 255, 255) var(--yw-if-dark, 26, 29, 39);
|
||||
--yw-surface-2: light-dark(#ececf4, #222634);
|
||||
--yw-surface-2-rgb: var(--yw-if-light, 236, 236, 244) var(--yw-if-dark, 34, 38, 52);
|
||||
--yw-text: light-dark(#23242e, #d5d8e2);
|
||||
--yw-text-rgb: var(--yw-if-light, 35, 36, 46) var(--yw-if-dark, 213, 216, 226);
|
||||
--yw-text-strong: light-dark(#0d0e14, #f4f5f9);
|
||||
--yw-text-strong-rgb: var(--yw-if-light, 13, 14, 20) var(--yw-if-dark, 244, 245, 249);
|
||||
--yw-muted: light-dark(#626679, #9095a8);
|
||||
--yw-border: light-dark(#d9dae6, #2e3345);
|
||||
--yw-chrome-bg: light-dark(#f5f5fa, #11131a);
|
||||
--yw-chrome-border: light-dark(#e2e3ec, #262a39);
|
||||
--yw-brand: light-dark(#1d1b2e, #f4f5f9);
|
||||
--yw-accent: light-dark(#5b45c9, #b4a2ff);
|
||||
--yw-accent-rgb: var(--yw-if-light, 91, 69, 201) var(--yw-if-dark, 180, 162, 255);
|
||||
--yw-link: light-dark(#5b45c9, #b4a2ff);
|
||||
--yw-link-rgb: var(--yw-if-light, 91, 69, 201) var(--yw-if-dark, 180, 162, 255);
|
||||
--yw-link-hover: light-dark(#4632a8, #cfc3ff);
|
||||
--yw-link-hover-rgb: var(--yw-if-light, 70, 50, 168) var(--yw-if-dark, 207, 195, 255);
|
||||
--yw-primary: light-dark(#5b45c9, #b9a8ff);
|
||||
--yw-primary-rgb: var(--yw-if-light, 91, 69, 201) var(--yw-if-dark, 185, 168, 255);
|
||||
--yw-on-primary: light-dark(#ffffff, #19142e);
|
||||
--yw-nav-link: light-dark(#3a3d4d, #c3c6d3);
|
||||
--yw-nav-link-hover-text: light-dark(#1d1b2e, #ffffff);
|
||||
--yw-subtitle: light-dark(#626679, #9095a8);
|
||||
--yw-subtitle-sep: light-dark(#cfd0dc, #2e3345);
|
||||
--yw-footer-text: light-dark(#7a7e90, #646a7e);
|
||||
--yw-info-bg: light-dark(#eeebfb, #1f1c33);
|
||||
--yw-info-border: light-dark(#cdc4f1, #3d3566);
|
||||
--yw-info-text: light-dark(#463399, #cfc3ff);
|
||||
}
|
||||
|
||||
/* --- Bootstrap bridge --------------------------------------------- */
|
||||
|
||||
/* Bootstrap's theme-dependent variables, taken from the palette. This
|
||||
@@ -582,3 +624,303 @@ body.no-sidebar main {
|
||||
align-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Style: modern (data-style="modern", PageHeader.Style) ---------- */
|
||||
/* The default design since v0.5.0, over the same markup and the same
|
||||
palettes: a calm navbar without a rule, the sidebar as a
|
||||
floating rounded card with group headings and icons, a pill for the
|
||||
active entry, and softer, rounder Bootstrap components. Everything
|
||||
here is scoped to [data-style="modern"], so data-style="classic"
|
||||
still gives exactly the classic look above. Icons and group headings come from
|
||||
NavItem.Icon/Group; classic hides the icons. */
|
||||
|
||||
.yw-nav-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.yw-nav-group {
|
||||
color: var(--yw-muted);
|
||||
font-size: .68rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: .09em;
|
||||
text-transform: uppercase;
|
||||
padding: .9rem 1rem .3rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] {
|
||||
--yw-radius: .75rem;
|
||||
--yw-radius-sm: .5rem;
|
||||
--bs-border-radius: var(--yw-radius-sm);
|
||||
--bs-border-radius-sm: .375rem;
|
||||
--bs-border-radius-lg: var(--yw-radius);
|
||||
--bs-border-radius-xl: 1rem;
|
||||
--bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
}
|
||||
|
||||
[data-style="modern"] body {
|
||||
font-size: .9rem;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
[data-style="modern"] h1,
|
||||
[data-style="modern"] h2,
|
||||
[data-style="modern"] h3 {
|
||||
color: var(--yw-text-strong);
|
||||
font-weight: 700;
|
||||
letter-spacing: -.02em;
|
||||
}
|
||||
|
||||
/* Navbar: same surface as the page, no rule; the brand reads as a
|
||||
product name, not a code. */
|
||||
[data-style="modern"] .navbar {
|
||||
background: var(--yw-bg) !important;
|
||||
border-bottom: 0;
|
||||
padding: .9rem 1.5rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .navbar-brand {
|
||||
color: var(--yw-text-strong) !important;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: -.01em;
|
||||
}
|
||||
|
||||
[data-style="modern"] .navbar-subtitle-sep {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-style="modern"] .navbar .btn-sm,
|
||||
[data-style="modern"] .yw-user {
|
||||
border-radius: var(--yw-radius-sm);
|
||||
padding: .35rem .8rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .navbar .btn-outline-secondary {
|
||||
--bs-btn-color: var(--yw-text);
|
||||
--bs-btn-border-color: var(--yw-border);
|
||||
--bs-btn-hover-color: var(--yw-text-strong);
|
||||
--bs-btn-hover-bg: var(--yw-surface-2);
|
||||
--bs-btn-hover-border-color: var(--yw-border);
|
||||
--bs-btn-active-color: var(--yw-text-strong);
|
||||
--bs-btn-active-bg: var(--yw-surface-2);
|
||||
--bs-btn-active-border-color: var(--yw-border);
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-user {
|
||||
color: var(--yw-text);
|
||||
background: var(--yw-surface);
|
||||
border: 1px solid var(--yw-border);
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-appearance-menu {
|
||||
background: var(--yw-surface);
|
||||
border-color: var(--yw-border);
|
||||
border-radius: var(--yw-radius);
|
||||
padding: .4rem;
|
||||
box-shadow: 0 .75rem 2rem rgba(0, 0, 0, .3);
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-appearance-menu h6 {
|
||||
margin: .4rem .6rem .2rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-appearance-menu button {
|
||||
border-radius: var(--yw-radius-sm);
|
||||
padding: .35rem .6rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-appearance-menu button[aria-pressed="true"] {
|
||||
background: color-mix(in srgb, var(--yw-accent) 16%, transparent);
|
||||
}
|
||||
|
||||
/* Sidebar: no full-height column any more, but a card that floats
|
||||
in the column and stays in view while the page scrolls. */
|
||||
[data-style="modern"] .sidebar {
|
||||
background: transparent;
|
||||
border-right: 0;
|
||||
padding: .5rem .25rem 1rem 1rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .sidebar > .nav {
|
||||
position: sticky;
|
||||
top: 1rem;
|
||||
background: var(--yw-surface);
|
||||
border: 1px solid var(--yw-border);
|
||||
border-radius: var(--yw-radius);
|
||||
padding: .5rem !important;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-nav-group {
|
||||
padding: .8rem .65rem .3rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-nav-group:first-child {
|
||||
padding-top: .35rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .sidebar .nav-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .6rem;
|
||||
color: var(--yw-text);
|
||||
font-size: .875rem;
|
||||
padding: .45rem .65rem;
|
||||
border-radius: var(--yw-radius-sm);
|
||||
border-left: 0;
|
||||
}
|
||||
|
||||
[data-style="modern"] .yw-nav-icon {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
color: var(--yw-muted);
|
||||
}
|
||||
|
||||
[data-style="modern"] .sidebar .nav-link:hover {
|
||||
background: var(--yw-surface-2);
|
||||
color: var(--yw-text-strong);
|
||||
}
|
||||
|
||||
[data-style="modern"] .sidebar .nav-link.active {
|
||||
background: color-mix(in srgb, var(--yw-accent) 18%, var(--yw-surface));
|
||||
color: var(--yw-accent);
|
||||
font-weight: 600;
|
||||
border-left: 0;
|
||||
}
|
||||
|
||||
[data-style="modern"] .sidebar .nav-link.active .yw-nav-icon {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
[data-style="modern"] main {
|
||||
padding-top: 1.25rem !important;
|
||||
padding-bottom: 2rem !important;
|
||||
}
|
||||
|
||||
[data-style="modern"] .footer {
|
||||
border-top: 0;
|
||||
color: var(--yw-muted);
|
||||
opacity: .75;
|
||||
}
|
||||
|
||||
/* Bootstrap components the consumers' pages use: rounder, quieter,
|
||||
cards on the surface color with a hairline border. */
|
||||
[data-style="modern"] .card {
|
||||
--bs-card-bg: var(--yw-surface);
|
||||
--bs-card-border-color: var(--yw-border);
|
||||
--bs-card-border-radius: var(--yw-radius);
|
||||
--bs-card-inner-border-radius: calc(var(--yw-radius) - 1px);
|
||||
--bs-card-cap-bg: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
[data-style="modern"] .card-header {
|
||||
font-weight: 600;
|
||||
color: var(--yw-text-strong);
|
||||
}
|
||||
|
||||
[data-style="modern"] .list-group {
|
||||
--bs-list-group-bg: var(--yw-surface);
|
||||
--bs-list-group-border-color: var(--yw-border);
|
||||
--bs-list-group-border-radius: var(--yw-radius);
|
||||
--bs-list-group-action-hover-bg: var(--yw-surface-2);
|
||||
}
|
||||
|
||||
[data-style="modern"] .btn {
|
||||
--bs-btn-font-weight: 600;
|
||||
--bs-btn-padding-x: 1rem;
|
||||
--bs-btn-border-radius: var(--yw-radius-sm);
|
||||
}
|
||||
|
||||
[data-style="modern"] .btn-sm {
|
||||
--bs-btn-padding-x: .7rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .form-control,
|
||||
[data-style="modern"] .form-select {
|
||||
background-color: color-mix(in srgb, var(--yw-bg) 60%, var(--yw-surface));
|
||||
border-color: var(--yw-border);
|
||||
border-radius: var(--yw-radius-sm);
|
||||
padding-top: .5rem;
|
||||
padding-bottom: .5rem;
|
||||
}
|
||||
|
||||
[data-style="modern"] .form-label {
|
||||
font-weight: 600;
|
||||
color: var(--yw-text-strong);
|
||||
}
|
||||
|
||||
[data-style="modern"] .table {
|
||||
--bs-table-bg: transparent;
|
||||
--bs-table-border-color: var(--yw-border);
|
||||
}
|
||||
|
||||
[data-style="modern"] .table > thead th {
|
||||
color: var(--yw-muted);
|
||||
font-size: .72rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: .06em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
[data-style="modern"] a:not(.btn):not(.nav-link):not(.navbar-brand):not(.list-group-item) {
|
||||
text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
|
||||
text-underline-offset: .2em;
|
||||
}
|
||||
|
||||
[data-style="modern"] a:not(.btn):not(.nav-link):not(.navbar-brand):not(.list-group-item):hover {
|
||||
text-decoration-color: currentColor;
|
||||
}
|
||||
|
||||
/* A table as the whole body of a card: the card draws the outline. */
|
||||
[data-style="modern"] .card > .table:last-child > tbody > tr:last-child > * {
|
||||
border-bottom-width: 0;
|
||||
}
|
||||
|
||||
/* Status badges as quiet tinted chips instead of solid blocks. */
|
||||
[data-style="modern"] .badge.text-bg-success { background: var(--yw-success-bg) !important; color: var(--yw-success-text) !important; box-shadow: inset 0 0 0 1px var(--yw-success-border); }
|
||||
[data-style="modern"] .badge.text-bg-danger { background: var(--yw-danger-bg) !important; color: var(--yw-danger-text) !important; box-shadow: inset 0 0 0 1px var(--yw-danger-border); }
|
||||
[data-style="modern"] .badge.text-bg-warning { background: var(--yw-warning-bg) !important; color: var(--yw-warning-text) !important; box-shadow: inset 0 0 0 1px var(--yw-warning-border); }
|
||||
[data-style="modern"] .badge.text-bg-info { background: var(--yw-info-bg) !important; color: var(--yw-info-text) !important; box-shadow: inset 0 0 0 1px var(--yw-info-border); }
|
||||
[data-style="modern"] .badge.text-bg-secondary { background: var(--yw-surface-2) !important; color: var(--yw-muted) !important; box-shadow: inset 0 0 0 1px var(--yw-border); }
|
||||
|
||||
[data-style="modern"] .alert {
|
||||
border-radius: var(--yw-radius-sm);
|
||||
}
|
||||
|
||||
[data-style="modern"] .badge {
|
||||
border-radius: 999px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
[data-style="modern"] hr {
|
||||
border-color: var(--yw-border);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Narrow screens: the card becomes a wrapping row of pills; group
|
||||
headings would only break the row, so they go. */
|
||||
@media (max-width: 767.98px) {
|
||||
[data-style="modern"] .sidebar {
|
||||
border-bottom: 0;
|
||||
padding: .25rem .75rem .5rem;
|
||||
}
|
||||
[data-style="modern"] .sidebar > .nav {
|
||||
position: static;
|
||||
padding: .35rem !important;
|
||||
gap: .25rem;
|
||||
}
|
||||
[data-style="modern"] .yw-nav-group {
|
||||
display: none;
|
||||
}
|
||||
[data-style="modern"] .sidebar .nav-link {
|
||||
border-bottom: 0;
|
||||
padding: .4rem .7rem;
|
||||
}
|
||||
[data-style="modern"] .sidebar .nav-link.active {
|
||||
border-bottom: 0;
|
||||
}
|
||||
[data-style="modern"] .navbar {
|
||||
padding: .7rem 1rem;
|
||||
}
|
||||
}
|
||||
+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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{{define "base"}}<!doctype html>
|
||||
<html lang="{{if .Lang}}{{.Lang}}{{else}}en{{end}}"{{if .Theme}} data-theme="{{.Theme}}"{{end}}{{if .Palette}} data-palette="{{.Palette}}"{{end}}>
|
||||
<html lang="{{if .Lang}}{{.Lang}}{{else}}en{{end}}"{{if .Theme}} data-theme="{{.Theme}}"{{end}}{{if .Palette}} data-palette="{{.Palette}}"{{end}} data-style="{{if .Style}}{{.Style}}{{else}}modern{{end}}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{{.NavbarLeftExtra}}
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
{{if .Username}}<span class="navbar-subtitle">{{.Username}}</span>{{end}}
|
||||
{{if .Username}}<span class="navbar-subtitle yw-user">{{.Username}}</span>{{end}}
|
||||
{{if .AppearancePath}}{{with .AppearanceMenu}}<details class="yw-appearance">
|
||||
<summary class="btn btn-outline-secondary btn-sm" title="{{.ThemeHeading}}: {{.Current.Label}}"><span aria-hidden="true">{{.Current.Symbol}}</span> {{.Current.Label}}</summary>
|
||||
<form method="post" action="{{$.BasePath}}{{$.AppearancePath}}" class="yw-appearance-menu m-0">
|
||||
@@ -18,6 +18,9 @@
|
||||
{{end}}<hr>
|
||||
<h6>{{.PaletteHeading}}</h6>
|
||||
{{range .Palettes}}<button type="submit" name="palette" value="{{.ID}}" aria-pressed="{{.Current}}">{{.Label}}</button>
|
||||
{{end}}<hr>
|
||||
<h6>{{.StyleHeading}}</h6>
|
||||
{{range .Styles}}<button type="submit" name="style" value="{{.ID}}" aria-pressed="{{.Current}}">{{.Label}}</button>
|
||||
{{end}}</form>
|
||||
</details>
|
||||
{{end}}{{end}}{{if .LogoutPath}}<form method="post" action="{{.BasePath}}{{.LogoutPath}}" class="d-inline m-0"><button type="submit" class="btn btn-outline-secondary btn-sm">Logout</button></form>{{end}}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{{define "sidebar"}}
|
||||
<div class="nav flex-column pt-2">
|
||||
{{range .NavItems}}<a class="nav-link{{if eq $.ActiveNav .ID}} active{{end}}" href="{{$.BasePath}}{{.Href}}">{{.Label}}</a>
|
||||
{{range .SidebarEntries}}{{if .GroupHead}}<div class="yw-nav-group">{{.GroupHead}}</div>
|
||||
{{end}}<a class="nav-link{{if .Active}} active{{end}}" href="{{$.BasePath}}{{.Href}}"{{if .Active}} aria-current="page"{{end}}>{{if .IconSVG}}<span class="yw-nav-icon" aria-hidden="true">{{.IconSVG}}</span>{{end}}{{.Label}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
Reference in new issue
Block a user