Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8774ef62ce | ||
|
|
e4f88485f2 | ||
|
|
03a1ce56d8 |
No files matched your search
@@ -96,10 +96,12 @@ German when `Lang` starts with `de`) with one POST form whose buttons
|
|||||||
submit `theme` or `palette`. `AppearanceHandler` stores the choice in
|
submit `theme` or `palette`. `AppearanceHandler` stores the choice in
|
||||||
the cookies `yw_theme`/`yw_palette` (path `BasePath/`, a year,
|
the cookies `yw_theme`/`yw_palette` (path `BasePath/`, a year,
|
||||||
`HttpOnly`, `SameSite=Lax`) and redirects to `back`, but only to a path
|
`HttpOnly`, `SameSite=Lax`) and redirects to `back`, but only to a path
|
||||||
inside the UI. Any other method gets 405. `ApplyAppearance` ignores unknown cookie
|
inside the UI. Any other method gets 405. `ApplyAppearance` ignores
|
||||||
values, so whatever the consumer set before stays the default. A
|
unknown cookie values, so whatever the consumer set before stays the
|
||||||
consumer with its own switch (e.g. `yareco`'s) can keep it and just set
|
default. A consumer whose middleware wants a CSRF token on every POST
|
||||||
`Theme`/`Palette`.
|
puts the hidden field into `AppearanceFormHTML`, which is rendered
|
||||||
|
inside the menu's form. A consumer with its own switch (e.g. `yareco`'s)
|
||||||
|
can keep it and just set `Theme`/`Palette`.
|
||||||
|
|
||||||
**Adding a palette:** a `:root[data-palette="..."]` block in
|
**Adding a palette:** a `:root[data-palette="..."]` block in
|
||||||
`static/style.css`, a constant and an entry in `Palettes` in
|
`static/style.css`, a constant and an entry in `Palettes` in
|
||||||
@@ -122,7 +124,8 @@ module).
|
|||||||
|
|
||||||
## Migration status
|
## Migration status
|
||||||
|
|
||||||
Seven projects use it (`yet serve` on `v0.1.7`, the others on `v0.1.6`).
|
Eight projects use it, all on `v0.2.3` (2026-10-29). `yareco` also uses
|
||||||
|
the built-in theme menu; `yakwui` still has its own switch.
|
||||||
|
|
||||||
| Project | Meta-repo | Status |
|
| Project | Meta-repo | Status |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
@@ -133,6 +136,7 @@ Seven projects use it (`yet serve` on `v0.1.7`, the others on `v0.1.6`).
|
|||||||
| `yamase-web` | yamase | migrated |
|
| `yamase-web` | yamase | migrated |
|
||||||
| `yamocir` | yetano | migrated |
|
| `yamocir` | yetano | migrated |
|
||||||
| `yet` (`yet serve`) | yetano | built on it (a server-rendered shell whose content area a small JS app fills) |
|
| `yet` (`yet serve`) | yetano | built on it (a server-rendered shell whose content area a small JS app fills) |
|
||||||
|
| `yareco` | yetano | built on it (reference consumer for themes) |
|
||||||
|
|
||||||
`yaais` was evaluated too and deliberately NOT migrated: it's a
|
`yaais` was evaluated too and deliberately NOT migrated: it's a
|
||||||
client-rendered SPA (static `index.html` + vanilla JS), not a
|
client-rendered SPA (static `index.html` + vanilla JS), not a
|
||||||
@@ -150,7 +154,7 @@ concurrent-edit conflict during the initial rollout) and can produce a
|
|||||||
force-move an existing tag again for any future change — always cut a
|
force-move an existing tag again for any future change — always cut a
|
||||||
new one, even for a one-line fix.
|
new one, even for a one-line fix.
|
||||||
|
|
||||||
## PageHeader fields (current as of v0.2.0)
|
## PageHeader fields (current as of v0.2.5)
|
||||||
|
|
||||||
`Title`, `AppName` (lowercase product name for `<title>`/footer — not
|
`Title`, `AppName` (lowercase product name for `<title>`/footer — not
|
||||||
`Name`, which collides with a domain type's own `Name` field once
|
`Name`, which collides with a domain type's own `Name` field once
|
||||||
@@ -158,8 +162,8 @@ embedded in the same struct, as yakwui's viewmodel types do), `Lang`
|
|||||||
(`<html lang>`, defaults to `"en"`), `Theme` (`<html data-theme>`, see
|
(`<html lang>`, defaults to `"en"`), `Theme` (`<html data-theme>`, see
|
||||||
Theming), `Brand`, `BrandInitial`, `Subtitle`,
|
Theming), `Brand`, `BrandInitial`, `Subtitle`,
|
||||||
`BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`,
|
`BasePath`, `NavItems`/`ActiveNav`, `Flash`/`FlashKind`, `Username`,
|
||||||
`Palette`, `AppearancePath`/`AppearanceBack` (since v0.2.0, see
|
`Palette`, `AppearancePath`/`AppearanceBack` (since v0.2.0) and
|
||||||
Theming), `LogoutPath` (since v0.1.10 a `<form method="post">` with a submit
|
`AppearanceFormHTML` (since v0.2.4, see Theming), `LogoutPath` (since v0.1.10 a `<form method="post">` with a submit
|
||||||
button styled like the former link, never a GET link: a logout reachable
|
button styled like the former link, never a GET link: a logout reachable
|
||||||
by GET can be triggered from any foreign page via an `<img>`/link and by
|
by GET can be triggered from any foreign page via an `<img>`/link and by
|
||||||
link prefetchers; the consumer registers the route as `POST` only and
|
link prefetchers; the consumer registers the route as `POST` only and
|
||||||
@@ -171,4 +175,7 @@ brand link, e.g. a mobile sidebar-toggle button),
|
|||||||
`ExtraHeadHTML`/`ExtraBodyHTML`, and `BodyAttrs`/`SidebarAttrs` —
|
`ExtraHeadHTML`/`ExtraBodyHTML`, and `BodyAttrs`/`SidebarAttrs` —
|
||||||
`template.HTMLAttr`, not `template.HTML` — raw extra attributes on
|
`template.HTMLAttr`, not `template.HTML` — raw extra attributes on
|
||||||
`<body>` and the sidebar `<nav>` for a consumer's own client-side
|
`<body>` and the sidebar `<nav>` for a consumer's own client-side
|
||||||
framework state (e.g. yakwui's Alpine.js collapsible sidebar).
|
framework state (e.g. yakwui's Alpine.js collapsible sidebar). A page
|
||||||
|
without a sidebar (a login page) sets `BodyAttrs` to
|
||||||
|
`` ` class="no-sidebar"` ``: since v0.2.5 `static/style.css` then hides
|
||||||
|
the sidebar column and gives `<main>` the full width.
|
||||||
+3
-2
@@ -209,14 +209,15 @@ func TestAppearanceMenu(t *testing.T) {
|
|||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
data := PageHeader{Title: "Dashboard", Lang: "de", BasePath: "/ui", AppearancePath: "/appearance",
|
data := PageHeader{Title: "Dashboard", Lang: "de", BasePath: "/ui", AppearancePath: "/appearance",
|
||||||
AppearanceBack: "/tasks", Theme: ThemeLight, Palette: PaletteGraphite}
|
AppearanceBack: "/tasks", Theme: ThemeLight, Palette: PaletteGraphite,
|
||||||
|
AppearanceFormHTML: `<input type="hidden" name="csrf_token" value="t0k">`}
|
||||||
if err := r.Page(&buf, "dashboard", data); err != nil {
|
if err := r.Page(&buf, "dashboard", data); err != nil {
|
||||||
t.Fatalf("Page: %v", err)
|
t.Fatalf("Page: %v", err)
|
||||||
}
|
}
|
||||||
out := buf.String()
|
out := buf.String()
|
||||||
for _, want := range []string{
|
for _, want := range []string{
|
||||||
`<form method="post" action="/ui/appearance"`,
|
`<form method="post" action="/ui/appearance"`,
|
||||||
`name="back" value="/tasks"`,
|
`name="back" value="/tasks"><input type="hidden" name="csrf_token" value="t0k">`,
|
||||||
`name="theme" value="light" aria-pressed="true"><span aria-hidden="true">☀</span> Hell</button>`,
|
`name="theme" value="light" aria-pressed="true"><span aria-hidden="true">☀</span> Hell</button>`,
|
||||||
`name="theme" value="dark" aria-pressed="false">`,
|
`name="theme" value="dark" aria-pressed="false">`,
|
||||||
`name="palette" value="graphite" aria-pressed="true">Graphit</button>`,
|
`name="palette" value="graphite" aria-pressed="true">Graphit</button>`,
|
||||||
|
|||||||
@@ -73,23 +73,27 @@ type PageHeader struct {
|
|||||||
// AppearanceHandler, e.g. "/appearance"; set, the navbar shows the
|
// AppearanceHandler, e.g. "/appearance"; set, the navbar shows the
|
||||||
// theme/palette menu. AppearanceBack is the BasePath-relative page
|
// theme/palette menu. AppearanceBack is the BasePath-relative page
|
||||||
// the menu returns to (ApplyAppearance sets it).
|
// the menu returns to (ApplyAppearance sets it).
|
||||||
AppearancePath string
|
AppearancePath string
|
||||||
AppearanceBack string
|
AppearanceBack string
|
||||||
Brand string // navbar brand text, e.g. "YASTA"
|
// AppearanceFormHTML is extra markup inside the menu's POST form,
|
||||||
BrandInitial string // single-letter favicon glyph, e.g. "y"
|
// e.g. a hidden CSRF token field for a consumer whose middleware
|
||||||
Subtitle string
|
// demands one on every POST.
|
||||||
BasePath string
|
AppearanceFormHTML template.HTML
|
||||||
NavItems []NavItem
|
Brand string // navbar brand text, e.g. "YASTA"
|
||||||
ActiveNav string
|
BrandInitial string // single-letter favicon glyph, e.g. "y"
|
||||||
Flash string
|
Subtitle string
|
||||||
FlashKind string // "ok" or "error"; meaningless if Flash == ""
|
BasePath string
|
||||||
Username string
|
NavItems []NavItem
|
||||||
LogoutPath string // BasePath-relative, e.g. "/logout"; rendered as a POST form (never a GET link); "" hides it
|
ActiveNav string
|
||||||
NavbarBeforeBrand template.HTML // extra markup rendered before the brand link, e.g. a mobile sidebar toggle
|
Flash string
|
||||||
NavbarLeftExtra template.HTML // extra markup rendered after Subtitle in the navbar's left group
|
FlashKind string // "ok" or "error"; meaningless if Flash == ""
|
||||||
NavbarRightExtra template.HTML // extra markup rendered after Username/Logout in the navbar's right group
|
Username string
|
||||||
ExtraHeadHTML template.HTML // extra <link>/<script> tags appended to <head>
|
LogoutPath string // BasePath-relative, e.g. "/logout"; rendered as a POST form (never a GET link); "" hides it
|
||||||
ExtraBodyHTML template.HTML // extra <script> tags appended before </body>
|
NavbarBeforeBrand template.HTML // extra markup rendered before the brand link, e.g. a mobile sidebar toggle
|
||||||
|
NavbarLeftExtra template.HTML // extra markup rendered after Subtitle in the navbar's left group
|
||||||
|
NavbarRightExtra template.HTML // extra markup rendered after Username/Logout in the navbar's right group
|
||||||
|
ExtraHeadHTML template.HTML // extra <link>/<script> tags appended to <head>
|
||||||
|
ExtraBodyHTML template.HTML // extra <script> tags appended before </body>
|
||||||
// BodyAttrs/SidebarAttrs are raw extra attributes (include their own
|
// BodyAttrs/SidebarAttrs are raw extra attributes (include their own
|
||||||
// leading space, e.g. ` x-data="{ open: true }"`) spliced into
|
// leading space, e.g. ` x-data="{ open: true }"`) spliced into
|
||||||
// <body...> and the sidebar's <nav...> tag -- an escape hatch for a
|
// <body...> and the sidebar's <nav...> tag -- an escape hatch for a
|
||||||
|
|||||||
@@ -508,6 +508,19 @@ a.navbar-subtitle:hover {
|
|||||||
border-left: 2px solid var(--yw-accent);
|
border-left: 2px solid var(--yw-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A page without a sidebar (a login page): BodyAttrs ` class="no-sidebar"`.
|
||||||
|
The layout always renders the sidebar column; this hides it and gives
|
||||||
|
<main> the full width. !important: Bootstrap's d-md-block, column and
|
||||||
|
ms-sm-auto classes on those elements are !important or more specific. */
|
||||||
|
body.no-sidebar .sidebar {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.no-sidebar main {
|
||||||
|
width: 100% !important;
|
||||||
|
margin-left: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
/* --- Alerts (flash banners) ---------------------------------------- */
|
/* --- Alerts (flash banners) ---------------------------------------- */
|
||||||
.alert-success { background: var(--yw-success-bg); border-color: var(--yw-success-border); color: var(--yw-success-text); }
|
.alert-success { background: var(--yw-success-bg); border-color: var(--yw-success-border); color: var(--yw-success-text); }
|
||||||
.alert-danger { background: var(--yw-danger-bg); border-color: var(--yw-danger-border); color: var(--yw-danger-text); }
|
.alert-danger { background: var(--yw-danger-bg); border-color: var(--yw-danger-border); color: var(--yw-danger-text); }
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
{{if .AppearancePath}}{{with .AppearanceMenu}}<details class="yw-appearance">
|
{{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>
|
<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">
|
<form method="post" action="{{$.BasePath}}{{$.AppearancePath}}" class="yw-appearance-menu m-0">
|
||||||
<input type="hidden" name="back" value="{{$.AppearanceBack}}">
|
<input type="hidden" name="back" value="{{$.AppearanceBack}}">{{$.AppearanceFormHTML}}
|
||||||
<h6>{{.ThemeHeading}}</h6>
|
<h6>{{.ThemeHeading}}</h6>
|
||||||
{{range .Themes}}<button type="submit" name="theme" value="{{.ID}}" aria-pressed="{{.Current}}"><span aria-hidden="true">{{.Symbol}}</span> {{.Label}}</button>
|
{{range .Themes}}<button type="submit" name="theme" value="{{.ID}}" aria-pressed="{{.Current}}"><span aria-hidden="true">{{.Symbol}}</span> {{.Label}}</button>
|
||||||
{{end}}<hr>
|
{{end}}<hr>
|
||||||
|
|||||||
Reference in new issue
Block a user