<Snaplines />
Shows alignment guides while you drag or resize elements, snapping them to the
edges and centers of nearby elements (and optionally to the paper grid) for
tidy, aligned layouts. Mount it inside a <Paper>; see SnaplinesProps
for the available options, including the options escape hatch for native
ui.Snaplines settings that have no dedicated prop.
Other components such as <Stencil> automatically detect and reuse the active
snaplines instance.
To turn snaplines off, conditionally render the component, unmounting removes
the instance entirely: {shouldSnap && <Snaplines />}.
Seeβ
Exampleβ
import { GraphProvider, Paper, Snaplines } from '@joint/react-plus';
function MyDiagram() {
return (
<GraphProvider initialCells={cells}>
<Paper renderElement={RenderElement}>
<Snaplines
distance={10}
usePaperGrid
canSnap={({ model }) => !model.get('locked')}
isSnapTarget={({ model, targetModel }) =>
targetModel.get('type') !== 'decoration' &&
targetModel.get('lane') === model.get('lane')
}
/>
</Paper>
</GraphProvider>
);
}
Propsβ
additionalSnapPoints?β
readonly optional additionalSnapPoints?: (params) => PlainPoint[];
Provide extra snap points (beyond the element's bbox) for the current move/resize gesture.
Parametersβ
| Parameter | Type |
|---|---|
params | SnaplinesAdditionalSnapPointsParams |
Returnsβ
PlainPoint[]
canSnap?β
readonly optional canSnap?: (params) => boolean;
Predicate deciding whether the dragged element may snap: return true to allow snapping.
Parametersβ
| Parameter | Type |
|---|---|
params | SnaplinesCanSnapParams |
Returnsβ
boolean
distance?β
readonly optional distance?: number;
Snap radius in pixels: how close an edge must get before it snaps.
Defaultβ
10
isSnapTarget?β
readonly optional isSnapTarget?: (params) => boolean;
Predicate deciding whether a candidate element may act as a snap target: return true to include it.
Parametersβ
| Parameter | Type |
|---|---|
params | SnaplinesIsSnapTargetParams |
Returnsβ
boolean
options?β
readonly optional options?: Partial<Options>;
Raw ui.Snaplines.Options passthrough for anything joint-react-plus
doesn't expose as a dedicated prop (mvc internals like theme, events,
attributes, tagName, etc.). Use this for the array forms of native
filter (string[] of cell types / dia.Cell[] to exclude as snap
targets); the dedicated isSnapTarget prop covers the predicate form.
Avoid overriding joint-react-plus-controlled options (paper).
usePaperGrid?β
readonly optional usePaperGrid?: boolean;
Snap to the paper grid in addition to other elements.
Defaultβ
false