-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLabel.go
More file actions
130 lines (83 loc) · 2.19 KB
/
Label.go
File metadata and controls
130 lines (83 loc) · 2.19 KB
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
package ui
import "github.com/cookiengineer/gooey/bindings/dom"
import "github.com/cookiengineer/gooey/components"
import "github.com/cookiengineer/gooey/components/utils"
import "github.com/cookiengineer/gooey/components/interfaces"
import "strings"
type Label struct {
Label string `json:"label"`
Type string `json:"type"`
Component *components.Component `json:"component"`
}
func NewLabel(lbl string, typ string) Label {
var label Label
element := dom.GetDocument().CreateElement("label")
component := components.NewComponent(element)
label.Component = &component
label.Label = lbl
label.Type = strings.ToLower(typ)
return label
}
func ToLabel(element *dom.Element) *Label {
var label Label
component := components.NewComponent(element)
label.Component = &component
label.Label = strings.TrimSpace(element.TextContent)
label.Type = element.GetAttribute("data-type")
return &label
}
func (label *Label) Disable() bool {
return false
}
func (label *Label) Enable() bool {
return false
}
func (label *Label) Mount() bool {
return true
}
func (label *Label) Query(query string) interfaces.Component {
selectors := utils.SplitQuery(query)
if len(selectors) == 1 {
if label.Component.Element != nil {
if utils.MatchesQuery(label.Component.Element, selectors[0]) == true {
return label
}
}
}
return nil
}
func (label *Label) Render() *dom.Element {
if label.Component.Element != nil {
if label.Label != "" {
label.Component.Element.SetInnerHTML(label.Label)
}
if label.Type != "" {
label.Component.Element.SetAttribute("data-type", label.Type)
}
}
return label.Component.Element
}
func (label *Label) SetLabel(label_value string) {
label.Label = strings.TrimSpace(label_value)
label.Render()
}
func (label *Label) SetType(typ string) {
label.Type = strings.TrimSpace(strings.ToLower(typ))
label.Render()
}
func (label *Label) String() string {
html := ""
if label.Type != "" {
html += "<label data-type=\"" + label.Type + "\">"
} else {
html += "<label>"
}
if label.Label != "" {
html += label.Label
}
html += "</label>"
return html
}
func (label *Label) Unmount() bool {
return true
}