<Stencil />
Drag shapes from a React-built palette onto the paper. Unlike the built-in
JointJS stencil, this one is headless: it renders a host <div> (forwarding
any div attributes you pass) that wraps your own palette UI as children,
so you control the look and layout entirely in React.
Start a drag by calling useStencil's startCellDrag from a palette
item. While dragging, the preview is rendered through the JointJS drag paper
via StencilProps.renderElement, which defaults to the target paper's
own renderElement so the preview matches the dropped element.
The drop target is resolved from the nearest <Paper> / <PaperScroller>
context, or set it explicitly with StencilProps.paper.
Type Parametersβ
| Type Parameter | Default type |
|---|---|
ElementData | unknown |
Seeβ
Exampleβ
import { Paper, HTMLBox, Diagram, PaperScroller, Stencil, useStencil } from '@joint/react-plus';
// Build the palette yourself; start a drag from any item.
function Palette() {
const { startCellDrag } = useStencil();
return (
<button
onPointerDown={(event) =>
startCellDrag({ type: 'element', data: { label: 'Task' } }, event)
}
>
Add task
</button>
);
}
function Editor() {
return (
<Diagram>
<PaperScroller>
<Paper renderElement={({ label }) => <HTMLBox>{label}</HTMLBox>} />
</PaperScroller>
<Stencil>
<Palette />
</Stencil>
</Diagram>
);
}
Propsβ
autoZIndex?β
readonly optional autoZIndex?: boolean;
Place dropped elements above existing ones by auto-assigning their z-index.
Defaultβ
true
children?β
readonly optional children?: ReactNode;
Your palette UI, rendered inside the stencil host element.
dropAnimation?β
readonly optional dropAnimation?: DropAnimation;
Animate the clone snapping into place on a valid drop. true for the
default animation, or an object to tune duration / easing.
Defaultβ
true
onCellDrag?β
optional onCellDrag?: (params) => void;
Fires continuously while an element is being dragged from the stencil.
Parametersβ
| Parameter | Type |
|---|---|
params | StencilDragParams |
Returnsβ
void
onCellDragEnd?β
optional onCellDragEnd?: (params) => void;
Fires once when the user releases, before onCellDrop / onCellDropInvalid.
Parametersβ
| Parameter | Type |
|---|---|
params | StencilDragParams |
Returnsβ
void
onCellDragStart?β
optional onCellDragStart?: (params) => void;
Fires when the drag actually starts (async, once the drag preview's size has been measured).
Parametersβ
| Parameter | Type |
|---|---|
params | StencilDragParams |
Returnsβ
void
onCellDrop?β
optional onCellDrop?: (params) => void;
Fires when the cell lands on a valid drop target.
Parametersβ
| Parameter | Type |
|---|---|
params | StencilDropParams |
Returnsβ
void
onCellDropInvalid?β
optional onCellDropInvalid?: (params) => void;
Fires when the cell is released outside any valid drop target.
Parametersβ
| Parameter | Type |
|---|---|
params | StencilDropInvalidParams |
Returnsβ
void
options?β
readonly optional options?: Options;
Raw ui.Stencil.Options passthrough for anything joint-react-plus doesn't
expose as a dedicated prop.
Values set here override top-level props of the same name: treat this as
the authoritative form for users who need direct access to the raw
JointJS API. Avoid overriding joint-react-plus-controlled options
(paper, groups, layout, paperOptions, search): the headless
component has no UI to consume them.
paper?β
readonly optional paper?: PaperTarget;
Target paper the stencil drops onto: a paper id, dia.Paper instance,
or paper ref. Defaults to the nearest <Paper> / <PaperScroller>
context when omitted.
renderElement?β
readonly optional renderElement?: RenderElement<ElementData>;
Renders the drag preview while a clone is dragged from the palette.
Defaults to the target paper's renderElement, so the preview matches the
element that will be dropped. Omit it to skip React-rendered previews.
scaleClones?β
readonly optional scaleClones?: boolean;
Scale the drag clone to match the target paper's current zoom.
Defaultβ
true
usePaperGrid?β
readonly optional usePaperGrid?: boolean;
Snap the dragged clone to the target paper's grid.
Defaultβ
true