forked from nobonobo/bootstrap4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.go
114 lines (109 loc) · 4.17 KB
/
button.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
package bootstrap4
import (
"github.com/gowasm/vecty"
"github.com/gowasm/vecty/elem"
"github.com/gowasm/vecty/prop"
)
// Button ...
type Button struct {
vecty.Core
Kind Kind `vecty:"prop"`
Type prop.InputType `vecty:"prop"`
ID string `vecty:"prop"`
Name string `vecty:"prop"`
Value string `vecty:"prop"`
Title string `vecty:"prop"`
TabIndex int `vecty:"prop"`
Active bool `vecty:"prop"`
Outline bool `vecty:"prop"`
Size Size `vecty:"prop"`
Block bool `vecty:"prop"`
Disabled bool `vecty:"prop"`
Checked bool `vecty:"prop"`
Toggle string `vecty:"prop"`
Target string `vecty:"prop"`
Dismiss string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *Button) Render() vecty.ComponentOrHTML {
if len(c.Kind) == 0 {
c.Kind = KindPrimary
}
return elem.Button(
vecty.Markup(
vecty.MarkupIf(len(c.Type) == 0, prop.Type(prop.TypeButton)),
vecty.MarkupIf(len(c.Type) > 0, prop.Type(c.Type)),
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.MarkupIf(len(c.Name) > 0, vecty.Attribute("name", c.Name)),
vecty.MarkupIf(len(c.Value) > 0, prop.Value(c.Value)),
vecty.MarkupIf(len(c.Title) > 0, vecty.Attribute("title", c.Title)),
vecty.MarkupIf(c.TabIndex != 0, vecty.Attribute("tabindex", c.TabIndex)),
vecty.ClassMap{
"btn": true,
"btn-" + c.Size.String(): len(c.Size) > 0,
"btn-block": c.Block,
"active": c.Active,
"dropdown-toggle": c.Toggle == "dropdown",
},
vecty.MarkupIf(!c.Outline, vecty.Class("btn-"+c.Kind.String())),
vecty.MarkupIf(c.Outline, vecty.Class("btn-outline-"+c.Kind.String())),
vecty.MarkupIf(c.Disabled, vecty.Attribute("disabled", nil)),
vecty.MarkupIf(len(c.Toggle) > 0, vecty.Data("toggle", c.Toggle)),
vecty.MarkupIf(len(c.Target) > 0, vecty.Data("target", c.Target)),
vecty.MarkupIf(len(c.Dismiss) > 0, vecty.Data("dismiss", c.Dismiss)),
),
c.Markup,
c.Children,
)
}
// ButtonLinks ...
type ButtonLinks struct {
vecty.Core
Kind Kind `vecty:"prop"`
Href string `vecty:"prop"`
ID string `vecty:"prop"`
Title string `vecty:"prop"`
TabIndex int `vecty:"prop"`
Outline bool `vecty:"prop"`
Size Size `vecty:"prop"`
Block bool `vecty:"prop"`
Disabled bool `vecty:"prop"`
Checked bool `vecty:"prop"`
WithDropdown bool `vecty:"prop"`
Toggle string `vecty:"prop"`
Target string `vecty:"prop"`
Dismiss string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *ButtonLinks) Render() vecty.ComponentOrHTML {
if len(c.Kind) == 0 {
c.Kind = KindPrimary
}
return elem.Anchor(
vecty.Markup(
vecty.MarkupIf(len(c.Href) > 0, prop.Href(c.Href)),
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.MarkupIf(len(c.Title) > 0, vecty.Attribute("title", c.Title)),
vecty.MarkupIf(c.TabIndex != 0, vecty.Attribute("tabindex", c.TabIndex)),
vecty.ClassMap{
"btn": true,
"btn-" + c.Size.String(): len(c.Size) > 0,
"btn-block": c.Block,
"disabled": c.Disabled,
"dropdown-toggle": c.Toggle == "dropdown",
},
vecty.MarkupIf(!c.Outline, vecty.Class("btn-"+c.Kind.String())),
vecty.MarkupIf(c.Outline, vecty.Class("btn-outline-"+c.Kind.String())),
vecty.Attribute("role", "button"),
vecty.MarkupIf(len(c.Toggle) > 0, vecty.Data("toggle", c.Toggle)),
vecty.MarkupIf(len(c.Target) > 0, vecty.Data("target", c.Target)),
vecty.MarkupIf(len(c.Dismiss) > 0, vecty.Data("dismiss", c.Dismiss)),
),
c.Markup,
c.Children,
)
}