bulpherjs/elements/navbar.go

65 lines
1.2 KiB
Go
Raw Normal View History

2022-01-07 10:53:39 +05:00
package elements
2020-05-17 21:57:45 +05:00
import (
"github.com/gopherjs/gopherjs/js"
)
// NavBarOptions is a "nav" HTML body element configuration structure.
type NavBarOptions struct {
IsDark bool
Title string
}
// NavBar is a controlling structure for "nav" HTML body element.
type NavBar struct {
options *NavBarOptions
2022-01-07 10:53:39 +05:00
navbar *Nav
2020-05-17 21:57:45 +05:00
}
// NewNavBar creates new "nav" HTML element controlling structure.
func NewNavBar(opts *NavBarOptions) *NavBar {
n := &NavBar{}
n.initialize(opts)
return n
}
// Build builds element and calls Build() for all child elements.
func (n *NavBar) Build() *js.Object {
return n.navbar.Build()
}
// Initializes controlling structure.
func (n *NavBar) initialize(opts *NavBarOptions) {
n.options = opts
2022-01-07 10:53:39 +05:00
navopts := &NavOptions{
2020-05-17 21:57:45 +05:00
Class: "navbar",
Data: map[string]string{},
Role: "navigation",
}
2022-01-07 10:53:39 +05:00
n.navbar = NewNav(navopts)
2020-05-17 21:57:45 +05:00
if n.options.IsDark {
n.navbar.AddClassesFromString("is-dark")
}
if n.options.Title != "" {
2022-01-07 10:53:39 +05:00
brandDiv := NewDiv(&DivOptions{
2020-05-17 21:57:45 +05:00
Class: "navbar-brand",
})
n.navbar.AddChild(brandDiv)
2022-01-07 10:53:39 +05:00
navMainLink := NewA(&AOptions{
2020-05-17 21:57:45 +05:00
Class: "navbar-item",
Href: "/",
2020-05-17 21:57:45 +05:00
Text: n.options.Title,
})
brandDiv.AddChild(navMainLink)
}
}