This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotnav.templ
75 lines (65 loc) · 1.51 KB
/
dotnav.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package franken
type DotNavigationType byte
const (
DotNavigationTypeHorizontal DotNavigationType = 0
DotNavigationTypeVertical DotNavigationType = 1
)
type DotNavigationData struct {
Type DotNavigationType
Items []singleDotNavigationData
Class []string
}
type singleDotNavigationData struct {
Title string
Link string
Active bool
Class []string
}
templ DotNavigation(data DotNavigationData) {
<ul
class={ templ.Classes(map[string]bool{
"uk-dotnav": true,
"uk-dotnav-vertical": data.Type == DotNavigationTypeVertical,
}), data.Class }
>
for _, item := range(data.Items) {
<li
class={ templ.Classes(map[string]bool{
"uk-active": item.Active,
}), item.Class }
>
if item.Link != "" {
<a href={ templ.URL(item.Link) }>{ item.Title }</a>
} else {
{ item.Title }
}
</li>
}
</ul>
}
func DotNavigationBuilder() *DotNavigationData {
return &DotNavigationData{
Type: DotNavigationTypeHorizontal,
Items: make([]singleDotNavigationData, 0),
}
}
func (d *DotNavigationData) SetType(dType DotNavigationType) *DotNavigationData {
d.Type = dType
return d
}
func (d *DotNavigationData) AddItem(title, link string, active bool, class ...string) *DotNavigationData {
d.Items = append(d.Items, singleDotNavigationData{
Title: title,
Link: link,
Active: active,
Class: class,
})
return d
}
func (d *DotNavigationData) SetClass(class ...string) *DotNavigationData {
d.Class = class
return d
}
templ (d DotNavigationData) Finish() {
@DotNavigation(d)
}