'use client' import { cn } from '@/utils/twMerge'; import * as LabelPrimitive from '@radix-ui/react-label' import { Slot } from '@radix-ui/react-slot' import { type ComponentPropsWithoutRef, type ComponentRef, type HTMLAttributes, createContext, forwardRef, useContext, useId } from 'react' import { Controller, type ControllerProps, type FieldPath, type FieldValues, FormProvider, useFormContext } from 'react-hook-form' import { Label } from './Label' const Form = FormProvider type FormFieldContextValue< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath > = { name: TName } const FormFieldContext = createContext( {} as FormFieldContextValue ) const FormField = < TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath >({ ...props }: ControllerProps) => { return ( ) } const useFormField = () => { const fieldContext = useContext(FormFieldContext) const itemContext = useContext(FormItemContext) const { getFieldState, formState } = useFormContext() const fieldState = getFieldState(fieldContext.name, formState) if (!fieldContext) { throw new Error('useFormField should be used within ') } const { id } = itemContext return { id, name: fieldContext.name, formItemId: `${id}-form-item`, formDescriptionId: `${id}-form-item-description`, formMessageId: `${id}-form-item-message`, ...fieldState } } type FormItemContextValue = { id: string } const FormItemContext = createContext( {} as FormItemContextValue ) const FormItem = forwardRef>( ({ className, ...props }, ref) => { const id = useId() return (
) } ) FormItem.displayName = 'FormItem' const FormLabel = forwardRef< ComponentRef, ComponentPropsWithoutRef >(({ className, ...props }, ref) => { const { error, formItemId } = useFormField() return (