1- import * as React from "react"
2- import * as LabelPrimitive from "@radix-ui/react-label"
3- import { Slot } from "@radix-ui/react-slot"
1+ import * as React from "react" ;
2+ import * as LabelPrimitive from "@radix-ui/react-label" ;
3+ import { Slot } from "@radix-ui/react-slot" ;
44import {
55 Controller ,
66 ControllerProps ,
77 FieldPath ,
88 FieldValues ,
99 FormProvider ,
1010 useFormContext ,
11- } from "react-hook-form"
11+ } from "react-hook-form" ;
1212
13- import { cn } from "@/lib/utils"
14- import { Label } from "@/components/ui/label"
13+ import { cn } from "@/lib/utils" ;
14+ import { Label } from "@/components/ui/label" ;
1515
16- const Form = FormProvider
16+ const Form = FormProvider ;
1717
1818type FormFieldContextValue <
1919 TFieldValues extends FieldValues = FieldValues ,
20- TName extends FieldPath < TFieldValues > = FieldPath < TFieldValues >
20+ TName extends FieldPath < TFieldValues > = FieldPath < TFieldValues > ,
2121> = {
22- name : TName
23- }
22+ name : TName ;
23+ } ;
2424
2525const FormFieldContext = React . createContext < FormFieldContextValue > (
2626 { } as FormFieldContextValue
27- )
27+ ) ;
2828
2929const FormField = <
3030 TFieldValues extends FieldValues = FieldValues ,
31- TName extends FieldPath < TFieldValues > = FieldPath < TFieldValues >
31+ TName extends FieldPath < TFieldValues > = FieldPath < TFieldValues > ,
3232> ( {
3333 ...props
3434} : ControllerProps < TFieldValues , TName > ) => {
3535 return (
3636 < FormFieldContext . Provider value = { { name : props . name } } >
3737 < Controller { ...props } />
3838 </ FormFieldContext . Provider >
39- )
40- }
39+ ) ;
40+ } ;
4141
4242const useFormField = ( ) => {
43- const fieldContext = React . useContext ( FormFieldContext )
44- const itemContext = React . useContext ( FormItemContext )
45- const { getFieldState, formState } = useFormContext ( )
43+ const fieldContext = React . useContext ( FormFieldContext ) ;
44+ const itemContext = React . useContext ( FormItemContext ) ;
45+ const { getFieldState, formState } = useFormContext ( ) ;
4646
47- const fieldState = getFieldState ( fieldContext . name , formState )
47+ const fieldState = getFieldState ( fieldContext . name , formState ) ;
4848
4949 if ( ! fieldContext ) {
50- throw new Error ( "useFormField should be used within <FormField>" )
50+ throw new Error ( "useFormField should be used within <FormField>" ) ;
5151 }
5252
53- const { id } = itemContext
53+ const { id } = itemContext ;
5454
5555 return {
5656 id,
@@ -59,36 +59,36 @@ const useFormField = () => {
5959 formDescriptionId : `${ id } -form-item-description` ,
6060 formMessageId : `${ id } -form-item-message` ,
6161 ...fieldState ,
62- }
63- }
62+ } ;
63+ } ;
6464
6565type FormItemContextValue = {
66- id : string
67- }
66+ id : string ;
67+ } ;
6868
6969const FormItemContext = React . createContext < FormItemContextValue > (
7070 { } as FormItemContextValue
71- )
71+ ) ;
7272
7373const FormItem = React . forwardRef <
7474 HTMLDivElement ,
7575 React . HTMLAttributes < HTMLDivElement >
7676> ( ( { className, ...props } , ref ) => {
77- const id = React . useId ( )
77+ const id = React . useId ( ) ;
7878
7979 return (
8080 < FormItemContext . Provider value = { { id } } >
8181 < div ref = { ref } className = { cn ( "space-y-2" , className ) } { ...props } />
8282 </ FormItemContext . Provider >
83- )
84- } )
85- FormItem . displayName = "FormItem"
83+ ) ;
84+ } ) ;
85+ FormItem . displayName = "FormItem" ;
8686
8787const FormLabel = React . forwardRef <
8888 React . ElementRef < typeof LabelPrimitive . Root > ,
8989 React . ComponentPropsWithoutRef < typeof LabelPrimitive . Root >
9090> ( ( { className, ...props } , ref ) => {
91- const { error, formItemId } = useFormField ( )
91+ const { error, formItemId } = useFormField ( ) ;
9292
9393 return (
9494 < Label
@@ -97,15 +97,16 @@ const FormLabel = React.forwardRef<
9797 htmlFor = { formItemId }
9898 { ...props }
9999 />
100- )
101- } )
102- FormLabel . displayName = "FormLabel"
100+ ) ;
101+ } ) ;
102+ FormLabel . displayName = "FormLabel" ;
103103
104104const FormControl = React . forwardRef <
105105 React . ElementRef < typeof Slot > ,
106106 React . ComponentPropsWithoutRef < typeof Slot >
107107> ( ( { ...props } , ref ) => {
108- const { error, formItemId, formDescriptionId, formMessageId } = useFormField ( )
108+ const { error, formItemId, formDescriptionId, formMessageId } =
109+ useFormField ( ) ;
109110
110111 return (
111112 < Slot
@@ -119,15 +120,15 @@ const FormControl = React.forwardRef<
119120 aria-invalid = { ! ! error }
120121 { ...props }
121122 />
122- )
123- } )
124- FormControl . displayName = "FormControl"
123+ ) ;
124+ } ) ;
125+ FormControl . displayName = "FormControl" ;
125126
126127const FormDescription = React . forwardRef <
127128 HTMLParagraphElement ,
128129 React . HTMLAttributes < HTMLParagraphElement >
129130> ( ( { className, ...props } , ref ) => {
130- const { formDescriptionId } = useFormField ( )
131+ const { formDescriptionId } = useFormField ( ) ;
131132
132133 return (
133134 < p
@@ -136,19 +137,19 @@ const FormDescription = React.forwardRef<
136137 className = { cn ( "text-sm text-muted-foreground" , className ) }
137138 { ...props }
138139 />
139- )
140- } )
141- FormDescription . displayName = "FormDescription"
140+ ) ;
141+ } ) ;
142+ FormDescription . displayName = "FormDescription" ;
142143
143144const FormMessage = React . forwardRef <
144145 HTMLParagraphElement ,
145146 React . HTMLAttributes < HTMLParagraphElement >
146147> ( ( { className, children, ...props } , ref ) => {
147- const { error, formMessageId } = useFormField ( )
148- const body = error ? String ( error ?. message ) : children
148+ const { error, formMessageId } = useFormField ( ) ;
149+ const body = error ? String ( error ?. message ) : children ;
149150
150151 if ( ! body ) {
151- return null
152+ return null ;
152153 }
153154
154155 return (
@@ -160,9 +161,9 @@ const FormMessage = React.forwardRef<
160161 >
161162 { body }
162163 </ p >
163- )
164- } )
165- FormMessage . displayName = "FormMessage"
164+ ) ;
165+ } ) ;
166+ FormMessage . displayName = "FormMessage" ;
166167
167168export {
168169 useFormField ,
@@ -173,4 +174,4 @@ export {
173174 FormDescription ,
174175 FormMessage ,
175176 FormField ,
176- }
177+ } ;
0 commit comments