# Split pane

> A desktop-grade resizable dual panel. Zero-lag drag, rubber-band spring limits, and double-click preset snapping.

Divide views cleanly with a 1px hairline boundary. Dragging adjusts panel ratios with immediate DOM updates, pulling past boundaries encounters logarithmic resistance before springing back through a damped harmonic oscillator (WAAPI), and double-clicking snaps cleanly between 50%, 25%, and 75% presets.

## Install

```bash
npx shadcn@latest add @hairline/split-pane
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/split-pane
- Registry item (source): https://hairlineui.com/r/split-pane.json

## Usage

```tsx
import { SplitPane } from "@/components/split-pane";

<SplitPane
  defaultSplit={50}
  first={<div className="p-4">Left Editor</div>}
  second={<div className="p-4">Right Preview</div>}
  onSplitCommit={setSplit}
/>
```

## Side-by-side markdown and live preview

Build dual-surface workspaces with independent scroll containers and zero layout jitter. Ideal for code playgrounds, markdown editors, and comparison screens.

```tsx
"use client";
import { useState } from "react";
import { SplitPane } from "@/components/split-pane";

export function DualWorkspace() {
  const [split, setSplit] = useState(50);

  return (
    <div className="h-[480px] w-full rounded-2xl border border-border">
      <SplitPane
        split={split}
        first={<div className="h-full bg-surface p-4 font-mono text-xs"># Document Source</div>}
        second={<div className="h-full bg-background p-4 text-sm">Rendered Output</div>}
        onSplitCommit={setSplit}
      />
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `first / second` | `React.ReactNode` | – | Content rendered inside the left/top and right/bottom panes. |
| `split / defaultSplit` | `number` | `50` | Controlled or initial percentage allocated to the first pane. |
| `minSize / maxSize` | `number` | `15 / 85` | Boundary thresholds in percentage before rubber-band resistance begins. |
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Primary axis of separation. |
| `collapsible` | `boolean` | `true` | Enables pane collapse buttons on the divider. |
| `disabled` | `boolean` | `false` | Locks the divider in place and prevents resizing. |
| `onSplitChange` | `(split: number) => void` | – | Fired during pointer movement with raw split percentages. |
| `onSplitCommit` | `(split: number) => void` | – | Fired upon pointer release or keyboard snap with normalized value. |

## States

- **resize**: Divider movement updates pane flex-basis directly without React state re-renders.
- **rubber-band**: Dragging beyond min/max bounds introduces logarithmic resistance; release triggers a WAAPI spring back.
- **snap**: Double-clicking the divider smoothly animates between 50/50, 25/75, and 75/25 presets over 380ms.
- **collapse**: Collapse arrows fold either pane to 0 width, docking the hairline divider flush against the frame.

## What it handles

Two panels that share a screen need a divider that feels right: it follows the pointer, resists at the limits, and can be reset in a double-click.

- **Dragging with no lag**: The divider updates the panes directly, without React re-rendering them.
- **Rubber-band limits**: Pulling past the minimum or maximum meets resistance, then springs back.
- **Double-click to snap**: Double-clicking the divider eases between 50/50, 25/75 and 75/25.
- **Collapse either pane**: Arrows on the divider fold a pane away so the other fills the frame.
- **Horizontal or vertical**: Split side by side or top and bottom.
- **Keyboard control**: The divider is a separator: arrow keys step by 1% (10% with Shift), Enter snaps to 50/50, and Home and End jump to the limits.

## Replaces

a resizable panel library, divider drag handling, min and max limits, snap presets, collapse buttons

## Where it fits

- **Code and docs editors**: An editor on one side and a live preview on the other.
- **Master and detail layouts**: A list on the left with the selected item on the right.
- **Consoles and logs**: Output beside the tool that produced it.
- **Comparison screens**: Two versions or two documents side by side.

## Notes

- The divider button acts as a semantic role="separator" with aria-valuenow.
- Arrow keys step by 1% (10% with Shift); Enter snaps to 50/50; Home and End jump to minimum and maximum limits.
- Past boundary limits, WAAPI springFrames computes 33 keyframe values for fluid physical return.
- Reduced motion removes transitions and settles snapped positions immediately.

License: MIT (https://hairlineui.com/license#components)
