ES Drager provides a powerful connection system that allows you to create visual relationships between elements using anchor points and bezier curves.
To enable connections, set the connectable
prop and provide a unique id
:
<Drager
id="node-1"
connectable
className="w-32 h-32 bg-blue-500"
>
Source
</Drager>
Hover over the blue dots (anchor points) and drag to another anchor point to create a connection. The connection will be visualized as a bezier curve.
Track connections using the onConnect
event handler. This event provides details about the source and target nodes:
const handleConnect = (
sourceId: string, // ID of the source node
sourceAnchor: string,// Position of source anchor ('top', 'right', 'bottom', 'left')
targetId: string, // ID of the target node
targetAnchor: string // Position of target anchor
) => {
console.log('Connected:', { sourceId, sourceAnchor, targetId, targetAnchor })
}
Connections work seamlessly with rotation and scaling:
Try creating connections between nodes while rotating and scaling them. The connections will automatically update to maintain their positions.