Add support for tabs
This commit is contained in:
parent
7b5f8a9882
commit
207e23778b
6 changed files with 50 additions and 12 deletions
|
|
@ -19,6 +19,7 @@ type Flags struct {
|
|||
assets.Assets // assets are the assets included in the template
|
||||
|
||||
Crumbs []component.MenuItem // crumbs are the breadcrumbs leading to a specific action
|
||||
Tabs []component.MenuItem // tabs are shown above actions, and act as a menu
|
||||
Actions []component.MenuItem // actions are the actions available to a specific thingy
|
||||
}
|
||||
|
||||
|
|
@ -77,12 +78,10 @@ func Actions(actions ...component.MenuItem) FlagFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// ReplaceAction replaces a specific action
|
||||
func ReplaceAction(old component.MenuItem, action component.MenuItem) FlagFunc {
|
||||
// Tabs sets the tabs
|
||||
func Tabs(actions ...component.MenuItem) FlagFunc {
|
||||
return func(flags Flags, r *http.Request) Flags {
|
||||
if !old.ReplaceWith(action, flags.Actions) {
|
||||
zerolog.Ctx(r.Context()).Warn().Str("action", fmt.Sprint(action)).Str("actions", fmt.Sprint(flags.Actions)).Msg("did not replace menu item")
|
||||
}
|
||||
flags.Tabs = slices.Clone(actions)
|
||||
return flags
|
||||
}
|
||||
}
|
||||
|
|
@ -97,6 +96,26 @@ func ReplaceCrumb(old component.MenuItem, action component.MenuItem) FlagFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// ReplaceAction replaces a specific action
|
||||
func ReplaceAction(old component.MenuItem, action component.MenuItem) FlagFunc {
|
||||
return func(flags Flags, r *http.Request) Flags {
|
||||
if !old.ReplaceWith(action, flags.Actions) {
|
||||
zerolog.Ctx(r.Context()).Warn().Str("action", fmt.Sprint(action)).Str("actions", fmt.Sprint(flags.Actions)).Msg("did not replace menu item")
|
||||
}
|
||||
return flags
|
||||
}
|
||||
}
|
||||
|
||||
// ReplaceTab replaces a specific tab
|
||||
func ReplaceTab(old component.MenuItem, tab component.MenuItem) FlagFunc {
|
||||
return func(flags Flags, r *http.Request) Flags {
|
||||
if !old.ReplaceWith(tab, flags.Tabs) {
|
||||
zerolog.Ctx(r.Context()).Warn().Str("tab", fmt.Sprint(tab)).Str("tabs", fmt.Sprint(flags.Tabs)).Msg("did not replace menu item")
|
||||
}
|
||||
return flags
|
||||
}
|
||||
}
|
||||
|
||||
// Title sets the title of this template
|
||||
func Title(title string) FlagFunc {
|
||||
return func(flags Flags, r *http.Request) Flags {
|
||||
|
|
|
|||
|
|
@ -40,9 +40,21 @@
|
|||
{{ end }}
|
||||
</header>
|
||||
<main>
|
||||
{{ if .Runtime.Flags.Tabs }}
|
||||
<div class="pure-menu tabs-menu">
|
||||
<ul class="pure-menu-list">
|
||||
{{ range .Runtime.Flags.Tabs }}
|
||||
<li class="pure-menu-item {{ if .Active }}pure-menu-selected{{ end }}">
|
||||
<a href="{{ .Path }}" class="pure-menu-link">{{ .Title }}</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div class="pure-g" id="main">
|
||||
{{ .Main }}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue