-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbottomNav.templ
61 lines (49 loc) · 1.17 KB
/
bottomNav.templ
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
package templdais
type BottomNavAttrs struct {
Size string
Brand string
Items []BtmNavItem
Class string
}
type BtmNavItem struct {
Body templ.Component
Button ButtonAttrs
Attrs templ.Attributes
Active bool
}
script SetActive(index int) {
var items = document.querySelectorAll('.btm-nav button')
items.forEach((item, i) => {
if (i === index) {
item.classList.add('active')
} else {
item.classList.remove('active')
}
})
}
func (btm BottomNavAttrs) GetClassName() string {
var class = "btm-nav" + getClassName("", btm.Size, "", "btm-nav")
if btm.Class != "" {
class += ` ` + btm.Class
}
return trimSpaces(class)
}
func (item BtmNavItem) GetClassName(brand string) string {
var class = getClassName(brand, item.Button.Figure, item.Button.Size, "text")
if item.Button.Class != "" {
class += " " + item.Button.Class
}
return trimSpaces(class)
}
templ BottomNav(attrs BottomNavAttrs) {
<nav class={ attrs.GetClassName() }>
for i, item := range attrs.Items {
<button
{item.Attrs...}
onfocus={SetActive(i)}
class={ item.GetClassName(attrs.Brand) }>
@item.Body
</button>
}
</nav>
}