Components

Resizable

Panels that share a row or a column, resized by dragging the hairline between them or with the keyboard.

Usage

import {
  Resizable,
  ResizableHandle,
  ResizablePanel,
} from 'nyctoui/resizable'

<Resizable>
  <ResizablePanel defaultSize={30} minSize={20}>Files</ResizablePanel>
  <ResizableHandle aria-label="Resize files" />
  <ResizablePanel>Editor</ResizablePanel>
</Resizable>

Give the group a size: its panels share whatever it has. A panel without a defaultSize takes what is left. Groups nest, so a panel can hold a vertical group of its own.

Good for

  • A code editor with a file tree, the editor and a terminal below.
  • An email client with a mailbox list beside a reading pane.
  • A SQL tool with the query on top and results below.
  • A design tool with layers on one side and the canvas in the middle.

Anatomy

<Resizable>
  <ResizablePanel />
  <ResizableHandle />
  <ResizablePanel />
</Resizable>

Examples

Vertical

orientation="vertical" stacks the panels. ArrowUp and ArrowDown move a focused handle.

Grip

The handle is a hairline with a hit area wider than it looks, and a bar fades in while it is hovered, dragged or focused. grip adds a small knob for a handle that is easy to miss, such as one between two panels of the same color.

Pixel sizes and collapsing

Sizes take px and rem as well as percentages, and pixel bounds hold as the group resizes. A collapsible panel closes when dragged below half its minimum, or when its handle is focused and Enter pressed; Enter again restores it.

Keyboard

A focused handle moves 1% per arrow key and 10% with Shift. Home and End move it as far as the panels allow, and Enter collapses or restores a collapsible panel beside it. Escape during a drag puts the panels back.

Best practices

Do
  • Set minSize on each panel so nothing can be dragged too small to use.
  • Name every ResizableHandle with an aria-label, such as “Resize terminal”, when a layout has more than one.
  • Save the layout with autoSaveId, so it’s the same on the next visit.
  • Make a side panel collapsible when people often want it out of the way.
Don’t
  • Wrap panels in extra boxes to resize them. Put the content straight in ResizablePanel.
  • Use resizable panels on phones. Show one panel at a time there.

API reference

Resizable

The group. Lays its panels out in a row or a column.

PropTypeDefault
orientation
Panels side by side, or stacked.
'horizontal' | 'vertical''horizontal'
layout
Each panel’s size in percent, in order. Pass it with onLayoutChange to control the group.
number[]—
defaultLayout
Every panel’s starting size at once, when uncontrolled.
number[]—
onLayoutChange
Runs on every frame of a drag and every key, with the reason.
(layout, details) => void—
onLayoutCommit
Runs once, when the drag or key press that changed the layout ends. Save here.
(layout, details) => void—
autoSaveId
Saves the layout in localStorage under this key and restores it on the next visit. Give panels an id.
string—
storage
Where autoSaveId saves: anything with getItem and setItem, such as a cookie store.
ResizableStorage—
controller
Collapses, expands and resizes panels from outside. Create one with createResizableController().
ResizableController—
step
How far an arrow key moves a handle, in percent.
number1
largeStep
How far Shift with an arrow key moves a handle, in percent.
number10
disabled
Fixes every handle in place and takes them out of the tab order.
boolean—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ResizablePanel

One pane. Clips what overflows; put a ScrollArea inside for content that scrolls.

PropTypeDefault
id
Names the panel for the controller and saved layouts.
string—
defaultSize
Where the panel starts. Without one, panels share what is left.
number | `${number}px` | `${number}%` | `${number}rem`—
minSize
The smallest the panel gets while open.
number | `${number}px` | `${number}%` | `${number}rem`—
maxSize
The largest the panel gets.
number | `${number}px` | `${number}%` | `${number}rem`—
collapsible
Lets the panel close below its minimum, to collapsedSize.
boolean—
collapsedSize
The size a collapsible panel closes to. At 0 its content leaves the tab order.
number | `${number}px` | `${number}%` | `${number}rem`0
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ResizableHandle

The focusable separator between two panels. Name it with aria-label.

PropTypeDefault
grip
Shows a small knob on the line.
booleanfalse
disabled
Fixes this handle in place.
boolean—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—