Home / File/ form.tsx — ui Source File

form.tsx — ui Source File

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

File tsx ComponentRegistry ChartRegistry 6 imports 7 functions

Entity Profile

Dependency Diagram

graph LR
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9["form.tsx"]
  1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"]
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2
  8b55cc60_1010_8be1_ff88_b2b7f1a553f7["react-label"]
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 --> 8b55cc60_1010_8be1_ff88_b2b7f1a553f7
  45bdba50_501d_4bbb_e6ef_5f033d29cffe["react-slot"]
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 --> 45bdba50_501d_4bbb_e6ef_5f033d29cffe
  6d65354d_8f59_2cfc_4783_24b2eb870bc4["react-hook-form"]
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 --> 6d65354d_8f59_2cfc_4783_24b2eb870bc4
  79081a1f_55a3_945a_fb8c_d53d6d3eab81["utils"]
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 --> 79081a1f_55a3_945a_fb8c_d53d6d3eab81
  fa665cdb_5f79_b81a_95ab_12ba182fc175["label"]
  7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 --> fa665cdb_5f79_b81a_95ab_12ba182fc175
  style 7c1a62f1_bcbe_4a44_ea32_9038a4216dc9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"use client"

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

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

const Form = FormProvider

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

const FormFieldContext = React.createContext<FormFieldContextValue | null>(null)

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, formState } = useFormContext()

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

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

  const fieldState = getFieldState(fieldContext.name, formState)

  const { id } = itemContext

  return {
    id,
// ... (119 more lines)

Subdomains

Dependencies

  • label
  • react
  • react-hook-form
  • react-label
  • react-slot
  • 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 6 module(s): label, react, react-hook-form, react-label, react-slot, utils.
Where is form.tsx in the architecture?
form.tsx is located at deprecated/www/registry/new-york/ui/form.tsx (domain: ComponentRegistry, subdomain: ChartRegistry, directory: deprecated/www/registry/new-york/ui).

Analyze Your Own Codebase

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

Try Supermodel Free