Netzo Logo

input

Displays a form input field or a component that looks like an input field.

shadcn/ui radix-ui Storybook Figma

Usage

After installation components can be imported and used directly.

import { Input } from 'netzo/components/input.tsx'

Examples

Working examples to copy-paste into projects under components/.

Default

import { Input } from "netzo/components/input.tsx";

export default () => {
  return <Input type="email" placeholder="Email" />;
};

Disabled

import { Input } from "netzo/components/input.tsx";

export default () => {
  return <Input disabled type="email" placeholder="Email" />;
};

File

import { Input } from "netzo/components/input.tsx";
import { Label } from "netzo/components/label.tsx";

export default () => {
  return (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="picture">Picture</Label>
      <Input id="picture" type="file" />
    </div>
  );
};

Form

import { zodResolver } from "netzo/deps/@hookform/resolvers/zod.ts";
import { useForm } from "netzo/deps/react-hook-form.ts";
import { z } from "zod";
import { Button } from "netzo/components/button.tsx";
import {
  Form,
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from "netzo/components/form.tsx";
import { Input } from "netzo/components/input.tsx";
import { toast } from "netzo/components/use-toast.ts";

const FormSchema = z.object({
  username: z.string().min(2, {
    message: "Username must be at least 2 characters.",
  }),
});

export default () => {
  const form = useForm<z.infer<typeof FormSchema>>({
    resolver: zodResolver(FormSchema),
  });

  function onSubmit(data: z.infer<typeof FormSchema>) {
    toast({
      title: "You submitted the following values:",
      description: (
        <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
          <code className="text-white">{JSON.stringify(data, null, 2)}</code>
        </pre>
      ),
    });
  }

  return (
    <Form {...form}>
      <form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6">
        <FormField
          control={form.control}
          name="username"
          render={({ field }) => (
            <FormItem>
              <FormLabel>Username</FormLabel>
              <FormControl>
                <Input placeholder="john" {...field} />
              </FormControl>
              <FormDescription>
                This is your public display name.
              </FormDescription>
              <FormMessage />
            </FormItem>
          )}
        />
        <Button type="submit">Submit</Button>
      </form>
    </Form>
  );
};

With Button

import { Button } from "netzo/components/button.tsx";
import { Input } from "netzo/components/input.tsx";

export default () => {
  return (
    <div className="flex w-full max-w-sm items-center space-x-2">
      <Input type="email" placeholder="Email" />
      <Button type="submit">Subscribe</Button>
    </div>
  );
};

With Label

import { Input } from "netzo/components/input.tsx";
import { Label } from "netzo/components/label.tsx";

export default () => {
  return (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="email">Email</Label>
      <Input type="email" id="email" placeholder="Email" />
    </div>
  );
};

With Text

import { Input } from "netzo/components/input.tsx";
import { Label } from "netzo/components/label.tsx";

export default () => {
  return (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="email-2">Email</Label>
      <Input type="email" id="email-2" placeholder="Email" />
      <p className="text-sm text-muted-foreground">Enter your email address.</p>
    </div>
  );
};