API: primitives (@fragiola/flow-react, @fragiola/flow-vue, @fragiola/flow-svelte, @fragiola/flow-angular)
NodeResizer
NodeResizer holds the resize handles of a node, with that node's own size limits and aspect ratio over the resize() feature's.
NodeResizer comes from @fragiola/flow-react/resize (@fragiola/flow-vue/resize), with the resize() feature it needs. It
must be rendered inside its node's element (Flow.Node): the engine finds the node a press
resizes from the DOM, the closest node part, and nodeId only names the node for the state and
the limits. It and renders a box over the node holding its ResizeHandles: by default
one at each corner and side. A drag on a handle resizes the node (node.resize, transient steps
then a final one), within this node's limits, which override resize()'s
(engine.adapter.setPartOptions("resizer", nodeId, …)). In a sub-flow, a child with extent: "parent"
stays inside its parent, and a parent never shrinks past its extent: "parent" children. Render it only when the node should be
resizable (while it is selected, say).
import { Flow, type FlowNode, type FlowTypes } from "@fragiola/flow-react";
import { drag } from "@fragiola/flow-react/drag";
import { NodeResizer, resize } from "@fragiola/flow-react/resize";
import { selection } from "@fragiola/flow-react/selection";
interface Types extends FlowTypes {
readonly nodes: { note: { label: string } };
}
export const features = [selection(), drag(), resize({ minWidth: 80, minHeight: 60 })] as const;
export function ResizableNode({ node }: { node: FlowNode<Types> }) {
return (
<Flow.Node<Types> node={node} className="relative">
{node.data.label}
{node.selected && <NodeResizer minWidth={120} maxWidth={360} keepAspectRatio={false} />}
</Flow.Node>
);
}One direction, and a grid
direction="horizontal" makes this node's resize move only its width (and its x, from the left);
"vertical" only its height (and its y, from the top). A corner handle then moves its one
dimension, and keepAspectRatio does not apply. Without it, both. Render only the handles that
make sense, the two sides:
<NodeResizer direction="horizontal">
<ResizeHandle position="left" aria-label="Resize banner: left" className="w-1" />
<ResizeHandle position="right" aria-label="Resize banner: right" className="w-1" />
</NodeResizer>The direction is the resizer's, sent with its limits (engine.adapter.setPartOptions("resizer", nodeId, { direction })). A ResizeHandle's own direction wins over it for that handle (see
Its own direction, and a line).
A resize snaps to a grid only with resize({ snap }): the sides the pointer moves land on it, so
sizes and positions do. The drag feature's snapGrid is the drag's alone and does not apply to a
resize, and an arrow key's step (with keyboard()) is never snapped:
const features = [drag({ snapGrid: [20, 20] }), resize({ snap: { x: 20, y: 20 } })] as const;Props
NodeResizerProps extends the common primitive props and
every div attribute.
| prop | type | default | description |
|---|---|---|---|
nodeId | string | the enclosing Flow.Node's | the node its state and its limits name (the node a press resizes is the one it is rendered in) |
minWidth | number | resize()'s (10) | this node's smallest width, in flow units |
minHeight | number | resize()'s (10) | this node's smallest height |
maxWidth | number | resize()'s (none) | this node's largest width |
maxHeight | number | resize()'s (none) | this node's largest height |
keepAspectRatio | boolean | resize()'s (false) | this node keeps its width-to-height ratio |
direction | ResizeDirection | both | "horizontal": its handles move only the width (and x); "vertical": only the height (and y); a corner then moves its one dimension |
children | ReactNode | a ResizeHandle at each corner and side | its handles |
State
NodeResizerState, what className, style and render receive:
| field | type | description |
|---|---|---|
nodeId | string | its node |
resizing | boolean | its node is being resized |
Data attributes
| attribute | value |
|---|---|
data-flow-part | "resizer" |
data-flow-id | its node's id |
data-resizing | present while its node is resized |
Structural style
position: absolute; inset: 0; pointer-events: none (its handles take the presses).