-
Notifications
You must be signed in to change notification settings - Fork 0
/
icon.go
70 lines (63 loc) · 1.08 KB
/
icon.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
package icon
import (
"github.com/gopherjs/vecty"
"github.com/gopherjs/vecty/elem"
"github.com/wizenerd/color"
)
// Size represents the icon size
type Size uint
//common icon size
const (
None Size = iota
Size18
Size24
Size36
Size48
)
func (s Size) String() string {
o := ""
switch s {
case Size18:
o = "18"
case Size24:
o = "24"
case Size36:
o = "36"
case Size48:
o = "48"
}
return o
}
// Icon represents material design icon component
type Icon struct {
vecty.Core
Name Name
Children vecty.MarkupOrComponentOrHTML
Size Size
Classes vecty.ClassMap
}
// Render implements vecty.COmponent
func (i *Icon) Render() *vecty.HTML {
c := make(vecty.ClassMap)
c["material-icons"] = true
if i.Size.String() != "" {
c["md="+i.Size.String()] = true
}
if i.Classes != nil {
for k, v := range i.Classes {
c[k] = v
}
}
return elem.Italic(
c,
i.Children,
vecty.Text(string(i.Name)),
)
}
//SetColor sets the icon color to c
func (i *Icon) SetColor(c color.Color) {
if i.Classes == nil {
i.Classes = make(vecty.ClassMap)
}
i.Classes[c.Text()] = true
}