组件

Resizable

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.

安装

terminal
npx shadcn@latest add @wobko/resizable

第一次使用?先把 registry 加进 components.json。 如何安装

示例

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).

Vertical, without a tab

`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.

Remembered layout

`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`.

Mail layout

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.

Demo

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.

Demo with handle

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.

Vertical

Official `resizable-vertical`: `orientation="vertical"` stacks a header over the content with one horizontal seam. Arrow Up and Down move it from the keyboard.

Handle

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.

API 参考

ResizablePanelGroup

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 / onLayoutChangedLayout / (layout, meta) => void-Remember a layout: keys are panel ids, values percentages. `useDefaultLayout({ id, storage })` returns both props for any storage with getItem / setItem.
groupRefRef<GroupImperativeHandle>-`getLayout()` and `setLayout()`; `useGroupRef()` makes one.
disabledbooleanfalseNo panel can be resized. Its handles stay focusable (as in the library) and are drawn as the faint disabled thread.

ResizablePanel

A panel. `className` goes to the panel's inner element (the library keeps its own flex style on the outer one).

属性类型默认值说明
idstring-Identifies the panel in layouts; give one to every panel of a persisted group.
defaultSize / minSize / maxSizenumber | string-Numbers are pixels; strings are percentages ("30", "30%") or units ("20rem").
collapsible / collapsedSize / collapsedThresholdboolean / size / size-A collapsible panel snaps shut when dragged below its minimum.
panelRef / onResizeRef<PanelImperativeHandle> / (size) => void-`collapse()`, `expand()`, `resize(size)`, `getSize()`, `isCollapsed()`; `usePanelRef()` makes one.

ResizableHandle

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.

属性类型默认值说明
withHandlebooleanfalseAdd the paper tab with a grip.
disabledbooleanfalseFaint thread, no tab, not draggable.
seedstring | number-Pins the hand. Default: derived from useId().

无障碍

  • The handle is a `role="separator"` with `aria-orientation`, `aria-valuenow` / `aria-valuemin` / `aria-valuemax` and `aria-controls` (the primary panel), and is in the tab order. Give it an `aria-label` that says what it resizes.
  • Arrow keys move it by 5%, Home and End jump to the limits, Enter collapses or restores a collapsible panel, all from react-resizable-panels. Dragging works with mouse, touch and pen; the hit area is larger than the drawing (at least 24 px for a mouse and 37 px for a finger; the group asks the library for that through `resizeTargetMinimumSize`, which you can override).
  • ArrowLeft / ArrowRight shrink / grow the first panel whatever the reading direction (react-resizable-panels does not mirror them), so on a `dir="rtl"` page the handle moves against the arrow. Up / Down are exact in a vertical group.
  • The stitches, the tab and the blue line are aria-hidden decoration; the grip glyph is decorative too.
  • Keyboard focus draws a blue ring round the middle of the seam (round the tab, when there is one). Windows high contrast draws a real outline round the handle.
  • Hover, dragging and focus each show without hue: the stitches darken, the seam becomes one continuous line, the ring appears.

源码

CLI 会复制进你项目的文件。

正在加载源码