# Kbd

A keycap sketched as a small box with a heavier bottom edge.

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

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

```tsx
import { Kbd, KbdGroup } from "@/components/ui/kbd"

<KbdGroup>
  <Kbd>⌘</Kbd>
  <Kbd>K</Kbd>
</KbdGroup>
```

Props:

- `children`: `ReactNode`. The key: a letter, a word, or an icon.
- `KbdGroup`: `component`. Sets keys pressed together side by side, in the hand.
- `seed`: `string | number`. Pins the drawing.

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

## Example

```tsx
import { Kbd, KbdGroup } from "@/components/ui/kbd";

export default function KbdDemo() {
  return (
    <div className="flex flex-col gap-5">
      <KbdGroup>
        <Kbd seed="kbd-cmd">⌘</Kbd>
        <Kbd seed="kbd-k">K</Kbd>
      </KbdGroup>
      <p className="text-ink-2">
        Press{" "}
        <KbdGroup>
          <Kbd seed="kbd-ctrl">Ctrl</Kbd>
          <span>+</span>
          <Kbd seed="kbd-shift">Shift</Kbd>
          <span>+</span>
          <Kbd seed="kbd-p">P</Kbd>
        </KbdGroup>{" "}
        to open the command palette.
      </p>
    </div>
  );
}
```

## Shortcut list

Each action with the keys that trigger it.

```tsx
import { Kbd, KbdGroup } from "@/components/ui/kbd";

const shortcuts = [
  ["Search the docs", ["/"]],
  ["Open the command palette", ["Ctrl", "K"]],
  ["Close a dialog", ["Esc"]],
  ["Move between tabs", ["←", "→"]],
] as const;

export default function KbdShortcuts() {
  return (
    <dl className="flex w-full max-w-sm flex-col gap-4">
      {shortcuts.map(([what, keys]) => (
        <div key={what} className="flex items-center justify-between gap-4">
          <dt className="text-ink-2">{what}</dt>
          <dd>
            <KbdGroup>
              {keys.map((key) => (
                <Kbd key={key} seed={`ks-${what}-${key}`}>
                  {key}
                </Kbd>
              ))}
            </KbdGroup>
          </dd>
        </div>
      ))}
    </dl>
  );
}
```

## In a button

A hint inside a button for its shortcut.

```tsx
import { Button } from "@/components/ui/button";
import { InkIcon } from "@/components/ui/ink-icons";
import { Kbd } from "@/components/ui/kbd";

export default function KbdInButton() {
  return (
    <div className="flex flex-wrap items-center gap-5">
      <Button variant="outline" seed="kb-search">
        <InkIcon name="search" /> Search <Kbd seed="kb-slash">/</Kbd>
      </Button>
      <Button seed="kb-save">
        Save <Kbd seed="kb-save-key" className="text-primary-foreground">⌘S</Kbd>
      </Button>
    </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.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `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.
