-
Notifications
You must be signed in to change notification settings - Fork 0
/
nav_links.go
52 lines (44 loc) · 1.03 KB
/
nav_links.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
package compton
import (
_ "embed"
"github.com/boggydigital/compton/consts/color"
"github.com/boggydigital/compton/consts/compton_atoms"
)
type NavLinksElement struct {
*BaseElement
}
func NavLinks(r Registrar) *NavLinksElement {
navLinks := &NavLinksElement{
BaseElement: NewElement(atomsEmbedMarkup(compton_atoms.NavLinks, DefaultMarkup)),
}
r.RegisterStyles(DefaultStyle,
compton_atoms.StyleName(compton_atoms.NavLinks))
return navLinks
}
func NavLinksTargets(r Registrar, targets ...*Target) *NavLinksElement {
nl := NavLinks(r)
for _, t := range targets {
appendTarget(r, nl, t)
}
return nl
}
func appendTarget(r Registrar, nl *NavLinksElement, t *Target) {
li := ListItem()
link := A(t.Href)
if t.Icon != None {
icon := SvgUse(r, t.Icon)
icon.SetAttribute("title", t.Title)
link.Append(icon)
if t.Current {
icon.ForegroundColor(color.Background)
link.Append(SpanText(t.Title))
}
} else {
link.Append(Text(t.Title))
}
if t.Current {
link.AddClass("selected")
}
li.Append(link)
nl.Append(li)
}