@activecollab/components
Version:
ActiveCollab Components
62 lines • 3.21 kB
TypeScript
import React from "react";
import { StackedCardContentMin, StackedCardResizeAxis, StackedCardResizePolicy, StackedCardResizeSource, StackedCardSize } from "./resizePolicy";
/**
* The one place pointer and keyboard input meet the resize policy.
*
* `StackedCard`'s built-in grip reports raw deltas and knows no policy — enough
* for a host that just tracks a width. This hook is the full contract: it
* captures the gesture start, funnels both inputs through the pure policy in
* `resizePolicy.ts`, streams preview events and fires exactly ONE commit per
* gesture. It returns the props to spread on the grip, including the live
* separator ARIA.
*
* Preview versus commit (spec §7e): the continuous stream is live feedback
* only. A host creates an undo entry on the COMMIT, never on a preview — and a
* gesture that never changed the size commits nothing at all, so a bare click
* on the grip is not a change.
*
* The hook never touches the card's content: the intrinsic minimum is read
* through `contentMin`, which may be a getter so a card that measures its own
* footer can answer at the moment it is asked.
*/
export interface UseStackedCardResizeArgs {
/** The card's current size, owned by the host. */
size: StackedCardSize;
policy: StackedCardResizePolicy;
/** Id of the element the grip resizes — becomes `aria-controls`. */
cardId: string;
/** The card's intrinsic minimum; a getter is read at the moment it is needed. */
contentMin: StackedCardContentMin | (() => StackedCardContentMin);
/** `width` locks the vertical axis (auto-height cards). Defaults to `both`. */
axis?: StackedCardResizeAxis;
/**
* Pointer deltas are divided by this before they reach the policy, so a grip
* inside a zoomed canvas tracks the cursor exactly. Keyboard nudges are
* already in the host's units and pass straight through. Defaults to 1.
*/
scale?: number;
/** Accessible name for the grip. Defaults to "Resize card". */
label?: string;
/** Live feedback during the gesture. Never an undoable change. */
onResize: (next: StackedCardSize, source: StackedCardResizeSource) => void;
/** Fires once per gesture, and only if the size actually changed. */
onResizeCommit: (final: StackedCardSize, source: StackedCardResizeSource) => void;
}
/** The props to spread on the grip — `StackedCard`'s `resizeHandleProps`. */
export interface StackedCardResizeHandleProps {
role: "separator";
tabIndex: 0;
"aria-label": string;
"aria-controls": string;
"aria-valuemin": number;
"aria-valuemax": number;
"aria-valuenow": number;
onPointerDown: (e: React.PointerEvent) => void;
onPointerMove: (e: React.PointerEvent) => void;
onPointerUp: (e: React.PointerEvent) => void;
onLostPointerCapture: (e: React.PointerEvent) => void;
onKeyDown: (e: React.KeyboardEvent) => void;
onKeyUp: (e: React.KeyboardEvent) => void;
}
export declare const useStackedCardResize: ({ size, policy, cardId, contentMin, axis, scale, label, onResize, onResizeCommit, }: UseStackedCardResizeArgs) => StackedCardResizeHandleProps;
//# sourceMappingURL=useStackedCardResize.d.ts.map