Panels
Three panels and two seams, nested: a row with a column inside, on a slip of paper. The seam is stitched by hand; `withHandle` adds a paper tab with a grip. Drag it, or focus it and use the arrow keys (Home and End jump to the limits).
Panels you can drag apart. The seam between two panels is stitched by hand, gets a paper tab with a grip if you ask, darkens under the pointer and is pulled tight into one blue line while you drag. Built on react-resizable-panels 4: keyboard resizing, collapsible panels and persisted layouts included.
npx shadcn@latest add @wobko/resizable第一次使用?先把 registry 加进 components.json。 如何安装
Three panels and two seams, nested: a row with a column inside, on a slip of paper. The seam is stitched by hand; `withHandle` adds a paper tab with a grip. Drag it, or focus it and use the arrow keys (Home and End jump to the limits).
`orientation="vertical"` stacks the panels and turns the seam; without `withHandle` the seam is only stitches. The middle panel has a minimum and a maximum, so the seams stop where the limits are.
`useDefaultLayout` saves and restores a layout through any object with `getItem` and `setItem`. Here that is a plain in-memory Map (no localStorage): resize, press Remount, and the panels come back where you left them. Reset uses the group's imperative `setLayout`.
A real screen: an inbox that collapses to nothing (a button, and dragging it past its minimum, both do it), a message and a details column. Collapsing uses the panel's imperative API.
Official `resizable-demo`: a row of two panels, the second split into a column. shadcn draws its `rounded-lg border` on the group; here the group sits on a slip of paper instead (the group clips, so it cannot wear a shadow itself). Drag a seam, or focus it and use the arrow keys.
Official `resizable-demo-with-handle`: the same layout with `withHandle`, which puts a small paper tab with a grip on each seam. The tab turns with the seam, so the column's seam is horizontal and its grip lies down.
Official `resizable-vertical`: `orientation="vertical"` stacks a header over the content with one horizontal seam. Arrow Up and Down move it from the keyboard.
Official `resizable-handle`: a narrow sidebar panel beside the content with the grip tab on the seam. This is the shape most apps start from; add `minSize` and `maxSize` on the panels to keep either side usable.
react-resizable-panels' `Group`. Sizes are percentages (or px, rem, vh: `"30%"`, `240`, `"20rem"`). The group clips (`overflow: hidden`, which the library does not let you override except through `style.overflow`): pass `style={{ overflow: "visible" }}` if a panel draws beyond its edge. Coming from react-resizable-panels 2 (older shadcn code): `direction` is now `orientation`, `autoSaveId` is `useDefaultLayout`, and a number size is pixels, so `defaultSize={30}` becomes `defaultSize="30%"`.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| orientation | "horizontal" | "vertical" | "horizontal" | Panels side by side (seams are vertical) or stacked (seams are horizontal). |
| defaultLayout / onLayoutChanged | Layout / (layout, meta) => void | - | Remember a layout: keys are panel ids, values percentages. `useDefaultLayout({ id, storage })` returns both props for any storage with getItem / setItem. |
| groupRef | Ref<GroupImperativeHandle> | - | `getLayout()` and `setLayout()`; `useGroupRef()` makes one. |
| disabled | boolean | false | No panel can be resized. Its handles stay focusable (as in the library) and are drawn as the faint disabled thread. |
A panel. `className` goes to the panel's inner element (the library keeps its own flex style on the outer one).
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | string | - | Identifies the panel in layouts; give one to every panel of a persisted group. |
| defaultSize / minSize / maxSize | number | string | - | Numbers are pixels; strings are percentages ("30", "30%") or units ("20rem"). |
| collapsible / collapsedSize / collapsedThreshold | boolean / size / size | - | A collapsible panel snaps shut when dragged below its minimum. |
| panelRef / onResize | Ref<PanelImperativeHandle> / (size) => void | - | `collapse()`, `expand()`, `resize(size)`, `getSize()`, `isCollapsed()`; `usePanelRef()` makes one. |
The separator (`role="separator"`, focusable). A row of 8 px: stitches, with a slip of paper carrying a grip glyph when `withHandle` is set. Its drawn layers follow the library's `data-separator` (`hover`, `active`) so the wider hit region works.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| withHandle | boolean | false | Add the paper tab with a grip. |
| disabled | boolean | false | Faint thread, no tab, not draggable. |
| seed | string | number | - | Pins the hand. Default: derived from useId(). |
CLI 会复制进你项目的文件。
正在加载源码