-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.go
101 lines (85 loc) · 2.5 KB
/
card.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
package compton
import (
"github.com/boggydigital/compton/consts/class"
"github.com/boggydigital/compton/consts/compton_atoms"
"github.com/boggydigital/compton/consts/size"
"github.com/boggydigital/issa"
"golang.org/x/net/html/atom"
)
type CardElement struct {
*BaseElement
r Registrar
}
func (ce *CardElement) AppendPoster(background, placeholder, poster string, hydrated bool) *CardElement {
if posterPlaceholder := ce.GetFirstElementByTagName(compton_atoms.Placeholder); posterPlaceholder != nil {
if hydrated {
hydratedPlaceholder := issa.HydrateColor(placeholder)
posterPlaceholder.Append(IssaImageHydrated(ce.r, background, hydratedPlaceholder, poster))
} else {
issaImg := IssaImageDehydrated(ce.r, background, placeholder, poster)
posterPlaceholder.Append(issaImg)
}
}
return ce
}
func (ce *CardElement) AppendTitle(title string) *CardElement {
if h3 := ce.GetFirstElementByTagName(atom.H3); h3 != nil {
h3.Append(Text(title))
}
return ce
}
func (ce *CardElement) AppendProperty(title string, values ...Element) *CardElement {
if ul := ce.GetFirstElementByTagName(atom.Ul); ul != nil {
liProperty := Li()
liProperty.AddClass("property")
spanTitle := SpanText(title)
spanTitle.AddClass("title")
spanValues := Span()
spanValues.AddClass("values")
spanValues.Append(values...)
liProperty.Append(spanTitle, spanValues)
ul.Append(liProperty)
}
return ce
}
func (ce *CardElement) AppendLabels(labels ...Element) *CardElement {
if liLables := ce.GetElementsByClassName("labels"); len(liLables) > 0 {
liLables[0].Append(labels...)
}
return ce
}
func (ce *CardElement) Width(s size.Size) *CardElement {
ce.AddClass(class.Width(s))
return ce
}
func (ce *CardElement) WidthPixels(px float64) *CardElement {
ce.AddClass(class.WidthPixels(px))
return ce
}
func (ce *CardElement) Height(s size.Size) *CardElement {
ce.AddClass(class.Height(s))
return ce
}
func (ce *CardElement) HeightPixels(px float64) *CardElement {
ce.AddClass(class.HeightPixels(px))
return ce
}
func Card(r Registrar, id string) *CardElement {
card := &CardElement{
BaseElement: NewElement(tacMarkup(compton_atoms.Card)),
r: r,
}
card.SetAttribute("data-id", id)
card.SetAttribute("tabindex", "-1")
// issa-image poster slot
card.Append(Placeholder())
ul := Ul()
liTitle := Li()
liTitle.Append(H3())
liLabels := Li()
liLabels.AddClass("labels")
ul.Append(liTitle, liLabels)
card.Append(ul)
r.RegisterStyles(DefaultStyle, compton_atoms.StyleName(compton_atoms.Card))
return card
}