{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "example-form", "type": "registry:component", "title": "Example Form", "description": "A contact form with Zod validation.", "dependencies": [ "zod" ], "registryDependencies": [ "button", "input", "label", "textarea", "card" ], "files": [ { "path": "registry/new-york/example-form/example-form.tsx", "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n Card,\n CardTitle,\n CardHeader,\n CardDescription,\n CardContent,\n CardFooter,\n} from \"@/components/ui/card\"\nimport { Input } from \"@/components/ui/input\"\nimport { Label } from \"@/components/ui/label\"\nimport { Button } from \"@/components/ui/button\"\nimport { Textarea } from \"@/components/ui/textarea\"\nimport { z } from \"zod\"\n\nconst exampleFormSchema = z.object({\n name: z.string().min(1),\n email: z.string().email(),\n message: z.string().min(1),\n})\n\nexport function ExampleForm() {\n const [pending, setPending] = React.useState(false)\n const [state, setState] = React.useState({\n defaultValues: {\n name: \"\",\n email: \"\",\n message: \"\",\n },\n success: false,\n errors: {\n name: \"\",\n email: \"\",\n message: \"\",\n },\n })\n\n const handleSubmit = React.useCallback(\n (e: React.FormEvent) => {\n e.preventDefault()\n setPending(true)\n\n const formData = new FormData(e.target as HTMLFormElement)\n const data = Object.fromEntries(formData.entries())\n const result = exampleFormSchema.safeParse(data)\n\n if (!result.success) {\n setState({\n ...state,\n errors: Object.fromEntries(\n Object.entries(result.error.flatten().fieldErrors).map(\n ([key, value]) => [key, value?.[0] ?? \"\"]\n )\n ) as Record,\n })\n setPending(false)\n return\n }\n\n setPending(false)\n },\n [state]\n )\n\n return (\n \n \n How can we help?\n \n Need help with your project? We're here to assist you.\n \n \n
\n \n \n \n Name *\n \n \n {state.errors?.name && (\n

\n {state.errors.name}\n

\n )}\n \n \n \n Email *\n \n \n {state.errors?.email && (\n

\n {state.errors.email}\n

\n )}\n \n \n \n Message *\n \n \n {state.errors?.message && (\n

\n {state.errors.message}\n

\n )}\n \n
\n \n \n \n
\n
\n )\n}\n", "type": "registry:component" } ] }