-
Notifications
You must be signed in to change notification settings - Fork 6
/
navbar.go
121 lines (101 loc) · 3.36 KB
/
navbar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package control
import (
"github.com/goradd/goradd/pkg/html"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/bootstrap/config"
)
const (
NavTabs = "nav-tabs"
NavPills = "nav-pills"
NavJustified = "nav-justified"
NavbarHeader = "navbar-header"
NavbarCollapse = "navbar-collapse"
NavbarBrand = "navbar-brand"
NavbarToggle = "navbar-toggle"
NavbarNav = "navbar-nav"
NavbarLeft = "navbar-left"
NavbarRight = "navbar-right"
NavbarForm = "navbar-form"
)
type NavbarExpandClass string
const (
NavbarExpandExtraLarge NavbarExpandClass = "navbar-expand-xl"
NavbarExpandLarge = "navbar-expand-lg"
NavbarExpandMedium = "navbar-expand-md"
NavbarExpandSmall = "navbar-expand-sm"
// NavbarExpandNone will always show the navbar as collapsed at any size
NavbarExpandNone = ""
)
// NavbarCollapsedBrandPlacement controls the location of the brand when the navbar is collapsed
type NavbarCollapsedBrandPlacement int
const (
// NavbarCollapsedBrandLeft will place the brand on the left and the toggle button on the right when collapsed
NavbarCollapsedBrandLeft NavbarCollapsedBrandPlacement = iota
// NavbarCollapsedBrandRight will place the brand on the right and the toggle button on the left when collapsed
NavbarCollapsedBrandRight
// NavbarCollapsedBrandHidden means the brand will be hidden when collapsed, and shown when expanded
NavbarCollapsedBrandHidden
)
type NavbarI interface {
page.ControlI
}
// Navbar is a bootstrap navbar object. Use SetText() to set the logo text of the navbar, and
// SetEscapeText() to false to turn off encoding if needed. Add child controls to populate it.
type Navbar struct {
page.Control
headerAnchor string
style NavbarStyle
//container ContainerClass ??
background BackgroundColorClass
expand NavbarExpandClass
brandLocation NavbarCollapsedBrandPlacement
}
type NavbarStyle string
const (
NavbarDark NavbarStyle = "navbar-dark" // black on white
NavbarLight = "navbar-light"
)
// NewNavbar returns a newly created Bootstrap Navbar object
func NewNavbar(parent page.ControlI, id string) *Navbar {
b := &Navbar{}
b.Init(b, parent, id)
return b
}
func (b *Navbar) Init(self page.ControlI, parent page.ControlI, id string) {
b.Control.Init(self, parent, id)
b.Tag = "nav"
b.style = NavbarDark // default
b.background = BackgroundColorDark
b.expand = NavbarExpandLarge
config.LoadBootstrap(b.ParentForm())
}
func (b *Navbar) this() NavbarI {
return b.Self.(NavbarI)
}
func (b *Navbar) SetNavbarStyle(style NavbarStyle) NavbarI {
b.style = style
return b.this()
}
func (b *Navbar) SetBackgroundClass(c BackgroundColorClass) NavbarI {
b.background = c
return b.this()
}
func (b *Navbar) SetHeaderAnchor(a string) NavbarI {
b.headerAnchor = a
return b.this()
}
// SetBrandPlacement places the brand left, right, or hidden (meaning inside the collapse area).
// The expand button location will be affected by the placement
func (b *Navbar) SetBrandPlacement(p NavbarCollapsedBrandPlacement) NavbarI {
b.brandLocation = p
return b.this()
}
func (b *Navbar) ΩDrawingAttributes() *html.Attributes {
a := b.Control.ΩDrawingAttributes()
a.AddClass("navbar")
a.AddClass(string(b.style))
a.AddClass(string(b.expand))
a.AddClass(string(b.background))
a.SetDataAttribute("grctl", "bs-navbar")
return a
}