File tree Expand file tree Collapse file tree 3 files changed +25
-59
lines changed
form/field-checkbox-group Expand file tree Collapse file tree 3 files changed +25
-59
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,14 @@ export default {
16
16
17
17
const zFormSchema = ( ) =>
18
18
z . object ( {
19
- bear : zu . array . nonEmpty ( z . string ( ) . array ( ) ) ,
19
+ bears : zu . array . nonEmpty ( z . string ( ) . array ( ) , 'Select at least one answer.' ) ,
20
20
} ) ;
21
21
22
22
const formOptions = {
23
23
mode : 'onBlur' ,
24
24
resolver : zodResolver ( zFormSchema ( ) ) ,
25
25
defaultValues : {
26
- bear : [ ] ,
26
+ bears : [ ] ,
27
27
} as z . infer < ReturnType < typeof zFormSchema > > ,
28
28
} as const ;
29
29
@@ -45,7 +45,7 @@ export const Default = () => {
45
45
< FormFieldController
46
46
type = "checkbox-group"
47
47
control = { form . control }
48
- name = "bear "
48
+ name = "bears "
49
49
options = { options }
50
50
/>
51
51
</ FormField >
@@ -61,7 +61,7 @@ export const DefaultValue = () => {
61
61
const form = useForm ( {
62
62
...formOptions ,
63
63
defaultValues : {
64
- bear : [ 'pawdrin' ] ,
64
+ bears : [ 'pawdrin' ] ,
65
65
} ,
66
66
} ) ;
67
67
@@ -74,7 +74,7 @@ export const DefaultValue = () => {
74
74
< FormFieldController
75
75
control = { form . control }
76
76
type = "checkbox-group"
77
- name = "bear "
77
+ name = "bears "
78
78
options = { options }
79
79
/>
80
80
</ FormField >
@@ -90,7 +90,7 @@ export const Disabled = () => {
90
90
const form = useForm ( {
91
91
...formOptions ,
92
92
defaultValues : {
93
- bear : [ 'pawdrin' ] ,
93
+ bears : [ 'pawdrin' ] ,
94
94
} ,
95
95
} ) ;
96
96
@@ -103,7 +103,7 @@ export const Disabled = () => {
103
103
< FormFieldController
104
104
control = { form . control }
105
105
type = "checkbox-group"
106
- name = "bear "
106
+ name = "bears "
107
107
options = { options }
108
108
disabled
109
109
/>
@@ -128,7 +128,7 @@ export const Row = () => {
128
128
< FormFieldController
129
129
control = { form . control }
130
130
type = "checkbox-group"
131
- name = "bear "
131
+ name = "bears "
132
132
options = { options }
133
133
className = "flex-row gap-6"
134
134
/>
@@ -159,7 +159,7 @@ export const WithDisabledOption = () => {
159
159
< FormFieldController
160
160
control = { form . control }
161
161
type = "checkbox-group"
162
- name = "bear "
162
+ name = "bears "
163
163
options = { optionsWithDisabled }
164
164
/>
165
165
</ FormField >
Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ export const FieldCheckboxGroup = <
46
46
} = props ;
47
47
const ctx = useFormField ( ) ;
48
48
49
- console . log ( options ) ;
50
49
return (
51
50
< Controller
52
51
name = { name }
@@ -75,30 +74,24 @@ export const FieldCheckboxGroup = <
75
74
: `${ ctx . descriptionId } ${ ctx . errorId } `
76
75
}
77
76
value = { value }
78
- size = { size }
79
77
onValueChange = { ( value , event ) => {
80
78
onChange ?.( value ) ;
81
79
rest . onValueChange ?.( value , event ) ;
82
80
} }
83
81
{ ...rest }
84
82
>
85
- { options . map ( ( { label, ...option } ) => {
86
- const checkboxId = `${ ctx . id } -${ option . value } ` ;
87
-
88
- return (
89
- < Checkbox
90
- key = { checkboxId }
91
- aria-invalid = { isInvalid }
92
- size = { size }
93
- { ...field }
94
- { ...option }
95
- >
96
- { label }
97
- </ Checkbox >
98
- ) ;
99
- } ) }
83
+ { options . map ( ( { label, ...option } ) => (
84
+ < Checkbox
85
+ key = { `${ ctx . id } -${ option . value } ` }
86
+ aria-invalid = { isInvalid }
87
+ size = { size }
88
+ { ...field }
89
+ { ...option }
90
+ >
91
+ { label }
92
+ </ Checkbox >
93
+ ) ) }
100
94
</ CheckboxGroup >
101
- [{ value } ]
102
95
< FormFieldError />
103
96
</ div >
104
97
) ;
Original file line number Diff line number Diff line change 1
1
import { CheckboxGroup as CheckboxGroupPrimitive } from '@base-ui-components/react/checkbox-group' ;
2
- import { cva , VariantProps } from 'class-variance-authority' ;
3
2
4
- const checkboxGroupVariants = cva ( 'flex flex-col items-start gap-1' , {
5
- variants : {
6
- size : {
7
- // TODO
8
- default : '' ,
9
- sm : '' ,
10
- lg : '' ,
11
- } ,
12
- } ,
13
- defaultVariants : {
14
- size : 'default' ,
15
- } ,
16
- } ) ;
3
+ import { cn } from '@/lib/tailwind/utils' ;
17
4
18
- type BaseCheckboxGroupProps = CheckboxGroupPrimitive . Props ;
19
-
20
- export type CheckboxGroupProps = BaseCheckboxGroupProps &
21
- VariantProps < typeof checkboxGroupVariants > ;
22
-
23
- export function CheckboxGroup ( {
24
- children,
25
- className,
26
- size,
27
- ...props
28
- } : CheckboxGroupProps ) {
5
+ type CheckboxGroupProps = CheckboxGroupPrimitive . Props ;
6
+ export function CheckboxGroup ( { className, ...props } : CheckboxGroupProps ) {
29
7
return (
30
8
< CheckboxGroupPrimitive
31
- className = { checkboxGroupVariants ( {
32
- size,
33
- className,
34
- } ) }
9
+ className = { cn ( 'flex flex-col gap-2' , className ) }
35
10
{ ...props }
36
- >
37
- { children }
38
- </ CheckboxGroupPrimitive >
11
+ />
39
12
) ;
40
13
}
You can’t perform that action at this time.
0 commit comments