# Input

A text field in a drawn box, or on the line you write on. Focus draws one more pass in full ink; invalid redraws it in red pen.

Docs: https://ballpoint.st9wd.com/docs/input

```bash
npx shadcn@latest add @ballpoint/input
```

```tsx
import { Input } from "@/components/ui/input"

<Input type="email" placeholder="you@example.com" />
```

Props:

- `variant`: `"box" | "line"` (default `"box"`). Drawn around the field, or the line you write on.
- `className`: `string`. Styles the drawn box (width, margins, type size). Every other prop goes to the <input>.
- `aria-invalid`: `boolean`. Redraws the box in red pen.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `roughness`, `passes`, `radius`, `corners`, `weight`, `speed` (see Pen settings).

Every other prop goes to Base UI's Input: https://base-ui.com/react/components/input

## Example

```tsx
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";

export default function InputDemo() {
  return (
    <div className="grid w-full max-w-md gap-6">
      <div className="grid gap-2">
        <Label htmlFor="input-email">Email</Label>
        <Input id="input-email" type="email" placeholder="you@example.com" seed="input-email" />
      </div>
      <div className="grid gap-2">
        <Label htmlFor="input-name">Name, written on the line</Label>
        <Input id="input-name" variant="line" placeholder="Oussama" seed="input-name" />
      </div>
      <div className="grid gap-2">
        <Label htmlFor="input-code">Invite code</Label>
        <Input id="input-code" aria-invalid defaultValue="NOPE-123" seed="input-code" />
        <p className="text-sm text-destructive">That code has already been used.</p>
      </div>
      <div className="grid grid-cols-2 gap-4">
        <Input placeholder="Rounded" radius={10} seed="input-rounded" aria-label="Rounded" />
        <Input placeholder="Disabled" disabled seed="input-disabled" aria-label="Disabled" />
      </div>
    </div>
  );
}
```

## Types

Password, number, search and file inputs, each with a field label and hint.

```tsx
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function InputTypes() {
  return (
    <div className="grid w-full max-w-md gap-6">
      <Field>
        <FieldLabel htmlFor="it-password">Password</FieldLabel>
        <Input id="it-password" type="password" placeholder="At least eight characters" autoComplete="new-password" seed="it-password" />
        <FieldDescription>Use a phrase you could write from memory.</FieldDescription>
      </Field>
      <Field>
        <FieldLabel htmlFor="it-number">Copies</FieldLabel>
        <Input id="it-number" type="number" min={1} max={20} defaultValue={3} seed="it-number" />
      </Field>
      <Field>
        <FieldLabel htmlFor="it-search">Search</FieldLabel>
        <Input id="it-search" type="search" placeholder="Find a page" seed="it-search" />
      </Field>
      <Field>
        <FieldLabel htmlFor="it-file">Photo</FieldLabel>
        <Input id="it-file" type="file" seed="it-file" />
      </Field>
    </div>
  );
}
```

## States

Read-only, disabled, and invalid in the box or on the line.

```tsx
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function InputStates() {
  return (
    <div className="grid w-full max-w-md gap-6">
      <Field>
        <FieldLabel htmlFor="is-readonly">Read-only</FieldLabel>
        <Input id="is-readonly" readOnly defaultValue="ballpoint.st9wd.com" seed="is-readonly" />
        <FieldDescription>You can select it and copy it, but not change it.</FieldDescription>
      </Field>
      <Field data-disabled>
        <FieldLabel htmlFor="is-disabled">Disabled</FieldLabel>
        <Input id="is-disabled" disabled defaultValue="Locked while it saves" seed="is-disabled" />
      </Field>
      <Field data-invalid>
        <FieldLabel htmlFor="is-invalid">Handle</FieldLabel>
        <Input id="is-invalid" aria-invalid defaultValue="ada lovelace" seed="is-invalid" />
        <FieldError>Handles can&apos;t have spaces.</FieldError>
      </Field>
      <Field>
        <FieldLabel htmlFor="is-line">On the line</FieldLabel>
        <Input id="is-line" variant="line" aria-invalid defaultValue="Wrong, in red pen" seed="is-line" />
      </Field>
    </div>
  );
}
```

## With a button

An email field and a submit button on one row.

```tsx
"use client";

import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";

export default function InputWithButton() {
  return (
    <form onSubmit={(event) => event.preventDefault()} className="flex w-full max-w-md items-center gap-3">
      <Input type="email" placeholder="you@example.com" aria-label="Email" className="flex-1" seed="iwb-email" />
      <Button type="submit" seed="iwb-submit">
        Subscribe
      </Button>
    </form>
  );
}
```

## Search

A leading icon, a shortcut hint that goes when you type, and a filtered list.

```tsx
"use client";

import { useState } from "react";
import { Input } from "@/components/ui/input";
import { InkIcon } from "@/components/ui/ink-icons";
import { Kbd } from "@/components/ui/kbd";

const things = ["Cream notebook", "Blue ballpoint", "Legal pad", "Fineliner set", "Graph pad", "Pencil case"];

export default function InputSearch() {
  const [query, setQuery] = useState("");
  const shown = things.filter((t) => t.toLowerCase().includes(query.trim().toLowerCase()));
  return (
    <div className="flex w-full max-w-sm flex-col gap-4">
      <div className="relative">
        <InkIcon name="search" className="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3" />
        <Input type="search" aria-label="Search" placeholder="Search the shop" value={query} onChange={(event) => setQuery(event.target.value)} seed="is-search" className="w-full pl-9" />
        {!query && <Kbd className="pointer-events-none absolute top-1/2 right-3 -translate-y-1/2">/</Kbd>}
      </div>
      <ul className="flex flex-col gap-1 text-ink-2">
        {shown.map((t) => (
          <li key={t}>{t}</li>
        ))}
        {shown.length === 0 && <li className="text-ink-3">Nothing called that.</li>}
      </ul>
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `corners`: `"crossed" | "joined"` (default `"crossed"`). Square corners: sides pulled separately past each other, or the box drawn in one motion.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
