File tree 4 files changed +137
-110
lines changed
4 files changed +137
-110
lines changed Original file line number Diff line number Diff line change 1
1
package input
2
2
3
3
import (
4
+ " github.com/Oudwins/tailwind-merge-go/pkg/twmerge"
4
5
icons " github.com/iota-uz/icons/phosphor"
5
6
" github.com/iota-uz/utils/random"
6
7
)
@@ -85,7 +86,7 @@ type CheckboxProps struct {
85
86
Error string
86
87
Checked bool
87
88
Attrs templ.Attributes
88
- Class string
89
+ Class templ. CSSClasses
89
90
ID string
90
91
}
91
92
@@ -97,16 +98,24 @@ func newCheckbox(p *CheckboxProps) *CheckboxProps {
97
98
}
98
99
99
100
templ (p *CheckboxProps) render () {
100
- <div class =" flex items-center gap-3" >
101
+ <label
102
+ for ={ p.ID }
103
+ class ={
104
+ twmerge.Merge (
105
+ " form-control-label flex items-center cursor-pointer gap-3" ,
106
+ p.Class .String (),
107
+ ),
108
+ }
109
+ >
101
110
<input
102
111
type =" checkbox"
103
112
id ={ p .ID }
104
- class ={ " peer appearance-none sr-only" , p. Class }
113
+ class =" peer appearance-none sr-only"
105
114
checked ?={ p.Checked }
106
115
{ p.Attrs ... }
107
116
/>
108
- <label
109
- for ={ p. ID }
117
+ <!-- Visual checkbox box -->
118
+ < div
110
119
class =" w-5 h-5 rounded-[5px] border border-gray-500 duration-200 flex items-center justify-center hover:border-brand-500 peer-indeterminate:bg-brand-500 peer-checked:bg-brand-500 peer-checked:text-white peer-indeterminate:text-white group"
111
120
>
112
121
@ icons.Check (icons.Props {
@@ -117,14 +126,13 @@ templ (p *CheckboxProps) render() {
117
126
Size : " 16" ,
118
127
Class : " scale-0 hidden peer-indeterminate:group-[]:inline peer-indeterminate:group-[]:scale-100" ,
119
128
})
120
- </label >
129
+ </div >
130
+ <!-- Optional label text -->
121
131
if len (p.Label ) > 0 {
122
- <label for ={ p.ID }>
123
- { p.Label }
124
- </label >
132
+ <span >{ p.Label }</span >
125
133
}
126
134
{ children... }
127
- </div >
135
+ </label >
128
136
}
129
137
130
138
templ Checkbox (p *CheckboxProps) {
Original file line number Diff line number Diff line change @@ -61,7 +61,10 @@ templ Dropdown(props DropdownProps) {
61
61
x-show =" open"
62
62
@click .away =" open = false"
63
63
x-transition
64
- class =" absolute z-20 mt-2 w-full bg-white border border-gray-200 rounded-md shadow-lg max-h-80 overflow-y-auto"
64
+ class ={
65
+ " absolute z-20 mt-2 bg-white max-h-80 overflow-y-auto min-w-fit" ,
66
+ " border border-gray-200 rounded-md shadow-lg" ,
67
+ }
65
68
>
66
69
{ children... }
67
70
</ul >
@@ -80,14 +83,15 @@ templ DropdownItem(props DropdownItemProps) {
80
83
<li
81
84
class ={
82
85
twmerge.Merge (
83
- " hover:bg-gray-100 p-2 " ,
86
+ " hover:bg-gray-100" ,
84
87
props.Class .String (),
85
88
),
86
89
}
87
90
>
88
91
@ input.Checkbox (&input.CheckboxProps {
89
92
Label : props.Label ,
90
93
Checked : props.Checked ,
94
+ Class : templ.Classes (" p-2" ),
91
95
Attrs : templ.Attributes {
92
96
" value" : props.Value ,
93
97
" name" : props.Name ,
You can’t perform that action at this time.
0 commit comments