Skip to content

Commit a08db54

Browse files
committed
fix: small issues
1 parent ba9382b commit a08db54

File tree

3 files changed

+25
-59
lines changed

3 files changed

+25
-59
lines changed

app/components/form/field-checkbox-group/docs.stories.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export default {
1616

1717
const zFormSchema = () =>
1818
z.object({
19-
bear: zu.array.nonEmpty(z.string().array()),
19+
bears: zu.array.nonEmpty(z.string().array(), 'Select at least one answer.'),
2020
});
2121

2222
const formOptions = {
2323
mode: 'onBlur',
2424
resolver: zodResolver(zFormSchema()),
2525
defaultValues: {
26-
bear: [],
26+
bears: [],
2727
} as z.infer<ReturnType<typeof zFormSchema>>,
2828
} as const;
2929

@@ -45,7 +45,7 @@ export const Default = () => {
4545
<FormFieldController
4646
type="checkbox-group"
4747
control={form.control}
48-
name="bear"
48+
name="bears"
4949
options={options}
5050
/>
5151
</FormField>
@@ -61,7 +61,7 @@ export const DefaultValue = () => {
6161
const form = useForm({
6262
...formOptions,
6363
defaultValues: {
64-
bear: ['pawdrin'],
64+
bears: ['pawdrin'],
6565
},
6666
});
6767

@@ -74,7 +74,7 @@ export const DefaultValue = () => {
7474
<FormFieldController
7575
control={form.control}
7676
type="checkbox-group"
77-
name="bear"
77+
name="bears"
7878
options={options}
7979
/>
8080
</FormField>
@@ -90,7 +90,7 @@ export const Disabled = () => {
9090
const form = useForm({
9191
...formOptions,
9292
defaultValues: {
93-
bear: ['pawdrin'],
93+
bears: ['pawdrin'],
9494
},
9595
});
9696

@@ -103,7 +103,7 @@ export const Disabled = () => {
103103
<FormFieldController
104104
control={form.control}
105105
type="checkbox-group"
106-
name="bear"
106+
name="bears"
107107
options={options}
108108
disabled
109109
/>
@@ -128,7 +128,7 @@ export const Row = () => {
128128
<FormFieldController
129129
control={form.control}
130130
type="checkbox-group"
131-
name="bear"
131+
name="bears"
132132
options={options}
133133
className="flex-row gap-6"
134134
/>
@@ -159,7 +159,7 @@ export const WithDisabledOption = () => {
159159
<FormFieldController
160160
control={form.control}
161161
type="checkbox-group"
162-
name="bear"
162+
name="bears"
163163
options={optionsWithDisabled}
164164
/>
165165
</FormField>

app/components/form/field-checkbox-group/index.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const FieldCheckboxGroup = <
4646
} = props;
4747
const ctx = useFormField();
4848

49-
console.log(options);
5049
return (
5150
<Controller
5251
name={name}
@@ -75,30 +74,24 @@ export const FieldCheckboxGroup = <
7574
: `${ctx.descriptionId} ${ctx.errorId}`
7675
}
7776
value={value}
78-
size={size}
7977
onValueChange={(value, event) => {
8078
onChange?.(value);
8179
rest.onValueChange?.(value, event);
8280
}}
8381
{...rest}
8482
>
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+
))}
10094
</CheckboxGroup>
101-
[{value}]
10295
<FormFieldError />
10396
</div>
10497
);

app/components/ui/checkbox-group.tsx

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
import { CheckboxGroup as CheckboxGroupPrimitive } from '@base-ui-components/react/checkbox-group';
2-
import { cva, VariantProps } from 'class-variance-authority';
32

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';
174

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) {
297
return (
308
<CheckboxGroupPrimitive
31-
className={checkboxGroupVariants({
32-
size,
33-
className,
34-
})}
9+
className={cn('flex flex-col gap-2', className)}
3510
{...props}
36-
>
37-
{children}
38-
</CheckboxGroupPrimitive>
11+
/>
3912
);
4013
}

0 commit comments

Comments
 (0)