forked from nobonobo/bootstrap4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
navbar.go
156 lines (144 loc) · 3.98 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package bootstrap4
//<nav class="navbar navbar-expand-lg navbar-light bg-light">
import (
"github.com/gowasm/vecty"
"github.com/gowasm/vecty/elem"
"github.com/gowasm/vecty/prop"
)
// Navbar ...
type Navbar struct {
vecty.Core
ID string `vecty:"prop"`
Size Size `vecty:"prop"`
Expand bool `vecty:"prop"`
Light bool `vecty:"prop"`
Dark bool `vecty:"prop"`
StickyTop bool `vecty:"prop"`
FixedTop bool `vecty:"prop"`
FixedBottom bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *Navbar) Render() vecty.ComponentOrHTML {
return elem.Navigation(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.ClassMap{
"navbar": true,
"navbar-" + c.Size.String(): !c.Expand && len(c.Size) > 0,
"navbar-expand-" + c.Size.String(): c.Expand && len(c.Size) > 0,
"bg-light": c.Light,
"navbar-light": c.Light,
"bg-dark": c.Dark,
"navbar-dark": c.Dark,
"sticky-top": c.StickyTop,
"fixed-top": c.FixedTop,
"fixed-bottom": c.FixedBottom,
},
),
c.Markup,
c.Children,
)
}
// NavbarToggler ...
type NavbarToggler struct {
vecty.Core
ID string `vecty:"prop"`
Type prop.InputType `vecty:"prop"`
Target string `vecty:"prop"`
Light bool `vecty:"prop"`
Dark bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
}
// Render ...
func (c *NavbarToggler) Render() vecty.ComponentOrHTML {
return elem.Button(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.MarkupIf(len(c.Type) > 0, prop.Type(c.Type)),
vecty.ClassMap{
"navbar-toggler": true,
"bg-light": c.Light,
"navbar-light": c.Light,
"bg-dark": c.Dark,
"navbar-dark": c.Dark,
},
vecty.Data("toggle", "collapse"),
vecty.MarkupIf(len(c.Target) > 0, vecty.Data("target", c.Target)),
),
c.Markup,
elem.Span(
vecty.Markup(vecty.Class("navbar-toggler-icon")),
),
)
}
// NavbarCollapse ...
type NavbarCollapse struct {
vecty.Core
ID string `vecty:"prop"`
Light bool `vecty:"prop"`
Dark bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *NavbarCollapse) Render() vecty.ComponentOrHTML {
return elem.Div(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.ClassMap{
"navbar-collapse": true,
"collapse": true,
"bg-light": c.Light,
"navbar-light": c.Light,
"bg-dark": c.Dark,
"navbar-dark": c.Dark,
},
),
c.Markup,
c.Children,
)
}
// NavbarNav ...
type NavbarNav struct {
vecty.Core
ID string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *NavbarNav) Render() vecty.ComponentOrHTML {
return elem.UnorderedList(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.ClassMap{
"navbar-nav": true,
},
),
c.Markup,
c.Children,
)
}
// NavbarBrand ...
type NavbarBrand struct {
vecty.Core
ID string `vecty:"prop"`
Href string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *NavbarBrand) Render() vecty.ComponentOrHTML {
return elem.Anchor(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.ClassMap{
"navbar-brand": true,
},
vecty.MarkupIf(len(c.Href) > 0, prop.Href(c.Href)),
),
c.Markup,
c.Children,
)
}