# Input Group

One drawn box around a field and what sits beside it: an icon, a prefix, a button, a shortcut.

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

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

```tsx
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group"

<InputGroup>
  <InputGroupInput placeholder="Search…" />
  <InputGroupAddon>…</InputGroupAddon>
</InputGroup>
```

Props:

- `InputGroupAddon align`: `"inline-start" | "inline-end" | "block-start" | "block-end"` (default `"inline-start"`). Which side of the field the addon sits on. Block addons stack above or below it.
- `InputGroupButton size`: `"xs" | "sm" | "icon-xs" | "icon-sm"` (default `"xs"`). Buttons small enough to live inside the box.
- `InputGroupInput / Textarea`: `input / textarea`. The field itself, with no box of its own.
- `seed`: `string | number`. Pins the drawing.

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

## Example

```tsx
import { InkIcon } from "@/components/ui/ink-icons";
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/ui/input-group";

export default function InputGroupDemo() {
  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <InputGroup seed="ig-search">
        <InputGroupInput placeholder="Search…" aria-label="Search" />
        <InputGroupAddon>
          <InkIcon name="search" />
        </InputGroupAddon>
        <InputGroupAddon align="inline-end">12 results</InputGroupAddon>
      </InputGroup>
      <InputGroup seed="ig-email">
        <InputGroupInput type="email" placeholder="you" aria-label="Email" />
        <InputGroupAddon align="inline-end">
          <InputGroupText>@example.com</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup seed="ig-price">
        <InputGroupAddon>
          <InputGroupText>$</InputGroupText>
        </InputGroupAddon>
        <InputGroupInput placeholder="0.00" aria-label="Amount" inputMode="decimal" />
        <InputGroupAddon align="inline-end">
          <InputGroupText>USD</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
    </div>
  );
}
```

## With buttons

Copy a value, or show and hide a password, from inside the box.

```tsx
"use client";

import { useState } from "react";
import { InkIcon } from "@/components/ui/ink-icons";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";

export default function InputGroupButtonExample() {
  const [copied, setCopied] = useState(false);
  const [shown, setShown] = useState(false);
  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <InputGroup seed="igb-copy">
        <InputGroupInput readOnly defaultValue="https://ballpoint.st9wd.com/r/button.json" aria-label="Registry address" />
        <InputGroupAddon align="inline-end">
          <InputGroupButton
            aria-label="Copy"
            size="icon-xs"
            onClick={() => {
              setCopied(true);
              setTimeout(() => setCopied(false), 1500);
            }}
          >
            <InkIcon name={copied ? "check" : "copy"} />
          </InputGroupButton>
        </InputGroupAddon>
      </InputGroup>
      <InputGroup seed="igb-password">
        <InputGroupInput type={shown ? "text" : "password"} defaultValue="correct horse" aria-label="Password" />
        <InputGroupAddon align="inline-end">
          <InputGroupButton onClick={() => setShown((v) => !v)} aria-pressed={shown}>
            {shown ? "Hide" : "Show"}
          </InputGroupButton>
        </InputGroupAddon>
      </InputGroup>
    </div>
  );
}
```

## With a textarea

A message field with its tools underneath.

```tsx
import { InkIcon } from "@/components/ui/ink-icons";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText, InputGroupTextarea } from "@/components/ui/input-group";

export default function InputGroupTextareaExample() {
  return (
    <InputGroup seed="igt" className="max-w-md">
      <InputGroupTextarea placeholder="Write a note to the margin…" aria-label="Note" />
      <InputGroupAddon align="block-end">
        <InputGroupButton aria-label="Attach a file" size="icon-xs">
          <InkIcon name="plus" />
        </InputGroupButton>
        <InputGroupText className="ml-auto text-sm">0 / 280</InputGroupText>
        <InputGroupButton variant="default" size="sm">
          Post
        </InputGroupButton>
      </InputGroupAddon>
    </InputGroup>
  );
}
```

## Above and below

A label or hint inside the box, over or under the field.

```tsx
import { InkIcon } from "@/components/ui/ink-icons";
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/ui/input-group";

export default function InputGroupBlock() {
  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <InputGroup seed="igk-top">
        <InputGroupAddon align="block-start">
          <InputGroupText>
            <InkIcon name="database" /> Database name
          </InputGroupText>
        </InputGroupAddon>
        <InputGroupInput placeholder="notebook_production" aria-label="Database name" className="h-10" />
      </InputGroup>
      <InputGroup seed="igk-bottom">
        <InputGroupInput placeholder="Your name" aria-label="Your name" className="h-10" />
        <InputGroupAddon align="block-end">
          <InputGroupText className="text-sm">As it should appear on the page.</InputGroupText>
        </InputGroupAddon>
      </InputGroup>
    </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.
