Add icons and context to mobile navigation menus
Use vendored Lucide icon tiles and chevrons with account/app identity above each index. Preserve native full-row links, accessible names and inset focus rings.
5 files changed,
+117
−23
internal/console/icons.go+56 −0internal/console/icons_test.go+7 −6internal/console/mobilenav_test.go+10 −5internal/console/templates/layout.html+19 −2internal/console/templates/navindex.html+25 −10
CI failed — run details
diff --git a/internal/console/icons.go b/internal/console/icons.go| index b0ddf2d32..e80849051 100644 |
| --- a/internal/console/icons.go |
| +++ b/internal/console/icons.go |
| @@ -129,11 +129,67 @@ const ( |
| iconFastForward template.HTML = iconOpen + |
| `<polygon points="13 19 22 12 13 5 13 19"/>` + |
| `<polygon points="2 19 11 12 2 5 2 19"/></svg>` |
| + // Lucide: activity. |
| + iconActivity template.HTML = iconOpen + `<path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" /></svg>` |
| + |
| + // Lucide: chart-no-axes-combined. |
| + iconChartNoAxesCombined template.HTML = iconOpen + `<path d="M12 16v5" /> <path d="M16 14.639V21" /> <path d="M20 10.656V21" /> <path d="m22 3-8.646 8.646a.5.5 0 0 1-.708 0L9.354 8.354a.5.5 0 0 0-.707 0L2 15" /> <path d="M4 18.463V21" /> <path d="M8 14.656V21" /></svg>` |
| + |
| + // Lucide: chevron-right. |
| + iconChevronRight template.HTML = iconOpen + `<path d="m9 18 6-6-6-6" /></svg>` |
| + |
| + // Lucide: credit-card. |
| + iconCreditCard template.HTML = iconOpen + `<rect width="20" height="14" x="2" y="5" rx="2" /> <line x1="2" x2="22" y1="10" y2="10" /> <path d="M6 14h2" /></svg>` |
| + |
| + // Lucide: database. |
| + iconDatabase template.HTML = iconOpen + `<ellipse cx="12" cy="5" rx="9" ry="3" /> <path d="M3 5V19A9 3 0 0 0 21 19V5" /> <path d="M3 12A9 3 0 0 0 21 12" /></svg>` |
| + |
| + // Lucide: flag. |
| + iconFlag template.HTML = iconOpen + `<path d="M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528" /></svg>` |
| + |
| + // Lucide: globe. |
| + iconGlobe template.HTML = iconOpen + `<circle cx="12" cy="12" r="10" /> <path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" /> <path d="M2 12h20" /></svg>` |
| + |
| + // Lucide: layout-grid. |
| + iconLayoutGrid template.HTML = iconOpen + `<rect width="7" height="7" x="3" y="3" rx="1" /> <rect width="7" height="7" x="14" y="3" rx="1" /> <rect width="7" height="7" x="14" y="14" rx="1" /> <rect width="7" height="7" x="3" y="14" rx="1" /></svg>` |
| + |
| + // Lucide: mail. |
| + iconMail template.HTML = iconOpen + `<path d="m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7" /> <rect x="2" y="4" width="20" height="16" rx="2" /></svg>` |
| + |
| + // Lucide: server. |
| + iconServer template.HTML = iconOpen + `<rect width="20" height="8" x="2" y="2" rx="2" ry="2" /> <rect width="20" height="8" x="2" y="14" rx="2" ry="2" /> <line x1="6" x2="6.01" y1="6" y2="6" /> <line x1="6" x2="6.01" y1="18" y2="18" /></svg>` |
| + |
| + // Lucide: shield. |
| + iconShield template.HTML = iconOpen + `<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z" /></svg>` |
| + |
| + // Lucide: sliders-horizontal. |
| + iconSlidersHorizontal template.HTML = iconOpen + `<path d="M10 5H3" /> <path d="M12 19H3" /> <path d="M14 3v4" /> <path d="M16 17v4" /> <path d="M21 12h-9" /> <path d="M21 19h-5" /> <path d="M21 5h-7" /> <path d="M8 10v4" /> <path d="M8 12H3" /></svg>` |
| + |
| + // Lucide: trash. |
| + iconTrash template.HTML = iconOpen + `<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" /></svg>` |
| + |
| + // Lucide: users. |
| + iconUsers template.HTML = iconOpen + `<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /> <path d="M16 3.128a4 4 0 0 1 0 7.744" /> <path d="M22 21v-2a4 4 0 0 0-3-3.87" /> <circle cx="9" cy="7" r="4" /></svg>` |
| ) |
| // icons maps each Lucide slug to its vendored markup. Slugs are the Lucide |
| // names so the mapping back to lucide.dev stays obvious. |
| var icons = map[string]template.HTML{ |
| + "activity": iconActivity, |
| + "chart-no-axes-combined": iconChartNoAxesCombined, |
| + "chevron-right": iconChevronRight, |
| + "credit-card": iconCreditCard, |
| + "database": iconDatabase, |
| + "flag": iconFlag, |
| + "globe": iconGlobe, |
| + "layout-grid": iconLayoutGrid, |
| + "mail": iconMail, |
| + "server": iconServer, |
| + "shield": iconShield, |
| + "sliders-horizontal": iconSlidersHorizontal, |
| + "trash": iconTrash, |
| + "users": iconUsers, |
| + |
| "external-link": iconExternalLink, |
| "chevron-down": iconChevronDown, |
| "check": iconCheck, |
diff --git a/internal/console/icons_test.go b/internal/console/icons_test.go| index 89fbe3ada..e626a31d6 100644 |
| --- a/internal/console/icons_test.go |
| +++ b/internal/console/icons_test.go |
| @@ -205,12 +205,13 @@ func TestVendoredIconsAreSelfContained(t *testing.T) { |
| t.Errorf("icon %q reaches outside the page (%q): %s", slug, bad, s) |
| } |
| } |
| - // No width/height of their own: they size from the .icon CSS rule so |
| - // one icon at a 0.9rem menu row and the same icon in body text are the |
| - // same shape at two sizes, not two hand-tuned copies. (The leading |
| - // space is what keeps stroke-width, a different thing entirely, out |
| - // of this check.) |
| - if strings.Contains(s, " width=") || strings.Contains(s, " height=") { |
| + // CSS sizes the outer SVG. Shapes inside its viewBox, such as rect, |
| + // need their own dimensions to draw the icon. |
| + opening, _, ok := strings.Cut(s, ">") |
| + if !ok { |
| + t.Fatalf("icon %q has no opening SVG tag: %s", slug, s) |
| + } |
| + if strings.Contains(opening, " width=") || strings.Contains(opening, " height=") { |
| t.Errorf("icon %q hardcodes a size instead of sizing from the text: %s", slug, s) |
| } |
| } |
diff --git a/internal/console/mobilenav_test.go b/internal/console/mobilenav_test.go| index 4d9b3a342..fa066772a 100644 |
| --- a/internal/console/mobilenav_test.go |
| +++ b/internal/console/mobilenav_test.go |
| @@ -10,7 +10,8 @@ import ( |
| ) |
| var ( |
| - indexLinkRE = regexp.MustCompile(`<a id="nav-([^"]+)" href="([^"]+)"[^>]*>([^<]+)</a>`) |
| + indexLinkRE = regexp.MustCompile(`(?s)<a id="nav-([^"]+)" href="([^"]+)"[^>]*>(.*?)</a>`) |
| + indexLabelRE = regexp.MustCompile(`<span class="index-label">([^<]+)</span>`) |
| mobileBackRE = regexp.MustCompile(`<div class="mobile-back"><a href="([^"]+)" rel="up">([^<]+)</a></div>`) |
| mobileHeadRE = regexp.MustCompile(`<h1 class="mobile-title">([^<]+)</h1>`) |
| ) |
| @@ -34,7 +35,11 @@ func indexRows(t *testing.T, body string) []indexRow { |
| } |
| var rows []indexRow |
| for _, m := range indexLinkRE.FindAllStringSubmatch(list, -1) { |
| - rows = append(rows, indexRow{m[1], html.UnescapeString(m[2]), html.UnescapeString(m[3])}) |
| + label := indexLabelRE.FindStringSubmatch(m[3]) |
| + if len(label) != 2 { |
| + t.Fatalf("index row %q has no label: %s", m[1], m[3]) |
| + } |
| + rows = append(rows, indexRow{m[1], html.UnescapeString(m[2]), html.UnescapeString(label[1])}) |
| } |
| return rows |
| } |
| @@ -302,9 +307,9 @@ func TestPhoneViewStyle(t *testing.T) { |
| if blk := cssBlock(t, body, "body[data-view] header :is(.switcher, .brand, .account-links)"); !strings.Contains(blk, "display: none") { |
| t.Errorf("a phone account page still shows the header nav: %s", blk) |
| } |
| - for _, sel := range []string{".index-nav a", ".mobile-back a"} { |
| - if blk := cssBlock(t, body, sel); !strings.Contains(blk, "min-height: 2.75rem") { |
| - t.Errorf("%s is under the 44px touch target: %s", sel, blk) |
| + for sel, height := range map[string]string{".index-nav a": "3.75rem", ".mobile-back a": "2.75rem"} { |
| + if blk := cssBlock(t, body, sel); !strings.Contains(blk, "min-height: "+height) { |
| + t.Errorf("%s is missing its %s minimum touch target: %s", sel, height, blk) |
| } |
| } |
| } |
diff --git a/internal/console/templates/layout.html b/internal/console/templates/layout.html| index e33cfcf1e..cdbc73194 100644 |
| --- a/internal/console/templates/layout.html |
| +++ b/internal/console/templates/layout.html |
| @@ -1044,10 +1044,27 @@ |
| .index-nav { display: flex; flex-direction: column; max-width: 32rem; margin: 0 0 2rem; border: 1px solid var(--rule); border-radius: var(--rst-radius); background: var(--bg); box-shadow: var(--shadow-module); overflow: hidden; } |
| .index-nav a:last-child { border-bottom: 0; } |
| .index-nav a { |
| - display: flex; align-items: center; min-height: 2.75rem; box-sizing: border-box; |
| - padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--rule); |
| + display: flex; align-items: center; box-sizing: border-box; |
| + gap: 0.75rem; min-height: 3.75rem; padding: 0.75rem 0.875rem; border-bottom: 1px solid var(--rule); |
| color: var(--ink); text-decoration: none; overflow-wrap: anywhere; |
| } |
| + .index-context { display: flex; align-items: center; gap: 0.875rem; max-width: 32rem; margin: 0.25rem 0 1.5rem; } |
| + .index-context-copy { min-width: 0; } |
| + .index-context h1 { margin: 0; } |
| + .index-context .eyebrow { margin: 0 0 0.25rem; font-size: 0.7rem; overflow-wrap: anywhere; } |
| + .index-meta { margin: 0.375rem 0 0; color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; } |
| + .index-meta code { font-size: 0.75rem; } |
| + .index-context-icon { display: flex; align-items: center; justify-content: center; flex: none; width: 2.75rem; height: 2.75rem; color: var(--accent-strong); background: var(--accent-soft); border: 1px solid var(--rack-edge); border-radius: 0.75rem; box-shadow: var(--shadow-raised); } |
| + .index-context-icon .icon { width: 1.4rem; height: 1.4rem; } |
| + .index-nav .index-icon { display: flex; align-items: center; justify-content: center; flex: none; width: 2rem; height: 2rem; border-radius: 0.5rem; background: light-dark(#f0e4ef, #382435); color: var(--accent-strong); box-shadow: inset 0 1px 0 var(--rst-depth-hl), 0 1px 1px var(--rst-depth-ambient); } |
| + .index-nav .index-icon .icon { width: 1.125rem; height: 1.125rem; } |
| + .index-label { flex: 1; min-width: 0; } |
| + .index-chevron { display: flex; flex: none; color: var(--muted); opacity: 0.65; } |
| + .index-chevron .icon { width: 1rem; height: 1rem; } |
| + .index-nav :is(.index-key-fleet, .index-key-instances, .index-key-placement, .index-key-domains, .index-key-email) .index-icon { background: light-dark(#e4edf9, #1e3049); color: light-dark(#32629c, #9cbfee); } |
| + .index-nav :is(.index-key-team, .index-key-availability, .index-key-protection, .index-key-storage) .index-icon { background: light-dark(#e1f0ed, #1b3833); color: light-dark(#28685e, #99d2c5); } |
| + .index-nav :is(.index-key-settings, .index-key-general, .index-key-logs, .index-key-environments) .index-icon { background: light-dark(#ececf0, #2c2d34); color: var(--muted); } |
| + .index-nav .index-key-delete .index-icon { background: light-dark(#f7e9e8, #3b2425); color: var(--bad); } |
| /* The box clips to its rounded corners, so the end rows take the same |
| curve (their background and focus ring follow it) and the ring sits |
| 3px inside, where the clip cannot reach it. */ |
diff --git a/internal/console/templates/navindex.html b/internal/console/templates/navindex.html| index 8b0b57626..88e97324f 100644 |
| --- a/internal/console/templates/navindex.html |
| +++ b/internal/console/templates/navindex.html |
| @@ -1,17 +1,32 @@ |
| +{{define "index_icon"}}{{if eq .Key "apps"}}{{icon "layout-grid"}}{{else if eq .Key "fleet"}}{{icon "server"}}{{else if eq .Key "team"}}{{icon "users"}}{{else if eq .Key "settings"}}{{icon "sliders-horizontal"}}{{else if eq .Key "billing"}}{{icon "credit-card"}}{{else if eq .Key "overview"}}{{icon "layout-grid"}}{{else if eq .Key "instances"}}{{icon "server"}}{{else if eq .Key "releases"}}{{icon "layers"}}{{else if eq .Key "logs"}}{{icon "menu"}}{{else if eq .Key "errors"}}{{icon "triangle-alert"}}{{else if eq .Key "availability"}}{{icon "activity"}}{{else if eq .Key "analytics"}}{{icon "chart-no-axes-combined"}}{{else if eq .Key "protection"}}{{icon "shield"}}{{else if eq .Key "activity"}}{{icon "activity"}}{{else if eq .Key "general"}}{{icon "sliders-horizontal"}}{{else if eq .Key "domains"}}{{icon "globe"}}{{else if eq .Key "placement"}}{{icon "server"}}{{else if eq .Key "pipeline"}}{{icon "layers"}}{{else if eq .Key "environments"}}{{icon "layers"}}{{else if eq .Key "storage"}}{{icon "database"}}{{else if eq .Key "email"}}{{icon "mail"}}{{else if eq .Key "features"}}{{icon "flag"}}{{else if eq .Key "errors-analytics"}}{{icon "activity"}}{{else if eq .Key "delete"}}{{icon "trash"}}{{else if eq .Key "new"}}{{icon "plus"}}{{else}}{{icon "layers"}}{{end}}{{end}} |
| {{define "nav_index"}}{{template "top" .}} |
| {{if .Flash}}<p class="banner">{{.Flash}}</p>{{end}} |
| {{if .FlashErr}}<p class="banner error">{{.FlashErr}}</p>{{end}} |
| -{{if or (eq .IndexOf "account") (eq .IndexOf "accounts")}} |
| -<h1 id="index-title">{{if eq .IndexOf "accounts"}}Accounts{{else}}{{.Account.Name}}{{end}}</h1> |
| -<nav class="index-nav" aria-labelledby="index-title"> |
| -{{else}} |
| -<div class="pagehead"> |
| - <p class="eyebrow">App · {{.Account.Name}}</p> |
| - <h1>{{if eq .IndexOf "settings"}}Settings{{else}}{{.AppName}}{{end}}</h1> |
| +<div class="index-context"> |
| + <span class="index-context-icon" aria-hidden="true">{{if eq .IndexOf "accounts"}}{{icon "user-round"}}{{else if eq .IndexOf "account"}}{{icon "layers"}}{{else}}{{icon "layout-grid"}}{{end}}</span> |
| + <div class="index-context-copy"> |
| + {{if eq .IndexOf "accounts"}} |
| + <h1 id="index-title">Accounts</h1> |
| + <p class="index-meta">{{.Address}}</p> |
| + {{else if eq .IndexOf "account"}} |
| + <p class="eyebrow">Account</p> |
| + <h1 id="index-title">{{.Account.Name}}</h1> |
| + <p class="index-meta"><code>{{.Account.Sqid}}</code><span aria-hidden="true"> · </span>{{.Role}}</p> |
| + {{else if eq .IndexOf "settings"}} |
| + <p class="eyebrow">{{.Account.Name}} · {{.AppName}}</p> |
| + <h1 id="index-title">Settings</h1> |
| + {{else}} |
| + <p class="eyebrow">App · {{.Account.Name}}</p> |
| + <h1 id="index-title">{{.AppName}}</h1> |
| + {{end}} |
| + </div> |
| </div> |
| -<nav class="index-nav" aria-label="{{if eq .IndexOf "settings"}}Settings sections{{else}}App sections{{end}}"> |
| -{{end}} |
| - {{range .IndexLinks}}<a id="nav-{{.Key}}" href="{{.Href}}">{{.Label}}</a> |
| +<nav class="index-nav" {{if or (eq .IndexOf "accounts") (eq .IndexOf "account")}}aria-labelledby="index-title"{{else}}aria-label="{{if eq .IndexOf "settings"}}Settings sections{{else}}App sections{{end}}"{{end}}> |
| + {{range .IndexLinks}}<a id="nav-{{.Key}}" href="{{.Href}}" class="index-row index-key-{{.Key}}"> |
| + <span class="index-icon" aria-hidden="true">{{template "index_icon" .}}</span> |
| + <span class="index-label">{{.Label}}</span> |
| + <span class="index-chevron" aria-hidden="true">{{icon "chevron-right"}}</span> |
| + </a> |
| {{end}} |
| </nav> |
| {{template "bottom" .}}{{end}} |