-
Notifications
You must be signed in to change notification settings - Fork 1
/
radio.go
154 lines (144 loc) · 3.8 KB
/
radio.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
package forms
import htmx "github.com/zeiss/fiber-htmx"
// RadioProps represents the properties for a radio element.
type RadioProps struct {
ClassNames htmx.ClassNames // The class names for the radio element.
Name string // The name of the radio element.
Value string // The value of the radio element.
Checked bool // Whether the radio element is checked.
}
// Radio generates a radio element based on the provided properties.
func Radio(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioSuccess component represents a successful radio element.
func RadioSuccess(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-success": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioInfo component represents a info radio element.
func RadioInfo(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-info": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioWarning component represents a warning radio element.
func RadioWarning(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-warning": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioError component represents an error radio element.
func RadioError(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-error": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioPrimary component represents a primary radio element.
func RadioPrimary(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-primary": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioSecondary component represents a secondary radio element.
func RadioSecondary(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-secondary": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}
// RadioAccent component represents an accent radio element.
func RadioAccent(p RadioProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"radio": true,
"radio-accent": true,
},
p.ClassNames,
),
htmx.Attribute("type", "radio"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.Group(children...),
)
}