@@ -4,15 +4,24 @@ import { useId } from 'react';
44import type { AllPathsKeys } from 'skyroc-form' ;
55import { Field , useFieldError } from 'skyroc-form' ;
66
7- import { cn } from '@/lib/utils' ;
8-
9- import FormLabel from '../label/Label' ;
10-
11- import { formVariants } from './form-variants' ;
7+ import FormDescription from './FormDescription' ;
8+ import FormItem from './FormItem' ;
9+ import FormLabel from './FormLable' ;
10+ import FormMessage from './FormMessage' ;
1211import type { FormFieldProps } from './types' ;
1312
1413const FormField = < Values = any , > ( props : FormFieldProps < Values > ) => {
15- const { children, className, description, label, name, size, ...rest } = props ;
14+ const {
15+ children,
16+ className,
17+ classNames,
18+ component : Component = Field ,
19+ description,
20+ label,
21+ name,
22+ size,
23+ ...rest
24+ } = props ;
1625
1726 const id = useId ( ) ;
1827
@@ -24,60 +33,48 @@ const FormField = <Values = any,>(props: FormFieldProps<Values>) => {
2433 const formDescriptionId = `${ id } -form-item-description` ;
2534 const formMessageId = `${ id } -form-item-message` ;
2635
27- const {
28- description : descriptionCls ,
29- item,
30- label : labelCls ,
31- message
32- } = formVariants ( { error : errors . length > 0 , size } ) ;
33-
34- const mergedCls = {
35- description : cn ( descriptionCls ( ) , className ) ,
36- item : cn ( item ( ) , className ) ,
37- label : cn ( labelCls ( ) ) ,
38- message : cn ( message ( ) , className )
39- } ;
40-
4136 return (
42- < div className = { mergedCls . item } >
37+ < FormItem
38+ className = { className }
39+ size = { size }
40+ >
4341 < FormLabel
44- className = { mergedCls . label }
45- data-error = { hasError }
46- data-slot = "form-label"
47- htmlFor = { id }
42+ className = { classNames ?. label }
43+ error = { hasError }
44+ htmlFor = { formItemId }
4845 size = { size }
4946 >
5047 { label }
5148 </ FormLabel >
5249
53- < Field
50+ < Component
5451 { ...rest }
5552 aria-describedby = { ! hasError ? `${ formDescriptionId } ` : `${ formDescriptionId } ${ formMessageId } ` }
5653 aria-invalid = { hasError }
5754 id = { id }
5855 name = { name }
5956 >
6057 { children }
61- </ Field >
58+ </ Component >
6259
6360 { description && (
64- < p
65- className = { mergedCls . description }
61+ < FormDescription
62+ className = { classNames ? .description }
6663 id = { formDescriptionId }
6764 >
6865 { description }
69- </ p >
66+ </ FormDescription >
7067 ) }
7168
7269 { hasError && (
73- < p
74- className = { mergedCls . message }
70+ < FormMessage
71+ className = { classNames ? .message }
7572 id = { formMessageId }
7673 >
7774 { errors [ 0 ] }
78- </ p >
75+ </ FormMessage >
7976 ) }
80- </ div >
77+ </ FormItem >
8178 ) ;
8279} ;
8380
0 commit comments