-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectitem.go
79 lines (67 loc) · 1.3 KB
/
selectitem.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
package carbon
import "io"
type selectItem struct {
attrs []Attr
value string
text string
hidden bool
disabled bool
selected bool
}
var _ Component = (*selectItem)(nil)
func SelectItem() *selectItem {
return &selectItem{
attrs: nil,
value: "",
text: "",
hidden: false,
disabled: false,
selected: false,
}
}
func (s *selectItem) Attr(name string, value string) *selectItem {
s.attrs = append(s.attrs, Attr{name, value})
return s
}
func (s *selectItem) Value(value string) *selectItem {
s.value = value
return s
}
func (s *selectItem) Text(text string) *selectItem {
s.text = text
return s
}
func (s *selectItem) Hidden(hidden bool) *selectItem {
s.hidden = hidden
return s
}
func (s *selectItem) Disabled(disabled bool) *selectItem {
s.disabled = disabled
return s
}
func (s *selectItem) Render(w io.Writer) {
w.Write([]byte(`<option`))
if s.value != "" {
w.Write([]byte(` value="`))
io.WriteString(w, s.value)
w.Write([]byte(`"`))
}
if s.disabled {
w.Write([]byte(` disabled`))
}
if s.hidden {
w.Write([]byte(` hidden`))
}
if s.selected {
w.Write([]byte(` selected`))
}
w.Write([]byte(` class="bx--select-option">`))
{
if s.text != "" {
io.WriteString(w, s.text)
} else {
io.WriteString(w, s.value)
}
}
w.Write([]byte(`</option>`))
}