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
+42
-13
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -143,9 +167,9 @@ 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
|
||||
Current AppearanceItem // the active theme, shown on the closed menu
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user