-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkbox.go
85 lines (67 loc) · 2.34 KB
/
checkbox.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
package forms
import htmx "github.com/zeiss/fiber-htmx"
// CheckboxProps represents the properties for a checkbox element.
type CheckboxProps struct {
ClassNames htmx.ClassNames // The class names for the checkbox element.
Name string // The name of the checkbox element.
Value string // The value of the checkbox element.
Checked bool // Whether the checkbox element is checked.
Disabled bool // Whether the checkbox element is disabled.
}
// Checkbox generates a checkbox element based on the provided properties.
func Checkbox(p CheckboxProps, children ...htmx.Node) htmx.Node {
return htmx.Input(
htmx.Merge(
htmx.ClassNames{
"checkbox": true,
},
p.ClassNames,
),
htmx.Attribute("type", "checkbox"),
htmx.Attribute("name", p.Name),
htmx.Attribute("value", p.Value),
htmx.If(p.Checked, htmx.Checked()),
htmx.If(p.Disabled, htmx.Disabled()),
htmx.Group(children...),
)
}
// CheckboxPrimary is a component that displays a primary checkbox.
func CheckboxPrimary(p CheckboxProps, children ...htmx.Node) htmx.Node {
classNames := htmx.ClassNames{
"checkbox-primary": true,
}.Merge(p.ClassNames)
p.ClassNames = classNames
return Checkbox(p, children...)
}
// CheckboxSuccess is a component that displays a success checkbox.
func CheckboxSuccess(p CheckboxProps, children ...htmx.Node) htmx.Node {
classNames := htmx.ClassNames{
"checkbox-success": true,
}.Merge(p.ClassNames)
p.ClassNames = classNames
return Checkbox(p, children...)
}
// CheckboxWarning is a component that displays a warning checkbox.
func CheckboxWarning(p CheckboxProps, children ...htmx.Node) htmx.Node {
classNames := htmx.ClassNames{
"checkbox-warning": true,
}.Merge(p.ClassNames)
p.ClassNames = classNames
return Checkbox(p, children...)
}
// CheckboxError is a component that displays an error checkbox.
func CheckboxError(p CheckboxProps, children ...htmx.Node) htmx.Node {
classNames := htmx.ClassNames{
"checkbox-error": true,
}.Merge(p.ClassNames)
p.ClassNames = classNames
return Checkbox(p, children...)
}
// CheckboxInfo is a component that displays an info checkbox.
func CheckboxInfo(p CheckboxProps, children ...htmx.Node) htmx.Node {
classNames := htmx.ClassNames{
"checkbox-info": true,
}.Merge(p.ClassNames)
p.ClassNames = classNames
return Checkbox(p, children...)
}