-
Notifications
You must be signed in to change notification settings - Fork 0
/
details_summary.go
132 lines (110 loc) · 3.38 KB
/
details_summary.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package compton
import (
_ "embed"
"github.com/boggydigital/compton/consts/align"
"github.com/boggydigital/compton/consts/class"
"github.com/boggydigital/compton/consts/color"
"github.com/boggydigital/compton/consts/compton_atoms"
"github.com/boggydigital/compton/consts/direction"
"github.com/boggydigital/compton/consts/font_weight"
"github.com/boggydigital/compton/consts/size"
"golang.org/x/net/html/atom"
"io"
)
type DetailsSummaryElement struct {
BaseElement
details Element
}
func (dse *DetailsSummaryElement) Append(children ...Element) {
dse.details.Append(children...)
}
func (dse *DetailsSummaryElement) AppendSummary(children ...Element) {
if summary := dse.getSummary(); summary != nil {
summary.Append(children...)
}
}
func (dse *DetailsSummaryElement) SummaryMarginBlockEnd(s size.Size) *DetailsSummaryElement {
if summaries := dse.details.GetElementsByTagName(atom.Summary); len(summaries) > 0 {
summaries[0].AddClass(class.MarginBlockEnd(s))
}
return dse
}
func (dse *DetailsSummaryElement) DetailsMarginBlockEnd(s size.Size) *DetailsSummaryElement {
dse.details.AddClass(class.MarginBlockEnd(s))
return dse
}
func (dse *DetailsSummaryElement) SummaryRowGap(s size.Size) *DetailsSummaryElement {
if summary := dse.getSummary(); summary != nil {
summary.AddClass(class.RowGap(s))
}
return dse
}
func (dse *DetailsSummaryElement) BackgroundColor(c color.Color) *DetailsSummaryElement {
if summary := dse.getSummary(); summary != nil {
summary.AddClass(class.BackgroundColor(c))
}
return dse
}
func (dse *DetailsSummaryElement) ForegroundColor(c color.Color) *DetailsSummaryElement {
if summary := dse.getSummary(); summary != nil {
summary.AddClass(class.ForegroundColor(c))
}
return dse
}
func (dse *DetailsSummaryElement) MarkerColor(c color.Color) *DetailsSummaryElement {
if summary := dse.getSummary(); summary != nil {
summary.AddClass(class.MarkerColor(c))
}
return dse
}
func (dse *DetailsSummaryElement) getSummary() Element {
if summaries := dse.details.GetElementsByTagName(atom.Summary); len(summaries) > 0 {
return summaries[0]
}
return nil
}
func (dse *DetailsSummaryElement) Write(w io.Writer) error {
return dse.details.Write(w)
}
func (dse *DetailsSummaryElement) SetId(id string) {
dse.details.SetId(id)
}
func create(r Registrar, summary Element, open bool) *DetailsSummaryElement {
dse := &DetailsSummaryElement{
BaseElement: BaseElement{
TagName: compton_atoms.DetailsSummary,
},
details: Details(),
}
if open {
dse.details.SetAttribute("open", "")
}
svgPlus := SvgUse(r, Plus)
svgPlus.AddClass("details-summary-marker")
summaryElement := Summary()
summaryTitleRow := FlexItems(r, direction.Row).
ColumnGap(size.Small).
AlignItems(align.Center)
summaryTitleRow.Append(svgPlus, summary)
summaryElement.Append(summaryTitleRow)
dse.details.Append(summaryElement)
r.RegisterStyles(DefaultStyle,
compton_atoms.StyleName(compton_atoms.DetailsSummary))
return dse
}
func DSLarge(r Registrar, summary Element, open bool) *DetailsSummaryElement {
dse := create(r, summary, open)
dse.details.AddClass("larger")
return dse
}
func DSSmall(r Registrar, summary Element, open bool) *DetailsSummaryElement {
dse := create(r, summary, open)
dse.details.AddClass("smaller")
return dse
}
func DSTitle(r Registrar, title string) Element {
fs := Fspan(r, title).
FontWeight(font_weight.Bolder).
FontSize(size.Large)
return fs
}