# Resizable

Panels side by side or one above another with a pen line between each pair to drag. Arrow keys work too. No library.

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

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

```tsx
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable"

<ResizablePanelGroup direction="horizontal">
  <ResizablePanel defaultSize={50}>One</ResizablePanel>
  <ResizableHandle />
  <ResizablePanel defaultSize={50}>Two</ResizablePanel>
</ResizablePanelGroup>
```

Props:

- `ResizablePanelGroup direction`: `"horizontal" | "vertical"` (default `"horizontal"`). Which way the panels run. Give the group a height.
- `ResizablePanelGroup framed`: `boolean` (default `false`). Pencils a box round the whole group.
- `ResizablePanelGroup onLayout`: `(sizes: number[]) => void`. Called with every panel's size, as percentages, as a handle moves.
- `ResizablePanel defaultSize / minSize / maxSize`: `number`. Percentages of the group. Panels without a defaultSize share what's left.
- `ResizableHandle withHandle`: `boolean` (default `false`). Adds a boxed grip on the line.
- `ResizableHandle keys`: `Arrow keys, Shift, Home, End`. Focus the handle: arrows move it 2%, with Shift 10%; Home and End send it as far as the panels allow.
- `seed`: `string | number`. Pins the drawing.

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

## Example

```tsx
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";

export default function ResizableDemo() {
  return (
    <ResizablePanelGroup framed seed="rz-demo-frame" direction="horizontal" className="h-48 w-full max-w-md" aria-label="Two panels">
      <ResizablePanel defaultSize={50} minSize={20}>
        <div className="flex h-full items-center justify-center p-6 text-lg font-bold">One</div>
      </ResizablePanel>
      <ResizableHandle seed="rz-demo" aria-label="Resize the panels" />
      <ResizablePanel defaultSize={50} minSize={20}>
        <div className="flex h-full items-center justify-center p-6 text-lg font-bold">Two</div>
      </ResizablePanel>
    </ResizablePanelGroup>
  );
}
```

## Vertical

Panels one above another.

```tsx
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";

export default function ResizableVertical() {
  return (
    <ResizablePanelGroup framed seed="rz-vert-frame" direction="vertical" className="h-64 w-full max-w-md" aria-label="Two panels, one above the other">
      <ResizablePanel defaultSize={30} minSize={15}>
        <div className="flex h-full items-center justify-center p-6 text-lg font-bold">Header</div>
      </ResizablePanel>
      <ResizableHandle seed="rzv" aria-label="Resize the panels" />
      <ResizablePanel defaultSize={70} minSize={20}>
        <div className="flex h-full items-center justify-center p-6 text-lg font-bold">Content</div>
      </ResizablePanel>
    </ResizablePanelGroup>
  );
}
```

## With a grip

A boxed grip on the handle, and a group nested inside a panel.

```tsx
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable";

export default function ResizableHandleExample() {
  return (
    <ResizablePanelGroup framed seed="rz-handle-frame" direction="horizontal" className="h-64 w-full max-w-xl" aria-label="Notebook layout">
      <ResizablePanel defaultSize={25} minSize={15} maxSize={40}>
        <div className="flex h-full items-center justify-center p-4 text-lg font-bold">Pages</div>
      </ResizablePanel>
      <ResizableHandle withHandle seed="rzh-a" aria-label="Resize the page list" />
      <ResizablePanel defaultSize={75}>
        <ResizablePanelGroup direction="vertical">
          <ResizablePanel defaultSize={65} minSize={25}>
            <div className="flex h-full items-center justify-center p-4 text-lg font-bold">Canvas</div>
          </ResizablePanel>
          <ResizableHandle withHandle seed="rzh-b" aria-label="Resize the notes" />
          <ResizablePanel defaultSize={35} minSize={15}>
            <div className="flex h-full items-center justify-center p-4 text-lg font-bold">Notes</div>
          </ResizablePanel>
        </ResizablePanelGroup>
      </ResizablePanel>
    </ResizablePanelGroup>
  );
}
```

## 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.
- `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.
