Home / File/ form.tsx — ui Source File

form.tsx — ui Source File

Architecture documentation for form.tsx, a tsx file in the ui codebase. 5 imports, 0 dependents.

File tsx ComponentRegistry ChartRegistry 5 imports 7 functions

Entity Profile

Dependency Diagram

graph LR
  26832279_f22a_39e6_9194_59ea47194309["form.tsx"]
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  26832279_f22a_39e6_9194_59ea47194309 --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  9c463da6_747b_38dc_586b_cbb4873070b1["radix-ui"]
  26832279_f22a_39e6_9194_59ea47194309 --> 9c463da6_747b_38dc_586b_cbb4873070b1
  6d65354d_8f59_2cfc_4783_24b2eb870bc4["react-hook-form"]
  26832279_f22a_39e6_9194_59ea47194309 --> 6d65354d_8f59_2cfc_4783_24b2eb870bc4
  79081a1f_55a3_945a_fb8c_d53d6d3eab81["utils"]
  26832279_f22a_39e6_9194_59ea47194309 --> 79081a1f_55a3_945a_fb8c_d53d6d3eab81
  d752035b_6ed3_c6ef_e27c_eef51af9ec8d["label"]
  26832279_f22a_39e6_9194_59ea47194309 --> d752035b_6ed3_c6ef_e27c_eef51af9ec8d
  style 26832279_f22a_39e6_9194_59ea47194309 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"use client"

import * as React from "react"
import type { Label as LabelPrimitive } from "radix-ui"
import { Slot } from "radix-ui"
import {
  Controller,
  FormProvider,
  useFormContext,
  useFormState,
  type ControllerProps,
  type FieldPath,
  type FieldValues,
} from "react-hook-form"

import { cn } from "@/lib/utils"
import { Label } from "@/registry/new-york-v4/ui/label"

const Form = FormProvider

type FormFieldContextValue<
  TFieldValues extends FieldValues = FieldValues,
  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
  name: TName
}

const FormFieldContext = React.createContext<FormFieldContextValue>(
  {} as FormFieldContextValue
)

const FormField = <
  TFieldValues extends FieldValues = FieldValues,
  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
  ...props
}: ControllerProps<TFieldValues, TName>) => {
  return (
    <FormFieldContext.Provider value={{ name: props.name }}>
      <Controller {...props} />
    </FormFieldContext.Provider>
  )
}

const useFormField = () => {
  const fieldContext = React.useContext(FormFieldContext)
  const itemContext = React.useContext(FormItemContext)
  const { getFieldState } = useFormContext()
  const formState = useFormState({ name: fieldContext.name })
  const fieldState = getFieldState(fieldContext.name, formState)

  if (!fieldContext) {
    throw new Error("useFormField should be used within <FormField>")
  }

  const { id } = itemContext

  return {
    id,
    name: fieldContext.name,
// ... (108 more lines)

Subdomains

Dependencies

  • label
  • radix-ui
  • react
  • react-hook-form
  • utils

Frequently Asked Questions

What does form.tsx do?
form.tsx is a source file in the ui codebase, written in tsx. It belongs to the ComponentRegistry domain, ChartRegistry subdomain.
What functions are defined in form.tsx?
form.tsx defines 7 function(s): FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField.
What does form.tsx depend on?
form.tsx imports 5 module(s): label, radix-ui, react, react-hook-form, utils.
Where is form.tsx in the architecture?
form.tsx is located at apps/v4/registry/new-york-v4/ui/form.tsx (domain: ComponentRegistry, subdomain: ChartRegistry, directory: apps/v4/registry/new-york-v4/ui).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free