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

View File

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