Ved UI
Components

Input Form

A styled form input component built with Shadcn UI, using Zod for schema validation and React Hook Form for form management.

Installation with shadcn/ui

CLI

npx shadcn@latest add https://ved-ui.vercel.app/registry/input-form.json

Manual

Install the following dependencies:

npx shadcn@latest add input form button sonner

Copy and paste the following code into your project.

"use client";
 
import { z } from "zod";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
 
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
  Form,
  FormControl,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
 
const FormSchema = z.object({
  text: z.string().min(2, {
    message: "text must be at least 2 characters.",
  }),
});
 
export function FormInput() {
  const form = useForm<z.infer<typeof FormSchema>>({
    resolver: zodResolver(FormSchema),
    defaultValues: {
      text: "",
    },
  });
 
  function onSubmit(data: z.infer<typeof FormSchema>) {
    toast.success(data.text);
  }
 
  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)} className=" space-y-6">
        <FormField
          control={form.control}
          name="text"
          render={({ field }) => (
            <FormItem>
              <FormLabel>Text</FormLabel>
              <FormControl>
                <Input placeholder="Wubba Lubba Dub-Dub!" {...field} />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />
        <Button type="submit">Submit</Button>
      </form>
    </Form>
  );
}

On this page