Move menu bar styling to template

This commit is contained in:
2025-10-15 09:45:17 +02:00
parent f9c5ccc378
commit 8a44f06fb1
2 changed files with 22 additions and 24 deletions

View File

@@ -1,7 +1,5 @@
package server
import "html/template"
// This file defines the data structures and helper functions for the template system.
//
// The template system uses Go's html/template package to provide:
@@ -25,13 +23,13 @@ type PageData struct {
// MenuGroup represents a dropdown menu in the navbar.
type MenuGroup struct {
LabelHTML template.HTML
Label string
Items []MenuItem
}
// MenuItem represents a single menu item.
type MenuItem struct {
LabelHTML template.HTML
Label string
URL string
IsDivider bool
}
@@ -42,29 +40,29 @@ func DefaultMenuBar() PageData {
ShowClock: true,
MenuGroups: []MenuGroup{
{
LabelHTML: template.HTML(`<span class="red-168-text">F</span>ile`),
Label: "File",
Items: []MenuItem{
{LabelHTML: template.HTML(`<span class="red-168-text">N</span>ew`), URL: "#!"},
{LabelHTML: template.HTML(`<span class="red-168-text">O</span>pen`), URL: "#!"},
{LabelHTML: template.HTML(`<span class="red-168-text">S</span>ave`), URL: "#!"},
{LabelHTML: template.HTML(`Save <span class="red-168-text">A</span>s`), URL: "#!"},
{Label: "New", URL: "#!"},
{Label: "Open", URL: "#!"},
{Label: "Save", URL: "#!"},
{Label: "Save As", URL: "#!"},
{IsDivider: true},
{LabelHTML: template.HTML(`<span class="red-168-text">E</span>xit`), URL: "#!"},
{Label: "Exit", URL: "#!"},
},
},
{
LabelHTML: template.HTML(`<span class="red-168-text">E</span>dit`),
Label: "Edit",
Items: []MenuItem{
{LabelHTML: template.HTML(`<span class="red-168-text">C</span>ut`), URL: "#!"},
{LabelHTML: template.HTML(`C<span class="red-168-text">o</span>py`), URL: "#!"},
{LabelHTML: template.HTML(`<span class="red-168-text">P</span>aste`), URL: "#!"},
{Label: "Cut", URL: "#!"},
{Label: "Copy", URL: "#!"},
{Label: "Paste", URL: "#!"},
},
},
{
LabelHTML: template.HTML(`<span class="red-168-text">H</span>elp`),
Label: "Help",
Items: []MenuItem{
{LabelHTML: template.HTML(`<span class="red-168-text">D</span>ocumentation`), URL: "#!"},
{LabelHTML: template.HTML(`<span class="red-168-text">A</span>bout`), URL: "#!"},
{Label: "Documentation", URL: "#!"},
{Label: "About", URL: "#!"},
},
},
},
@@ -75,11 +73,11 @@ func DefaultMenuBar() PageData {
func AdminMenuBar() PageData {
data := DefaultMenuBar()
data.MenuGroups = append(data.MenuGroups, MenuGroup{
LabelHTML: template.HTML(`<span class="red-168-text">A</span>dmin`),
Label: "Admin",
Items: []MenuItem{
{LabelHTML: template.HTML(`<span class="red-168-text">U</span>sers`), URL: "/admin/users"},
{LabelHTML: template.HTML(`<span class="red-168-text">S</span>ettings`), URL: "/admin/settings"},
{LabelHTML: template.HTML(`<span class="red-168-text">L</span>ogs`), URL: "/admin/logs"},
{Label: "Users", URL: "/admin/users"},
{Label: "Settings", URL: "/admin/settings"},
{Label: "Logs", URL: "/admin/logs"},
},
})
return data

View File

@@ -3,14 +3,14 @@
<ul>
{{range .MenuGroups}}
<li class="tui-dropdown">
{{.LabelHTML}}
<span class="red-168-text">{{slice .Label 0 1}}</span>{{slice .Label 1}}
<div class="tui-dropdown-content">
<ul>
{{range .Items}}
{{if .IsDivider}}
<li class="tui-divider"></li>
{{else}}
<li><a href="{{.URL}}">{{.LabelHTML}}</a></li>
<li><a href="{{.URL}}"><span class="red-168-text">{{slice .Label 0 1}}</span>{{slice .Label 1}}</a></li>
{{end}}
{{end}}
</ul>