Skip to content

hooks/useResizeDrag

import { … } from 'zidane-ui'ui/src/hooks/useResizeDrag.ts

Functions#

clampWidthFunction#

Clamps a size to a range and rounds it to whole pixels.

TypeScript
function clampWidth(value: number, min: number, max: number): number
Parameters
NameTypeDescription
valuenumber

The size to clamp.

minnumber

The lower bound.

maxnumber

The upper bound.

number

The clamped, rounded size.

ui/src/hooks/useResizeDrag.ts:99

useResizeDragFunction#

Resizes a side panel by dragging its edge. While dragging, it writes the clamped size to a CSS variable on target without React state changes, and calls onCommit once on release.

TypeScript
function useResizeDrag(options: ResizeDragOptions): ResizeDrag
Parameters
NameTypeDescription
optionsResizeDragOptions

See ResizeDragOptions.

ResizeDrag

Whether a drag is active, and the props for the handle.

ui/src/hooks/useResizeDrag.ts:110

Interfaces#

ResizeDragInterface#

What useResizeDrag returns.

TypeScript
interface ResizeDrag
ResizeDrag properties
NameTypeDescription
activeboolean

Whether a drag is in progress.

handlePropsResizeDragHandleProps

Props to spread onto the handle element.

ui/src/hooks/useResizeDrag.ts:82

ResizeDragHandlePropsInterface#

Props useResizeDrag returns for the drag handle element.

TypeScript
interface ResizeDragHandleProps
ResizeDragHandleProps properties
NameTypeDescription
aria-orientation'horizontal' | 'vertical'

Orientation of the separator: vertical when resizing a width, horizontal for a height.

aria-valuemaxnumber

The largest size.

aria-valueminnumber

The smallest size.

aria-valuenownumber

The current size.

onDoubleClick() => void

Resets the size to defaultValue.

onPointerDown(e: PointerEvent<HTMLElement>) => void

Starts a drag on a primary-button press, with pointer capture.

role'separator'

The handle is a separator.

tabIndex-1

The handle is not in the tab order.

ui/src/hooks/useResizeDrag.ts:62

ResizeDragOptionsInterface#

Options of useResizeDrag.

TypeScript
interface ResizeDragOptions
ResizeDragOptions properties
NameTypeDescription
axis?'x' | 'y'

x (default) resizes a width; y a height, with start the top edge (a drawer anchored at the bottom) and end the bottom edge.

defaultValuenumber

Size in px restored by a double-click on the handle.

edge'start' | 'end'

Which side of the element the handle sits on. end is for a panel anchored at the left, such as the sidebar, and start for one anchored at the right. It sets the drag direction.

maxnumber

Largest size in px a drag can reach.

minnumber

Smallest size in px a drag can reach.

onCommit(width: number) => void

Called once on release with the final size in px, and on a double-click with defaultValue. Nothing is called while dragging.

target{ cssVar: string; ref: RefObject<HTMLElement | null> }

Element whose CSS variable receives the live width during a drag.

valuenumber

The current size in px. A drag starts from it.

ui/src/hooks/useResizeDrag.ts:33