forked from nobonobo/bootstrap4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.go
229 lines (213 loc) · 6.63 KB
/
forms.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package bootstrap4
import (
"github.com/gowasm/vecty"
"github.com/gowasm/vecty/elem"
"github.com/gowasm/vecty/prop"
)
// FormGroup ...
type FormGroup struct {
vecty.Core
ID string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *FormGroup) Render() vecty.ComponentOrHTML {
return elem.Div(
vecty.Markup(vecty.Class("form-group")),
c.Markup,
c.Children,
)
}
// FormCheck ...
type FormCheck struct {
vecty.Core
ID string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *FormCheck) Render() vecty.ComponentOrHTML {
return elem.Div(
vecty.Markup(vecty.Class("form-check")),
c.Markup,
c.Children,
)
}
// Label ...
type Label struct {
vecty.Core
ID string `vecty:"prop"`
For string `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *Label) Render() vecty.ComponentOrHTML {
return elem.Label(
vecty.Markup(
vecty.MarkupIf(len(c.For) > 0, vecty.Attribute("for", c.For)),
),
c.Markup,
c.Children,
)
}
// Input ...
type Input struct {
vecty.Core
Type prop.InputType `vecty:"prop"`
ID string `vecty:"prop"`
Name string `vecty:"prop"`
Value string `vecty:"prop"`
PlaceHolder string `vecty:"prop"`
Title string `vecty:"prop"`
TabIndex int `vecty:"prop"`
Size Size `vecty:"prop"`
Readonly bool `vecty:"prop"`
PlainText bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *Input) Render() vecty.ComponentOrHTML {
return elem.Input(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.MarkupIf(len(c.Type) > 0, prop.Type(c.Type)),
vecty.MarkupIf(len(c.Name) > 0, vecty.Attribute("name", c.Name)),
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{
"form-control": c.Type != prop.TypeFile,
"form-control-file": c.Type == prop.TypeFile,
"form-control-plaintext": c.PlainText,
"form-control-" + c.Size.String(): len(c.Size) > 0,
},
vecty.MarkupIf(len(c.PlaceHolder) > 0,
vecty.Attribute("placeholder", c.PlaceHolder),
),
vecty.MarkupIf(c.Readonly || c.PlainText,
vecty.Attribute("readonly", ""),
),
vecty.MarkupIf(len(c.Value) > 0,
vecty.Attribute("value", c.Value),
),
),
c.Markup,
c.Children,
)
}
// CheckInput ...
type CheckInput struct {
vecty.Core
ID string `vecty:"prop"`
Type prop.InputType `vecty:"prop"`
Name string `vecty:"prop"`
Checked bool `vecty:"prop"`
Title string `vecty:"prop"`
TabIndex int `vecty:"prop"`
Size Size `vecty:"prop"`
Disabled bool `vecty:"prop"`
NoLabel bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *CheckInput) Render() vecty.ComponentOrHTML {
return elem.Input(
vecty.Markup(
vecty.MarkupIf(len(c.ID) > 0, prop.ID(c.ID)),
vecty.MarkupIf(len(c.Type) > 0, prop.Type(c.Type)),
vecty.MarkupIf(len(c.Name) > 0, vecty.Attribute("name", c.Name)),
vecty.MarkupIf(len(c.Title) > 0, vecty.Attribute("title", c.Title)),
vecty.MarkupIf(c.TabIndex != 0, vecty.Attribute("tabindex", c.TabIndex)),
vecty.ClassMap{
"form-check-input": true,
"position-static": c.NoLabel,
"form-control-" + c.Size.String(): len(c.Size) > 0,
},
vecty.MarkupIf(c.Disabled,
vecty.Attribute("disabled", ""),
),
vecty.MarkupIf(c.Checked,
vecty.Attribute("checked", ""),
),
),
c.Markup,
c.Children,
)
}
// TextArea ...
type TextArea struct {
vecty.Core
ID string `vecty:"prop"`
Name string `vecty:"prop"`
PlaceHolder string `vecty:"prop"`
Title string `vecty:"prop"`
TabIndex int `vecty:"prop"`
Size Size `vecty:"prop"`
Readonly bool `vecty:"prop"`
Rows int `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *TextArea) Render() vecty.ComponentOrHTML {
return elem.TextArea(
vecty.Markup(
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.Title) > 0, vecty.Attribute("title", c.Title)),
vecty.MarkupIf(c.TabIndex != 0, vecty.Attribute("tabindex", c.TabIndex)),
vecty.ClassMap{
"form-control": true,
"form-control-" + c.Size.String(): len(c.Size) > 0,
},
vecty.MarkupIf(len(c.PlaceHolder) > 0,
vecty.Attribute("placeholder", c.PlaceHolder),
),
vecty.MarkupIf(c.Readonly,
vecty.Attribute("readonly", ""),
),
vecty.MarkupIf(c.Rows > 0,
vecty.Attribute("rows", c.Rows),
),
),
c.Markup,
c.Children,
)
}
// Select ...
type Select struct {
vecty.Core
ID string `vecty:"prop"`
Name string `vecty:"prop"`
Title string `vecty:"prop"`
TabIndex int `vecty:"prop"`
Size Size `vecty:"prop"`
Readonly bool `vecty:"prop"`
Multiple bool `vecty:"prop"`
Markup vecty.MarkupList `vecty:"prop"`
Children vecty.ComponentOrHTML `vecty:"prop"`
}
// Render ...
func (c *Select) Render() vecty.ComponentOrHTML {
return elem.Select(
vecty.Markup(
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.Title) > 0, vecty.Attribute("title", c.Title)),
vecty.MarkupIf(c.TabIndex != 0, vecty.Attribute("tabindex", c.TabIndex)),
vecty.ClassMap{
"form-control": true,
"form-control-" + c.Size.String(): len(c.Size) > 0,
},
vecty.MarkupIf(c.Multiple, vecty.Attribute("multiple", "")),
vecty.MarkupIf(c.Readonly, vecty.Attribute("readonly", "")),
),
c.Markup,
c.Children,
)
}
// Custom forms not supported.