cnippet/ui
  1. ui
  2. layout
  3. resizable

layout

Resizable

Panels that users resize by dragging a handle or with the keyboard, for editors, mail clients and split views, with nesting, collapsing and saved layouts. Copy-paste ready.

Installation

Usage

Good to know

  • Built on react-resizable-panels v4. Every prop it takes passes through.
  • Sizes: a string is a percentage ("30%" or "30") and a number is pixels (200). Other units such as "16rem" work too.
  • The group needs a height. Give it one with className, or let it fill a parent that has one.
  • Stack panels with orientation="vertical" on the group, and nest a group inside a panel for editor-style layouts.
  • Handles are focusable: the arrow keys resize, Home and End jump to the limits, and double-clicking a handle resets its panels to their default sizes.
  • Add collapsible (and optionally collapsedSize) to a panel to let it snap shut when dragged past minSize.
  • To remember the layout, pass useDefaultLayout({ id, storage: localStorage }) to the group, and give each panel an id, as in the mail example.

API Reference

ResizablePanelGroup

ResizablePanel

ResizableHandle

Examples

Horizontal

Vertical

Collapsible with saved layout

The nav collapses to icons when dragged past its minimum, and the sizes survive a reload.