BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/gr8monk3ys/form

form

gr8monk3ys/form
FreeComponent

form (identity-styled).

Install it

npx shadcn@latest add https://ui.lscaturchio.xyz/r/form.json

Source

components/ui/form.tsxui.lscaturchio.xyz/r/form.json
1"use client"
2
3import * as React from "react"
4import type { Label as LabelPrimitive } from "radix-ui"
5import { Slot } from "radix-ui"
6import {
7 Controller,
8 FormProvider,
9 useFormContext,
10 useFormState,
11 type ControllerProps,
12 type FieldPath,
13 type FieldValues,
14} from "react-hook-form"
15
16import { cn } from "@/lib/utils"
17import { Label } from "@/components/ui/label"
18
19const Form = FormProvider
20
21type FormFieldContextValue<
22 TFieldValues extends FieldValues = FieldValues,
23 TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
24> = {
25 name: TName
26}
27
28const FormFieldContext = React.createContext<FormFieldContextValue>(
29 {} as FormFieldContextValue
30)
31
32const FormField = <
33 TFieldValues extends FieldValues = FieldValues,
34 TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
35>({
36 ...props
37}: ControllerProps<TFieldValues, TName>) => {
38 return (
39 <FormFieldContext.Provider value={{ name: props.name }}>
40 <Controller {...props} />
41 </FormFieldContext.Provider>
42 )
43}
44
45const useFormField = () => {
46 const fieldContext = React.useContext(FormFieldContext)
47 const itemContext = React.useContext(FormItemContext)
48 const { getFieldState } = useFormContext()
49 const formState = useFormState({ name: fieldContext.name })
50 const fieldState = getFieldState(fieldContext.name, formState)
51
52 if (!fieldContext) {
53 throw new Error("useFormField should be used within <FormField>")
54 }
55
56 const { id } = itemContext
57
58 return {
59 id,
60 name: fieldContext.name,
61 formItemId: `${id}-form-item`,
62 formDescriptionId: `${id}-form-item-description`,
63 formMessageId: `${id}-form-item-message`,
64 ...fieldState,
65 }
66}
67
68type FormItemContextValue = {
69 id: string
70}
71
72const FormItemContext = React.createContext<FormItemContextValue>(
73 {} as FormItemContextValue
74)
75
76function FormItem({ className, ...props }: React.ComponentProps<"div">) {
77 const id = React.useId()
78
79 return (
80 <FormItemContext.Provider value={{ id }}>
81 <div
82 data-slot="form-item"
83 className={cn("grid gap-2", className)}
84 {...props}
85 />
86 </FormItemContext.Provider>
87 )
88}
89
90function FormLabel({
91 className,
92 ...props
93}: React.ComponentProps<typeof LabelPrimitive.Root>) {
94 const { error, formItemId } = useFormField()
95
96 return (
97 <Label
98 data-slot="form-label"
99 data-error={!!error}
100 className={cn("data-[error=true]:text-destructive", className)}
101 htmlFor={formItemId}
102 {...props}
103 />
104 )
105}
106
107// … truncated

What it pulls in

npm packages

  • radix-ui
  • @hookform/resolvers
  • zod
  • react-hook-form

Other registry items

  • https://ui.lscaturchio.xyz/r/button.json
  • https://ui.lscaturchio.xyz/r/label.json

Files it writes

  • components/ui/form.tsx

Facts

Registry
gr8monk3ys
Type
registry:ui
Access
Free
Files written
1
Licence
GPL-3.0
First indexed
2026-08-10
Last confirmed
today

Go to the source

ui.lscaturchio.xyz gr8monk3ys/ui on GitHub Raw registry item This item as JSON

More from gr8monk3ys

All 69 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Accordionaccordiongr8monk3ysComponentsFree2 deps
ActiveNavLinkactive-nav-linkgr8monk3ysComponentsFreeno deps · 2 files
alertalertgr8monk3ysComponentsFree1 dep
alert-dialogalert-dialoggr8monk3ysComponentsFree1 dep
aspect-ratioaspect-ratiogr8monk3ysComponentsFree1 dep
attachmentattachmentgr8monk3ysComponentsFree2 deps
Avataravatargr8monk3ysComponentsFree1 dep
Badgebadgegr8monk3ysComponentsFree1 dep
BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex