Form
fysk/formFreeComponent
Building forms with React Hook Form and Zod.
Install it
npx shadcn@latest add https://fysk.dev/r/form.jsonSource
1"use client"2import * as React from "react"3import * as LabelPrimitive from "@radix-ui/react-label"4import { Slot } from "@radix-ui/react-slot"5import { Loader2, CheckCircle2, XCircle, X } from "lucide-react"6import {7 useFormContext,8 Controller,9 FormProvider,10 type ControllerProps,11 type FieldPath,12 type FieldValues13} from "react-hook-form"14import { cn } from "@/lib/utils"15import { useFyskConfig } from "@/components/fysk-provider"161718// Types1920type FormState = "idle" | "loading" | "success" | "error"2122interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {23 state?: FormState24 error?: React.ReactNode // For manual/server-side error messages25 afterSubmission?: React.ReactNode26 onCloseAfterSubmission?: () => void27 LoadingIcon?: React.ReactNode28 SuccessIcon?: React.ReactNode29 ErrorIcon?: React.ReactNode30 CloseIcon?: React.ReactNode31}3233// Context Types3435type FormFieldContextValue<36 TFieldValues extends FieldValues = FieldValues,37 TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>38> = {39 name: TName40}4142type FormItemContextValue = {43 id: string44}4546// Contexts4748const FormFieldContext = React.createContext<FormFieldContextValue>(49 {} as FormFieldContextValue50)5152const FormItemContext = React.createContext<FormItemContextValue>({ id: "" })5354// useFormField Hook5556/**57 * Hook to access the current form field's state and metadata.58 * Must be used within a `FormField` and `FormItem` component.59 *60 * @returns An object containing:61 * - `id` - The unique ID for the form item62 * - `name` - The field name registered with react-hook-form63 * - `formItemId` - ID for the form item element64 * - `formDescriptionId` - ID for the description element (for aria-describedby)65 * - `formMessageId` - ID for the error message element66 * - `error` - The current field error (if any)67 * - `invalid` - Whether the field has a validation error68 * - `isDirty` - Whether the field value has been modified69 * - `isTouched` - Whether the field has been touched/focused70 *71 * @example72 * ```tsx73 * const CustomInput = () => {74 * const { error, formItemId } = useFormField()75 * return (76 * <input77 * id={formItemId}78 * className={error ? "border-red-500" : ""}79 * />80 * )81 * }82 * ```83 */84const useFormField = () => {85 const fieldContext = React.useContext(FormFieldContext)86// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fysk
All 18 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Avataravatar | fysk | Components | Free | 2 deps | |
| Badgebadge | fysk | Components | Free | 1 dep | |
| Buttonbutton | fysk | Components | Free | 2 deps | |
| Empty Stateempty | fysk | Components | Free | 2 deps | |
| fysk-providerfysk-provider | fysk | Components | Free | 2 deps | |
| Inputinput | fysk | Components | Free | 1 dep | |
| Input OTPinput-otp | fysk | Components | Free | no deps | |
| Kbdkbd | fysk | Components | Free | 1 dep |
