-
Notifications
You must be signed in to change notification settings - Fork 0
/
labels.go
81 lines (67 loc) · 1.71 KB
/
labels.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
package compton
import (
_ "embed"
"github.com/boggydigital/compton/consts/class"
"github.com/boggydigital/compton/consts/compton_atoms"
"github.com/boggydigital/compton/consts/size"
"golang.org/x/net/html/atom"
"io"
)
type FormattedLabel struct {
Property string
Title string
Class string
}
type LabelsElement struct {
BaseElement
//r compton.Registrar
container Element
}
func createLabelElement(fmtLabel FormattedLabel) Element {
label := ListItemText(fmtLabel.Title)
cs := []string{"label", fmtLabel.Property, fmtLabel.Title, fmtLabel.Class}
label.AddClass(cs...)
return label
}
func (lse *LabelsElement) unorderedList() Element {
if uls := lse.container.GetElementsByTagName(atom.Ul); len(uls) > 0 {
return uls[0]
} else {
panic("labels missing ul element")
}
}
func (lse *LabelsElement) Write(w io.Writer) error {
return lse.container.Write(w)
}
func (lse *LabelsElement) FontSize(s size.Size) *LabelsElement {
lse.unorderedList().AddClass(class.FontSize(s))
return lse
}
func (lse *LabelsElement) RowGap(s size.Size) *LabelsElement {
lse.unorderedList().AddClass(class.RowGap(s))
return lse
}
func (lse *LabelsElement) ColumnGap(s size.Size) *LabelsElement {
lse.unorderedList().AddClass(class.ColumnGap(s))
return lse
}
func Labels(r Registrar, fmtLabels ...FormattedLabel) *LabelsElement {
lse := &LabelsElement{
BaseElement: BaseElement{
TagName: compton_atoms.Labels,
},
//r: r,
}
lse.container = Span()
lse.container.AddClass("labels")
ul := Ul()
for _, fl := range fmtLabels {
if fl.Title != "" {
ul.Append(createLabelElement(fl))
}
}
lse.container.Append(ul)
r.RegisterStyles(DefaultStyle,
compton_atoms.StyleName(compton_atoms.Labels))
return lse
}