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
- Set
minSizeon each panel so nothing can be dragged too small to use. - Name every
ResizableHandlewith anaria-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
collapsiblewhen people often want it out of the way.
- 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.
| Prop | Type | Default |
|---|---|---|
orientationPanels side by side, or stacked. | 'horizontal' | 'vertical' | 'horizontal' |
layoutEach panel’s size in percent, in order. Pass it with onLayoutChange to control the group. | number[] | — |
defaultLayoutEvery panel’s starting size at once, when uncontrolled. | number[] | — |
onLayoutChangeRuns on every frame of a drag and every key, with the reason. | (layout, details) => void | — |
onLayoutCommitRuns once, when the drag or key press that changed the layout ends. Save here. | (layout, details) => void | — |
autoSaveIdSaves the layout in localStorage under this key and restores it on the next visit. Give panels an id. | string | — |
storageWhere autoSaveId saves: anything with getItem and setItem, such as a cookie store. | ResizableStorage | — |
controllerCollapses, expands and resizes panels from outside. Create one with createResizableController(). | ResizableController | — |
stepHow far an arrow key moves a handle, in percent. | number | 1 |
largeStepHow far Shift with an arrow key moves a handle, in percent. | number | 10 |
disabledFixes every handle in place and takes them out of the tab order. | boolean | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ResizablePanel
One pane. Clips what overflows; put a ScrollArea inside for content that scrolls.
| Prop | Type | Default |
|---|---|---|
idNames the panel for the controller and saved layouts. | string | — |
defaultSizeWhere the panel starts. Without one, panels share what is left. | number | `${number}px` | `${number}%` | `${number}rem` | — |
minSizeThe smallest the panel gets while open. | number | `${number}px` | `${number}%` | `${number}rem` | — |
maxSizeThe largest the panel gets. | number | `${number}px` | `${number}%` | `${number}rem` | — |
collapsibleLets the panel close below its minimum, to collapsedSize. | boolean | — |
collapsedSizeThe size a collapsible panel closes to. At 0 its content leaves the tab order. | number | `${number}px` | `${number}%` | `${number}rem` | 0 |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ResizableHandle
The focusable separator between two panels. Name it with aria-label.
| Prop | Type | Default |
|---|---|---|
gripShows a small knob on the line. | boolean | false |
disabledFixes this handle in place. | boolean | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |