Skip to content

useResizable

@astryxdesign/core v0.7.1 · useResizable

Parameters ​

NameTypeDefaultDescription
defaultSizeResizableSize | string250Initial size. Numbers, exact "Npx", and pixel(value) are pixels. Exact "N%" has no additional pixel bound. percent(value, { min: pixel(value) }) or percent(value, { max: pixel(value) }) adds one pixel floor or ceiling. A percentage resolves once into pixels, against containerRef when supplied and against the viewport otherwise, and does not track its basis afterwards.
minSizeResizableSize | string50Minimum size. Numbers, exact "Npx", and pixel(value) remain pixels; exact "N%" has no additional pixel bound; percent() adds exactly one. Percentage minimums re-resolve when their basis changes and clamp the current pixel selection.
maxSizeResizableSize | stringInfinityMaximum size. Numbers, exact "Npx", and pixel(value) remain pixels; exact "N%" has no additional pixel bound; percent() adds exactly one. Percentage maximums re-resolve when their basis changes and clamp the current pixel selection.
containerRefRef<HTMLElement | null>—The element a percentage is a share of. Caller-owned: the hook never infers one. Omitted, percentages use the viewport. The ref may point at a different element over time and the basis follows it. Until that element is laid out (not yet mounted, display:none, detached) percentages use a temporary 1200px basis and nothing is persisted from it.
direction'horizontal' | 'vertical''horizontal'Which axis this region resizes along. Selects the container's inline or block content-box size as the percentage basis, and must match the direction given to ResizeHandle.
collapsiblebooleanfalseWhether dragging below the collapsed threshold collapses the region to zero.
collapsedSizenumber40Pixel threshold below which a collapsible region snaps to zero.
snapsnumber[][]The size stops only on these pixel points. An equal distance stays on the earlier point.
autoSaveIdstring—Key for localStorage persistence of size and collapse state across sessions, stored under astryx-resizable:.
defaultIsCollapsedbooleanfalseInitial collapse state (uncontrolled). A persisted entry wins over it.
isCollapsedboolean—Controlled collapse state. collapse(), expand() and a drag past the threshold then report through onCollapseChange instead of changing state internally.
onSizeChange(size: number) => void—Called with the resolved pixel size after every drag, resize, or collapse.
onCollapseChange(isCollapsed: boolean) => void—Called once per collapse state change, via drag or programmatically.

useResizable({ regions }) instead takes regions (a map of key to ResizableRegionConfig) plus direction, containerRef, and autoSaveId. Each region accepts the size, collapse, and snap fields above, and shrinkOrder: a lower number gives up space first when the container is narrower than the regions.

Returns ​

NameTypeDescription
sizenumberCurrent size in pixels. Reactive.
isCollapsedbooleanWhether the region is currently collapsed. Reactive.
collapse() => voidProgrammatically collapse the region.
expand() => voidExpand from collapsed state.
resize(size: number) => voidResize to a specific pixel value.
propsResizablePropsProps to spread on the resizable component or pass to ResizeHandle.

With a regions map, the return value is Record<string, ResizableRegion>: one object of the same shape per key.