Skip to Content
📣 We just released Svelte Flow 1.0 Alpha — try it out and give us your feedback!
ExamplesEdgesCustom Edges

Custom Edges

Svelte Flow comes with four different edge types - default (bezier), straight, step and smoothstep. It’s also possible to create a custom edge, if you need a special edge routing or controls at the edge. In this example we are demonstrating how to implement an edge with a button, a bi-directional edge, a self connecting edge. In all examples we are using the BaseEdge component as a helper.

<script lang="ts"> import { SvelteFlow, Background, ConnectionMode, Controls, type Node, type Edge, } from '@xyflow/svelte'; import '@xyflow/svelte/dist/style.css'; import { initialNodes, initialEdges } from './nodes-and-edges'; import ButtonEdge from './ButtonEdge.svelte'; import BiDirectionalEdge from './BiDirectionalEdge.svelte'; import BiDirectionalNode from './BiDirectionalNode.svelte'; import SelfConnectingEdge from './SelfConnectingEdge.svelte'; let nodes = $state.raw<Node[]>(initialNodes); let edges = $state.raw<Edge[]>(initialEdges); const nodeTypes = { bidirectional: BiDirectionalNode, }; const edgeTypes = { buttonedge: ButtonEdge, bidirectional: BiDirectionalEdge, selfconnecting: SelfConnectingEdge, }; </script> <SvelteFlow bind:nodes {nodeTypes} bind:edges {edgeTypes} connectionMode={ConnectionMode.Loose} fitView > <Controls /> <Background /> </SvelteFlow>
Last updated on