Resizable for Astro
Astro panels with pointer and keyboard size controls.
Installation
bunx --bun shadcn@latest add @gnostic/resizablenpx shadcn@latest add @gnostic/resizablepnpm dlx shadcn@latest add @gnostic/resizableInstall component packages
bun add @data-slot/core @data-slot/resizablenpm install @data-slot/core @data-slot/resizablepnpm add @data-slot/core @data-slot/resizableCopy the files
src/components/ui/resizable/index.tssrc/components/ui/resizable/resizable-handle.astrosrc/components/ui/resizable/resizable-panel-group.astrosrc/components/ui/resizable/resizable-panel.astrosrc/components/ui/resizable/snap-points.tssrc/components/ui/resizable/types.ts
Usage
---
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable"
---
<ResizablePanelGroup class="h-48 w-full rounded-lg border">
<ResizablePanel defaultSize={50} minSize={20}>
<div class="flex h-full items-center justify-center p-6">One</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel defaultSize={50} minSize={20}>
<div class="flex h-full items-center justify-center p-6">Two</div>
</ResizablePanel>
</ResizablePanelGroup>
Composition
Place one ResizableHandle between each pair of panels. Sizes are percentages of the group. Give the group a height.
ResizablePanelGroup
├── ResizablePanel
├── ResizableHandle
└── ResizablePanel
Examples
Vertical
Set direction="vertical" to stack the panels. The handle moves up and down.
Custom handle
Add a custom handle by passing a direct child to ResizableHandle.
Nested groups
A panel can contain another group. Use withHandle to show a grip on the separator.
Collapsible panel
Set collapsible on a panel to let it collapse past minSize. Focus the handle and press Enter to collapse and expand that panel. Arrow keys resize by 10 percent. Home and End move to the limits.
Snap points
Set snapPoints on a handle to give the panel before it a set of widths or heights. Each number is a percentage of the whole group. Release a drag to select the nearest size that both adjacent panels allow. A tie selects the smaller size. Use the arrow keys to move between stops. Home and End still move to the panel limits.
API Reference
ResizablePanelGroup, ResizablePanel, and ResizableHandle accept native div attributes.
ResizablePanelProps
defaultSize?number
Initial size as a percentage of the group. Panels without a size share the remaining space.
numberminSize?number
Minimum size as a percentage.
number0maxSize?number
Maximum size as a percentage.
number100collapsible?boolean
Allow this panel to collapse past `minSize`. Press Enter on the preceding handle to collapse and expand it.
booleanfalsecollapsedSize?number
Size as a percentage when the panel is collapsed. This value must not exceed `minSize`.
number0ResizableProps
direction?ResizableDirection
Layout axis for the panels. `horizontal` places panels side by side. `vertical` stacks the panels.
ResizableDirection"horizontal"keyboardResizeBy?number
Percent added or removed for each arrow key press. Shift with an arrow key moves to the limit.
number10ResizableHandleProps
snapPoints?readonly number[]
Optional sizes for the panel before this handle, as percentages of the group. Release a drag to select the nearest available size. Arrow keys select the previous or next size. Both adjacent panels must allow that size.
readonly number[]withHandle?boolean
Show a grip in the center of the handle.
booleanfalseEvents
Dispatch these events on the resizable group root. The root emits the outbound events. The component does not store the layout.
Outbound events
| Event | Detail |
|---|---|
resizable:change |
{ layout: number[] } |
resizable:dragging |
{ dragging: boolean } |
Inbound events
| Event | Detail |
|---|---|
resizable:set |
{ layout: number[] } |
See the data-slot docs for keyboard behavior and the controller API.
Read the installed source for the component source.
When to use Resizable
Compose panels and resize handles inside a ResizablePanelGroup. Choose an orientation and useful size bounds so neither panel becomes unusable. Keep the panel content independent of its starting size.
Keyboard and behavior
The existing data-slot controller handles pointer and keyboard resizing. Give each handle a useful label and test its arrow-key behavior. A panel that contains a form must still expose all controls at its minimum size.
Theme and layout
The handle uses shared border and focus colors. Check content overflow after a resize and at narrow viewport widths. Some layouts are clearer when panels stack instead of remaining resizable on a phone.