# Vue Flow Documentation What is Vue Flow? Vue Flow is a library that allows you to create interactive, node-based user interfaces: flowcharts, diagrams, visual programming tools, and workflows inside your vue applications. It supports theming, custom nodes and edges, a library of shadcn UI components, and offers a large collection of examples for rapid development. Developers can leverage the Vue Flow Pro platform for advanced features like real-time collaboration, complex layouts, and enhanced performance, making it suitable for both simple and large-scale, production-ready visual applications. ## Learn ### Quick Start This page will take you from zero to a working Vue Flow app in a few minutes. You'll learn how to install Vue Flow, configure it, and create your first flow. From there you can check out the examples,or dive into the API docs. If you want to get up and running as soon as possible, you're in the right place! #### Installation To install Vue Flow in an existing Vue project, run the following command: ```bash copy npm2yarn npm install @xyflow/vue ``` Using Nuxt? Head to [Usage with Nuxt](/learn/nuxt), which covers the same setup plus what the server renders. #### Usage The `@xyflow/vue` package exports the `` component, which is the entrypoint for your flow. Importing the default styles and defining a handful of nodes and edges are all we need to get started! There are a few things to pay attention to here: * You must import the Vue Flow stylesheet. * Each node must have a unique id. * Using `shallowRef` is preferable for nodes and edges to avoid costly deep reactivity. * The `` component inherits the size of its parent. Make sure to wrap it in an element with explicit dimensions. ```vue ``` #### Result Et voila. You've already created your first interactive flow! Example: learn/quickstart ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### Next steps Where to head next depends on what you need to know and how you like to learn. Check out the core concepts to better understand how Vue Flow works and the common terminology we use throughout our docs. If you're interested in how to render your own custom nodes in a flow, then the customization docs are for you. If you just want to see some code, head over to our examples to see how to implement different features and functionality. ### Usage with Nuxt [Nuxt](https://nuxt.com) renders your pages on the server by default and Vue Flow works there out of the box. How much of your flow ends up in the HTML is up to your node data though, because there is no DOM to measure on the server. #### Installation If you don't have a Nuxt app yet, create one: ```bash copy npm2yarn npm create nuxt@latest my-flow-app ``` Then install Vue Flow: ```bash copy npm2yarn npm install @xyflow/vue ``` Finally, add the stylesheet to your Nuxt config. That's the only setup Vue Flow needs, you can leave `build.transpile` and `vite.ssr.noExternal` alone. ```ts filename="nuxt.config.ts" export default defineNuxtConfig({ css: ['@xyflow/vue/style.css'], }); ``` #### Usage Nodes and edges can come from anywhere you can fetch during SSR, like `useAsyncData` or `useFetch`. Static data is enough for this example. There are a few things to pay attention to here: * Nodes need a `width` and a `height`, otherwise they are rendered hidden until the browser measures them. * Nodes need `handles`, otherwise their edges don't make it into the HTML at all. * The server has no container to measure, so `fitView` needs the `width` and `height` props to run there. ```vue filename="app/pages/index.vue" ``` To see what the server actually sent, run `nuxt build && node .output/server/index.mjs` and look at the page source, or turn JavaScript off in your browser. #### Node dimensions Vue Flow measures your nodes in the browser and stores the result in `measured`. There is no layout engine on the server, so a node without dimensions is rendered with `visibility: hidden` and only shows up once the client has measured it. Use `width` and `height` for nodes whose size you decide. Use `initialWidth` and `initialHeight` for nodes that size themselves from their content: the server uses them for layout and edge paths and the real measurement takes over after hydration. #### Handle positions Edges attach to handles and handle positions come from measuring them. Without them there is no edge in the HTML, not even an empty path. Declare them with the `handles` property: ```ts handles: [{ type: 'source', position: Position.Bottom, x: 46, y: 35, width: 8, height: 8 }], ``` `x` and `y` are the top left corner of the handle, not its center, and `width` and `height` default to `1` if you leave them out. The built-in handle is an 8 by 8 box sitting on the node border, one pixel inside it, which is where the numbers above come from: on a 100 by 40 node a `Bottom` handle starts at `x: 46, y: 35` and a `Top` handle at `x: 46, y: -3`. Declare the same box the browser is going to measure and server and client draw the exact same path. If they differ the edge is still correct, it just jumps by the difference on the first client render. #### The viewport Panning and zooming need a real element, so the pan-zoom instance is only created on the client. Until then the viewport uses what you declared: `defaultViewport`, or the fit computed from the `width` and `height` props when you use `fitView`. Those two props tell the flow what size to assume until it has been measured, which is the frame `fitView` would otherwise have to measure for itself, so this renders fitted on the server: ```vue ``` They don't size the flow, your CSS still does, so the numbers should match. If the element turns out to be a different size the client re-fits once it has measured it and you see a small correction, which is still better than the empty canvas you get without the props. That makes an estimate worth passing even for a flow that fills the window. Without them `fitView` has nothing to work with, so it waits for the browser and renders the viewport with `opacity: 0` until the client has fitted it. The other option is to lay your nodes out near `0, 0` and leave `fitView` off, which is what the example further up does. Whichever component creates the store is the one that reads these props, so if you create it yourself with [``](/api-reference/vue-flow-provider) or `setupVueFlow()`, pass them there. On a `` inside a provider they're ignored. #### Client-side only Not every flow has to be in the HTML. Wrap it in Nuxt's [``](https://nuxt.com/docs/api/components/client-only) and you can skip all of the above: ```vue ``` For server side rendering outside of Nuxt, like rendering a flow to an HTML string, check out the [server side rendering guide](/learn/advanced/server-side-rendering). ### Accessibility If you have suggestions for how we can improve the accessibility of Vue Flow, please [contact us](https://xyflow.com/contact). Vue Flow provides keyboard and screen-reader support to help meet accessibility standards. By default, all nodes and edges are keyboard-focusable and operable. You can toggle these features with props such as [`nodesFocusable`](/api-reference/vue-flow#nodesfocusable), [`edgesFocusable`](/api-reference/vue-flow#edgesfocusable), and [`disableKeyboardA11y`](/api-reference/vue-flow#disablekeyboarda11y), passed to ``: ```vue ``` #### Built-in features * **Tab navigation:** Pressing `Tab` moves focus through all focusable nodes and edges. These elements receive `tabindex="0"` and, by default, `role="group"`. * **Select / deselect:** Press `Enter` or `Space` to select the focused node or edge, and `Escape` to clear the selection. * **Move nodes with arrow keys:** If `nodesDraggable` and `nodesFocusable` are both true (the default), you can move the selected node with the arrow keys. Hold `Shift` to move faster. Setting `:disable-keyboard-a11y="true"` disables arrow-key movement, while tab-focus and selection still work. * **Automatic panning:** When a node receives focus, Vue Flow pans the canvas to bring it into view. Toggle this with the [`autoPanOnNodeFocus`](/api-reference/vue-flow#autopanonnodefocus) prop. * **ARIA descriptions:** Vue Flow adds ARIA descriptions for keyboard guidance, configurable through [`ariaLabelConfig`](/api-reference/vue-flow#arialabelconfig). For full keyboard accessibility, keep both `nodesFocusable` and `edgesFocusable` set to `true`. If either is `false`, those elements won't be keyboard-focusable. #### ARIA roles for nodes and edges By default Vue Flow uses semantic ARIA roles for interactive elements. Override a node's role with the `ariaRole` field: ```ts const nodes = [ { id: '1', position: { x: 0, y: 0 }, data: { label: 'Hello' }, ariaRole: 'button' }, ]; ``` If you don't set a role, `role="group"` is applied. Customizing `ariaRole` lets you match any relevant role (`'listitem'`, `'region'`, and so on), improving the semantics for assistive technology. `ariaRole` is applied to the node wrapper. If a custom node contains interactive elements, don't set `ariaRole: 'button'` on the node itself. Apply the appropriate role directly to the interactive element inside. ##### DOM attributes To pass custom ARIA or other DOM-level attributes (`aria-roledescription`, `data-*`, `tabindex`, and so on), use the `domAttributes` field. It's available on both nodes and edges: ```ts const nodes = [ { id: '2', position: { x: 0, y: 100 }, data: { label: 'Accessible Node' }, domAttributes: { 'aria-roledescription': 'collapsible node', 'data-test-id': 'node-2', }, }, ]; ``` This gives you full control over accessibility-related attributes while keeping Vue Flow's built-in roles and behavior. #### Localizing accessibility messages Vue Flow's built-in accessibility text (keyboard instructions and live updates) can be customized or localized with the [`ariaLabelConfig`](/api-reference/vue-flow#arialabelconfig) prop, an object mapping message keys to strings (or functions). The keys are: | Key | Default value | | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `node.a11yDescription.default` | Press enter or space to select a node. Press delete to remove it and escape to cancel. | | `node.a11yDescription.keyboardDisabled` | Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel. | | `node.a11yDescription.ariaLiveMessage` | `Moved selected node {direction}. New position, x: {x}, y: {y}` | | `edge.a11yDescription.default` | Press enter or space to select an edge. You can then press delete to remove it or escape to cancel. | | `controls.ariaLabel` | Control Panel | | `controls.zoomIn.ariaLabel` | Zoom In | | `controls.zoomOut.ariaLabel` | Zoom Out | | `controls.fitView.ariaLabel` | Fit View | | `controls.interactive.ariaLabel` | Toggle Interactivity | | `minimap.ariaLabel` | Mini Map | | `handle.ariaLabel` | Handle | For example, to localize the node instructions: ```vue ``` Vue Flow then uses your text instead of the defaults, so screen readers announce messages in the user's language. #### WCAG 2.1 AA Vue Flow provides features that help you meet key WCAG 2.1 AA criteria when implemented properly: * **Keyboard:** `Tab` navigation to nodes and edges, interaction with `Enter` / `Space`, and arrow-key movement for nodes support keyboard operability. * **Screen reader:** Semantic ARIA roles and labels (`role="group"`, `aria-label`, `aria-roledescription`) let assistive technology announce nodes and edges meaningfully. * **ARIA live regions:** Dynamic updates are announced through an `aria-live="assertive"` region that reports node movements. * **Instructions and focus management:** Contextual instructions ("Press enter or space to select a node…") plus automatic panning-into-view on focus help satisfy input-assistance requirements. See the [ARIA authoring practices](https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/) for background on ARIA best practices. ### Composables and Providers Vue Flow ships a set of [composables](/api-reference/composables) and a provider that let you manage state, reach the flow's methods, and build custom components. The composables read the flow's store, so that store has to exist above them in the component tree. #### Providing a store `` creates the store itself, but you can also create and provide one higher up so that parents and siblings can reach it. There are two ways to do it, and they do the same thing: * [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) β€” a composable you call in a component's `setup`. It creates the store, provides it to that component's subtree, and returns the instance right there. This is the idiomatic choice when you own the component that renders ``. * [``](/api-reference/vue-flow-provider) β€” a component you wrap around a subtree. Reach for it when you want to share one store across several sibling components. You'll want one of them when: * a composable such as `useVueFlow` is used outside of ``, * you need the flow's state or methods from a parent or sibling of ``, * you render multiple flows on a page (each one scopes its own store), or * you're working with a client-side router. ```vue filename="App.vue" ``` Or with the provider component wrapping the subtree: ```vue filename="Wrapper.vue" ``` #### `useVueFlow()` [`useVueFlow()`](/api-reference/composables/use-vue-flow) returns the flow instance and its methods, so you can read and change nodes, edges, and the viewport from anywhere inside the store. In the example below a toolbar calls the viewport helpers `zoomIn`, `zoomOut`, and `fitView`: Example: learn/composables ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .toolbar { display: flex; gap: 5px; } ``` ##### App.vue ```vue ``` ### Computing Flows This guide assumes you're familiar with [custom nodes](/learn/customization/custom-nodes) and the [core concepts](/learn/concepts/terms-and-definitions). Usually you'd handle your data outside of Vue Flow β€” on a server or in a store. But you can also compute data directly inside the graph, updating a node from the data of the nodes connected to it. This guide builds a small app that mixes a color from three number inputs and decides whether that color is light or dark. #### What we're going to build Three number inputs (red, green, blue) feed a color node, which feeds a "lightness" node that branches to a log node depending on whether the color is light or dark. Change the inputs and watch the values flow through: Example: learn/computing ##### useChannel.ts ```ts import type { NumberNode } from './types'; import { useNodeConnections, useNodesData } from '@xyflow/vue'; import { computed } from 'vue'; // read the value connected to one of the color node's channel handles export function useChannel(handleId: string) { const connections = useNodeConnections({ handleType: 'target', handleId }); const nodeData = useNodesData( () => connections.value[0]?.source ?? '', ); return computed(() => nodeData.value?.data.value ?? 0); } ``` ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export interface RGB { r: number; g: number; b: number; } export type NumberNode = Node<{ label: string; value: number }, 'number'>; export type ColorNode = Node<{ color: RGB }, 'color'>; export type LightnessNode = Node< { light: RGB | null; dark: RGB | null }, 'lightness' >; export type LogNode = Node, 'log'>; export type AppNode = NumberNode | ColorNode | LightnessNode | LogNode; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .number-input, .lightness-node, .log-node { padding: 10px; border-radius: 4px; background: var(--xy-node-background-color-default); color: var(--xy-node-color-default); font-size: 12px; } .number-input label { display: block; margin-bottom: 4px; } .number-input input { width: 60px; } .color-node { width: 90px; height: 90px; border-radius: 4px; display: flex; align-items: center; justify-content: center; } .color-label { color: #fff; mix-blend-mode: difference; font-size: 11px; font-family: monospace; } ``` ##### NumberInput.vue ```vue ``` ##### Log.vue ```vue ``` ##### Lightness.vue ```vue ``` ##### ColorPreview\.vue ```vue ``` ##### App.vue ```vue ``` #### Reading and writing node data Two composables do the work: * [`useNodeConnections`](/api-reference/composables/use-node-connections) tells a node which other nodes are connected to a given handle. * [`useNodesData`](/api-reference/composables/use-nodes-data) reads the `data` of those connected nodes. And you write to a node's own data with [`updateNodeData`](/api-reference/composables/use-vue-flow) from `useVueFlow()`. ##### The input node `NumberInput` keeps its value in local state (writing straight into node data can make the cursor jump), caps it to 0–255, and mirrors it into the node's `data` on every change: ```vue filename="NumberInput.vue" ``` By default `updateNodeData` merges into the existing `data`. Pass `{ replace: true }` as a second option to overwrite it instead. ##### Reading connected data The color node has one target handle per channel. Reading a channel β€” find the connection, then read the connected node's data β€” is a natural composable, so extract it into its own file: ```ts filename="useChannel.ts" import type { NumberNode } from './types'; import { useNodeConnections, useNodesData } from '@xyflow/vue'; import { computed } from 'vue'; export function useChannel(handleId: string) { const connections = useNodeConnections({ handleType: 'target', handleId }); const nodeData = useNodesData(() => connections.value[0]?.source ?? ''); return computed(() => nodeData.value?.data.value ?? 0); } ``` The color node calls it once per channel, computes the color, and writes it back to its own data so the next node can read it: ```vue filename="ColorPreview.vue" ``` When a node has multiple handles of the same type, give each one an `id` and pass it to `useNodeConnections` so you read the right connection. #### Transforming and branching Because a node's `data` is reactive, you can chain transforms. The `Lightness` node reads the color, computes its [relative luminance](https://en.wikipedia.org/wiki/Relative_luminance), and splits the result across two source handles β€” writing the color to `light` or `dark` and setting the other to `null`: ```ts const luminance = computed(() => 0.2126 * color.value.r + 0.7152 * color.value.g + 0.0722 * color.value.b); const isLight = computed(() => luminance.value >= 128); watch([color, isLight], () => { updateNodeData(props.id, { light: isLight.value ? color.value : null, dark: isLight.value ? null : color.value, }); }, { immediate: true }); ``` A downstream node then reads only the handle it's connected to, through the connection's `sourceHandle`. Treating a `null` value as "no data" is a simple way to keep one branch active at a time: ```ts const connections = useNodeConnections({ handleType: 'target' }); const sourceData = useNodesData(() => connections.value[0]?.source ?? ''); const sourceHandle = computed(() => connections.value[0]?.sourceHandle ?? ''); const value = computed(() => sourceData.value?.data?.[sourceHandle.value as 'light' | 'dark'] ?? null); ``` #### Summary To compute data through a flow: 1. store values on a node with [`updateNodeData`](/api-reference/composables/use-vue-flow), 2. find connected nodes with [`useNodeConnections`](/api-reference/composables/use-node-connections), and 3. read their data with [`useNodesData`](/api-reference/composables/use-nodes-data). Chain those together to transform data along the way, and branch by treating missing data as a "stop". Pick one consistent shape for your node data across the whole graph and it stays easy to reason about. ### Devtools and Debugging Vue Flow can feel like a black box, but you can reveal a lot about its internal state if you know where to look. This guide covers the built-in debugging aids, then shows how to build a few small inspectors of your own. #### Built-in aids * **The `debug` prop.** Set [`debug`](/api-reference/vue-flow#debug) on `` and it logs each event to the console as it fires (high-frequency ones like move, drag, and hover are skipped), so you can see which events run. ```vue ``` * **The `@error` event.** Vue Flow reports problems as [`VueFlowError`](/learn/troubleshooting/common-errors) instances through the `@error` event β€” listen to it to log them or surface them to the user. * **Vue Devtools.** Because nodes and edges are ordinary Vue components, the [Vue Devtools](https://devtools.vuejs.org/) browser extension lets you inspect the component tree, props, and reactive state of your flow like any other Vue app. #### Build your own inspectors Vue Flow doesn't ship a devtools package, but its store is easy to read with `useVueFlow()`. The example below adds three small inspectors β€” copy any of them into your own project, they each work independently: Example: learn/devtools ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .logger { font-family: monospace; font-size: 11px; background: var(--xy-theme-panel-bg, #fff); color: var(--xy-theme-panel-text, #111); padding: 6px 8px; border-radius: 4px; } .node-inspector { position: absolute; top: 0; left: 0; font-family: monospace; font-size: 9px; line-height: 1.35; background: rgba(0, 0, 0, 0.75); color: #fff; padding: 3px 5px; border-radius: 3px; pointer-events: none; white-space: nowrap; } .devtools { display: flex; padding: 0; } .devtools button { border: none; border-right: 1px solid var(--xy-theme-subtle-border, #ddd); padding: 5px 15px; font-family: monospace; font-size: 12px; font-weight: bold; cursor: pointer; background: var(--xy-theme-panel-bg, #fff); color: var(--xy-theme-panel-text, #222); } .devtools button:first-child { border-radius: 4px 0 0 4px; } .devtools button:last-child { border-right: none; border-radius: 0 4px 4px 0; } .devtools button.active, .devtools button:hover { background: rgb(238, 58, 115); color: #fff; } ``` ##### ViewportLogger.vue ```vue ``` ##### NodeInspector.vue ```vue ``` ##### ChangeLogger.vue ```vue ``` ##### App.vue ```vue ``` ##### Viewport logger The simplest thing to pull from the store is the viewport. `useVueFlow().viewport` is a `{ x, y, zoom }` object derived from the pane transform; render it into a [``](/api-reference/components/panel): ```vue filename="ViewportLogger.vue" ``` ##### Change logger Every change Vue Flow makes to your nodes flows through the `onNodesChange` hook. Subscribe to it to log each batch as it's dispatched β€” a great way to see what Vue Flow does under the hood: ```vue filename="ChangeLogger.vue" ``` See the [`NodeChange`](/api-reference/types/node-change) and [`EdgeChange`](/api-reference/types/edge-change) types for everything a change can be. ##### Node inspector To render debug info that pans and zooms along with the flow, use the `#zoom-pane` slot β€” content there lives inside the transformed viewport, so you can position it in flow coordinates. Here we read every node with `useVueFlow().getNodes` and render its id and type above it: ```vue filename="NodeInspector.vue" ``` Render it through the slot on ``: ```vue filename="App.vue" ``` The `#zoom-pane` slot is Vue Flow's way to render into the viewport: its content is positioned and transformed along with the nodes and edges as the user pans and zooms. ### Multiplayer Node-based UIs are often visual and explorative in nature. For collaborative features that usually means there's no satisfying "middle-ground" like sparsely syncing state between users, because it would break visual consistency or make collaborative exploration more complicated. Often a full live multiplayer system needs to be put in place. This guide explores best practices for adding realtime multiplayer collaboration to a Vue Flow application with a sync engine such as [Yjs](https://github.com/yjs/yjs). #### What are multiplayer applications? Although **realtime collaboration** would be the correct term, we refer to it as **multiplayer**, which was most likely popularized in this context by Figma. Besides being more intuitive, it also does a better job of communicating the commitment to something truly realtime by putting it in the same category as competitive video games. To figure out what degree of collaboration your application supports, look at how closely it resembles a multiplayer game. Those features likely include: * No manual saving is required; all users share a world where actions are persisted. * Any change made by another user is immediately visible to you. * Not only completed actions but transitive states are synced too (dragging a node, not only dropping it). * You can see other users (their cursors or viewport positions). ##### A word of caution Making multiplayer applications is hard. When users collaboratively edit shared objects, conflicts, delays, connection drops, and concurrent operations are all expected. The hardest challenge is **conflict resolution**: you need a sync engine that can merge changes coming from the server (or other clients) into the (often optimistic) client state, handle conflicts and disconnects gracefully, and provide a reliable network layer. The simplest sync engine would be "first come, first served", with failed requests ignored. Try to handle this by hand and a wide variety of edge cases emerge: networks are slow, clients disconnect, and the order of actions matters. ##### Local-first and CRDTs Depending on how far you take conflict and disconnect handling, you quickly land in **local-first** territory. When your sync engine lets a user stay disconnected for an indefinite amount of time, you have a local-first application. For a good primer, we recommend [Ink & Switch's essay](https://www.inkandswitch.com/essay/local-first/) that coined the term. A **CRDT** (*Conflict-free Replicated Data Type*) is a data structure that lets multiple users edit the same data simultaneously on different devices, then automatically merges all changes without conflicts β€” no central server needed. Rather than storing only the current value, CRDTs keep the operation history on every connected client, so any replica can merge changes into the same final state regardless of the order updates arrive. A couple of popular solutions are [Yjs](https://github.com/yjs/yjs), [Automerge](https://automerge.org/), and [Loro](https://loro.dev). #### What Vue Flow state should I sync? Among your first considerations is **how** you want to sync **what** parts of your app's local state. ##### Ephemeral vs durable There are many ways to sync state between clients, but they fall into two groups: ephemeral and durable (atomic) changes. **Ephemeral changes are not persisted**, and neither their consistency nor their correctness is very important β€” things like cursor or viewport positions, or transient interaction state. Missing some of these updates won't break anything; after a connection loss a client can just listen for the newest changes and restore any lost state. **Updates to the nodes and edges, on the other hand, should be persistent and consistent.** Imagine Alice deletes a node and Bob misses the update β€” now if Bob moves that node, the application state is inconsistent. This kind of data needs a solution that handles disconnects more aggressively and can discard impossible actions like moving a deleted node. At the core of a multiplayer Vue Flow app is syncing the nodes and edges. But not all of their state should be synced: which nodes and edges are selected should differ per client, and some fields are computed or transient (`dragging`, `resizing`, `measured`). Here's an overview of what to sync and what not to. ##### Nodes | Field | Durable | Ephemeral | Explanation | | ----------------- | ------- | --------- | ------------------------------------- | | `id` | βœ… | ❌ | Important, always needs to be in sync | | `type` | βœ… | ❌ | Important, always needs to be in sync | | `data` | βœ… | ❌ | Important, always needs to be in sync | | `position` | βœ… | ✳️ | Important, includes transient state | | `width`, `height` | βœ… | ✳️ | Important, includes transient state | | `dragging` | ❌ | βœ… | Transient interaction state | | `resizing` | ❌ | βœ… | Transient interaction state | | `selected` | ❌ | ❌ | Per-user UI state | | `measured` | ❌ | ❌ | Computed from the DOM | ##### Edges | Field | Durable | Ephemeral | Explanation | | -------------- | ------- | --------- | ------------------------------------- | | `id` | βœ… | ❌ | Important, always needs to be in sync | | `type` | βœ… | ❌ | Important, always needs to be in sync | | `data` | βœ… | ❌ | Important, always needs to be in sync | | `source` | βœ… | ❌ | Important, always needs to be in sync | | `target` | βœ… | ❌ | Important, always needs to be in sync | | `sourceHandle` | βœ… | ❌ | Important, always needs to be in sync | | `targetHandle` | βœ… | ❌ | Important, always needs to be in sync | | `selected` | ❌ | ❌ | Per-user UI state | ##### Connections and cursors Good examples of ephemeral data are [connections](/api-reference/composables/use-connection) (the transient part of an edge being created) and cursors. Sharing each user's connection status improves visual consistency across clients, but losing it on disconnect doesn't affect the correctness of the shared data β€” it's purely presentational. The same goes for cursors: they help create the immersion of a shared workspace, but they aren't essential to the app's integrity. As long as the nodes and edges stay in sync, cursor state can be safely discarded. Both can be shared as purely ephemeral state. To reduce the frequency of live updates you can debounce them, and smooth other users' cursor movements with a library like [perfect-cursors](https://github.com/steveruizok/perfect-cursors). #### Third-party libraries and services There's no one-size-fits-all backend. The choice between CRDT-based local-first libraries (like [Yjs](https://yjs.dev/) and [Jazz](https://jazz.tools)) and server-authoritative approaches (like [Liveblocks](https://liveblocks.io/), [Supabase](https://supabase.com/), and [Convex](https://convex.dev/)) shapes how you build: * **CRDT libraries** make offline-first multiplayer easier, with automatic conflict resolution for free. But if your app is also structured around a database, you'll need to write your own adapters between the CRDT library and the database. * **Server-authoritative solutions** are easier to pair with a database and classical application logic, but complicate offline-first support, conflict resolution, and development. | Name | Architecture | Offline support | Conflict resolution | Notes | | ---------------------------------------- | ------------------------------- | -------------------------- | ------------------------- | ------------------------------------------------------------------------------------------- | | [**Yjs**](https://yjs.dev/) | CRDT (local-first) | βœ… Full offline support | Automatic (CRDT) | Collaborative editing, offline-first CRDT for local-first apps. | | [**Jazz**](https://jazz.tools/) | CRDT (local-first) | βœ… Full offline support | Automatic (CRDT) | A full, offline-first database solution that handles multiplayer natively. | | [**Liveblocks**](https://liveblocks.io/) | Server-authoritative, CRDT-like | 🟑 Partial offline support | Uses CRDTs under the hood | Real-time collaboration platform with an open-source backend. | | [**Supabase**](https://supabase.com/) | Server-authoritative | ❌ Requires connection | Manual / RLS policies | Classic SQL-based database with realtime support, but no CRDT (resolve conflicts manually). | | [**Convex**](https://convex.dev/) | Server-authoritative | ❌ Requires connection | Optimistic | TypeScript-first database with real-time queries and a sync engine. | | [**Automerge**](https://automerge.org/) | CRDT (local-first) | βœ… Full offline support | Automatic (CRDT) | The canonical CRDT library; can be paired with a database like Convex. | | [**Loro**](https://loro.dev/) | CRDT (local-first) | βœ… Full offline support | Automatic (CRDT) | A fast CRDT library in Rust and WebAssembly with history tracking and version control. | ### Performance When you're dealing with a large number of nodes or complex custom components, performance can become challenging. Here are a few effective strategies to keep Vue Flow fast. #### Keep reactivity shallow The most common source of performance problems is unnecessary reactivity. Node drags, pans, and zooms all update state frequently, so the cost of each update matters. Store your `nodes` and `edges` in a [`shallowRef`](https://vuejs.org/api/reactivity-advanced.html#shallowref) rather than a deep `ref`, and replace the whole array when you change it (for example with `Array.prototype.map`) instead of mutating individual nodes. A deep `ref` makes every property of every node reactive, which is expensive for large flows and buys you nothing here, because Vue Flow tracks changes at the array level. ```ts import type { Node } from '@xyflow/vue'; import { shallowRef } from 'vue'; // one dependency for the whole array const nodes = shallowRef([/* ... */]); // update by replacing, not mutating nodes.value = nodes.value.map(n => (n.id === '1' ? { ...n, selected: true } : n)); ``` With `v-model:nodes` / `v-model:edges`, Vue Flow already replaces the whole array when it applies a change, so a `shallowRef` is all you need. See [Adding Interactivity](/learn/concepts/adding-interactivity). #### Memoize expensive custom nodes Custom nodes and edges are ordinary Vue components, so Vue only re-renders them when their props change. If a custom node has an expensive template that depends on only a few props, you can skip re-rendering while those props are unchanged with [`v-memo`](https://vuejs.org/api/built-in-directives.html#v-memo): ```vue ``` Unlike React, you don't need to wrap handlers or option objects such as `defaultEdgeOptions` and `snapGrid` in anything: ` ``` Instead, read only what you need through a targeted composable such as [`useNodesData`](/api-reference/composables/use-nodes-data) or [`useNodeConnections`](/api-reference/composables/use-node-connections), so the component reacts only when that specific data changes: ```vue ``` #### Collapse large node trees If your graph is deeply nested, rendering every node at once is wasteful. Render a limited set and let users expand on demand by toggling each node's `hidden` field with [`updateNode`](/api-reference/composables/use-vue-flow): ```ts import { useVueFlow } from '@xyflow/vue'; const { updateNode } = useVueFlow(); function toggleChildren(node) { for (const childId of node.data.children ?? []) { updateNode(childId, prev => ({ hidden: !prev.hidden })); } } ``` Hiding nodes until they're expanded keeps the rendered graph small without losing any state. #### Simplify node and edge styles If you've optimized everything else and large graphs still feel sluggish, look at your CSS. Complex styles, especially animations, gradients, and box-shadows, are re-rasterized by the browser on every frame while panning and zooming, which can dominate the frame budget. A heavy, multi-layer blurred `box-shadow` on nodes is a frequent culprit: it looks fine when static but hurts pan and zoom smoothness on large flows in Chromium. Prefer a light, single-layer shadow or a `border` for nodes you render in bulk. #### See it at scale The [stress test example](/examples/nodes/stress) renders a large graph you can pan and zoom to feel these trade-offs in practice. ### Server Side Rendering ### Server side rendering, server side generation This is an advanced use case and assumes you are already familiar with Vue Flow. If you're new to Vue Flow, check out our [getting started guide](/learn). In this guide, you'll learn how to configure Vue Flow for server-side rendering, enabling you to: * Generate static HTML diagrams for documentation * Render Vue Flow diagrams in non-JavaScript environments * Create dynamic Open Graph images for social media sharing ##### Why Server-Side Rendering is Complex To understand why server-side rendering in Vue Flow requires special configuration, let's look at what Vue Flow typically handles on the client side: 1. **Node Dimension Calculation** * Nodes can contain any content, so their dimensions are determined by the browser's layout engine * This dynamic sizing isn't available during server-side rendering 2. **Handle Position Detection** * Edge connections require precise handle positions * These positions are calculated based on CSS layout, which isn't available on the server 3. **Container Size Adaptation** * Vue Flow adapts to its container's dimensions * Server-side rendering needs an explicit viewport ##### Node Dimensions The most crucial aspect of server-side rendering is specifying node dimensions. On the client, Vue Flow automatically measures nodes and stores dimensions in `measured.width` and `measured.height`. For server-side rendering, you must provide these dimensions explicitly using either: Node Dimension Options: 1. `width` and `height`: Static dimensions that won't change 2. `initialWidth` and `initialHeight`: Dynamic dimensions that may change after client-side hydration ```ts import type { Node } from '@xyflow/vue'; const nodes: Node[] = [ { id: '1', type: 'default', position: { x: 0, y: 0 }, data: { label: 'Node 1' }, width: 100, height: 50, }, ]; ``` ##### Handle Positions To render edges on the server, you need to provide handle positions explicitly. On the client, Vue Flow calculates these positions automatically, but for server-side rendering, you must specify them using the `handles` property: ```ts import type { Node } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; const nodes: Node[] = [ { id: '1', type: 'default', position: { x: 0, y: 0 }, data: { label: 'Node 1' }, width: 100, height: 50, handles: [ { type: 'target', position: Position.Top, x: 100 / 2, y: 0, }, { type: 'source', position: Position.Bottom, x: 100 / 2, y: 50, }, ], }, ]; ``` ##### Setting the viewport for Server-Side Rendering Vue Flow normally takes its size from the element it's in, which is something the server can't measure. The `width` and `height` props tell it what size to assume until it can, and that's enough for `fitView` to compute a transform before anything is rendered: ```vue ``` The props don't size the element, that's still your CSS, so the two should agree. If they don't, the server renders the fit you declared and the client re-fits to the real size after measuring it, which shows up as a small jump. For a flow that fills a responsive container an estimate is still worth passing: a roughly right first paint beats an empty one. Without the props `fitView` has to wait for the browser and renders the viewport with `opacity: 0` until the client has fitted it, so the server output is an empty canvas. In that case position your nodes near `0, 0` and leave `fitView` off, or set [`defaultViewport`](/api-reference/vue-flow) to the transform you want the server to render. Whichever component creates the store reads these props, so with a [``](/api-reference/vue-flow-provider) they belong on the provider. On a `` inside one they're ignored. ##### Generating Static HTML To create static HTML output, you can use Vue's server renderer. This generates an HTML string that you can use for static files or HTTP responses: ```vue filename="Flow.vue" ``` ```ts import { createSSRApp } from 'vue'; import { renderToString } from 'vue/server-renderer'; import Flow from './Flow.vue'; async function toHTML({ nodes, edges }) { const app = createSSRApp(Flow, { nodes, edges }); return await renderToString(app); } ``` ### State Management This guide assumes you're familiar with [custom nodes](/learn/customization/custom-nodes) and the [core concepts](/learn/concepts/terms-and-definitions). As your app grows, you often need to update the graph from inside a node β€” a color picker that recolors its own node, say. In React Flow you'd reach for a state library like Zustand to do this. In Vue Flow you usually don't have to. #### You already have a store: `useVueFlow()` `useVueFlow()` returns the same flow instance from anywhere inside `` (or a ``), so a custom node can read and update the graph directly, with no external library and no callbacks threaded through `data`. To recolor a node from within it, call [`updateNodeData`](/api-reference/composables/use-vue-flow): ```vue filename="ColorChooserNode.vue" ``` The `nodrag` class stops the node from being dragged while the user interacts with the input. Example: learn/state-management ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .color-chooser-node { padding: 20px; border-radius: 5px; } .color-chooser-node input { cursor: pointer; } ``` ##### ColorChooserNode.vue ```vue ``` ##### App.vue ```vue ``` #### When you want an external store: Pinia Reach for [Pinia](https://pinia.vuejs.org/) when the graph is part of larger app state, or when components outside the flow need to read or change it. Keep the `nodes` and `edges` in the store and expose actions to mutate them: ```ts filename="stores/flow.ts" import type { Edge, Node } from '@xyflow/vue'; import { defineStore } from 'pinia'; import { shallowRef } from 'vue'; export const useFlowStore = defineStore('flow', () => { const nodes = shallowRef([/* ... */]); const edges = shallowRef([/* ... */]); function updateNodeColor(id: string, color: string) { // replace the array so Vue Flow sees the change nodes.value = nodes.value.map(n => n.id === id ? { ...n, data: { ...n.data, color } } : n, ); } return { nodes, edges, updateNodeColor }; }); ``` Bind the store's arrays to `` with `v-model` and Vue Flow keeps them in sync as the user drags, selects, and connects: ```vue filename="App.vue" ``` Any component can now call `useFlowStore().updateNodeColor(id, color)` and the flow updates. If you'd rather inspect or intercept every change before it's applied, drop `v-model` and use the [controlled flow](/learn/concepts/adding-interactivity#controlled-flow) pattern with `@nodes-change` / `@edges-change` instead. ### Testing There are plenty of ways to test a Vue application. For a Vue Flow app we recommend [Cypress](https://www.cypress.io/) or [Playwright](https://playwright.dev/): Vue Flow measures nodes in order to render edges, and that relies on real DOM elements, which a headless browser provides. #### Using Cypress or Playwright No extra setup is needed. See the getting-started guides for [Cypress](https://docs.cypress.io/guides/getting-started/installing-cypress) and [Playwright](https://playwright.dev/docs/intro). #### Using Vitest [Vitest](https://vitest.dev/) runs in a simulated DOM (jsdom or happy-dom) that doesn't implement the layout APIs Vue Flow relies on, so you need to shim them. Add this helper and call `mockVueFlow()` in a setup file (or a `beforeEach`): ```ts filename="mockVueFlow.ts" // A jsdom/happy-dom-friendly stand-in for the ResizeObserver and DOMMatrixReadOnly APIs // Vue Flow uses to measure nodes and read the viewport transform. class ResizeObserver { callback: globalThis.ResizeObserverCallback; constructor(callback: globalThis.ResizeObserverCallback) { this.callback = callback; } observe(target: Element) { setTimeout(() => { this.callback([{ target } as globalThis.ResizeObserverEntry], this); }, 0); } unobserve() {} disconnect() {} } class DOMMatrixReadOnly { m22: number; constructor(transform: string) { const scale = transform?.match(/scale\(([1-9.])\)/)?.[1]; this.m22 = scale !== undefined ? +scale : 1; } } let init = false; export function mockVueFlow() { if (init) { return; } init = true; global.ResizeObserver = ResizeObserver as unknown as typeof globalThis.ResizeObserver; global.DOMMatrixReadOnly = DOMMatrixReadOnly as unknown as typeof globalThis.DOMMatrixReadOnly; Object.defineProperties(global.HTMLElement.prototype, { offsetHeight: { get() { return Number.parseFloat(this.style.height) || 1; }, }, offsetWidth: { get() { return Number.parseFloat(this.style.width) || 1; }, }, }); (global.SVGElement.prototype as unknown as { getBBox: () => DOMRect }).getBBox = () => ({ x: 0, y: 0, width: 0, height: 0 }) as DOMRect; } ``` Register it as a Vitest setup file: ```ts filename="vitest.config.ts" import vue from '@vitejs/plugin-vue'; import { defineConfig } from 'vitest/config'; export default defineConfig({ plugins: [vue()], test: { environment: 'jsdom', setupFiles: ['./mockVueFlow.ts'], }, }); ``` ##### Testing edges Edges only render once their nodes have been measured, so mount inside a sized container and wait for them with `vi.waitFor`: ```ts filename="flow.test.ts" import { mount } from '@vue/test-utils'; import { VueFlow } from '@xyflow/vue'; import { expect, test, vi } from 'vitest'; import { mockVueFlow } from './mockVueFlow'; mockVueFlow(); test('renders edges', async () => { const wrapper = mount(VueFlow, { attrs: { style: 'width: 800px; height: 600px' }, props: { nodes, edges }, }); await vi.waitFor(() => { expect(wrapper.findAll('.vue-flow__edge').length).toBeGreaterThan(0); }); }); ``` To test mouse events inside a custom node with Vitest, disable dragging and panning so `d3-drag` β€” which needs a real browser β€” stays out of the way: ```vue ``` ### Usage with TypeScript Vue Flow is written in TypeScript because we value the additional safety barrier it provides. We export all the types you need for correctly typing data structures and functions you pass to the Vue Flow component. We also provide a way to extend the types of nodes and edges. #### Basic Usage Let's start with the essential types needed for a basic implementation. While TypeScript can infer some types automatically, we'll define them explicitly for clarity. ```vue ``` ##### Custom Nodes When working with [custom nodes](/learn/customization/custom-nodes), you can extend the base `Node` type to include your custom data and pass it to `NodeProps` as a generic. It's a good idea to keep these types in a shared `types.ts` so you can reuse them: ```ts filename="types.ts" import type { Node } from '@xyflow/vue'; export type NumberNode = Node<{ number: number }, 'number'>; ``` When defining node data, you must use a `type` alias (interfaces won't satisfy the `Record` constraint on node data). ```vue filename="NumberNode.vue" ``` For a single custom node that renders different content based on the node type, use a union type and narrow on `type`: ```vue filename="CustomNode.vue" ``` Vue templates do not narrow `props.data` from a `props.type` check; for strict type safety, narrow in ` ``` #### Advanced Usage In complex applications, you'll likely have multiple custom nodes and edges with different data structures. When using built-in functions and composables, you'll need to properly [narrow down](https://www.typescriptlang.org/docs/handbook/2/narrowing.html) the types to prevent runtime errors. ##### `Node` and `Edge` Type Unions Many functions, callbacks, and composables (including the `` component) accept `NodeType` or `EdgeType` generics. These are unions of all your custom node and edge types. As long as you've properly typed your data objects, you can reuse their exported types, typically from a shared `types.ts`: If you're using any built-in nodes (`'input'`, `'output'`, `'default'`, `'group'`), include the `BuiltInNode` type from `@xyflow/vue` in your node union. Built-in edges are already covered by the base `Edge` type. ```ts filename="types.ts" import type { BuiltInNode, Edge, Node } from '@xyflow/vue'; export type NumberNode = Node<{ number: number }, 'number'>; export type TextNode = Node<{ text: string }, 'text'>; export type CustomEdge = Edge<{ value: number }, 'custom'>; export type AppNode = BuiltInNode | NumberNode | TextNode; export type AppEdge = Edge | CustomEdge; ``` You then register the components through the `#node-` / `#edge-` slots and bind your typed arrays: ```vue filename="App.vue" ``` ##### Composables You can use these type unions to properly type the return values of composables: ```vue ``` ##### Type Guards TypeScript provides several ways to implement [type guards](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#typeof-type-guards). One common approach is to create type guard functions like `isNumberNode` to filter specific nodes from a list: ```ts import type { AppNode, NumberNode } from './types'; function isNumberNode(node: AppNode): node is NumberNode { return node.type === 'number'; } // numberNodes is now correctly typed as NumberNode[] const numberNodes = computed(() => nodes.value.filter(isNumberNode)); ``` Vue Flow also ships the `isNode` and `isEdge` type guards for narrowing an element to a node or an edge. ### Uncontrolled Flow Vue Flow runs in two modes. In a **controlled** flow you own the `nodes` and `edges` state and apply every change yourself. In an **uncontrolled** (managed) flow Vue Flow keeps the state and you read or change it through the instance. [Adding Interactivity](/learn/concepts/adding-interactivity) covers the controlled path and the `v-model` managed path in detail; this guide focuses on running a flow with no binding at all. Unlike React Flow, Vue Flow has no `defaultNodes` / `defaultEdges` props. You seed the initial graph through [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) (or [``](/api-reference/vue-flow-provider)) instead. #### Seeding and driving through the instance Pass the initial `nodes` and `edges` to `setupVueFlow()`, render `` with no `nodes` / `edges` binding, and change the graph through the returned instance β€” here with `addNodes`: ```vue filename="App.vue" ``` Because you don't hold the nodes and edges in local state, you change them through instance actions like [`addNodes`](/api-reference/composables/use-vue-flow), `updateNode`, and `removeNodes` rather than reassigning an array. Example: learn/uncontrolled ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### Connecting nodes Vue Flow has no auto-connect, so new connections always come through the [`@connect`](/learn/concepts/adding-interactivity#connecting-nodes) event. In an uncontrolled flow, add the edge through the instance's `addEdges` instead of reassigning a local array: ```ts const { addEdges } = setupVueFlow(/* ... */); function onConnect(connection: Connection) { addEdges([connection]); } ``` `defaultEdgeOptions` is handy here: since you're not building each edge by hand, it's how you give programmatically added edges a consistent look, such as making them `animated`. ### Whiteboard Features Vue Flow is designed for building node-based UIs like workflow editors, flowcharts, and diagrams. It isn't a whiteboard library, but you might still want common whiteboard features to annotate or sketch alongside your nodes and edges. These examples show how to add drawing capabilities to your application. #### Examples ##### ✏️ Freehand draw (Pro) Draw smooth curves on your Vue Flow pane, useful for annotations or sketching around existing nodes. **Features:** * Mouse/touch drawing * Adjustable brush size and color * Converts drawn paths into custom nodes **Common uses:** * Annotating flowcharts * Adding notes to diagrams * Sketching ideas around nodes Freehand draw is available as a [Vue Flow Pro](/pro) example. ##### 🎯 Lasso selection Select multiple elements by drawing a freeform selection area, with an option to include partially selected elements. **Features:** * Freeform selection shapes * Partial selection of elements **Common uses:** * Selecting nodes and annotations together * Complex selections in mixed content Example: examples/whiteboard/lasso-selection ##### utils.ts ```ts import getStroke from 'perfect-freehand'; export const pathOptions = { size: 7, thinning: 0.5, smoothing: 0.5, streamline: 0.5, easing: (t: number) => t, start: { taper: 0, easing: (t: number) => t, cap: true, }, end: { taper: 0.1, easing: (t: number) => t, cap: true, }, }; export function getSvgPathFromStroke(stroke: number[][]) { if (!stroke.length) { return ''; } const d = stroke.reduce( (acc, [x0, y0], i, arr) => { const [x1, y1] = arr[(i + 1) % arr.length]; acc.push(x0, y0, ',', (x0 + x1) / 2, (y0 + y1) / 2); return acc; }, ['M', ...stroke[0], 'Q'] as (string | number)[], ); d.push('Z'); return d.join(' '); } export function pointsToPath(points: [number, number, number][], zoom = 1) { const stroke = getStroke(points, { ...pathOptions, size: pathOptions.size * zoom, }); return getSvgPathFromStroke(stroke); } ``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('@xyflow/vue/xy-theme.css'); @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .tool-overlay { pointer-events: auto; position: absolute; top: 0; left: 0; z-index: 4; height: 100%; width: 100%; transform-origin: top left; touch-action: none; } .lasso-controls { display: flex; align-items: center; gap: 10px; } .lasso-controls button { width: 150px; } .lasso-controls label { display: flex; align-items: center; justify-content: center; line-height: 1; color: light-dark(#111827, #f3f4f6); } ``` ##### Lasso.vue ```vue ``` ##### App.vue ```vue ``` ##### 🧹 Eraser Remove items by "erasing" over them. Uses collision detection to determine what to delete. **Features:** * Collision-based erasing * Visual eraser cursor **Common uses:** * Removing parts of a flow Example: examples/whiteboard/eraser ##### utils.ts ```ts // Utility functions for geometric intersection detection type Point = [number, number]; type Rectangle = { x: number; y: number; width: number; height: number }; // Check if two line segments intersect function lineSegmentsIntersect( p1: Point, p2: Point, p3: Point, p4: Point, ): boolean { const [x1, y1] = p1; const [x2, y2] = p2; const [x3, y3] = p3; const [x4, y4] = p4; const denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); if (Math.abs(denom) < 1e-10) { return false; // Lines are parallel } const t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / denom; const u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denom; return t >= 0 && t <= 1 && u >= 0 && u <= 1; } // Check if a point is inside a rectangle function pointInRectangle(point: Point, rect: Rectangle): boolean { const [x, y] = point; return ( x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height ); } // Get the four edges of a rectangle as line segments function getRectangleEdges(rect: Rectangle): [Point, Point][] { const { x, y, width, height } = rect; return [ [ [x, y], [x + width, y], ], // top edge [ [x + width, y], [x + width, y + height], ], // right edge [ [x + width, y + height], [x, y + height], ], // bottom edge [ [x, y + height], [x, y], ], // left edge ]; } // Check if a polyline (series of connected line segments) intersects with a rectangle export function polylineIntersectsRectangle( points: Point[], rect: Rectangle, ): boolean { if (points.length < 2) { return false; } // Early return if any point is inside the rectangle for (const point of points) { if (pointInRectangle(point, rect)) { return true; } } // Check if any line segment intersects with rectangle edges const rectEdges = getRectangleEdges(rect); for (let i = 0; i < points.length - 1; i++) { const lineStart = points[i]; const lineEnd = points[i + 1]; for (const [edgeStart, edgeEnd] of rectEdges) { if (lineSegmentsIntersect(lineStart, lineEnd, edgeStart, edgeEnd)) { return true; } } } return false; } // Calculate distance between two points function distanceBetweenPoints(p1: Point, p2: Point): number { const [x1, y1] = p1; const [x2, y2] = p2; return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2); } // Calculate the closest point on a line segment to a given point function closestPointOnSegment( point: Point, segmentStart: Point, segmentEnd: Point, ): Point { const [px, py] = point; const [x1, y1] = segmentStart; const [x2, y2] = segmentEnd; const dx = x2 - x1; const dy = y2 - y1; const lengthSquared = dx * dx + dy * dy; if (lengthSquared === 0) { return segmentStart; // Segment is a point } const t = Math.max( 0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / lengthSquared), ); return [x1 + t * dx, y1 + t * dy]; } // Check if two paths intersect using a more efficient approach export function pathsIntersect( path1: Point[], path2: Point[], threshold = 1, ): boolean { if (path1.length < 2 || path2.length < 2) { return false; } // First, do the more precise line segment intersection check for (let i = 0; i < path1.length - 1; i++) { for (let j = 0; j < path2.length - 1; j++) { if ( lineSegmentsIntersect(path1[i], path1[i + 1], path2[j], path2[j + 1]) ) { return true; } } } // If no exact intersection, check for proximity based on threshold if (threshold > 0) { for (let i = 0; i < path1.length - 1; i++) { const segment1Start = path1[i]; const segment1End = path1[i + 1]; for (let j = 0; j < path2.length - 1; j++) { const segment2Start = path2[j]; const segment2End = path2[j + 1]; // Check distance between segment endpoints and closest points const distances = [ distanceBetweenPoints( segment1Start, closestPointOnSegment(segment1Start, segment2Start, segment2End), ), distanceBetweenPoints( segment1End, closestPointOnSegment(segment1End, segment2Start, segment2End), ), distanceBetweenPoints( segment2Start, closestPointOnSegment(segment2Start, segment1Start, segment1End), ), distanceBetweenPoints( segment2End, closestPointOnSegment(segment2End, segment1Start, segment1End), ), ]; if (Math.min(...distances) <= threshold) { return true; } } } } return false; } ``` ##### types.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export type ErasableNodeType = Node< { toBeDeleted?: boolean; label?: string }, 'erasable-node' >; export type ErasableEdgeType = Edge<{ toBeDeleted?: boolean }, 'erasable-edge'>; ``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('@xyflow/vue/xy-theme.css'); @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .tool-overlay { pointer-events: auto; position: absolute; top: 0; left: 0; z-index: 4; height: 100%; width: 100%; transform-origin: top left; cursor: crosshair; touch-action: none; } ``` ##### Eraser.vue ```vue ``` ##### ErasableNode.vue ```vue ``` ##### ErasableEdge.vue ```vue ``` ##### App.vue ```vue ``` ##### πŸ“ Rectangle draw Create rectangular shapes by clicking and dragging. Good for highlighting areas or creating backgrounds for node groups. **Features:** * Click-and-drag rectangle creation * Customizable colors **Common uses:** * Creating background containers * Grouping related nodes visually * Highlighting sections of diagrams Example: examples/whiteboard/rectangle ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type RectangleNodeType = Node<{ color: string }, 'rectangle'>; ``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('@xyflow/vue/xy-theme.css'); @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .vue-flow__node { padding: 0; border: none; } .tool-overlay { pointer-events: auto; position: absolute; top: 0; left: 0; z-index: 4; height: 100%; width: 100%; transform-origin: top left; cursor: copy; touch-action: none; } .rectangle-preview { position: absolute; z-index: 10; } .rectangle-toolbar { display: flex; gap: 0.25rem; border-radius: 0.5rem; border: 1px solid #e5e5e5; background-color: white; padding: 0.5rem; box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); } .rectangle-color-button { height: 1.5rem; width: 1.5rem; border-radius: 9999px; border: none; cursor: pointer; transition: transform 0.15s ease-in-out; } .rectangle-color-button:hover { transform: scale(1.1); } .rectangle-outer { display: flex; height: 100%; width: 100%; align-items: center; justify-content: center; } .rectangle-inner { position: relative; height: calc(100% - 5px); width: calc(100% - 5px); display: flex; align-items: center; justify-content: center; background-color: white; border-radius: 0.375rem; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); border: 1px solid #e5e5e5; } .rectangle-inner.selected { outline: 2px solid #3b82f6; outline-offset: 2px; } ``` ##### RectangleTool.vue ```vue ``` ##### RectangleNode.vue ```vue ``` ##### App.vue ```vue ``` #### Whiteboard libraries If you're looking for a more complete whiteboard solution, consider libraries designed specifically for it, like [tldraw](https://tldraw.dev/) or [Excalidraw](https://docs.excalidraw.com/). These provide a full set of features for collaborative drawing, shapes, text, and more. ### Adding Interactivity In the [previous guide](/learn/concepts/building-a-flow) we built a flow with a couple of nodes and an edge. Because we bound our nodes and edges with `v-model`, that flow is *already* interactive: you can select, drag, and delete nodes and edges out of the box. This is the biggest difference from React Flow and Svelte Flow. When you use `v-model:nodes` / `v-model:edges`, Vue Flow **manages the state for you**: it applies changes, like a node being dragged or an element being deleted, directly to your arrays. We call this an **uncontrolled** flow. #### Uncontrolled flow with v-model Binding `nodes` and `edges` with `v-model` is all you need for a flow where users can move, select, and remove elements: ```vue "v-model:nodes" "v-model:edges" ``` Vue Flow replaces the whole `nodes` / `edges` array when it applies a change, so a [`shallowRef`](https://vuejs.org/api/reactivity-advanced.html#shallowref) is enough, and much cheaper than a deep `ref` for large flows. #### Connecting nodes One thing is *not* applied automatically: creating a new edge when the user drags from one node's handle to another. For that, listen to the `@connect` event and append the new edge with the [`addEdge`](/api-reference/utils/add-edge) utility. ##### Import `addEdge` ```ts import { addEdge } from '@xyflow/vue'; ``` ##### Add a connect handler `addEdge` takes the new [`Connection`](/api-reference/types/connection) and the current edges array, and returns a new array with the edge appended: ```ts function onConnect(connection: Connection) { edges.value = addEdge(connection, edges.value); } ``` ##### Pass it to VueFlow ```vue "@connect" ``` ##### Connectable flow Try dragging from one node's handle to the other. The `@connect` handler fires and the new edge is added. πŸ₯³ Example: learn/make-it-interactive-1 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ```
#### Controlled flow Sometimes you want full control over the state so you can validate, transform, or persist every change yourself rather than letting Vue Flow apply it. To do that, drop `v-model` and pass `nodes` and `edges` as one-way props, then handle the `@nodes-change` and `@edges-change` events yourself β€” each one hands you a changeset that knows how to apply itself. For most apps `v-model` is the simpler choice. Reach for a controlled flow only when you need to inspect or intercept every change before it is applied. ##### Handle the change events Each handler receives a changeset of [changes](/api-reference/types/node-change). Call `applyTo` with your current array and it returns the next one: ```ts import type { Edge, EdgeChangeset, Node, NodeChangeset } from '@xyflow/vue'; import { addEdge } from '@xyflow/vue'; function onNodesChange(changes: NodeChangeset) { nodes.value = changes.applyTo(nodes.value); } function onEdgesChange(changes: EdgeChangeset) { edges.value = changes.applyTo(edges.value); } function onConnect(connection: Connection) { edges.value = addEdge(connection, edges.value); } ``` ##### Pass them to VueFlow ```vue "@nodes-change" "@edges-change" "@connect" ``` ##### Controlled flow The result looks identical, but now every change passes through your handlers before it touches the arrays. Example: learn/make-it-interactive-2 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ```
#### What you get Whichever approach you choose, an interactive flow lets your users: * select nodes and edges * drag nodes around the canvas * connect nodes by dragging from one handle to another * draw a multi-selection box by holding `Shift` β€” the default [`selectionKeyCode`](/api-reference/vue-flow) * add to a selection by holding `Meta`/`Control` β€” the default [`multiSelectionKeyCode`](/api-reference/vue-flow) * remove selected elements with `Backspace` β€” the default [`deleteKeyCode`](/api-reference/vue-flow) If you want to jump straight into building your own application, we recommend checking out the [Customization](/learn/customization/custom-nodes) section. ### Building a Flow In the following pages we will introduce you to the core concepts of Vue Flow and explain how to create a basic interactive flow. A flow consists of [nodes](/api-reference/types/node) and [edges](/api-reference/types/edge) placed inside a pannable and zoomable viewport. If you haven't already, we recommend having a look at the [core concepts overview](/learn/concepts/terms-and-definitions) first. To follow along with this guide you will need to have a Vue project set up and install the `@xyflow/vue` package: ```bash copy npm2yarn npm install @xyflow/vue ``` #### Creating the flow Let's start by creating an empty flow with [``](/api-reference/components/controls) for the viewport and a dotted [``](/api-reference/components/background). ##### Add imports All the imports we need are importable from `@xyflow/vue`, so let's import the main `` component and the background and controls components mentioned above. ```vue ``` It's also important to import the default styles for Vue Flow. You can't skip this step because the styles are required for the flow to render *and* function correctly. ```vue ``` ##### Render VueFlow Next, render the main component inside an element with defined dimensions and place the [``](/api-reference/components/background) and [``](/api-reference/components/controls) components inside `` Content inside `` is fixed _on top_ of the viewport. The `` component transforms its pattern to match viewport movement. ```vue ``` ##### Empty flow That's it! You have created your first empty flow πŸŽ‰ If everything is set up correctly, you should see a blank canvas like this: Example: learn/building-a-flow-1 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ```
#### Adding nodes Now that the flow is set up, let's add some nodes. Each node represents an element placed on the canvas with a specific position and content. ##### Create node objects In the ` ``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` We have several built-in nodes that you can explore in the [node](/api-reference/types/node) reference. However, once you start building your own application, you will want to use [custom nodes](/learn/customization/custom-nodes). #### Adding edges Now that we have two nodes, let’s connect them with an edge. ### Create edge objects To create an edge, we define an array of [edge](/api-reference/types/edge) objects. Each edge object needs to have an `id`, a `source` (where the edge begins), and a `target` (where it ends). In this example, we use the `id` values of the two nodes we created so far (`n1` and `n2`) to define the edge: Just like our nodes, we use a [`shallowRef`](https://vuejs.org/api/reactivity-advanced.html#shallowref) to make the edges array reactive. ```js const edges = shallowRef([{ id: 'n1-n2', source: 'n1', target: 'n2' }]); ``` ##### Add edges to the flow And again, as with nodes, we add the edges to the `VueFlow` component using `v-model`. ```vue "v-model:edges" ``` Your flow should now look like this: Example: learn/building-a-flow-3 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ##### Edge label and type By default, Vue Flow allows you to add text labels to edges that will float in the middle of the edge via the `label` property. Vue Flow also comes with a handful of built-in edge *types* which can draw the connection line between two nodes in different ways. Let's add a label to the edge and change its type to `"smoothstep"`: an orthogonal-style edge with rounded 90 degree angles. ```js {6-7} const edges = shallowRef([ { id: 'n1-n2', source: 'n1', target: 'n2', type: 'smoothstep', label: 'connects with', }, ]); ``` ##### Done! πŸŽ‰ Congratulations! You have completed a basic flow with nodes and edges! πŸŽ‰
#### Full code example 🏁 You took your first steps in Vue Flow! The completed flow will look like this: Example: learn/building-a-flow-4 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ### Built-In Components Vue Flow comes with several additional components that you can plug into your flow. All you have to do is import and add them as children to the `VueFlow` component. ```vue ``` #### MiniMap The [`MiniMap`](/api-reference/components/minimap) provides a bird's-eye view of your flowgraph, making navigation easier, especially for larger flows. You can customize the appearance of nodes in the minimap by providing a `nodeColor` function. Example: learn/minimap ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### MiniMapNode For full control over how nodes are drawn in the minimap, `MiniMap` exposes a `#node-` slot for each node type. The slot receives the same props as the default `MiniMapNode` renderer, which you can render (and tweak) directly: ```vue ``` #### Controls Vue Flow comes with a set of customizable [`Controls`](/api-reference/components/controls) for the viewport. You can zoom in and out, fit the viewport and toggle if the user can move, select and edit the nodes. Example: learn/controls ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### ControlButton Add your own buttons to the [`Controls`](/api-reference/components/controls) panel with the [`ControlButton`](/api-reference/components/control-button) component. It renders a button styled to match the built-in controls, takes an optional `label` (used as the accessible label and tooltip), and emits a `click` event: ```vue ``` #### Background The [`Background`](/api-reference/components/background) component adds a visual grid pattern to your flowgraph, helping users maintain orientation. You can choose from different pattern variants, or if you need more advanced customization, you can explore the [source code](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Background/Background.vue) to implement your own pattern. Example: learn/background ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### Panel The [`Panel`](/api-reference/components/panel) component allows you to add fixed overlays to your flowgraph, perfect for titles, controls, or any other UI elements that should remain stationary. Example: learn/panel ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .vue-flow__panel { padding: 5px 10px; background: var(--xy-theme-panel-bg, #ffffff); color: var(--xy-theme-panel-text, #111827); border-radius: 3px; box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px; } ``` ##### App.vue ```vue ``` ### Overview At its core, Vue Flow is about creating interactive graphs called flows. A flow is a collection of nodes connected by edges, and while this may sound simple in theory, Vue Flow provides the foundation for building complex diagrams and rich interactive experiences through features such as: * An infinite, interactive canvas for your flowgraph * The ability to render and connect nodes with edges * **Everything built using standard Vue components** To help you understand the terminology used throughout the documentation, take a look at the example flow below: Example: learn/basic-terms ##### nodes-and-edges.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: 'annotation-1', type: 'annotation', draggable: false, selectable: false, data: { label: 'This is a "node"', arrowStyle: 'arrow-bottom-right', }, position: { x: -65, y: -50 }, }, { id: '1-1', type: 'default', data: { label: 'node label', }, position: { x: 150, y: 0 }, }, { id: 'annotation-2', type: 'annotation', draggable: false, selectable: false, data: { label: 'This is a "handle"', arrowStyle: 'arrow-top-left', }, position: { x: 235, y: 35 }, }, { id: 'annotation-3', type: 'annotation', draggable: false, selectable: false, data: { label: 'This is an "edge"', arrowStyle: 'arrow-top-right', }, position: { x: 20, y: 120 }, }, { id: '1-2', type: 'default', data: { label: 'node label', }, position: { x: 350, y: 200 }, }, { id: 'annotation-4', type: 'annotation', draggable: false, selectable: false, data: { label: 'Try dragging the handle', arrowStyle: 'arrow-top-left', }, position: { x: 430, y: 240 }, }, ]; export const initialEdges: Edge[] = [ { id: 'e1-2', source: '1-1', target: '1-2', label: 'edge label', type: 'smoothstep', }, ]; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } /* Annotation Node */ .vue-flow__node-annotation { font-size: 16px; max-width: 300px; color: #683bfa; position: absolute; box-shadow: none; font-family: monospace; text-align: left; background-color: transparent; border: none; pointer-events: none; } .vue-flow__node-annotation .annotation-content { padding: 10px; display: flex; } .vue-flow__node-annotation .annotation-arrow { position: absolute; font-size: 24px; } .arrow-top-right { right: 0; bottom: 0; transform: translate(10px, -25px) rotate(-140deg); position: absolute; } .arrow-top-left { left: 0; bottom: 0; transform: translate(-5px, -25px) rotate(145deg) scale(-1, 1); position: absolute; } .arrow-bottom-left { left: 0; bottom: 0; transform: translate(0px, -20px) rotate(90deg); position: absolute; } .arrow-bottom-right { right: 0; bottom: 0; transform: translate(10px, 5px) rotate(-60deg); position: absolute; } /* Viewport Logger */ .viewport-logger { font-family: monospace; background: var(--xy-theme-panel-bg); color: var(--xy-theme-panel-text); padding: 5px; border-radius: 3px; } ``` ##### NodeWrapper.vue ```vue ``` ##### Flow\.vue ```vue ``` ##### App.vue ```vue ``` ##### AnnotationNode.vue ```vue ``` ##### Nodes For basic applications, Vue Flow has a handful of default node types available out of the box. These let you quickly create simple diagrams with labelled nodes and edges or prototype an experience. The built-in node types are: * `"default"` for a node with both a source (aka output) and target (aka input) handle. * `"input"` for a node with just a source handle. * `"output"` for a node with only a target handle. * `"group"` to act as a selectable container for multiple nodes. Vue Flow's real power comes from the ability to define [custom nodes](/learn/customization/custom-nodes). Custom nodes are just Vue components and allow you to embed interactive form controls, display dynamic data visualizations, or incorporate more-complex nodes with multiple connection handles directly into the flow. We have a guide on creating your own [custom nodes](/learn/customization/custom-nodes) and you can find all the options for customizing your nodes in the [Node](/api-reference/types/node) reference. ##### Handles A handle (sometimes known as a β€œport” in other libraries) is the attachment point where an edge connects to a node. By default, they appear as grey circles on the top, bottom, left, or right sides of a node. But they are just `
` elements, and can be positioned and styled any way you’d like. When creating a custom node, you can include as many handles as needed. For more information, refer to the [Handle](/learn/customization/handles) guide. ##### Edges Edges connect nodes. Every edge needs a target and a source node. Vue Flow comes with five built-in [edge types](/examples/edges/edge-types): `default` (bezier), `smoothstep`, `step`, `straight`, and `simplebezier`. An edge is an SVG path that can be styled with CSS and is completely customizable. If you are using multiple handles, you can reference them individually to create multiple connections for a node. Like custom nodes, you can also customize edges. Things that people do with custom edges include: * Adding buttons to remove edges * Custom routing behavior * Complex styling or interactions that cannot be solved with just one SVG path For more information, refer to the [Edges](/learn/customization/custom-edges) page. ##### Selection You can select an edge or a node by clicking on it. If you want to select multiple nodes/edges via clicking, you can hold the `Meta/Control` key and click on multiple elements to select them. If you want to change the keyboard key for multiselection to something else, you can use the [`multiSelectionKeyCode`](/api-reference/vue-flow) prop. You can also select multiple edges/nodes by holding down `Shift` and dragging the mouse to make a selection box. When you release the mouse, any node or edge that falls within the selection box is selected. If you want to change the keyboard key for this behavior, you can use the [`selectionKeyCode`](/api-reference/vue-flow) prop. Selected nodes and edges are elevated (assigned a higher `zIndex` than other elements), so that they are shown on top of all the other elements. For default edges and nodes, selection is shown by a darker stroke/border than usual. If you are using a custom node/edge, you can use the `selected` prop to customize selection appearance inside your custom component. ##### Connection line Vue Flow has built-in functionality that allows you to click and drag from one handle to another to create a new edge. While dragging, the placeholder edge is referred to as a connection line. The connection line comes with the same built-in types as edges and is customizable. You can find the props for configuring the connection line in the [connection props](/api-reference/vue-flow#connection-line-props) reference. ##### Viewport All of Vue Flow is contained within the viewport. Each node has an x- and y-coordinate, which indicates its position within the viewport. The viewport has x, y, and zoom values. When you drag the pane, you change the x and y coordinates. When you zoom in or out, you alter the zoom level. You can read more about the viewport on the [Viewport](/learn/concepts/the-viewport) page. ### Panning and Zooming The default pan and zoom behavior of Vue Flow is inspired by [slippy maps](https://wiki.openstreetmap.org/wiki/Slippy_map). You pan by dragging your pointer and zoom by scrolling. You can customize this behavior easily with the [interaction](/api-reference/vue-flow#interaction-props) and [keyboard](/api-reference/vue-flow#keyboard-props) props on the `` component. #### Common viewport configurations There are two common viewport configurations that most Vue Flow apps will use, inspired by existing canvas-based tools. One is based on how map tools often work and is the default Vue Flow setup, and the other is based on design tools like Figma and Sketch. ##### Map-style configuration The configuration affects how three common interactions work: panning, zooming, and selection. The default, map-style configuration works as follows: | Interaction | Behaviour | | ----------- | :-------------------------- | | Pan | On pointer drag | | Zoom | On scroll | | Selection | Hold shift and pointer drag | Example: learn/zoom-pan ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ##### Design tool viewport controls If you'd prefer a configuration that is more similar to design tools like Figma or Sketch, there are a couple of props you can change on the `` component: * `panOnScroll` and `selectionOnDrag` should be set to `true`. * `panOnDrag` should be set to `false` or a non-left mouse button (e.g. `[1, 2]`). This produces the following behavior: | Interaction | Behaviour | | ----------- | :---------------------------------------------------------------------------------------- | | Pan | On scroll, hold the middle or right mouse button and drag, or hold space and pointer drag | | Zoom | Pinch gesture or hold cmd/ctrl and scroll | | Selection | Press and hold pointer and drag | Example: learn/zoom-pan-2 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` In this example we also set `selectionMode` prop to `"partial"`. This makes it possible to add nodes to a selection that are only partially selected. ### Custom Edges Like [custom nodes](/learn/customization/custom-nodes), parts of a custom edge in Vue Flow are just Vue components: that means you can render anything you want along an edge! This guide shows you how to implement a custom edge with some additional controls. For a comprehensive reference of props available for custom edges, see the [`EdgeProps`](/api-reference/types/edge-props) documentation. #### A basic custom edge An edge isn't much use to us if it doesn't render a path between two connected nodes. These paths are always SVG-based and are typically rendered using the [``](/api-reference/components/base-edge) component. To calculate the actual SVG path to render, Vue Flow comes with some handy utility functions: * [`getBezierPath`](/api-reference/utils/get-bezier-path) * [`getSmoothStepPath`](/api-reference/utils/get-smooth-step-path) * [`getStraightPath`](/api-reference/utils/get-straight-path) To kick start our custom edge, we'll just render a straight path between the source and target. ```vue filename="CustomEdge.vue" ``` All the props passed to your custom edge component can be found in the API reference under the [`EdgeProps`](/api-reference/types/edge-props) type. The path utilities return a tuple of `[path, labelX, labelY]`, which is why we read `path[0]` for the SVG path. This gives us a straight edge that behaves the same as the default `"straight"` [edge type](/api-reference/types/edge). To use it, register the component through the `#edge-` slot on the `` component, the same way you register a [custom node](/learn/customization/custom-nodes#adding-the-node-type): ```vue filename="App.vue" ``` After registering the slot, we can use our new custom edge by setting the `type` field of an edge to `"custom-edge"`. Example: learn/custom-edge ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### CustomEdge.vue ```vue ``` ##### App.vue ```vue ``` #### Making Custom SVG Edge Paths As discussed previously, if you want to make a custom edge in Vue Flow, you have to use either of the three path creation functions discussed above (e.g [`getBezierPath`](/api-reference/utils/get-bezier-path)). However if you want to make some other path shape like a Sinusoidal edge or some other edge type then you will have to make the edge path yourself. The edge path we get from functions like [`getBezierPath`](/api-reference/utils/get-bezier-path) is just a path string which we pass into the `path` prop of the `` component. It contains the necessary information needed in order to draw that path, like where it should start from, where it should curve, where it should end, etc. A simple straight path string between two points `(x1, y1)` to `(x2, y2)` would look like: ``` M x1 y1 L x2 y2 ``` An SVG path is a concatenated list of commands like `M`, `L`, `Q`, etc, along with their values. Some of these commands are listed below, along with their supported values. * `M x1 y1` is the Move To command which moves the current point to the x1, y1 coordinate. * `L x1 y1` is the Line To command which draws a line from the current point to x1, y1 coordinate. * `Q x1 y1 x2 y2` is the Quadratic Bezier Curve command which draws a bezier curve from the current point to the x2, y2 coordinate. x1, y1 is the control point of the curve which determines the curviness of the curve. Whenever we want to start a path for our custom edge, we use the `M` command to move our current point to `sourceX, sourceY` which we get as props in the custom edge component. Then based on the shape we want, we will use other commands like `L`(to make lines), `Q`(to make curves) and then finally end our path at `targetX, targetY` which we get as props in the custom edge component. If you want to learn more about SVG paths, you can check out [SVG-Path-Editor](https://yqnn.github.io/svg-path-editor/). You can paste any SVG path there and analyze individual path commands via an intuitive UI. Here is an example with two types of custom edge paths, a Step edge and a Sinusoidal edge. You should look at the Step edge first to get your hands dirty with custom SVG paths since it's simple, and then look at how the Sinusoidal edge is made. After going through this example, you will have the necessary knowledge to make custom SVG paths for your custom edges. Example: learn/custom-edge-path ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### StepEdge.vue ```vue ``` ##### SineEdge.vue ```vue ``` ##### App.vue ```vue ``` ### Custom Nodes A powerful feature of Vue Flow is the ability to create custom nodes. This gives you the flexibility to render anything you want within your nodes. We generally recommend creating your own custom nodes rather than relying on built-in ones. With custom nodes, you can add as many source and target handles as you likeβ€”or even embed form inputs, charts, and other interactive elements. In this section, we'll walk through creating a custom node featuring an input field that updates text elsewhere in your application. For further examples, we recommend checking out our [Custom Node Example](/examples/nodes/custom-node). #### Implementing a Custom Node To create a custom node, all you need to do is create a Vue component. Vue Flow will automatically wrap it in an interactive container that injects essential props like the node's id, position, and data, and provides functionality for selection, dragging, and connecting handles. For a full reference on all available custom node props, take a look at the [Node Props](/api-reference/types/node-props). Let's dive into an example by creating a custom node called `TextUpdaterNode`. For this, we've added an input field with an `input` handler. We use the `text` property from the node's data for the input and update the node's data via the [`updateNodeData`](/api-reference/composables/use-vue-flow) function, which can be accessed through the [`useVueFlow`](/api-reference/composables/use-vue-flow) composable. ```vue filename="TextUpdaterNode.vue" ``` #### Adding the Node Type Now we need to tell Vue Flow how to render our new node type. Vue Flow maps a node's `type` to a [named slot](https://vuejs.org/guide/components/slots.html#named-slots) of the form `#node-` on the `` component. Add a `#node-textUpdater` slot and render your component, forwarding the slot props with `v-bind`: ```vue filename="App.vue" ``` Prefer registering by object? Vue Flow also accepts a [`nodeTypes`](/api-reference/vue-flow) prop as an alternative to the `#node-` slots. After defining your new node type, you can refer to it by using the `type` node option: ```js const nodes = shallowRef([ { id: 'node-1', type: 'textUpdater', position: { x: 0, y: 0 }, data: { text: 'some text' }, }, ]); ``` After putting it all together and adding some basic styles we get a custom node that lets you update the node text in real time: Example: learn/custom-node ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .text-updater-node { height: 50px; padding: 5px; background: var(--xy-node-background-color-default); } .text-updater-node label { display: block; color: var(--xy-node-color-default); font-size: 12px; } .text-updater-node input { color: var(--xy-node-color-default); background: var(--xy-node-background-color-default); border-radius: 3px; padding: 5px; font-size: 12px; } ``` ##### TextUpdaterNode.vue ```vue ``` ##### App.vue ```vue ``` To enable your custom node to connect with other nodes, check out the [Handles](/learn/customization/handles) page to learn how to add source and target handles. ### Edge Labels One of the more common uses for custom edges is rendering some controls or info along an edge's path. In Vue Flow we call that an *edge label* and unlike the edge path, edge labels can be any Vue component! #### Adding an edge label Because Vue Flow's edges are mounted inside an SVG component, we need to escape its context to render a custom edge label. For this, we have a handy [``](/api-reference/components/edge-label-renderer) component. It functions as a portal that mounts the child components in the viewport div. Let's add a button to our custom edge that can be used to delete the edge it's attached to: ```vue filename="CustomEdge.vue" ``` To make sure our edge labels are interactive and not just for presentation, it is important to add `pointer-events: all` along with the `nodrag` and `nopan` classes to the label to stop mouse events from controlling the canvas. Here's an interactive example with our updated custom edge. Clicking the delete button will remove that edge from the flow. Example: learn/custom-edge-2 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### CustomEdge.vue ```vue ``` ##### App.vue ```vue ``` ### Handles Handles are the connection points on [nodes](/learn/concepts/terms-and-definitions#nodes) in Vue Flow. Our built-in nodes include one source and one target handle, but you can customize your nodes with as many different handles as you need. #### Creating a node with handles To create a [custom node](/learn/customization/custom-nodes) with handles, you can use the [``](/api-reference/components/handle) component provided by Vue Flow. This component allows you to define source and target handles for your custom nodes. Here's an example of how to implement a custom node with two handles: ```vue ``` #### Using multiple handles If you want to use multiple source or target handles in your custom node, you need to specify each handle with a unique `id`. This allows Vue Flow to differentiate between the handles when connecting edges. ```vue ``` To connect an edge to a specific handle of a node, use the properties `sourceHandle` (for the edge's starting point) and `targetHandle` (for the edge's ending point). By defining `sourceHandle` or `targetHandle` with the appropriate handle `id`, you instruct Vue Flow to attach the edge to that specific handle, ensuring that connections are made where you intend. ```js const edges = shallowRef([ { id: 'n1-n2', source: 'n1', sourceHandle: 'a', target: 'n2' }, { id: 'n1-n3', source: 'n1', sourceHandle: 'b', target: 'n3' }, ]); ``` In this case, the source node is `n1` for both handles but the handle `id`s are different. One comes from handle id `a` and the other one from `b`. Both edges also have different target nodes: Example: learn/custom-node-2 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### CustomNode.vue ```vue ``` ##### App.vue ```vue ``` By default Vue Flow positions a handle in the center of the specified side. If you want to display multiple handles on a side, you can adjust the position via inline styles or overwrite the default CSS and position it on your own. #### Custom handles You can use any custom component as a Handle by wrapping it with the [``](/api-reference/components/handle) component. Follow these steps to integrate your custom component: 1. Wrap your custom component with the [``](/api-reference/components/handle) component. 2. Hide the built-in [``](/api-reference/components/handle) appearance by setting `border` and `background` to `none`. 3. Set the `width` and `height` of [``](/api-reference/components/handle) to match your custom component. 4. Style the child component with `pointer-events: none`. 5. Then, reposition the child custom component using CSS position properties like `top, left` if necessary to position it perfectly inside the [``](/api-reference/components/handle) component. This example shows a custom icon used as a Handle: ```vue ``` #### Typeless handles If you want to create a handle that does not have a specific type (source or target), you can set [connectionMode](/api-reference/vue-flow) to `ConnectionMode.Loose` on the `` component. This allows the handle to be used for both incoming and outgoing connections. ```vue ``` #### Dynamic handles If you are programmatically changing the position or number of handles in your custom node, you need to update the node internals with the `updateNodeInternals` method from the [`useVueFlow`](/api-reference/composables/use-vue-flow) composable. #### Custom handle styles Since the handle is a div, you can use CSS to style it or pass a style prop to customize a Handle. You can see this in the [Add Node On Edge Drop](/examples/nodes/add-node-on-edge-drop) example. ##### Styling handles when connecting The handle receives the additional class names `connectingfrom` and `connectingto` when the connection line is above the handle and `valid` if the connection is valid. You can find an example which uses these classes [here](/examples/interaction/validation). ##### Hiding handles If you need to hide a handle for some reason, you must use `visibility: hidden` or `opacity: 0` instead of `display: none`. This is important because Vue Flow needs to calculate the dimensions of the handle to work properly and using `display: none` will report a width and height of `0`! ### Theming Vue Flow comes with minimal default styles and was designed to be fully customizable. Many of our users fully transform the look and feel of Vue Flow to match their own brand or design system. This guide will introduce you to the different ways you can customize Vue Flow's appearance. #### Default styles Vue Flow's default styles are enough to get going with the built-in nodes. They provide some sensible defaults for styles like padding, border radius, and animated edges. You can see what they look like below: ```js import '@xyflow/vue/style.css'; ``` The shorter `@xyflow/vue/style.css` import is available in Vue Flow 2. The previous `@xyflow/vue/dist/style.css` path is still supported. Example: learn/theming-default ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### index.css ```css html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` You'll typically load these default styles by importing them in your `main.ts`, `App.vue`, or another entry point. Without dipping into [custom nodes](/learn/customization/custom-nodes) and [edges](/learn/customization/custom-edges), there are several ways you can style Vue Flow's basic look: * Passing inline styles through `style` props * Overriding the built-in classes with custom CSS * Overriding the CSS variables Vue Flow uses * Using scoped styles in your Vue components for custom nodes and edges ##### Using our theme For xyflow's themed appearance, import `xy-theme.css` in place of `style.css`: ```js import '@xyflow/vue/xy-theme.css'; ``` This stylesheet builds on `base.css` and includes the styles needed for Vue Flow to work, so you don't need a separate base-style import. It adds themed nodes, handles, and controls, with support for light and dark mode. You can customize it with CSS variables and class overrides as described below. #### Layered CSS Since Vue Flow 2, the library styles are in a CSS layer named `xyflow`. Declare your layer order before importing styles to control their precedence: ```css @layer reset, xyflow, app; @import '@xyflow/vue/style.css'; ``` For normal declarations, styles in `app` take precedence over `xyflow`, while `reset` has lower priority. Styles outside any layer take precedence over layered styles. Read more about [CSS layers on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer). #### Base styles If you just want to load the very basic styles that are necessary for Vue Flow to work, you can import the base styles instead: ```js import '@xyflow/vue/base.css'; ``` These base styles are **required** for Vue Flow to function correctly. If you don't import them or you override them with your own styles, some things might not work as expected! Example: learn/theming-base ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### index.css ```css html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### Customization ##### Built in dark and light mode Vue Flow automatically follows your site's color mode when an ancestor has `data-theme="dark"`, `data-theme="light"`, or a `dark` or `light` class. Otherwise, it follows the user's operating-system color scheme. To force a specific mode regardless of your site's theme, use the `forceColorMode` prop with `'light'` or `'dark'`: ```vue ``` You can use `light-dark()` in your own CSS to follow the same color scheme: ```css .vue-flow__node { background: light-dark(white, #777); color: light-dark(#111, white); } ``` ##### Customizing with `style` props The easiest way to start customizing the look and feel of your flows is to use the `style` prop on `` and other components to inline your own CSS. ```vue ``` A `background` set this way styles the outer element. The flow canvas is painted by an inner pane, so set the `--xy-background-color` CSS variable to change the canvas color. ##### CSS variables If you don't want to replace the default styles entirely but just want to tweak the overall look and feel, you can override some of the CSS variables we use throughout the library. For an example of how to use these CSS variables, check out our [Feature Overview](/examples/overview) example. The following table lists the defaults when importing `style.css`, including the shared base styles. In `light-dark(light, dark)` values, the first color applies in light mode and the second in dark mode, according to the flow's CSS `color-scheme`. `CanvasText` is the browser's system text color. Importing only `base.css` provides fewer styles with some different defaults. These variables are used to define the *defaults* for the various elements of Vue Flow. This means they can still be overridden by inline styles or custom classes on a per-element basis. If you want to override a variable, you can do so by adding: ```css .vue-flow { --xy-node-background-color: #ff5050; } ``` These defaults are defined on `.vue-flow`. Set your overrides on that element. Use the variable without the `-default` suffix to override its fallback value. ##### Overriding built-in classes Some consider heavy use of inline styles to be an anti-pattern. In that case, you can override the built-in classes that Vue Flow uses with your own CSS. There are many classes attached to all sorts of elements in Vue Flow, but the ones you'll likely want to override are listed below: Be careful if you go poking around the source code looking for other classes to override. Some classes are used internally and are required in order for the library to be functional. If you replace them you may end up with unexpected bugs or errors! ##### Scoped styles for custom nodes and edges Custom nodes and edges are Vue components. You can use [` ``` Each of the examples that follow will be built on this empty flow. Where possible we've tried to keep the examples confined to a single `.vue` file so it's easy for you to compare how they're set up. #### Layouting Nodes For layouting nodes, there are a few third-party libraries that we think are worth checking out: ΒΉ Dagre currently has an [open issue](https://github.com/dagrejs/dagre/issues/238) that prevents it from laying out sub-flows correctly if any nodes in the sub-flow are connected to nodes outside the sub-flow. We've loosely ordered these options from simplest to most complex, where dagre is largely a drop-in solution and elkjs is a full-blown highly configurable layouting engine. Below, we'll take a look at a brief example of how each of these libraries can be used with Vue Flow. ##### Dagre * Repo: * Docs: Dagre is a simple library for layouting directed graphs. It has minimal configuration options and a focus on speed over choosing the most optimal layout. If you need to organize your flows into a tree, *we highly recommend dagre*. Example: learn/layouting-flow-2-dagre ##### nodes-edges.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'input' }, position: { x: 0, y: 0 }, }, { id: '2', data: { label: 'node 2' }, position: { x: 0, y: 100 } }, { id: '2a', data: { label: 'node 2a' }, position: { x: 0, y: 200 } }, { id: '2b', data: { label: 'node 2b' }, position: { x: 0, y: 300 } }, { id: '2c', data: { label: 'node 2c' }, position: { x: 0, y: 400 } }, { id: '2d', data: { label: 'node 2d' }, position: { x: 0, y: 500 } }, { id: '3', data: { label: 'node 3' }, position: { x: 200, y: 100 } }, ]; export const initialEdges: Edge[] = [ { id: 'e12', source: '1', target: '2', animated: true }, { id: 'e13', source: '1', target: '3', animated: true }, { id: 'e22a', source: '2', target: '2a', animated: true }, { id: 'e22b', source: '2', target: '2b', animated: true }, { id: 'e22c', source: '2', target: '2c', animated: true }, { id: 'e2c2d', source: '2c', target: '2d', animated: true }, ]; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### Flow\.vue ```vue ``` ##### App.vue ```vue ``` With no effort at all we get a well-organized tree layout! Whenever `getLayoutedElements` is called, we'll reset the dagre graph and set the graph's direction (either left-to-right or top-to-bottom) based on the `direction` argument. Dagre needs to know the dimensions of each node in order to lay them out, so we iterate over our list of nodes and add them to dagre's internal graph. After laying out the graph, we'll return an object with the layouted nodes and edges. We do this by mapping over the original list of nodes and updating each node's position according to the node stored in the dagre graph. Documentation for dagre's configuration options can be found [here](https://github.com/dagrejs/dagre/wiki#configuring-the-layout), including properties to set for spacing and alignment. ##### D3-Hierarchy * Repo: * Docs: When you know your graph is a tree with a single root node, d3-hierarchy can provide a handful of interesting layouting options. While the library can layout a simple tree just fine, it also has layouting algorithms for tree maps, partition layouts, and enclosure diagrams. Example: learn/layouting-flow-3-d3-hierarchy ##### nodes-edges.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'input' }, position: { x: 0, y: 0 }, }, { id: '2', data: { label: 'node 2' }, position: { x: 0, y: 100 } }, { id: '2a', data: { label: 'node 2a' }, position: { x: 0, y: 200 } }, { id: '2b', data: { label: 'node 2b' }, position: { x: 0, y: 300 } }, { id: '2c', data: { label: 'node 2c' }, position: { x: 0, y: 400 } }, { id: '2d', data: { label: 'node 2d' }, position: { x: 0, y: 500 } }, { id: '3', data: { label: 'node 3' }, position: { x: 200, y: 100 } }, ]; export const initialEdges: Edge[] = [ { id: 'e12', source: '1', target: '2', animated: true }, { id: 'e13', source: '1', target: '3', animated: true }, { id: 'e22a', source: '2', target: '2a', animated: true }, { id: 'e22b', source: '2', target: '2b', animated: true }, { id: 'e22c', source: '2', target: '2c', animated: true }, { id: 'e2c2d', source: '2c', target: '2d', animated: true }, ]; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### Flow\.vue ```vue ``` ##### App.vue ```vue ``` D3-hierarchy expects your graphs to have a single root node, so it won't work in all cases. It's also important to note that d3-hierarchy assigns the same width and height to _all_ nodes when calculating the layout, so it's not the best choice if you're displaying lots of different node types. ##### D3-Force * Repo: * Docs: For something more interesting than a tree, a force-directed layout might be the way to go. D3-Force is a physics-based layouting library that can be used to position nodes by applying different forces to them. As a consequence, it's a little more complicated to configure and use compared to dagre and d3-hierarchy. Importantly, d3-force's layouting algorithm is iterative, so we need a way to keep computing the layout across multiple renders. First, let's see what it does: Example: learn/layouting-flow-4-d3-force ##### nodes-edges.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'input' }, position: { x: 0, y: 0 }, }, { id: '2', data: { label: 'node 2' }, position: { x: 0, y: 100 } }, { id: '2a', data: { label: 'node 2a' }, position: { x: 0, y: 200 } }, { id: '2b', data: { label: 'node 2b' }, position: { x: 0, y: 300 } }, { id: '2c', data: { label: 'node 2c' }, position: { x: 0, y: 400 } }, { id: '2d', data: { label: 'node 2d' }, position: { x: 0, y: 500 } }, { id: '3', data: { label: 'node 3' }, position: { x: 200, y: 100 } }, ]; export const initialEdges: Edge[] = [ { id: 'e12', source: '1', target: '2', animated: true }, { id: 'e13', source: '1', target: '3', animated: true }, { id: 'e22a', source: '2', target: '2a', animated: true }, { id: 'e22b', source: '2', target: '2b', animated: true }, { id: 'e22c', source: '2', target: '2c', animated: true }, { id: 'e2c2d', source: '2c', target: '2d', animated: true }, ]; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### collide.ts ```ts import { quadtree } from 'd3-quadtree'; export function collide() { let nodes: any[] = []; function force(alpha: number) { const tree = quadtree( nodes, (d) => d.x, (d) => d.y, ); for (const node of nodes) { const r = node.measured.width / 2; const nx1 = node.x - r; const nx2 = node.x + r; const ny1 = node.y - r; const ny2 = node.y + r; tree.visit((quad: any, x1, y1, x2, y2) => { if (!quad.length) { do { if (quad.data !== node) { const r = node.measured.width / 2 + quad.data.width / 2; let x = node.x - quad.data.x; let y = node.y - quad.data.y; let l = Math.hypot(x, y); if (l < r) { l = ((l - r) / l) * alpha; node.x -= x *= l; node.y -= y *= l; quad.data.x += x; quad.data.y += y; } } } while ((quad = quad.next)); } return x1 > nx2 || x2 < nx1 || y1 > ny2 || y2 < ny1; }); } } force.initialize = (newNodes: any[]) => (nodes = newNodes); return force; } export default collide; ``` ##### Flow\.vue ```vue ``` ##### App.vue ```vue ``` In our Vue implementation, we use Vue's lifecycle hooks (`onMounted`/`onUnmounted`) and reactive refs to manage the force simulation. The simulation is configured with a number of different forces applied so you can see how they interact: play around in your own code to see how you want to configure those forces. You can find the documentation and some different examples of d3-force [here](https://d3js.org/d3-force). Rectangular collisions D3-Force has a built-in collision force, but it assumes nodes are circles. We've thrown together a custom force in `collide.ts` that uses a similar algorithm but accounts for our rectangular nodes instead. Feel free to steal it or let us know if you have any suggestions for improvements! The tick function progresses the simulation by one step and then updates Vue Flow with the new node positions. We've also included a demonstration on how to handle node dragging while the simulation is running: if your flow isn't interactive you can ignore that part! For larger graphs, computing the force layout every render forever is going to incur a big performance hit. In this example we have a simple toggle to turn the layouting on and off, but you might want to come up with some other approach to only compute the layout when necessary. ##### Elkjs * Repo: * Docs: (good luck!) Elkjs is certainly the most configurable option available, but it's also the most complicated. Elkjs is a Java library that's been ported to JavaScript, and it provides a huge number of options for configuring the layout of your graph. Example: learn/layouting-flow-6-elkjs ##### nodes-edges.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'input' }, position: { x: 0, y: 0 }, }, { id: '2', data: { label: 'node 2' }, position: { x: 0, y: 100 } }, { id: '2a', data: { label: 'node 2a' }, position: { x: 0, y: 200 } }, { id: '2b', data: { label: 'node 2b' }, position: { x: 0, y: 300 } }, { id: '2c', data: { label: 'node 2c' }, position: { x: 0, y: 400 } }, { id: '2d', data: { label: 'node 2d' }, position: { x: 0, y: 500 } }, { id: '3', data: { label: 'node 3' }, position: { x: 200, y: 100 } }, ]; export const initialEdges: Edge[] = [ { id: 'e12', source: '1', target: '2', animated: true }, { id: 'e13', source: '1', target: '3', animated: true }, { id: 'e22a', source: '2', target: '2a', animated: true }, { id: 'e22b', source: '2', target: '2b', animated: true }, { id: 'e22c', source: '2', target: '2c', animated: true }, { id: 'e2c2d', source: '2c', target: '2d', animated: true }, ]; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### Flow\.vue ```vue ``` ##### App.vue ```vue ``` At its most basic we can compute layouts similar to dagre, but because the layouting algorithm runs asynchronously we need to handle promises and update our Vue state accordingly. The ELK reference is your new best friend We don't often recommend elkjs because its complexity makes it difficult for us to support folks when they need it. If you do decide to use it, you'll want to keep the original [Java API reference](https://eclipse.dev/elk/reference.html) handy. We've also included a few examples of some of the other layouting algorithms available, including a non-interactive force layout. ##### Honourable Mentions Of course, we can't go through every layouting library out there: we'd never work on anything else! Here are some other libraries we've come across that might be worth taking a look at: * If you want to use dagre or d3-hierarchy but need to support nodes with different dimensions, both [d3-flextree](https://github.com/klortho/d3-flextree) and [entitree-flex](https://github.com/codeledge/entitree-flex) look promising. * [Cola.js](https://github.com/tgdwyer/WebCola) looks like a promising option for so-called "constraint-based" layouts. We haven't had time to properly investigate it yet, but it looks like you can achieve results similar to d3-force but with a lot more control. #### Routing Edges If you don't have any requirements for edge routing, you can use one of the layouting libraries above to position nodes and let the edges fall wherever they may. Otherwise, you'll want to look into some libraries and techniques for edge routing. Your options here are more limited than for node layouting, but here are some resources we thought looked promising: * [Routing Orthogonal Diagram Connectors in JavaScript](https://medium.com/swlh/routing-orthogonal-diagram-connectors-in-javascript-191dc2c5ff70) If you do explore some custom edge routing options, consider contributing back to the community by writing a blog post or creating a library! You can use the [custom edges guide](/learn/customization/custom-edges) as a starting point for implementing a custom edge that can be routed along a specific path. ### Sub Flows A sub flow is a flowgraph contained within a node. These nested flows can operate independently or connect with nodes outside their parent node, making them perfect for organizing and grouping related nodes. This guide will show you how to implement sub flows and explain the available options for child nodes. ##### Defining Child Nodes To define a child node, use the `parentId` option (see all available options in the [node options section](/api-reference/types/node)). Child nodes are positioned relative to their parent, with `{ x: 0, y: 0 }` representing the top-left corner of the parent node. ```js "parentId: 'A'" const nodes = shallowRef([ { id: 'A', data: { label: 'parent' }, position: { x: 0, y: 0 }, }, { id: 'B', data: { label: 'child' }, position: { x: 10, y: 10 }, parentId: 'A', }, ]); ``` Order of Nodes: Parents have to appear before their child nodes in the `nodes` array! ###### `extent: 'parent'` When a parent node has defined dimensions, you can restrict child node movement to stay within the parent's boundaries by setting `extent: 'parent'`. This prevents child nodes from being dragged outside their parent's area. Example: learn/sub-flows ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ##### Child Node Behavior Child nodes maintain their relative position when the parent node is moved. While the `parentId` option establishes the parent-child relationship, child nodes can still be positioned outside their parent (unless `extent: 'parent'` is set). However, they will always move with their parent when it's dragged. In our examples, we use the built-in `group` node type for parent nodes, which provides a transparent background with a border. You can also use [any custom node type](/learn/layouting/sub-flows#using-a-custom-parent-node) as a parent. Let's explore more complex scenarios by adding additional nodes and edges. You can create connections both within a group and between sub flows and outer nodes: Example: learn/sub-flows-2 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ##### Using a Custom Parent Node To demonstrate the flexibility of parent nodes, let's modify our example by removing the label from node B and adding child nodes. This example shows how you can use any node type as a parent. We'll also set `draggable: false` on the child nodes to make them static. Example: learn/sub-flows-3 ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Example
``` ##### xy-extras.css ```css /* Extras for the xyflow examples. These styles sit on top of `@xyflow/vue/xy-theme.css`, which has to be imported before this file. They only add what the library theme doesn't ship with. */ .vue-flow__panel { color: var(--xy-theme-panel-text); } .vue-flow__node { box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-resizer { border-radius: 0; border: none; } /* Custom Example CSS - This CSS is to improve the example experience. You can remove it if you want to use the default styles. New Theme Classes: .xy-theme__button - Styles for buttons. .xy-theme__input - Styles for text inputs. .xy-theme__checkbox - Styles for checkboxes. .xy-theme__select - Styles for dropdown selects. .xy-theme__label - Styles for labels. .xy-theme__range - Styles for range sliders (set --range-progress for the filled part). Use these classes to apply consistent theming across your components. */ :root { --color-primary: var(--xy-theme-primary); --color-background: light-dark(#fefefe, #1a1b1e); --color-hover-bg: light-dark(#f6f6f6, #24262c); --color-disabled: light-dark(#76797e, #8b9099); --color-primary-muted: color-mix( in srgb, var(--color-primary) 40%, transparent ); --color-primary-focus: color-mix( in srgb, var(--color-primary) 30%, transparent ); } .xy-theme__button-group { display: flex; align-items: center; .xy-theme__button:first-child { border-radius: 100px 0 0 100px; } .xy-theme__button:last-child { border-radius: 0 100px 100px 0; margin: 0; } } /* Custom Button Styling */ .xy-theme__button { display: inline-flex; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1rem; border-radius: 100px; border: 1px solid var(--color-primary); background-color: var(--color-background); color: var(--color-primary); transition: background-color 0.2s ease, border-color 0.2s ease; box-shadow: var(--xy-node-boxshadow-default); cursor: pointer; } .xy-theme__button.active { background-color: var(--color-primary); color: white; border-color: var(--color-primary); } .xy-theme__button.active:hover, .xy-theme__button.active:active { background-color: var(--color-primary); opacity: 0.9; } .xy-theme__button:hover { background-color: var(--xy-controls-button-background-color-hover-default); } .xy-theme__button:active { background-color: var(--color-hover-bg); } .xy-theme__button:disabled { color: var(--color-disabled); opacity: 0.8; cursor: not-allowed; border: 1px solid var(--color-disabled); } .xy-theme__button > span { margin-right: 0.2rem; } /* Add gap between adjacent buttons */ .xy-theme__button + .xy-theme__button { margin-left: 0.3rem; } /* Example Input Styling */ .xy-theme__input { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 7px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); } .xy-theme__input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Specific Checkbox Styling */ .xy-theme__checkbox { appearance: none; -webkit-appearance: none; width: 1.25rem; height: 1.25rem; border-radius: 7px; border: 2px solid var(--color-primary); background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; cursor: pointer; display: inline-block; vertical-align: middle; margin-right: 0.5rem; } .xy-theme__checkbox:checked { background-color: var(--color-primary); border-color: var(--color-primary); } .xy-theme__checkbox:focus { outline: none; box-shadow: 0 0 0 2px var(--color-primary-focus); } /* Dropdown Styling */ .xy-theme__select { padding: 0.5rem 0.75rem; border: 1px solid var(--color-primary); border-radius: 50px; background-color: var(--color-background); transition: background-color 0.2s ease, border-color 0.2s ease; font-size: 1rem; color: var(--xy-theme-panel-text); margin-right: 0.5rem; box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-focus); } .xy-theme__label { margin-top: 10px; margin-bottom: 3px; display: inline-block; color: var(--xy-theme-panel-text); } /* Range Slider Styling */ .xy-theme__input[type='range'], .xy-theme__range { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 0.5rem; padding: 0; border: none; border-radius: 100px; background: transparent; cursor: pointer; } .xy-theme__input[type='range']:focus, .xy-theme__range:focus { outline: none; box-shadow: none; } .xy-theme__input[type='range']::-webkit-slider-runnable-track, .xy-theme__range::-webkit-slider-runnable-track { width: 100%; height: 0.5rem; border-radius: 100px; background: linear-gradient( to right, var(--color-primary-muted) 0%, var(--color-primary-muted) var(--range-progress, 0%), var(--color-hover-bg) var(--range-progress, 0%), var(--color-hover-bg) 100% ); } .xy-theme__input[type='range']::-webkit-slider-thumb, .xy-theme__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1.25rem; height: 1.25rem; margin-top: -0.375rem; border-radius: 50%; border: 2px solid var(--color-background); background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-track, .xy-theme__range::-moz-range-track { width: 100%; height: 0.5rem; border-radius: 100px; background: var(--color-hover-bg); } .xy-theme__input[type='range']::-moz-range-thumb, .xy-theme__range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border: none; border-radius: 50%; background: var(--color-primary); box-shadow: var(--xy-node-boxshadow-default); } .xy-theme__input[type='range']::-moz-range-progress, .xy-theme__range::-moz-range-progress { height: 0.5rem; border-radius: 100px 0 0 100px; background: var(--color-primary-muted); } ``` ##### index.css ```css @import url('./xy-extras.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ### Common Errors This guide lists the warnings and errors Vue Flow can emit, what triggers them, and how to fix them. We also collect common questions and pitfalls from our [Discord Server](https://discord.gg/RVmnytFmGW), [Github Issues](https://github.com/xyflow/xyflow/issues) and [Github Discussions](https://github.com/xyflow/xyflow/discussions). #### How Vue Flow reports errors Every error is a [`VueFlowError`](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/utils/errors.ts) with a `code` (an [`ErrorCode`](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/utils/errors.ts)), a human-readable `message`, and the `args` used to build it. In development Vue Flow logs these to the console (prefixed with `[Vue Flow]`); in production it stays quiet. To react to them yourself, for logging or a toast, listen to the `@error` event on ``. Narrow a specific one with `isErrorOfType` or by checking `error.code`: ```vue ``` One error is _thrown_ rather than emitted: [`USE_VUE_FLOW_OUTSIDE_PROVIDER`](#USE_VUE_FLOW_OUTSIDE_PROVIDER). It never reaches the `@error` handler because there is no store to report through yet. #### Setup errors
### useVueFlow() was called without a provider **Code:** `USE_VUE_FLOW_OUTSIDE_PROVIDER` (thrown) `useVueFlow()` and `useVueFlowStore()` need a Vue Flow store. A store is created by ``, by a [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) call, or by a [``](/api-reference/vue-flow-provider). Calling them where none of those has provided one, or outside a component's `setup`, throws this error. This throws, because the store doesn't exist yet: ```vue ``` **Preferred:** call [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) instead of `useVueFlow()`. It creates the store, provides it to the subtree, and returns the same instance, so the `` below reuses it: ```vue ``` Or move the `useVueFlow()` call into a child rendered inside ``: ```vue filename="App.vue" ``` ```vue filename="FlowControls.vue" ``` Or wrap the tree in a [``](/api-reference/vue-flow-provider), the component form of `setupVueFlow()`, when several sibling components above `` need to share one store: ```vue filename="Wrapper.vue" ```
### It seems that you haven't loaded the necessary styles **Code:** `MISSING_STYLES` Vue Flow needs its stylesheet to position and render the graph. Import it once, near your app entry: ```ts import '@xyflow/vue/style.css'; ``` If you only want the minimum required rules and bring your own theme, import the base styles instead (`@xyflow/vue/base.css`). See [theming](/learn/customization/theming) for the difference.
### The Vue Flow parent container needs a width and a height **Code:** `MISSING_VIEWPORT_DIMENSIONS` Vue Flow measures its parent element to size the renderer. A wrapper with no height leaves nothing to render into. This has no height, so the graph never appears: ```vue ``` Give the wrapper a fixed or inherited size: ```vue ``` #### Node errors
### Node type is missing **Code:** `NODE_TYPE_MISSING` A node has a `type` with no matching component, so Vue Flow can't render it. The idiomatic fix is to register the type through a [`#node-` slot](/learn/customization/custom-nodes), where the slot name must match the node's `type` exactly: ```vue ``` You can also register components with the `nodeTypes` prop. The key has to match the node's `type` exactly (`custom`, not `Custom`): ```vue ```
### Node is invalid **Code:** `NODE_INVALID` A node object failed validation while Vue Flow was adding it to the store. Every node needs a unique string `id` and a `position`: ```ts const nodes = [{ id: 'n1', position: { x: 0, y: 0 }, data: {} }]; ```
### Node not found **Code:** `NODE_NOT_FOUND` You looked up a node `id` that isn't in the graph, for example with `useNode(id)` or an instance getter. It also fires when a handler runs after its node was removed, so read the node up front rather than inside a delayed callback.
### Node is missing a parent **Code:** `NODE_MISSING_PARENT` A node's `parentId` points to a node that doesn't exist, or that appears *after* the child in the array. List the parent before its children so it's in the lookup first: ```ts const nodes = [ { id: 'group', position: { x: 0, y: 0 }, data: {} }, { id: 'child', parentId: 'group', position: { x: 20, y: 20 }, data: {} }, ]; ```
### Node id is not unique **Code:** `NODE_DUPLICATE_ID` Two nodes share the same `id`, so the later one overwrites the earlier one in the internal lookup. Give every node a unique `id`. #### Edge errors
### An edge needs a source and a target **Code:** `EDGE_INVALID` An edge was created without a `source` or a `target`, so there's nothing to connect. Missing endpoints: ```ts const edges = [{ id: 'e1' }]; ``` Both endpoints set: ```ts const edges = [{ id: 'e1', source: 'n1', target: 'n2' }]; ```
### Edge source or target is missing **Codes:** `EDGE_SOURCE_MISSING`, `EDGE_TARGET_MISSING`, `EDGE_SOURCE_TARGET_MISSING` The edge's `source` and/or `target` references a node `id` that isn't in the graph. Make sure both nodes exist, and that the ids match exactly (they're case-sensitive).
### Edge type is missing **Code:** `EDGE_TYPE_MISSING` An edge has a `type` with no matching component. Register it through an [`#edge-` slot](/learn/customization/custom-edges) (the slot name matching the edge's `type`), or through the `edgeTypes` prop: ```vue ```
### Edge id is not unique **Code:** `EDGE_DUPLICATE_ID` Two edges share the same `id`, so the later one overwrites the earlier one. Give every edge a unique `id`.
### Edge not found **Code:** `EDGE_NOT_FOUND` You referenced an edge that isn't in the state, most often when [reconnecting an edge](/examples/edges/reconnect-edge) that was already removed, or in a click/selection handler that runs after the edge was deleted. Read the edge before the async gap that might remove it. #### Composable errors
### useNodeConnections: No node ID found **Code:** `NODE_CONNECTIONS_MISSING_ID` [`useNodeConnections`](/api-reference/composables/use-node-connections) reads the current node from context. Call it inside a custom node, or pass an explicit `id`: ```ts const connections = useNodeConnections({ id: 'n1' }); ``` #### Other common issues ##### Mouse events aren't working consistently when my nodes contain a `` element If you use a `` inside a custom node, you might get incorrect coordinates in mouse events from the canvas. Vue Flow uses CSS transforms to scale nodes as you zoom, but from the DOM's perspective the element keeps its original size. That mismatch throws off any listener that computes the mouse position relative to the canvas. In handlers you control, scale your computed relative position by `1 / zoom`, where `zoom` is the current zoom level. Read it with `getZoom` from [`useVueFlow`](/api-reference/composables/use-vue-flow). ##### Edges are not displaying If your edges don't show up, check the following: * You imported the stylesheet (`import '@xyflow/vue/style.css';`). * If you replaced the default node with a custom node, make sure it renders `source`/`target` [handles](/api-reference/components/handle). An edge can't attach without a handle. * If you use a styling library like Tailwind, make sure it doesn't override the edge styles. Some libraries set `overflow: hidden` on the `.vue-flow__edges` SVG selector, which hides the edges. * After an async operation (like a backend request) that changes handles, call `updateNodeInternals` from [`useVueFlow`](/api-reference/composables/use-vue-flow) so Vue Flow re-measures the handle positions. ##### Edges are not displaying correctly If your edges render but look wrong: * To hide handles, use `opacity: 0` or `visibility: hidden`, not `display: none`. * If an edge connects to the wrong handle, check for more than one handle of the same type (`source` or `target`) on the node. Give same-type handles distinct `id`s so Vue Flow knows which one an edge belongs to. * If you move handles around (reordering and such), call `updateNodeInternals` from [`useVueFlow`](/api-reference/composables/use-vue-flow) afterwards so Vue Flow re-measures them. * In a custom edge, pass the `sourceX`, `sourceY`, `targetX`, and `targetY` props into your path function (for example [`getBezierPath`](/api-reference/utils/get-bezier-path)). Those are the coordinates of the source and target handles. * If an edge enters or exits a handle at an odd angle, also pass the `sourcePosition` and `targetPosition` props into the path function so it starts and ends against the handle correctly. ### Migrate to v2 ### Migrate to Vue Flow 2 If you are looking for the Vue Flow 1.x docs, please refer to [v1.vueflow.dev](https://v1.vueflow.dev). We are excited to welcome Vue Flow to the xyflow family! Vue Flow now lives next to React Flow and Svelte Flow in the [xyflow repository](https://github.com/xyflow/xyflow), is maintained by the xyflow team and is published as [`@xyflow/vue`](https://www.npmjs.com/package/@xyflow/vue). Vue developers get the same features, fixes and docs as the other two libraries, and every improvement to the shared core benefits all three. Vue Flow 2 rebuilds the core on top of [`@xyflow/system`](https://github.com/xyflow/xyflow) β€” the framework-agnostic engine that also powers React Flow and Svelte Flow. The payoff is a smaller, faster, and far more consistent API: the same node/edge model, the same accessor names, and the same store shape across the three libraries. For a full list of changes, see the [release notes](https://github.com/xyflow/xyflow/releases). That alignment means **breaking changes**. This guide walks through them, grouped by theme, with before/after for each. If you just want the lookup tables, jump to the [cheat sheet](#cheat-sheet). > Most apps are touched by **Β§1 (one package)**, **Β§2 (binding)**, **Β§3 (changesets)** and **Β§4 (immutability)** β€” start there. **Overview of the changes:** 1. [One package](#1-one-package-xyflowvue): `@vue-flow/*` packages are replaced by `@xyflow/vue`. 2. [Binding nodes & edges](#2-binding-nodes--edges): `v-model="elements"` is gone and the binding decides how changes are handled. 3. [Changesets](#3-changes-are-a-changeset-not-an-array): change events receive a `NodeChangeset`/`EdgeChangeset` instead of an array. 4. [Immutability](#4-nodes-and-edges-are-immutable): in-place mutations of nodes and edges are no longer tracked. 5. [Node shape](#5-the-node-shape-node-vs-internalnode): user `Node`s are split from `InternalNode`s. 6. [Edge shape](#6-the-edge-shape-no-more-graphedge): `GraphEdge` is gone, edges are stored as plain `Edge` objects. 7. [Store split](#7-the-store-split-usevueflow--usevueflowstore): state moved from `useVueFlow` to `useVueFlowStore`. 8. [Provider model](#8-no-global-registry--the-provider-model): no global registry, `useVueFlow()` takes no arguments. 9. [API renames](#9-api-renames): accessors, reconnect APIs, event payloads and `paneDragThreshold`. 10. [`connectionMode`](#10-connectionmode-defaults-to-strict) defaults to `strict`. 11. [Init, fit & viewport](#11-init--fit-props--defaults): `fitView` props, new defaults, pixel padding and interrupted animations. 12. [Deleting elements](#12-deleting-elements): `removeNodes` removes connected edges, new `onBeforeDelete`. 13. [Removed deprecated APIs](#13-removed-deprecated-apis). 14. [Types & change shapes](#14-types--change-shapes). 15. [Styles & CSS variables](#15-styles--css-variables): new stylesheets, `--xy-*` variables, a CSS layer and renamed classes. 16. [`selectionOnDrag`](#16-selectionondrag-replaces-selection-key-codetrue) replaces `:selection-key-code="true"`. Curious about what else is new? **Check out the [new features](#new-features)**. #### 1. One package: `@xyflow/vue` Vue Flow 2.0 is published under a new name β€” **`@xyflow/vue`** β€” and that single package ships every built-in: [`Background`](/api-reference/components/background), [`Controls`](/api-reference/components/controls), [`MiniMap`](/api-reference/components/minimap), [`NodeToolbar`](/api-reference/components/node-toolbar), [`NodeResizer`](/api-reference/components/node-resizer)/[`NodeResizeControl`](/api-reference/components/node-resize-control). The `@vue-flow/core` package and the separate `@vue-flow/node-resizer`, `@vue-flow/node-toolbar`, `@vue-flow/background`, `@vue-flow/controls`, and `@vue-flow/minimap` add-ons are all replaced by it. ```ts // before import { VueFlow } from '@vue-flow/core'; import { NodeResizer } from '@vue-flow/node-resizer'; import { NodeToolbar } from '@vue-flow/node-toolbar'; import '@vue-flow/core/dist/style.css'; import '@vue-flow/node-resizer/dist/style.css'; // after β€” everything from one package import { NodeResizer, NodeToolbar, VueFlow } from '@xyflow/vue'; import '@xyflow/vue/style.css'; // ships the resize-control styles too ``` Uninstall the `@vue-flow/*` packages and install `@xyflow/vue`, then bump the peers: Vue Flow 2.0 requires **Vue `>=3.5.27`** (it uses `useId()`, and 3.5.27 is the first release whose SFC compiler resolves the component prop types) and **`@vueuse/core` v14**. ```bash npm2yarn npm uninstall @vue-flow/core @vue-flow/background @vue-flow/controls @vue-flow/minimap @vue-flow/node-resizer @vue-flow/node-toolbar npm install @xyflow/vue@latest ``` The IIFE / browser-global build (`vue-flow-core.iife.js`) is no longer shipped. If you load Vue Flow from a CDN, use the ESM build instead (for example via esm.sh). #### 2. Binding nodes & edges The combined `v-model="elements"` (and the whole mixed-elements API) is **removed**. Nodes and edges are separate. ```vue ``` The element-bucket actions are gone too β€” use the node/edge equivalents: | Removed | Use | | ------------------------------------- | ----------------------------------------------------------------- | | `setElements(...)` | `setNodes(...)` + `setEdges(...)` | | `addSelectedElements(...)` | `addSelectedNodes(...)` / `addSelectedEdges(...)` | | `getElements` / `getSelectedElements` | `getNodes` / `getEdges` / `getSelectedNodes` / `getSelectedEdges` | ##### The binding decides how changes are handled The `applyDefault` prop is **removed** β€” the binding you choose now determines this: * `v-model:nodes` / `v-model:edges` (or **no binding at all**, when driving the flow through [`useVueFlow()`](/api-reference/composables/use-vue-flow) / [`setupVueFlow()`](/api-reference/composables/setup-vue-flow)) is **managed**: Vue Flow applies changes (drag, select, remove) to its store and mirrors them back to your ref. * A bare one-way `:nodes` / `:edges` is **controlled**: changes are delivered via `@nodes-change` / `@edges-change` and nothing is applied until you handle them. What those events hand you changed in 2.0, see [Changes are a changeset, not an array](#3-changes-are-a-changeset-not-an-array). ```vue ``` #### 3. Changes are a changeset, not an array `@nodes-change` / `@edges-change` β€” and the `onNodesChange` / `onEdgesChange` hooks β€” used to hand you a `NodeChange[]` / `EdgeChange[]`, which you applied with the standalone `applyNodeChanges` / `applyEdgeChanges` helpers (both now removed). They now hand you a **changeset**: a [`NodeChangeset`](/api-reference/types/node-changeset) or [`EdgeChangeset`](/api-reference/types/edge-changeset) that carries the changes queued for that update and knows how to apply them. This only concerns you if you run a **controlled** flow (a one-way `:nodes` / `:edges` binding) or listen to the change events yourself. With `v-model` Vue Flow applies the changeset for you. ##### Applying changes Call `applyTo` with your current array; it returns the next one. ```ts // before import { applyEdgeChanges, applyNodeChanges } from '@vue-flow/core'; function onNodesChange(changes: NodeChange[]) { nodes.value = applyNodeChanges(changes, nodes.value); } function onEdgesChange(changes: EdgeChange[]) { edges.value = applyEdgeChanges(changes, edges.value); } ``` ```ts // now import type { Edge, EdgeChangeset, Node, NodeChangeset } from '@xyflow/vue'; function onNodesChange(changes: NodeChangeset) { nodes.value = changes.applyTo(nodes.value); } function onEdgesChange(changes: EdgeChangeset) { edges.value = changes.applyTo(edges.value); } ``` ##### Reading changes A changeset is iterable, and it can hand you changes by type or by element β€” so you no longer scan an array to find out what happened. ```ts // before if (changes.some((change) => change.type === 'remove')) { saveUndoSnapshot(); } // now if (changes.getByType('remove').length > 0) { saveUndoSnapshot(); } ``` ```ts for (const change of changes) { console.log(change.type, change.id); } changes.toArray(); // every queued change, as a flat array changes.getForNode('node-1'); // everything queued for one node (getForEdge on an EdgeChangeset) changes.size; // how many elements the changeset touches ``` ##### Editing a changeset before applying it Because it's a real object rather than an array you rebuild, you can drop or add changes before applying β€” useful for vetoing part of an update. ```ts function onNodesChange(changes: NodeChangeset) { // ignore anything that would move or delete the locked node changes.removeForNode('locked-node'); nodes.value = changes.applyTo(nodes.value); } ``` `add(change)` queues a change and `remove(change)` drops one by reference. You can also build a changeset from scratch β€” handy in tests, or in a helper that transforms changes before handing them back: ```ts import { NodeChangeset } from '@xyflow/vue'; const changes = new NodeChangeset([{ id: 'node-1', type: 'select', selected: true }]); nodes.value = changes.applyTo(nodes.value); ``` ##### What happened to `applyNodeChanges` / `applyEdgeChanges` Both are **removed**, along with `applyChanges` β€” and so are the `applyNodeChanges`/`applyEdgeChanges` methods that `useVueFlow()` used to return. Use `changes.applyTo(...)` as shown [above](#applying-changes). The individual change shapes were renamed in the same release (`NodePositionChange` β†’ `PositionChange`, and so on) β€” see [Types & change shapes](#14-types--change-shapes). #### 4. Nodes and edges are immutable This is the most important behavioral change. To skip deep-reactifying every node and edge (a big perf win on large graphs), Vue Flow no longer tracks **in-place mutations** of the objects you pass in. ```ts // ❌ no longer triggers a re-render const node = getNode('1'); node.position = { x: 10, y: 10 }; node.data.label = 'changed'; node.selected = true; edge.animated = !edge.animated; ``` Update through the [`useVueFlow()`](/api-reference/composables/use-vue-flow) helpers, or reassign your `v-model` array immutably: ```ts const { updateNode, updateNodeData, updateEdge, updateEdgeData, setNodes, setEdges } = useVueFlow(); updateNode('1', { position: { x: 10, y: 10 } }); updateNodeData('1', { label: 'changed' }); updateEdge('e1-2', { animated: true }); // or immutable reassignment of the bound array nodes.value = nodes.value.map((n) => (n.id === '1' ? { ...n, selected: true } : n)); ``` Two related changes: * **Node defaults are no longer stamped.** A node passed without `data` keeps `data: undefined` (was `{}`); `selected`/`dragging` stay `undefined` until set. Guard optional reads: `node.data?.label`. * **`getNodes`/`getEdges`/`getSelectedNodes`/`getSelectedEdges` return `readonly` arrays.** `.filter`/`.map` work fine; reassign/`push` is a type error β€” change membership via `setNodes`/`addNodes`/etc. #### 5. The node shape: `Node` vs `InternalNode` Your nodes array (`v-model:nodes`, `store.nodes`, `getNodes()`, `getNode(id)`) now returns the **raw `Node`s you passed in** β€” no store-computed fields. The enriched node (absolute position, z-index, measured size, handle bounds) is the [`InternalNode`](/api-reference/types/internal-node), kept in `nodeLookup` and reached via new accessors: ```ts const { getInternalNode } = useVueFlow(); const internal = getInternalNode('1'); // InternalNode internal.internals.positionAbsolute; internal.measured; // { width, height } // or as a composable (re-resolves reactively) import { useInternalNode } from '@xyflow/vue'; const node = useInternalNode('1'); ``` Field moves on the node: | Before (top-level) | After | | ------------------------ | -------------------------------------------------------- | | `node.parentNode` | `node.parentId` | | `node.computedPosition` | `node.internals.positionAbsolute` (+ `node.internals.z`) | | `node.dimensions` | `node.measured` | | `node.handleBounds` | `node.internals.handleBounds` | | `node.isParent` | `parentLookup.get(node.id)?.size > 0` | | `node.label` (top-level) | `node.data.label` | [`useNode`](/api-reference/composables/use-node) now returns the user-facing **[`Node`](/api-reference/types/node)** (it used to return the enriched `InternalNode`) β€” reach for [`useInternalNode`](/api-reference/composables/use-internal-node) when you need `internals`/`measured`. Its `id` argument also accepts a ref or getter. > Custom node components are unaffected β€” they still receive `position`, dimensions, etc. through their > props. But **node event payloads now carry the user `Node`, not the `InternalNode`** β€” > `onNodeClick`, `onNodeDrag*`, the minimap node events, `nodesInitialized`, etc. emit your raw node. If a > handler read store-computed fields off the event node, resolve the enriched node by id: > `getInternalNode(node.id)`. #### 6. The edge shape: no more `GraphEdge` Edges are stored verbatim as your plain `Edge` objects β€” there is no enriched edge representation. * **`GraphEdge` and `isGraphEdge` are removed** β€” use [`Edge`](/api-reference/types/edge). * `edge.sourceNode` / `edge.targetNode` / `edge.sourceX` no longer exist. In a custom edge, resolve nodes with `useInternalNode(() => props.source)` and read positions straight off `EdgeProps` (`sourceX`, `sourceY`, …). * **[`EdgeProps`](/api-reference/types/edge-props)** drops `sourceNode`/`targetNode`, exposes handles as `sourceHandleId`/`targetHandleId`, gains `selectable`/`deletable`, and makes `type`/`data` optional. * [`useEdge`](/api-reference/composables/use-edge)`().edge` is now a `ComputedRef`. * The per-edge **`template` option (`edge.template`) is removed** β€” use edge slots (`#edge-`) or map an edge `type` to a component via the [`edgeTypes`](/api-reference/vue-flow#edgetypes) prop. * **Auto-generated edge IDs use the `xy-edge__` prefix** (was `vueflow__edge-`), matching React Flow and Svelte Flow β€” this only affects edges created without an explicit `id`. Update any CSS/selectors or persisted references that matched `vueflow__edge-`. * **`setEdges`/`addEdges` keep edges whose source/target node isn't in the store yet** (the edge simply isn't drawn until both nodes exist, emitting the `EDGE_SOURCE_MISSING`/`EDGE_TARGET_MISSING` dev warning). The order of `setNodes` vs `setEdges` no longer matters. #### 7. The store split: `useVueFlow` + `useVueFlowStore` [`useVueFlow()`](/api-reference/composables/use-vue-flow) is now the curated **instance** β€” actions, computed getters, and event hooks. The raw reactive state moved to [`useVueFlowStore()`](/api-reference/composables/use-vue-flow-store), with [`storeToRefs()`](/api-reference/composables/store-to-refs) as the Pinia-style destructure bridge. ```ts // before β€” everything off useVueFlow() const { nodes, transform, nodeLookup, setViewport, onConnect } = useVueFlow(); // after const { setViewport, onConnect, getNodes } = useVueFlow(); // actions + getters + hooks const { nodes, transform } = storeToRefs(useVueFlowStore()); // value-type state β†’ refs const { nodeLookup } = useVueFlowStore(); // reactive-Map lookups (no .value) ``` > **Inside a component (incl. custom nodes/edges), prefer reading the store directly** β€” > `const store = useVueFlowStore()` then `store.transform`, `store.nodesDraggable`, … . Reads inside a > computed/render track reactively without `.value`, and you skip re-projecting the whole state into refs > on every instance. | Before | After | | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------- | | `const { nodes } = useVueFlow()` | `const { nodes } = storeToRefs(useVueFlowStore())` | | `const { transform, dimensions, nodesDraggable } = useVueFlow()` | `const { transform, dimensions, nodesDraggable } = storeToRefs(useVueFlowStore())` | | `const { nodeLookup } = useVueFlow()` | `const { nodeLookup } = useVueFlowStore()` | | `const { setViewport, getNodes, onConnect } = useVueFlow()` | unchanged | There is intentionally **no `useStoreApi`** β€” Vue's reactivity makes it redundant (`useVueFlowStore()` serves both reactive reads and current-value reads; subscribe with `watch(() => store.x, …)`). The ongoing connection is also consolidated: the separate `connectionStartHandle`, `connectionEndHandle`, `connectionPosition`, and `connectionStatus` store fields are replaced by a single `connection` object ([`ConnectionState`](/api-reference/types/connection-state)). Read `connection.fromHandle`, `connection.toHandle`, `connection.pointer`, and `connection.isValid` β€” matching [`useConnection()`](/api-reference/composables/use-connection). #### 8. No global registry β€” the provider model `useVueFlow()` no longer takes any argument; it's a pure consumer that returns the store from the nearest [``](/api-reference/vue-flow) / [``](/api-reference/vue-flow-provider) ancestor (and throws if there isn't one). The global flow registry and the `$vueFlowStorage` singleton are gone. ```ts // before const { ... } = useVueFlow({ nodes, edges, id: 'my-flow' }); const { ... } = useVueFlow('my-flow'); // reach a flow from outside // after β€” pass options as props, consume with no args from any descendant const { ... } = useVueFlow(); ``` Multiple flows on a page each get their own `` (or ``) tree β€” they no longer share a registry, so they can't collide and don't need distinct ids. `` accepts the same options as `setupVueFlow()` to **seed** its store β€” pass `nodes`, `edges`, or any other `VueFlowProps` and they become the store's initial values (read once at creation): ```vue ``` When you own the component that renders ``, prefer [`setupVueFlow()`](/api-reference/composables/setup-vue-flow), the composable form that provides (and seeds) the store from the same ` ``` ### Mind Map App In this tutorial we build a mind-map app: an editable root node you can branch from by dragging onto the pane, where each new node becomes a child of the one you dragged from. We'll start from an empty canvas and build up to the finished app. #### Getting started Start with a bare `` plus [`Controls`](/api-reference/components/controls) and a [`Panel`](/api-reference/components/panel) for the title: ```vue filename="App.vue" ``` Example: tutorials/mindmap/getting-started ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Mind Map
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### A store for nodes and edges The React version of this tutorial adds Zustand here. Vue Flow already ships a store, so instead we call [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) and bind `nodes`/`edges` with `v-model` β€” Vue Flow applies drags, connections, and removals for us. We also set `node-origin` to `[0.5, 0.5]` so a node's position refers to its center (which keeps the map tidy as it grows), and style the connection line to match the custom edge we'll add next. ```vue filename="App.vue" ``` Example: tutorials/mindmap/store-nodes-edges ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Mind Map
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` #### Custom nodes and edges A mind-map node is just an editable label between two handles. Register it with a `#node-mindmap` slot, and give it a matching custom edge β€” a straight line via [`getStraightPath`](/api-reference/utils/get-straight-path). Every edge gets the `mindmap` type through `default-edge-options`. ```vue filename="MindMapNode.vue" ``` ```vue filename="MindMapEdge.vue" ``` Example: tutorials/mindmap/custom-nodes-edges ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type MindMapNode = Node<{ label: string }, 'mindmap'>; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Mind Map
``` ##### index.css ```css html, body { margin: 0; height: 100%; background: #f8f8f8; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } .vue-flow__node-mindmap { background: #f6ad55; border-radius: 2px; border: 1px solid transparent; padding: 2px 5px; font-weight: 700; } .vue-flow__node-mindmap input { border: none; padding: 0 2px; border-radius: 1px; font-weight: 700; background: transparent; color: #222; } ``` ##### MindMapNode.vue ```vue ``` ##### MindMapEdge.vue ```vue ``` ##### App.vue ```vue ``` #### New nodes When you drag from a node and drop on the pane, `@connect-end` fires with a `connectionState`. If the connection wasn't dropped on a handle (`!connectionState.isValid`), we create a child of the node the drag started from and wire an edge to it. Giving the child a `parentId` positions it relative to its parent β€” so we subtract the parent's absolute position (from [`getInternalNode`](/api-reference/composables/use-vue-flow)) from the drop point. ```ts filename="App.vue" const { screenToFlowPosition, addNodes, addEdges, getInternalNode } = setupVueFlow(); let count = 0; function onConnectEnd({ event, connectionState }: ConnectEndEvent) { if (connectionState.isValid) { return; } const parent = connectionState.fromNode; const internal = parent && getInternalNode(parent.id); if (!parent || !internal) { return; } const { clientX, clientY } = 'changedTouches' in event ? event.changedTouches[0] : event; const pane = screenToFlowPosition({ x: clientX, y: clientY }); const { x, y } = internal.internals.positionAbsolute; const id = `node-${(count += 1)}`; addNodes([{ id, type: 'mindmap', data: { label: 'New Node' }, position: { x: pane.x - x, y: pane.y - y }, parentId: parent.id, }]); addEdges([{ id: `e-${parent.id}-${id}`, source: parent.id, target: id }]); } ``` ##### Keeping data in sync The label is an `` β€” editing it should update the graph, so the node writes changes straight back with [`updateNodeData`](/api-reference/composables/use-vue-flow): ```vue filename="MindMapNode.vue" ``` Example: tutorials/mindmap/create-nodes ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type MindMapNode = Node<{ label: string }, 'mindmap'>; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Mind Map
``` ##### index.css ```css html, body { margin: 0; height: 100%; background: #f8f8f8; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } .vue-flow__node-mindmap { background: #f6ad55; border-radius: 2px; border: 1px solid transparent; padding: 2px 5px; font-weight: 700; } .vue-flow__node-mindmap input { border: none; padding: 0 2px; border-radius: 1px; font-weight: 700; background: transparent; color: #222; } ``` ##### MindMapNode.vue ```vue ``` ##### MindMapEdge.vue ```vue ``` ##### App.vue ```vue ``` #### Simpler UX and nicer styling Dragging from a small handle is fiddly, so we make the **whole node** the source handle β€” a much bigger target to start a connection from. Style the source handle to fill the node and hide the target handle (Vue Flow still needs it to connect): ```css filename="index.css" .vue-flow__handle.source { top: 0; left: 0; transform: none; background: #f6ad55; height: 100%; width: 100%; border-radius: 2px; border: none; } .vue-flow__handle.target { top: 50%; pointer-events: none; opacity: 0; } ``` Now the handle covers the input, so we add a small drag handle to move the node and toggle `pointer-events` so the input is only editable once focused. Set `dragHandle: '.dragHandle'` on new nodes so only that grip moves them. To grow the input with its text and focus a freshly created node, add a template `ref` to the input, set its width in a `watchEffect` on `data.label`, and call `inputRef.value?.focus()` from `onMounted`. Example: tutorials/mindmap/node-as-handle ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type MindMapNode = Node<{ label: string }, 'mindmap'>; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Mind Map
``` ##### index.css ```css html, body { margin: 0; height: 100%; background: #f8f8f8; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .header { color: #cdcdcd; } .vue-flow__node-mindmap { background: #f6ad55; border-radius: 2px; border: 1px solid transparent; padding: 2px 5px; font-weight: 700; } /* the whole node is the source handle, so there's a big area to start a connection from */ .vue-flow__handle.source { top: 0; left: 0; transform: none; background: #f6ad55; height: 100%; width: 100%; border-radius: 2px; border: none; } /* the target handle stays for connecting but is hidden */ .vue-flow__handle.target { top: 50%; pointer-events: none; opacity: 0; } .inputWrapper { display: flex; height: 20px; position: relative; z-index: 1; pointer-events: none; } .dragHandle { background: transparent; width: 14px; height: 100%; margin-right: 4px; display: flex; align-items: center; pointer-events: all; } .input { border: none; padding: 0 2px; border-radius: 1px; font-weight: 700; background: transparent; height: 100%; color: #222; pointer-events: none; } .input:focus { border: none; outline: none; background: rgba(255, 255, 255, 0.25); pointer-events: all; } ``` ##### MindMapNode.vue ```vue ``` ##### MindMapEdge.vue ```vue ``` ##### App.vue ```vue ``` #### Final thoughts That's a working mind map. Seed it with a starter map by giving the initial nodes `parentId`s and edges, and you get the finished app: Example: tutorials/mindmap/app ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type MindMapNode = Node<{ label: string }, 'mindmap'>; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Mind Map
``` ##### index.css ```css html, body { margin: 0; height: 100%; background: #f8f8f8; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .header { color: #cdcdcd; } .vue-flow__node-mindmap { background: #f6ad55; border-radius: 2px; border: 1px solid transparent; padding: 2px 5px; font-weight: 700; } /* the whole node is the source handle, so there's a big area to start a connection from */ .vue-flow__handle.source { top: 0; left: 0; transform: none; background: #f6ad55; height: 100%; width: 100%; border-radius: 2px; border: none; } /* the target handle stays for connecting but is hidden */ .vue-flow__handle.target { top: 50%; pointer-events: none; opacity: 0; } .inputWrapper { display: flex; height: 20px; position: relative; z-index: 1; pointer-events: none; } .dragHandle { background: transparent; width: 14px; height: 100%; margin-right: 4px; display: flex; align-items: center; pointer-events: all; } .input { border: none; padding: 0 2px; border-radius: 1px; font-weight: 700; background: transparent; height: 100%; color: #222; pointer-events: none; } .input:focus { border: none; outline: none; background: rgba(255, 255, 255, 0.25); pointer-events: all; } ``` ##### MindMapNode.vue ```vue ``` ##### MindMapEdge.vue ```vue ``` ##### App.vue ```vue ``` From here you could add nodes by clicking the pane, or persist the graph with [save and restore](/examples/interaction/save-and-restore). ### Slideshow In this tutorial we turn Vue Flow into a slideshow: every slide is a node, the slides are laid out on a grid, and you move between them by clicking a slide, pressing an arrow on a slide, or using the keyboard. Navigation is just [`fitView`](/api-reference/composables/use-vue-flow) panning the viewport to the target slide. #### Setting up the project A slide is a custom node β€” an `
` sized to the slide dimensions. Register it with a `#node-slide` slot, and because the slides are large, set a low `min-zoom` so you can zoom out to see more than one at a time. ```vue filename="Slide.vue" ``` ```vue filename="App.vue" ``` Example: tutorials/slideshow/scaffold ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Slideshow
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } /* a slideshow reads best on a light canvas, like a projector screen */ .vue-flow { --xy-background-color: #f8f8f8; } /* the slide provides its own chrome, so reset the node wrapper */ .vue-flow__node-slide { padding: 0; border: none; background: transparent; } .slide { box-sizing: border-box; position: relative; overflow: hidden; padding: 6rem; padding-top: 10rem; padding-left: 8rem; font-size: 4rem; color: #111; background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 16px 64px 4px rgba(0, 0, 0, 0.06); } .slide h1 { font-size: 8rem; margin: 0 0 1rem; } .slide h2 { font-size: 6rem; margin: 0 0 1rem; } .slide p { margin: 0; } .slide code { background: #f0f0f0; padding: 0.1em 0.3em; border-radius: 0.3rem; } .slide__controls { position: absolute; right: 4rem; bottom: 4rem; display: flex; gap: 1rem; justify-content: flex-end; } .slide__controls button { font-size: 4rem; padding: 1rem 2rem; color: #111; background: #fff; border: 2px solid #000; border-radius: 1rem; cursor: pointer; } .slide__controls button:hover { background: #f8f8f8; } .slide__controls button:active { background: #e0e0e0; } ``` ##### Slide.vue ```vue ``` ##### App.vue ```vue ``` #### Rendering markdown We want slides authored in [Markdown](https://www.markdownguide.org/basic-syntax/), so store the source on the node's `data` and render it with [`markdown-it`](https://github.com/markdown-it/markdown-it): ```ts filename="slides.ts" import type { Node } from '@xyflow/vue'; import MarkdownIt from 'markdown-it'; export const SLIDE_WIDTH = 1920; export const SLIDE_HEIGHT = 1080; export type SlideData = { source: string }; export type SlideNode = Node; const md = new MarkdownIt(); export function renderMarkdown(source: string) { return md.render(source); } ``` ```vue filename="Slide.vue" ``` With `SlideData` in place we can hand-place a few slides by offsetting each one by `SLIDE_WIDTH`. Example: tutorials/slideshow/rendering-markdown ##### slides.ts ```ts import type { Node } from '@xyflow/vue'; import MarkdownIt from 'markdown-it'; export const SLIDE_WIDTH = 1920; export const SLIDE_HEIGHT = 1080; export type SlideData = { source: string }; export type SlideNode = Node; const md = new MarkdownIt(); export function renderMarkdown(source: string) { return md.render(source); } ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Slideshow
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } /* a slideshow reads best on a light canvas, like a projector screen */ .vue-flow { --xy-background-color: #f8f8f8; } /* the slide provides its own chrome, so reset the node wrapper */ .vue-flow__node-slide { padding: 0; border: none; background: transparent; } .slide { box-sizing: border-box; position: relative; overflow: hidden; padding: 6rem; padding-top: 10rem; padding-left: 8rem; font-size: 4rem; color: #111; background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 16px 64px 4px rgba(0, 0, 0, 0.06); } .slide h1 { font-size: 8rem; margin: 0 0 1rem; } .slide h2 { font-size: 6rem; margin: 0 0 1rem; } .slide p { margin: 0; } .slide code { background: #f0f0f0; padding: 0.1em 0.3em; border-radius: 0.3rem; } .slide__controls { position: absolute; right: 4rem; bottom: 4rem; display: flex; gap: 1rem; justify-content: flex-end; } .slide__controls button { font-size: 4rem; padding: 1rem 2rem; color: #111; background: #fff; border: 2px solid #000; border-radius: 1rem; cursor: pointer; } .slide__controls button:hover { background: #f8f8f8; } .slide__controls button:active { background: #e0e0e0; } ``` ##### Slide.vue ```vue ``` ##### App.vue ```vue ``` #### Laying out the nodes Placing slides by hand doesn't scale. Instead, describe each slide's neighbours (`left` / `right` / `up` / `down`) and compute the layout: start at `{ x: 0, y: 0 }`, then walk the connected slides, offsetting each by a slide-plus-padding in the linked direction and wiring an edge to it. ```ts filename="Flow.vue" function slidesToElements(slides: Record) { const offsets = { left: { x: -(SLIDE_WIDTH + SLIDE_PADDING), y: 0 }, right: { x: SLIDE_WIDTH + SLIDE_PADDING, y: 0 }, up: { x: 0, y: -(SLIDE_HEIGHT + SLIDE_PADDING) }, down: { x: 0, y: SLIDE_HEIGHT + SLIDE_PADDING }, } as const; const stack = [{ id: Object.keys(slides)[0], position: { x: 0, y: 0 } }]; const visited = new Set(); const nodes = []; const edges = []; while (stack.length) { const current = stack.pop()!; if (visited.has(current.id)) { continue; } visited.add(current.id); const data = slides[current.id]; nodes.push({ id: current.id, type: 'slide', position: current.position, data }); for (const dir of ['left', 'right', 'up', 'down'] as const) { const target = data?.[dir]; if (target && !visited.has(target)) { const offset = offsets[dir]; stack.push({ id: target, position: { x: current.position.x + offset.x, y: current.position.y + offset.y } }); edges.push({ id: `${current.id}->${target}`, source: current.id, target }); } } } return { nodes, edges }; } ``` This tiny algorithm has two known limitations: two slides can end up in the same spot, and slides unreachable from the start are skipped. Both are fine for a hand-authored deck. Edit the `slides` object in the demo below to see different layouts. Example: tutorials/slideshow/layout-demo ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Slideshow
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } .vue-flow { --xy-background-color: #f8f8f8; } /* the slide provides its own chrome, so reset the node wrapper */ .vue-flow__node-slide { padding: 0; border: none; background: transparent; } .slide { width: 100px; height: 100px; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid #e0e0e0; border-radius: 4px; } ``` ##### Flow\.vue ```vue ``` ##### App.vue ```vue ``` #### Navigating between slides Panning by hand isn't much of a presentation, so we add three ways to move around β€” all built on [`fitView`](/api-reference/composables/use-vue-flow), which pans and zooms the viewport to fit a set of nodes. `fitView` only needs an `id`, so we never have to look a node up ourselves. ##### Focus on click `` emits `@node-click` with the clicked node; fit the view to it: ```vue filename="App.vue" ``` [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) creates and provides the store, and returns the instance we pull `fitView` from. Example: tutorials/slideshow/focus-on-click ##### slides.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import MarkdownIt from 'markdown-it'; export const SLIDE_WIDTH = 1920; export const SLIDE_HEIGHT = 1080; // space between neighbouring slides so they don't sit edge-to-edge export const SLIDE_PADDING = 100; // `type` (not `interface`) so the data satisfies Node's `Record` constraint export type SlideData = { source: string; left?: string; up?: string; down?: string; right?: string; }; export type SlideNode = Node; const md = new MarkdownIt(); export function renderMarkdown(source: string) { return md.render(source); } export const slides: Record = { 0: { source: '# Vue Flow\n\nA slideshow built with Vue Flow.', right: '1', down: '2', }, 1: { source: '## Navigate\n\nUse the arrows on a slide, click a slide, or press the arrow keys.', left: '0', }, 2: { source: '## Layout\n\nSlides sit on a grid built from their `left` / `right` / `up` / `down` links.', up: '0', right: '3', }, 3: { source: '## The end\n\nThanks for watching! πŸ‘‹', left: '2' }, }; const offsets = { left: { x: -(SLIDE_WIDTH + SLIDE_PADDING), y: 0 }, right: { x: SLIDE_WIDTH + SLIDE_PADDING, y: 0 }, up: { x: 0, y: -(SLIDE_HEIGHT + SLIDE_PADDING) }, down: { x: 0, y: SLIDE_HEIGHT + SLIDE_PADDING }, } as const; // walk the connected slides, placing each on a grid and wiring an edge to it export function slidesToElements( initial: string, slidesMap: Record, ) { const stack = [{ id: initial, position: { x: 0, y: 0 } }]; const visited = new Set(); const nodes: SlideNode[] = []; const edges: Edge[] = []; while (stack.length) { const current = stack.pop()!; if (visited.has(current.id)) { continue; } visited.add(current.id); const data = slidesMap[current.id]; nodes.push({ id: current.id, type: 'slide', position: current.position, data, }); for (const dir of ['left', 'right', 'up', 'down'] as const) { const targetId = data[dir]; if (targetId && !visited.has(targetId)) { const offset = offsets[dir]; stack.push({ id: targetId, position: { x: current.position.x + offset.x, y: current.position.y + offset.y, }, }); edges.push({ id: `${current.id}->${targetId}`, source: current.id, target: targetId, }); } } } return { nodes, edges }; } ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Slideshow
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } /* a slideshow reads best on a light canvas, like a projector screen */ .vue-flow { --xy-background-color: #f8f8f8; } /* the slide provides its own chrome, so reset the node wrapper */ .vue-flow__node-slide { padding: 0; border: none; background: transparent; } .slide { box-sizing: border-box; position: relative; overflow: hidden; padding: 6rem; padding-top: 10rem; padding-left: 8rem; font-size: 4rem; color: #111; background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 16px 64px 4px rgba(0, 0, 0, 0.06); } .slide h1 { font-size: 8rem; margin: 0 0 1rem; } .slide h2 { font-size: 6rem; margin: 0 0 1rem; } .slide p { margin: 0; } .slide code { background: #f0f0f0; padding: 0.1em 0.3em; border-radius: 0.3rem; } .slide__controls { position: absolute; right: 4rem; bottom: 4rem; display: flex; gap: 1rem; justify-content: flex-end; } .slide__controls button { font-size: 4rem; padding: 1rem 2rem; color: #111; background: #fff; border: 2px solid #000; border-radius: 1rem; cursor: pointer; } .slide__controls button:hover { background: #f8f8f8; } .slide__controls button:active { background: #e0e0e0; } ``` ##### Slide.vue ```vue ``` ##### App.vue ```vue ``` ##### Slide controls Next, a button on each slide for every direction it connects to. The buttons live inside the node, so a click would bubble up and trigger `@node-click` too β€” stop it with `@click.stop`, and reach for `fitView` through [`useVueFlow()`](/api-reference/composables/use-vue-flow) right inside the slide: ```vue filename="Slide.vue" ``` The `nopan` class stops the canvas from panning while you interact with the buttons. Example: tutorials/slideshow/slide-controls ##### slides.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import MarkdownIt from 'markdown-it'; export const SLIDE_WIDTH = 1920; export const SLIDE_HEIGHT = 1080; // space between neighbouring slides so they don't sit edge-to-edge export const SLIDE_PADDING = 100; // `type` (not `interface`) so the data satisfies Node's `Record` constraint export type SlideData = { source: string; left?: string; up?: string; down?: string; right?: string; }; export type SlideNode = Node; const md = new MarkdownIt(); export function renderMarkdown(source: string) { return md.render(source); } export const slides: Record = { 0: { source: '# Vue Flow\n\nA slideshow built with Vue Flow.', right: '1', down: '2', }, 1: { source: '## Navigate\n\nUse the arrows on a slide, click a slide, or press the arrow keys.', left: '0', }, 2: { source: '## Layout\n\nSlides sit on a grid built from their `left` / `right` / `up` / `down` links.', up: '0', right: '3', }, 3: { source: '## The end\n\nThanks for watching! πŸ‘‹', left: '2' }, }; const offsets = { left: { x: -(SLIDE_WIDTH + SLIDE_PADDING), y: 0 }, right: { x: SLIDE_WIDTH + SLIDE_PADDING, y: 0 }, up: { x: 0, y: -(SLIDE_HEIGHT + SLIDE_PADDING) }, down: { x: 0, y: SLIDE_HEIGHT + SLIDE_PADDING }, } as const; // walk the connected slides, placing each on a grid and wiring an edge to it export function slidesToElements( initial: string, slidesMap: Record, ) { const stack = [{ id: initial, position: { x: 0, y: 0 } }]; const visited = new Set(); const nodes: SlideNode[] = []; const edges: Edge[] = []; while (stack.length) { const current = stack.pop()!; if (visited.has(current.id)) { continue; } visited.add(current.id); const data = slidesMap[current.id]; nodes.push({ id: current.id, type: 'slide', position: current.position, data, }); for (const dir of ['left', 'right', 'up', 'down'] as const) { const targetId = data[dir]; if (targetId && !visited.has(targetId)) { const offset = offsets[dir]; stack.push({ id: targetId, position: { x: current.position.x + offset.x, y: current.position.y + offset.y, }, }); edges.push({ id: `${current.id}->${targetId}`, source: current.id, target: targetId, }); } } } return { nodes, edges }; } ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Slideshow
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } /* a slideshow reads best on a light canvas, like a projector screen */ .vue-flow { --xy-background-color: #f8f8f8; } /* the slide provides its own chrome, so reset the node wrapper */ .vue-flow__node-slide { padding: 0; border: none; background: transparent; } .slide { box-sizing: border-box; position: relative; overflow: hidden; padding: 6rem; padding-top: 10rem; padding-left: 8rem; font-size: 4rem; color: #111; background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 16px 64px 4px rgba(0, 0, 0, 0.06); } .slide h1 { font-size: 8rem; margin: 0 0 1rem; } .slide h2 { font-size: 6rem; margin: 0 0 1rem; } .slide p { margin: 0; } .slide code { background: #f0f0f0; padding: 0.1em 0.3em; border-radius: 0.3rem; } .slide__controls { position: absolute; right: 4rem; bottom: 4rem; display: flex; gap: 1rem; justify-content: flex-end; } .slide__controls button { font-size: 4rem; padding: 1rem 2rem; color: #111; background: #fff; border: 2px solid #000; border-radius: 1rem; cursor: pointer; } .slide__controls button:hover { background: #f8f8f8; } .slide__controls button:active { background: #e0e0e0; } ``` ##### Slide.vue ```vue ``` ##### App.vue ```vue ``` ##### Keyboard navigation Finally, the arrow keys. [`useKeyPress`](/api-reference/composables/use-key-press) returns a ref that's `true` while its key is held; we watch each direction and move to the connected slide. Tracking `currentSlide` is what tells us where an arrow should lead, so we update it here and in the click handler (guarding it so clicking the current slide doesn't re-fit). We also set `:nodes-draggable="false"` β€” slides are for navigating, not dragging. ```ts filename="App.vue" const arrowKeys = { left: useKeyPress('ArrowLeft'), up: useKeyPress('ArrowUp'), down: useKeyPress('ArrowDown'), right: useKeyPress('ArrowRight'), }; const currentSlide = shallowRef(initialSlide); for (const dir of ['left', 'up', 'down', 'right'] as const) { watch(arrowKeys[dir], (pressed) => { if (!pressed) { return; } const target = slides[currentSlide.value][dir]; if (target) { goToSlide(target); } }); } function goToSlide(id: string) { currentSlide.value = id; fitView({ nodes: [{ id }], duration: 150 }); } function onNodeClick({ node }: NodeMouseEvent) { if (node.id !== currentSlide.value) { goToSlide(node.id); } } ``` Example: tutorials/slideshow/app ##### slides.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import MarkdownIt from 'markdown-it'; export const SLIDE_WIDTH = 1920; export const SLIDE_HEIGHT = 1080; // space between neighbouring slides so they don't sit edge-to-edge export const SLIDE_PADDING = 100; // `type` (not `interface`) so the data satisfies Node's `Record` constraint export type SlideData = { source: string; left?: string; up?: string; down?: string; right?: string; }; export type SlideNode = Node; const md = new MarkdownIt(); export function renderMarkdown(source: string) { return md.render(source); } export const slides: Record = { 0: { source: '# Vue Flow\n\nA slideshow built with Vue Flow.', right: '1', down: '2', }, 1: { source: '## Navigate\n\nUse the arrows on a slide, click a slide, or press the arrow keys.', left: '0', }, 2: { source: '## Layout\n\nSlides sit on a grid built from their `left` / `right` / `up` / `down` links.', up: '0', right: '3', }, 3: { source: '## The end\n\nThanks for watching! πŸ‘‹', left: '2' }, }; const offsets = { left: { x: -(SLIDE_WIDTH + SLIDE_PADDING), y: 0 }, right: { x: SLIDE_WIDTH + SLIDE_PADDING, y: 0 }, up: { x: 0, y: -(SLIDE_HEIGHT + SLIDE_PADDING) }, down: { x: 0, y: SLIDE_HEIGHT + SLIDE_PADDING }, } as const; // walk the connected slides, placing each on a grid and wiring an edge to it export function slidesToElements( initial: string, slidesMap: Record, ) { const stack = [{ id: initial, position: { x: 0, y: 0 } }]; const visited = new Set(); const nodes: SlideNode[] = []; const edges: Edge[] = []; while (stack.length) { const current = stack.pop()!; if (visited.has(current.id)) { continue; } visited.add(current.id); const data = slidesMap[current.id]; nodes.push({ id: current.id, type: 'slide', position: current.position, data, }); for (const dir of ['left', 'right', 'up', 'down'] as const) { const targetId = data[dir]; if (targetId && !visited.has(targetId)) { const offset = offsets[dir]; stack.push({ id: targetId, position: { x: current.position.x + offset.x, y: current.position.y + offset.y, }, }); edges.push({ id: `${current.id}->${targetId}`, source: current.id, target: targetId, }); } } } return { nodes, edges }; } ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Slideshow
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } /* a slideshow reads best on a light canvas, like a projector screen */ .vue-flow { --xy-background-color: #f8f8f8; } /* the slide provides its own chrome, so reset the node wrapper */ .vue-flow__node-slide { padding: 0; border: none; background: transparent; } .slide { box-sizing: border-box; position: relative; overflow: hidden; padding: 6rem; padding-top: 10rem; padding-left: 8rem; font-size: 4rem; color: #111; background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 16px 64px 4px rgba(0, 0, 0, 0.06); } .slide h1 { font-size: 8rem; margin: 0 0 1rem; } .slide h2 { font-size: 6rem; margin: 0 0 1rem; } .slide p { margin: 0; } .slide code { background: #f0f0f0; padding: 0.1em 0.3em; border-radius: 0.3rem; } .slide__controls { position: absolute; right: 4rem; bottom: 4rem; display: flex; gap: 1rem; justify-content: flex-end; } .slide__controls button { font-size: 4rem; padding: 1rem 2rem; color: #111; background: #fff; border: 2px solid #000; border-radius: 1rem; cursor: pointer; } .slide__controls button:hover { background: #f8f8f8; } .slide__controls button:active { background: #e0e0e0; } ``` ##### Slide.vue ```vue ``` ##### App.vue ```vue ``` #### Final thoughts That's a working slideshow: slides laid out on a grid, navigable by click, button, and keyboard. From here you could animate transitions differently, generate the deck from a folder of markdown files, or add a minimap for an overview. ### Web Audio In this tutorial we build a small modular synthesizer: an **Osc** node makes a tone, an **Amp** node controls its volume, and an **Out** node plays it through your speakers. Each Vue Flow node mirrors a node in a [Web Audio](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API) graph, and connecting them on the canvas connects the audio. #### The Web Audio API A quick tour of the parts we need: * The API gives you audio **nodes** β€” sources like an [`OscillatorNode`](https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode), effects like a [`GainNode`](https://developer.mozilla.org/en-US/docs/Web/API/GainNode), and the output [`AudioDestinationNode`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/destination). * You `connect` nodes together to form a signal graph. * An [`AudioContext`](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext) is the brain: it creates nodes and can suspend or resume playback. Everything runs on a separate audio thread, so it keeps making sound even when the UI is busy. ##### Hello, sound! Before any Vue Flow, let's make noise with a mouse theremin β€” the mouse's x position sets the pitch and its y position sets the volume. Create an `AudioContext`, wire an oscillator through a gain node to the speakers, and start it: ```vue filename="App.vue" ``` Two gotchas: oscillators must be `start()`-ed, and a context starts **suspended** (browsers block autoplay), so nothing plays until a user gesture resumes it β€” hence the toggle button. Note also `osc.frequency.value` / `amp.gain.value`: these are [`AudioParam`](https://developer.mozilla.org/en-US/docs/Web/API/AudioParam)s, set through `.value`, not plain properties. Example: tutorials/webaudio/mouse-theremin ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Web Audio
``` ##### index.css ```css html, body { margin: 0; height: 100%; background-color: #f8f8f8; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } main { height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; } button { padding: 15px 32px; font-size: 32px; background: none; border: none; cursor: pointer; } ``` ##### App.vue ```vue ``` #### Scaffolding a Vue Flow project Now the graph. Unlike the React version of this tutorial, we don't reach for a separate state library β€” Vue Flow already has a store. Keep your `nodes` and `edges` in a `shallowRef`, bind them with `v-model` (Vue Flow applies drags, selections, and removals for you), and add edges on `@connect` with the [`addEdge`](/api-reference/utils/add-edge) helper: ```vue filename="App.vue" ``` That's a fully interactive graph already β€” move the nodes, connect them, delete them. Example: tutorials/webaudio/state-management ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Web Audio
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ##### Custom nodes Plain labels won't cut it β€” each node needs its own controls. Register custom node types with `#node-` slots and give each an `` so it can be wired up. The **Osc** node has a frequency slider and a waveform picker; changes write straight back to the node's data with [`updateNodeData`](/api-reference/composables/use-vue-flow) (the graph stays the source of truth): ```vue filename="Osc.vue" ``` The node data types double as the audio-node config, and β€” since `Node` requires the data to satisfy `Record` β€” they're written as `type` aliases (an `interface` wouldn't): ```ts filename="nodes.ts" import type { Node } from '@xyflow/vue'; export type OscData = { frequency: number; type: OscillatorType }; export type AmpData = { gain: number }; export type OutData = Record; export type OscNode = Node; export type AmpNode = Node; export type OutNode = Node; export type SoundNode = OscNode | AmpNode | OutNode; ``` The **Amp** node is the same idea with a gain slider; **Out** is a target handle and a toggle button. There's no sound yet β€” the nodes only update the graph. Example: tutorials/webaudio/custom-nodes ##### nodes.ts ```ts import type { Node } from '@xyflow/vue'; // `type` (not `interface`) so the data satisfies Node's `Record` constraint β€” // a type alias for an object literal gets an implicit index signature, an interface does not export type OscData = { frequency: number; type: OscillatorType; }; export type AmpData = { gain: number; }; export type OutData = Record; export type OscNode = Node; export type AmpNode = Node; export type OutNode = Node; export type SoundNode = OscNode | AmpNode | OutNode; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Web Audio
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } .node { border-radius: 6px; background: #fff; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12); color: #111; font-size: 12px; } .node__title { margin: 0; padding: 4px 8px; border-radius: 6px 6px 0 0; color: #fff; font-size: 13px; } .osc__title { background: #ec4899; } .amp__title { background: #3b82f6; } .node__row { display: flex; flex-direction: column; padding: 4px 8px; } .node__row:last-of-type { padding-bottom: 12px; } .node__label { margin-bottom: 6px; font-weight: 700; } .node__value { text-align: right; } .node__divider { margin: 0 8px; border: none; border-top: 1px solid #eee; } .out { display: flex; justify-content: center; padding: 8px 16px; } .out__toggle { border: none; background: none; font-size: 18px; cursor: pointer; } .vue-flow__handle { width: 8px; height: 8px; } ``` ##### Out.vue ```vue ``` ##### Osc.vue ```vue ``` ##### App.vue ```vue ``` ##### Amp.vue ```vue ``` #### Doing sound to it Time to connect the visual graph to a real audio graph. That audio graph lives in a plain `audio.ts` module that has no idea Vue Flow exists β€” it holds the `AudioContext` and a `Map` of audio nodes keyed by id, and exposes functions to create, update, connect, and remove them: ```ts filename="audio.ts" const context = new AudioContext(); const nodes = new Map(); context.suspend(); nodes.set('output', context.destination); export function createAudioNode(id: string, type: 'osc' | 'amp', data: OscData | AmpData) { if (type === 'osc') { const node = context.createOscillator(); node.frequency.value = (data as OscData).frequency; node.type = (data as OscData).type; node.start(); nodes.set(id, node); } else { const node = context.createGain(); node.gain.value = (data as AmpData).gain; nodes.set(id, node); } } export function connect(sourceId: string, targetId: string) { nodes.get(sourceId)?.connect(nodes.get(targetId)!); } export function disconnect(sourceId: string, targetId: string) { nodes.get(sourceId)?.disconnect(nodes.get(targetId)!); } ``` ##### Node changes When a slider moves we need to update **both** graphs: the node's data (so the UI reflects it) and the matching audio node's parameter. Rather than repeat that in every node, extract it into a composable: ```ts filename="useUpdateNode.ts" import { useVueFlow } from '@xyflow/vue'; import { updateAudioNode } from './audio'; export function useUpdateNode() { const { updateNodeData } = useVueFlow(); return function updateNode(id: string, data: Record) { updateNodeData(id, data); updateAudioNode(id, data); }; } ``` `updateAudioNode` walks the changed fields and writes them back β€” through `.value` for `AudioParam`s like `frequency`/`gain`, directly for everything else (e.g. the oscillator's `type`). Now the nodes call `updateNode` instead of `updateNodeData`. ##### Edge changes Connections and deletions are where the audio graph gets wired and torn down. Every graph event has an audio side-effect: `@connect` adds the edge **and** connects the audio nodes; `@nodes-delete` and `@edges-delete` clean up. Because `v-model` already applies the visual changes, these handlers only keep the audio graph in sync: ```ts filename="App.vue" function onConnect(connection: Connection) { addEdges([connection]); connect(connection.source, connection.target); } function onNodesDelete(deleted: SoundNode[]) { for (const { id } of deleted) { removeAudioNode(id); } } function onEdgesDelete(deleted: Edge[]) { for (const { source, target } of deleted) { disconnect(source, target); } } ``` ##### Switching the speakers on The **Out** node owns the play/pause control. `audio.ts` exposes a reactive `isRunning` ref and a `toggleAudio` that resumes or suspends the context, so the node just reads and calls them: ```vue filename="Out.vue" ``` Here the audio nodes are hardcoded in `audio.ts` and matched to three seeded visual nodes β€” wire Osc β†’ Amp β†’ Out and hit the speaker to hear it. Example: tutorials/webaudio/hardcoded-audio ##### useUpdateNode.ts ```ts import { useVueFlow } from '@xyflow/vue'; import { updateAudioNode } from './audio'; // update a node's data on the graph and mirror the change into the audio graph export function useUpdateNode() { const { updateNodeData } = useVueFlow(); return function updateNode(id: string, data: Record) { updateNodeData(id, data); updateAudioNode(id, data); }; } ``` ##### nodes.ts ```ts import type { Node } from '@xyflow/vue'; // `type` (not `interface`) so the data satisfies Node's `Record` constraint β€” // a type alias for an object literal gets an implicit index signature, an interface does not export type OscData = { frequency: number; type: OscillatorType; }; export type AmpData = { gain: number; }; export type OutData = Record; export type OscNode = Node; export type AmpNode = Node; export type OutNode = Node; export type SoundNode = OscNode | AmpNode | OutNode; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Web Audio
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } .node { border-radius: 6px; background: #fff; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12); color: #111; font-size: 12px; } .node__title { margin: 0; padding: 4px 8px; border-radius: 6px 6px 0 0; color: #fff; font-size: 13px; } .osc__title { background: #ec4899; } .amp__title { background: #3b82f6; } .node__row { display: flex; flex-direction: column; padding: 4px 8px; } .node__row:last-of-type { padding-bottom: 12px; } .node__label { margin-bottom: 6px; font-weight: 700; } .node__value { text-align: right; } .node__divider { margin: 0 8px; border: none; border-top: 1px solid #eee; } .out { display: flex; justify-content: center; padding: 8px 16px; } .out__toggle { border: none; background: none; font-size: 18px; cursor: pointer; } .vue-flow__handle { width: 8px; height: 8px; } ``` ##### audio.ts ```ts import { shallowRef } from 'vue'; const context = new AudioContext(); const nodes = new Map(); // browsers start an AudioContext suspended until a user gesture resumes it context.suspend(); // hardcode the audio nodes up front; the visual nodes 'a' / 'b' / 'c' line up with these const osc = context.createOscillator(); osc.frequency.value = 220; osc.type = 'square'; osc.start(); const amp = context.createGain(); amp.gain.value = 0.5; nodes.set('a', osc); nodes.set('b', amp); nodes.set('c', context.destination); // reactive so the Out node can show whether sound is playing export const isRunning = shallowRef(context.state === 'running'); export async function toggleAudio() { await (isRunning.value ? context.suspend() : context.resume()); isRunning.value = context.state === 'running'; } export function updateAudioNode(id: string, data: Record) { const node = nodes.get(id) as unknown as Record | undefined; if (!node) { return; } for (const [key, value] of Object.entries(data)) { const target = node[key]; if (target instanceof AudioParam) { target.value = value as number; } else { node[key] = value; } } } export function removeAudioNode(id: string) { const node = nodes.get(id); if (!node) { return; } node.disconnect(); if ('stop' in node && typeof node.stop === 'function') { node.stop(); } nodes.delete(id); } export function connect(sourceId: string, targetId: string) { const source = nodes.get(sourceId); const target = nodes.get(targetId); if (source && target) { source.connect(target); } } export function disconnect(sourceId: string, targetId: string) { const source = nodes.get(sourceId); const target = nodes.get(targetId); if (source && target) { source.disconnect(target); } } ``` ##### Out.vue ```vue ``` ##### Osc.vue ```vue ``` ##### App.vue ```vue ``` ##### Amp.vue ```vue ``` ##### Creating new nodes Finally, make it a real instrument you build from scratch. Start with just the **Out** node and add oscillators and amps with a couple of [`Panel`](/api-reference/components/panel) buttons. Creating a node means creating its audio node **and** adding it to the graph via [`setupVueFlow`](/api-reference/composables/setup-vue-flow)'s `addNodes`: ```ts filename="App.vue" const { addNodes, addEdges } = setupVueFlow(); function createNode(type: 'osc' | 'amp') { const id = nanoid(); const data = type === 'osc' ? { frequency: 440, type: 'sine' as const } : { gain: 0.5 }; createAudioNode(id, type, data); addNodes([{ id, type, data, position: { x: 0, y: 0 } }]); } ``` Example: tutorials/webaudio/demo ##### useUpdateNode.ts ```ts import { useVueFlow } from '@xyflow/vue'; import { updateAudioNode } from './audio'; // update a node's data on the graph and mirror the change into the audio graph export function useUpdateNode() { const { updateNodeData } = useVueFlow(); return function updateNode(id: string, data: Record) { updateNodeData(id, data); updateAudioNode(id, data); }; } ``` ##### nodes.ts ```ts import type { Node } from '@xyflow/vue'; // `type` (not `interface`) so the data satisfies Node's `Record` constraint β€” // a type alias for an object literal gets an implicit index signature, an interface does not export type OscData = { frequency: number; type: OscillatorType; }; export type AmpData = { gain: number; }; export type OutData = Record; export type OscNode = Node; export type AmpNode = Node; export type OutNode = Node; export type SoundNode = OscNode | AmpNode | OutNode; ``` ##### index.ts ```ts import { createApp } from 'vue'; import App from './App.vue'; import './index.css'; createApp(App).mount('#app'); ``` ##### index.html ```html Vue Flow Web Audio
``` ##### index.css ```css html, body { margin: 0; height: 100%; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } .node { border-radius: 6px; background: #fff; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12); color: #111; font-size: 12px; } .node__title { margin: 0; padding: 4px 8px; border-radius: 6px 6px 0 0; color: #fff; font-size: 13px; } .osc__title { background: #ec4899; } .amp__title { background: #3b82f6; } .node__row { display: flex; flex-direction: column; padding: 4px 8px; } .node__row:last-of-type { padding-bottom: 12px; } .node__label { margin-bottom: 6px; font-weight: 700; } .node__value { text-align: right; } .node__divider { margin: 0 8px; border: none; border-top: 1px solid #eee; } .out { display: flex; justify-content: center; padding: 8px 16px; } .out__toggle { border: none; background: none; font-size: 18px; cursor: pointer; } .controls button { margin-left: 8px; padding: 4px 8px; border: none; border-radius: 4px; background: #fff; color: #111; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); cursor: pointer; } .vue-flow__handle { width: 8px; height: 8px; } ``` ##### audio.ts ```ts import type { AmpData, OscData } from './nodes'; import { shallowRef } from 'vue'; const context = new AudioContext(); const nodes = new Map(); // browsers start an AudioContext suspended until a user gesture resumes it context.suspend(); nodes.set('output', context.destination); // reactive so the Out node can show whether sound is playing export const isRunning = shallowRef(context.state === 'running'); export async function toggleAudio() { if (isRunning.value) { await context.suspend(); } else { await context.resume(); } isRunning.value = context.state === 'running'; } export function createAudioNode( id: string, type: 'osc' | 'amp', data: OscData | AmpData, ) { switch (type) { case 'osc': { const node = context.createOscillator(); node.frequency.value = (data as OscData).frequency; node.type = (data as OscData).type; node.start(); nodes.set(id, node); break; } case 'amp': { const node = context.createGain(); node.gain.value = (data as AmpData).gain; nodes.set(id, node); break; } } } export function updateAudioNode(id: string, data: Record) { const node = nodes.get(id) as unknown as Record | undefined; if (!node) { return; } for (const [key, value] of Object.entries(data)) { const target = node[key]; // frequency/gain are AudioParams, everything else (e.g. the oscillator type) is a plain field if (target instanceof AudioParam) { target.value = value as number; } else { node[key] = value; } } } export function removeAudioNode(id: string) { const node = nodes.get(id); if (!node) { return; } node.disconnect(); if ('stop' in node && typeof node.stop === 'function') { node.stop(); } nodes.delete(id); } export function connect(sourceId: string, targetId: string) { const source = nodes.get(sourceId); const target = nodes.get(targetId); if (source && target) { source.connect(target); } } export function disconnect(sourceId: string, targetId: string) { const source = nodes.get(sourceId); const target = nodes.get(targetId); if (source && target) { source.disconnect(target); } } ``` ##### Out.vue ```vue ``` ##### Osc.vue ```vue ``` ##### App.vue ```vue ``` ##### Amp.vue ```vue ``` #### Final thoughts That's a working modular synth. The pattern β€” a framework-agnostic module for the "real" work, Vue Flow's store for the graph, and event handlers that keep the two in sync β€” scales to all sorts of node-based tools: shader graphs, data pipelines, no-code builders. From here you could add more node types (a delay, a filter), or persist and restore patches with [save and restore](/examples/interaction/save-and-restore).