# 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). ## Examples ### Overview Browse our examples for practical copy-paste solutions to common use cases with Vue Flow. Here you can find our MIT Licensed examples, which you are free to use in your projects without restrictions, as well as our Pro examples that come with our Vue Flow Pro subscription plans. ### Feature Overview An overview of what's possible with Vue Flow, bringing together built-in node and edge types, [sub flows](/learn/layouting/sub-flows), the [``](/api-reference/components/node-toolbar) and [``](/api-reference/components/node-resizer) components, plus the [``](/api-reference/components/controls) and [``](/api-reference/components/minimap) at the bottom. Example: examples/misc/overview ##### types.ts ```ts import type { CSSProperties } from 'vue'; import type { BuiltInNode, Node, NodeProps } from '@xyflow/vue'; export type AnnotationNodeData = { level: number; label: string; arrowStyle?: CSSProperties; }; export type AnnotationNode = Node; export type AnnotationNodeProps = NodeProps; export type ResizerNodeData = { label: string; }; export type ResizerNode = Node; export type ResizerNodeProps = NodeProps; export type ToolbarNodeData = { label?: string; }; export type ToolbarNode = Node; export type ToolbarNodeProps = NodeProps; export type CircleNode = Node, 'circle'>; export type CircleNodeProps = NodeProps; export type TextInputNode = Node, 'textinput'>; export type TextInputNodeProps = NodeProps; export type OverviewNode = | AnnotationNode | BuiltInNode | ToolbarNode | ResizerNode | CircleNode | TextInputNode; ``` ##### initial-elements.ts ```ts import type { Edge } from '@xyflow/vue'; import type { OverviewNode } from './types'; import { MarkerType } from '@xyflow/vue'; export const nodes: OverviewNode[] = [ { id: 'annotation-1', type: 'annotation', draggable: false, selectable: false, data: { level: 1, label: 'Built-in node and edge types. Draggable, deletable and connectable!', arrowStyle: { right: 0, bottom: 0, transform: 'translate(-30px,10px) rotate(-80deg)', }, }, position: { x: -200, y: -30 }, }, { id: '1-1', type: 'input', data: { label: 'Input Node', }, position: { x: 150, y: 0 }, }, { id: '1-2', type: 'default', data: { label: 'Default Node', }, position: { x: 0, y: 100 }, }, { id: '1-3', type: 'output', data: { label: 'Output Node', }, position: { x: 300, y: 100 }, }, { id: 'annotation-2', type: 'annotation', draggable: false, selectable: false, data: { level: 2, label: 'Sub flows, toolbars and resizable nodes!', arrowStyle: { left: 0, bottom: 0, transform: 'translate(5px, 25px) scale(1, -1) rotate(100deg)', }, }, position: { x: 220, y: 200 }, }, { id: '2-1', type: 'group', data: {}, position: { x: -170, y: 250, }, width: 380, height: 180, }, { id: '2-2', data: {}, type: 'tools', position: { x: 50, y: 50 }, width: 80, height: 80, parentId: '2-1', extent: 'parent', }, { id: '2-3', type: 'resizer', data: { label: 'Resize Me', }, position: { x: 250, y: 50 }, width: 80, height: 80, parentId: '2-1', extent: 'parent', }, { id: 'annotation-3', type: 'annotation', draggable: false, selectable: false, data: { level: 3, label: 'Nodes and edges can be anything and are fully customizable!', arrowStyle: { right: 0, bottom: 0, transform: 'translate(-35px, 20px) rotate(-80deg)', }, }, position: { x: -40, y: 570 }, }, { id: '3-2', type: 'textinput', position: { x: 150, y: 650 }, data: {}, }, { id: '3-1', type: 'circle', position: { x: 350, y: 500 }, data: {}, }, ]; export const edges: Edge[] = [ { id: 'e1-2', source: '1-1', target: '1-2', label: 'edge', type: 'smoothstep', }, { id: 'e1-3', source: '1-1', target: '1-3', animated: true, label: 'animated edge', }, { id: 'e2-2', source: '1-2', target: '2-2', type: 'smoothstep', markerEnd: { type: MarkerType.ArrowClosed, }, }, { id: 'e2-3', source: '2-2', target: '2-3', type: 'smoothstep', markerEnd: { type: MarkerType.ArrowClosed, }, }, { id: 'e3-3', source: '2-3', sourceHandle: 'a', target: '3-2', type: 'button', animated: true, style: { stroke: 'rgb(158, 118, 255)' }, }, { id: 'e3-4', source: '2-3', sourceHandle: 'b', target: '3-1', type: 'button', }, ]; ``` ##### 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; } /* Circle Node */ .vue-flow__node-circle { border-radius: 50%; height: 100px; width: 100px; font-family: monospace; text-align: center; } /* Text Input Node */ .vue-flow__node-textinput { width: 150px; font-family: monospace; text-align: left; } .text-input-node__input { width: 100%; box-sizing: border-box; margin: 5px 0; } /* Annotation Node */ .vue-flow__node-annotation { font-size: 16px; width: 200px; color: #683bfa; position: absolute; box-shadow: none; font-family: monospace; text-align: left; background-color: transparent; border: none; } .vue-flow__node-annotation .annotation-content { padding: 10px; display: flex; } .vue-flow__node-annotation .annotation-level { margin-right: 4px; } .vue-flow__node-annotation .annotation-arrow { position: absolute; font-size: 24px; } /* Toolbar Node */ .vue-flow__node-toolbar { background-color: #000000; border-radius: 16px; overflow: hidden; } .vue-flow__node-toolbar button { cursor: pointer; background: inherit; border: none; padding: 5px 7px; margin: 3px; border-radius: 50%; box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__node-toolbar button:hover { background: #4d4d4d; } /* Resizer Node */ .resizer-node__handles { display: flex; position: absolute; bottom: 0; width: 100%; justify-content: space-evenly; left: 0; } .resizer-node__handle { position: relative; left: 0; transform: none; } /* Button Edge */ .button-edge__label { position: absolute; pointer-events: all; transform-origin: center; } .button-edge__button { width: 30px; height: 30px; border: 5px solid var(--xy-background-color); color: var(--xy-edge-node-color-default); background-color: var(--xy-theme-muted-bg); cursor: pointer; border-radius: 50%; font-size: 12px; padding-top: 0px; } .button-edge__button:hover { background-color: var(--xy-theme-hover); color: #ffffff; } /* Custom Handles */ .vue-flow__handle.custom-handle { background-color: var(--xy-handle-border-color-default); border-radius: 1px; width: 8px; height: 4px; border: none; min-width: 2px; min-height: 2px; } .vue-flow__handle.custom-handle:hover, .vue-flow__handle.custom-handle.connectionindicator:focus, .vue-flow__handle.custom-handle.connectingfrom, .vue-flow__handle.custom-handle.connectingto { background-color: var(--xy-theme-edge-hover); } .vue-flow__handle-bottom.custom-handle { bottom: -5px; transform: none; } .vue-flow__handle-top.custom-handle { top: -5px; transform: none; } .vue-flow__handle-left.custom-handle { height: 8px; width: 4px; left: -3px; } /* Minimap */ .vue-flow__minimap .group { fill-opacity: 0.4; } .vue-flow__minimap .resizer, .vue-flow__minimap .tools, .vue-flow__minimap .circle, .vue-flow__minimap .textinput { fill: rgb(208, 192, 247); } .vue-flow__minimap .circle { rx: 100%; ry: 100%; } .vue-flow__minimap .annotation { display: none; } ``` ##### ToolbarNode.vue ```vue ``` ##### TextInputNode.vue ```vue ``` ##### ResizerNode.vue ```vue ``` ##### CircleNode.vue ```vue ``` ##### ButtonEdge.vue ```vue ``` ##### App.vue ```vue ``` ##### AnnotationNode.vue ```vue ``` ### Pro Examples Here you can find all the advanced Vue Flow Pro examples to use in your node-based UIs, crafted by the Vue Flow core team. ### Animating Edges Vue Flow provides a simple built-in animation for the default edge type, but it is possible to create more advanced animations by using custom edges. Below are a collection of examples showing different ways an edge path might be animated. #### Animating SVG elements Example: examples/edges/animating-edges-svg ##### types.ts ```ts import type { Edge } from '@xyflow/vue'; export type AnimatedSvgEdgeType = Edge, 'animatedSvg'>; ``` ##### 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; } ``` ##### App.vue ```vue ``` ##### AnimatedSVGEdge.vue ```vue ``` #### Animating other nodes Example: examples/edges/animating-edges ##### types.ts ```ts import type { Edge } from '@xyflow/vue'; export type AnimatedEdge = Edge<{ node: string }, 'animated'>; ``` ##### 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; } ``` ##### App.vue ```vue ``` ##### AnimatedEdge.vue ```vue ``` ### Connection Line A Connection Line is what you see when you click and drag out from a handle. It represents a possible edge and can snap to valid handles in close proximity. Example: examples/edges/custom-connectionline ##### 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; } ``` ##### CustomNode.vue ```vue ``` ##### ConnectionLine.vue ```vue ``` ##### App.vue ```vue ``` ### Custom Edges Vue Flow comes with four different edge types - `default` (bezier), `straight`, `step` and `smoothstep`. Example: examples/edges/custom-edges ##### 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; } .button-edge__label { position: absolute; pointer-events: all; transform-origin: center; } .button-edge__button { width: 30px; height: 30px; border: 5px solid #f7f9fb; color: var(--xy-edge-label-color-default); background-color: #f3f3f4; cursor: pointer; border-radius: 50%; font-size: 12px; padding-top: 0px; } .button-edge__button:hover { background-color: var(--xy-theme-hover); color: #ffffff; } ``` ##### SelfConnectingEdge.vue ```vue ``` ##### ButtonEdge.vue ```vue ``` ##### BiDirectionalNode.vue ```vue ``` ##### BiDirectionalEdge.vue ```vue ``` ##### App.vue ```vue ``` ### Delete Edge on Drop In this example we are showing how to delete an edge by using the `@reconnect`, `@reconnect-start` and `@reconnect-end` events. Example: examples/edges/delete-edge-on-drop ##### 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; } ``` ##### App.vue ```vue ``` ### Edge Intersection This example shows how you can detect an intersection between a dragged node and an edge. Example: examples/edges/edge-intersection ##### 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; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ### Edge Label Renderer To escape the SVG world inside an edge, use the [``](/api-reference/components/edge-label-renderer) β€” a portal that renders edge labels as plain divs on top of the edges. If a label needs mouse interactions, set `pointer-events: all` on it. Example: examples/edges/edge-label-renderer ##### types.ts ```ts import type { Edge } from '@xyflow/vue'; export type CustomEdgeType = Edge<{ label: string }, 'custom'>; export type StartEndEdgeType = Edge< { startLabel: string; endLabel: string }, 'start-end' >; export type EdgeLabelExampleEdge = CustomEdgeType | StartEndEdgeType; ``` ##### 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; } .edge-label-renderer__custom-edge { position: absolute; background-color: #ffcc00; padding: 10px; border-radius: 5px; font-size: 12px; font-weight: 700; } ``` ##### EdgeLabel.vue ```vue ``` ##### CustomEdgeStartEnd.vue ```vue ``` ##### CustomEdge.vue ```vue ``` ##### App.vue ```vue ``` ### Edge Routing This example shows how to implement a custom edge that uses [libavoid](https://github.com/Aksem/libavoid-js) for automatic edge routing. See the [layouting guide](/learn/layouting/overview#routing-edges) for more context on edge routing in Vue Flow. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [libavoid](https://github.com/Aksem/libavoid-js) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Edge Toolbar The [``](/api-reference/components/edge-toolbar) component displays unscaled content on top of an edge β€” for example a button at its center, or a toolbar floating above it. Example: examples/edges/edge-toolbar ##### 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; } ``` ##### EdgeWithToolbar.vue ```vue ``` ##### EdgeWithButton.vue ```vue ``` ##### App.vue ```vue ``` ### Edge Types You can choose different kinds of edge types in Vue Flow: `default` (bezier), `straight`, `step` and `smoothstep`. As you can see, you can define a type for each edge and mix them in one graph. Example: examples/edges/edge-types ##### 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; } ``` ##### App.vue ```vue ``` ### Editable Edge This example explains how to implement a routable and editable edge with draggable control points to change the path of an edge. It also includes a custom connection line that can be used to draw a freeform edge. For this you need to press "Space" while doing a connection. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Floating Edges This is an example implementation for floating edges. The source and target position of the edges are getting calculated dynamically. You can find the implementation details in the utils.js file. Example: examples/edges/floating-edges ##### utils.ts ```ts import type { InternalNode } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; // returns the intersection point of the line between the center of intersectionNode and the target node // https://math.stackexchange.com/questions/1724792 function getNodeIntersection( intersectionNode: InternalNode, targetNode: InternalNode, ) { const intersectionNodeWidth = intersectionNode.measured.width ?? 0; const intersectionNodeHeight = intersectionNode.measured.height ?? 0; const intersectionNodePosition = intersectionNode.internals.positionAbsolute; const targetPosition = targetNode.internals.positionAbsolute; const w = intersectionNodeWidth / 2; const h = intersectionNodeHeight / 2; const x2 = intersectionNodePosition.x + w; const y2 = intersectionNodePosition.y + h; const x1 = targetPosition.x + (targetNode.measured.width ?? 0) / 2; const y1 = targetPosition.y + (targetNode.measured.height ?? 0) / 2; const xx1 = (x1 - x2) / (2 * w) - (y1 - y2) / (2 * h); const yy1 = (x1 - x2) / (2 * w) + (y1 - y2) / (2 * h); const a = 1 / (Math.abs(xx1) + Math.abs(yy1) || 1); const xx3 = a * xx1; const yy3 = a * yy1; const x = w * (xx3 + yy3) + x2; const y = h * (-xx3 + yy3) + y2; return { x, y }; } // returns the position (Top, Right, Bottom or Left) of the node relative to the intersection point function getEdgePosition( node: InternalNode, intersectionPoint: { x: number; y: number }, ) { const pos = node.internals.positionAbsolute; const nx = Math.round(pos.x); const ny = Math.round(pos.y); const px = Math.round(intersectionPoint.x); const py = Math.round(intersectionPoint.y); const width = node.measured.width ?? 0; const height = node.measured.height ?? 0; if (px <= nx + 1) { return Position.Left; } if (px >= nx + width - 1) { return Position.Right; } if (py <= ny + 1) { return Position.Top; } if (py >= ny + height - 1) { return Position.Bottom; } return Position.Top; } // returns the params (sx, sy, tx, ty, sourcePos, targetPos) needed to draw a floating edge between two nodes export function getEdgeParams(source: InternalNode, target: InternalNode) { const sourceIntersectionPoint = getNodeIntersection(source, target); const targetIntersectionPoint = getNodeIntersection(target, source); const sourcePos = getEdgePosition(source, sourceIntersectionPoint); const targetPos = getEdgePosition(target, targetIntersectionPoint); return { sx: sourceIntersectionPoint.x, sy: sourceIntersectionPoint.y, tx: targetIntersectionPoint.x, ty: targetIntersectionPoint.y, sourcePos, targetPos, }; } ``` ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import { MarkerType } from '@xyflow/vue'; export function initialElements() { const nodes: Node[] = []; const edges: Edge[] = []; const center = { x: window.innerWidth / 2, y: window.innerHeight / 2 }; nodes.push({ id: 'target', data: { label: 'Target' }, position: center }); for (let i = 0; i < 8; i++) { const degrees = i * (360 / 8); const radians = degrees * (Math.PI / 180); const x = 250 * Math.cos(radians) + center.x; const y = 250 * Math.sin(radians) + center.y; nodes.push({ id: `${i}`, data: { label: 'Source' }, position: { x, y } }); edges.push({ id: `edge-${i}`, target: 'target', source: `${i}`, type: 'floating', markerEnd: { type: MarkerType.Arrow }, }); } return { nodes, edges }; } ``` ##### 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; } .floating-edges { flex-direction: column; display: flex; flex-grow: 1; height: 100%; } .floating-edges .vue-flow__handle { opacity: 0; } ``` ##### FloatingEdge.vue ```vue ``` ##### FloatingConnectionLine.vue ```vue ``` ##### App.vue ```vue ``` ### Edge Markers Vue Flow has built-in support for different marker types for your edges. It's possible to add your own [SVG markers](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker), too. The markers are defined as SVG elements, so you can use any SVG you want. The Vue Flow edge renderer will expect the marker definition to be in a `` element. Example: examples/edges/markers ##### 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; } ``` ##### CustomMarker.vue ```vue ``` ##### CustomEdge.vue ```vue ``` ##### App.vue ```vue ``` ### Multi Connection Line Vue Flow typically only allows one connection to be created at a time. This example builds on the custom connection line example to show how to draw multiple connection lines from any selected nodes at once. Example: examples/edges/multi-connection-line ##### 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; } ``` ##### ConnectionLine.vue ```vue ``` ##### App.vue ```vue ``` ### Reconnect Edge Drag either end of an edge onto another handle to reconnect it. The `@reconnect` event fires once the edge is dropped on a new handle; use the [`reconnectEdge`](/api-reference/utils/reconnect-edge) helper to update your edges accordingly. Whether an edge can be reconnected is controlled by the `edges-reconnectable` prop on `` and a per-edge `reconnectable` option. Example: examples/edges/reconnect-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; } ``` ##### App.vue ```vue ``` ### Simple Floating Edges This is a simplified version of the [Floating Edges](/examples/edges/floating-edges) example. It's not as flexible as the floating edges example, but the edges stick to the top, right, bottom or left side of the nodes. You can find the implementation details in the utils.js file. Example: examples/edges/simple-floating-edges ##### utils.ts ```ts import type { InternalNode } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; function getNodeCenter(node: InternalNode) { return { x: node.internals.positionAbsolute.x + (node.measured.width ?? 0) / 2, y: node.internals.positionAbsolute.y + (node.measured.height ?? 0) / 2, }; } function getHandleCoordsByPosition( node: InternalNode, handlePosition: Position, ): [number, number] { // all handles are type source, so we look them up in handleBounds.source const handle = node.internals.handleBounds?.source?.find( (h) => h.position === handlePosition, ); if (!handle) { return [0, 0]; } let offsetX = (handle.width ?? 0) / 2; let offsetY = (handle.height ?? 0) / 2; // the calculated handle position has its origin top-left, so shift by the handle size on the far sides // to keep the edge's markerEnd visible switch (handlePosition) { case Position.Left: offsetX = 0; break; case Position.Right: offsetX = handle.width ?? 0; break; case Position.Top: offsetY = 0; break; case Position.Bottom: offsetY = handle.height ?? 0; break; } const x = node.internals.positionAbsolute.x + handle.x + offsetX; const y = node.internals.positionAbsolute.y + handle.y + offsetY; return [x, y]; } function getParams( nodeA: InternalNode, nodeB: InternalNode, ): [number, number, Position] { const centerA = getNodeCenter(nodeA); const centerB = getNodeCenter(nodeB); const horizontalDiff = Math.abs(centerA.x - centerB.x); const verticalDiff = Math.abs(centerA.y - centerB.y); let position: Position; // pick the handle side based on the bigger center-to-center difference if (horizontalDiff > verticalDiff) { position = centerA.x > centerB.x ? Position.Left : Position.Right; } else { position = centerA.y > centerB.y ? Position.Top : Position.Bottom; } const [x, y] = getHandleCoordsByPosition(nodeA, position); return [x, y, position]; } // returns the params (sx, sy, tx, ty, sourcePos, targetPos) needed to draw a simple floating edge export function getEdgeParams(source: InternalNode, target: InternalNode) { const [sx, sy, sourcePos] = getParams(source, target); const [tx, ty, targetPos] = getParams(target, source); return { sx, sy, tx, ty, sourcePos, targetPos }; } ``` ##### 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; } .simple-floatingedges { flex-direction: column; display: flex; flex-grow: 1; height: 100%; } .simple-floatingedges .vue-flow__handle { width: 8px; height: 8px; } .simple-floatingedges .vue-flow__handle-top { top: -15px; } .simple-floatingedges .vue-flow__handle-bottom { bottom: -15px; } .simple-floatingedges .vue-flow__handle-left { left: -15px; } .simple-floatingedges .vue-flow__handle-right { right: -15px; } ``` ##### SimpleFloatingEdge.vue ```vue ``` ##### CustomNode.vue ```vue ``` ##### App.vue ```vue ``` ### Temporary Edges In Vue Flow, almost everything is built around the concepts of nodes and edges. Edges are the connections between nodes, but what if we want to create an edge that is only connected to one node? What about an "edge" not connected to any nodes at all? This example shows how to create an "incomplete" edge when a user releases a connection line without making a connection. A ghost node is rendered where the connection line was released, and a temporary edge is added to the flow. Making use of editable edges, the user can pick the edge back up and complete the connection at which point the ghost node is removed! Instead of connecting `A` directly to `B` in the flow, try releasing the connection line in an empty space to create a temporary edge! Example: examples/edges/temporary-edges ##### useIncompleteEdge.ts ```ts import type { ConnectEndEvent, Connection, Edge, EdgeChangeset, EdgeReconnectEndEvent, EdgeReconnectEvent, } from '@xyflow/vue'; import { nextTick } from 'vue'; import { useVueFlow } from '@xyflow/vue'; export function useIncompleteEdge() { const { addEdges, addNodes, removeEdges, removeNodes, reconnectEdge, screenToFlowPosition, getNodes, getEdges, } = useVueFlow(); let ghostId = 0; let isReconnecting = false; function onConnect(connection: Connection) { addEdges([connection]); } function onReconnectStart() { isReconnecting = true; } // a fresh connection dropped in empty space spawns a ghost node and a temporary edge to it. // `connectEnd` also fires while reconnecting, so skip the spawn in that case. function onConnectEnd({ event, connectionState }: ConnectEndEvent) { if ( isReconnecting || connectionState.isValid || connectionState.fromHandle?.type === 'target' || !connectionState.fromNode ) { return; } const point = 'changedTouches' in event ? event.changedTouches[0] : event; const position = screenToFlowPosition({ x: point.clientX, y: point.clientY, }); const fromNodeId = connectionState.fromNode.id; const id = `ghost-${++ghostId}`; addNodes([{ id, type: 'ghost', position, data: {} }]); addEdges([ { id: `${fromNodeId}->${id}`, source: fromNodeId, target: id, reconnectable: 'target', }, ]); } function onReconnect(event: EdgeReconnectEvent) { reconnectEdge(event.edge, event.connection); } // dropping a temporary edge's reconnectable (target) end in empty space removes it; either way the // now-orphaned ghost node is pruned function onReconnectEnd(event: EdgeReconnectEndEvent) { if (event.handleType !== 'source') { return; } if (!event.connectionState.isValid && event.edge) { removeEdges([event.edge.id]); } isReconnecting = false; nextTick(pruneGhostNodes); } // there's no `edgesDelete` event, so prune ghost nodes whenever an edge is removed function onEdgesChange(changes: EdgeChangeset) { if (changes.getByType('remove').length > 0) { nextTick(pruneGhostNodes); } } function pruneGhostNodes() { const connected = new Set(); for (const edge of getEdges.value) { connected.add(edge.source); connected.add(edge.target); } const orphans = getNodes.value .filter((node) => node.type === 'ghost' && !connected.has(node.id)) .map((node) => node.id); if (orphans.length) { removeNodes(orphans); } } return { connect: onConnect, connectEnd: onConnectEnd, reconnectStart: onReconnectStart, reconnect: onReconnect, reconnectEnd: onReconnectEnd, edgesChange: onEdgesChange, }; } ``` ##### 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-ghost, .vue-flow__node-ghost.selected.selectable, .vue-flow__node-ghost.selectable:focus { border: 0; box-shadow: none; background-color: transparent; } ``` ##### GhostNode.vue ```vue ``` ##### App.vue ```vue ``` ### Change Parent The `changeParent` helper from `useVueFlow` reparents a node without you having to recalculate its position β€” it converts the node's absolute position (accounting for its origin) into a position relative to the new parent. Pass `null` as the parent to detach the node back to the root. Example: examples/grouping/change-parent ##### 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; } ``` ##### App.vue ```vue ``` ### Parent Child Relation This example demonstrates how to dynamically create parent-child relationships between nodes. You can drag a node over a group node to attach it as a child, and drag it out of the group again to detach it. The group node highlights itself while a node is dragged over it, and absolute positions are converted to parent-relative coordinates when a node changes its parent. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Selection Grouping This example demonstrates how to create dynamic node grouping in Vue Flow. You can select multiple nodes by holding Shift and clicking, then use the "Group Nodes" button in the appearing toolbar to group them together. When a group node is selected, an "Ungroup" button appears that detaches all child nodes. Group nodes automatically adjust their dimensions based on their child nodes. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Sub Flows Vue Flow supports nested graphs and grouping. Keep a child inside its parent with `extent: 'parent'`, and render a group container without handles by giving the node `type: 'group'`. See the [Sub Flows guide](/learn/layouting/sub-flows) for more. Example: examples/grouping/sub-flows ##### 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; } ``` ##### App.vue ```vue ``` ### Collaborative This example shows how to build a collaborative graph for multiple users with Vue Flow and [yjs](https://github.com/yjs/yjs). The example can be used as a starting point to build multi-user flows and editors. Note that the room is not globally shared: to open the same flow in another tab, you can click the button below, or copy the URL from the "Share" button inside the flow. **To add new nodes to the flow, right click on the canvas.** ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [yjs](https://www.npmjs.com/package/yjs), [y-websocket](https://www.npmjs.com/package/y-websocket) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Computing Flows This example uses the computing-flow helpers β€” [`useNodesData`](/api-reference/composables/use-nodes-data), [`useNodeConnections`](/api-reference/composables/use-node-connections) and `updateNodeData` β€” to pass data along the graph, so a node can react to the output of the nodes connected to it. Example: examples/interaction/computing-flows ##### types.ts ```ts import type { Node } from '@xyflow/vue'; // distributes Pick across a union so `.type` narrows `.data` (mirrors what useNodesData returns) type DistributivePick = T extends unknown ? Pick : never; export type TextNode = Node<{ text: string }, 'text'>; export type ResultNode = Node, 'result'>; export type UppercaseNode = Node<{ text: string }, 'uppercase'>; export type MyNode = TextNode | ResultNode | UppercaseNode; // the id/type/data slice returned by useNodesData type MyNodeData = DistributivePick; export function isTextNode( node: MyNodeData | null | undefined, ): node is DistributivePick { return !node ? false : node.type === 'text' || node.type === 'uppercase'; } ``` ##### 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; } ``` ##### UppercaseNode.vue ```vue ``` ##### TextNode.vue ```vue ``` ##### ResultNode.vue ```vue ``` ##### App.vue ```vue ``` ### Confirm Delete Example: examples/interaction/confirm-delete ##### useDialog.ts ```ts import type { InjectionKey, ShallowRef } from 'vue'; import { inject, provide, shallowRef } from 'vue'; interface ConfirmDialog { isVisible: ShallowRef; message: ShallowRef; /** open the dialog and resolve with the user's choice */ confirm: (message: string) => Promise; /** resolve the open dialog β€” wired to the dialog's Confirm/Cancel buttons */ settle: (value: boolean) => void; } const DialogKey: InjectionKey = Symbol('confirm-dialog'); /** * Scoped confirm dialog. Call `provideConfirmDialog()` once in an ancestor (it returns the instance so that * same component can use it too) and `useConfirmDialog()` in any descendant. */ export function provideConfirmDialog(): ConfirmDialog { const isVisible = shallowRef(false); const message = shallowRef(''); let resolveFn: ((value: boolean) => void) | null = null; function confirm(next: string) { message.value = next; isVisible.value = true; return new Promise((resolve) => { resolveFn = resolve; }); } function settle(value: boolean) { isVisible.value = false; resolveFn?.(value); resolveFn = null; } const dialog: ConfirmDialog = { isVisible, message, confirm, settle }; provide(DialogKey, dialog); return dialog; } export function useConfirmDialog(): ConfirmDialog { const dialog = inject(DialogKey); if (!dialog) { throw new Error( 'useConfirmDialog() must be used under a component that called provideConfirmDialog()', ); } return dialog; } ``` ##### 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; } .dialog-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; background-color: rgba(0, 0, 0, 0.5); z-index: 1000; } .dialog { display: flex; flex-direction: column; align-items: center; gap: 8px; background: #2d3748; padding: 20px; border-radius: 5px; text-align: center; color: white; } .dialog p { margin: 0; white-space: pre-line; } .dialog .actions { margin-top: 12px; display: flex; justify-content: center; gap: 8px; } .dialog .actions button { background: #4a5568; color: white; border: none; padding: 8px 16px; border-radius: 5px; cursor: pointer; } .dialog .actions button:first-of-type:hover { background: #2563eb; } .dialog .actions button:last-of-type:hover { background: #e53e3e; } ``` ##### Dialog.vue ```vue ``` ##### App.vue ```vue ``` ### Connection Events Vue Flow emits different events during the connection process that you can use to update your UI or your flow in different ways. The example below demonstrates which events are fired and when. Example: examples/interaction/connection-events ##### 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; } #event-list { position: absolute; top: 4px; left: 4px; pointer-events: none; font-family: monospace; padding: 0.5rem; background-color: var(--xy-theme-panel-bg); color: var(--xy-theme-panel-text); border: 1px solid var(--xy-theme-subtle-border); border-radius: 4px; } #event-list > p { margin: 0; } ``` ##### App.vue ```vue ``` ### Context Menu This example shows a simple menu with buttons to duplicate or delete the clicked node. Example: examples/interaction/context-menu ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', position: { x: 175, y: 0 }, data: { label: 'a' } }, { id: '2', position: { x: 0, y: 250 }, data: { label: 'b' } }, { id: '3', position: { x: 175, y: 250 }, data: { label: 'c' } }, { id: '4', position: { x: 350, y: 250 }, data: { label: 'd' } }, ]; export const initialEdges: Edge[] = [ { id: 'e1-2', source: '1', target: '2' }, { id: 'e1-3', source: '1', target: '3' }, { id: 'e1-4', source: '1', target: '4' }, ]; ``` ##### 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; } .context-menu-flow { width: 100%; height: 100%; } .context-menu { background: white; border-style: solid; box-shadow: 10px 19px 20px rgba(0, 0, 0, 10%); position: absolute; z-index: 10; } .context-menu button { border: none; display: block; padding: 0.5em; text-align: left; width: 100%; } .context-menu button:hover { background: white; } ``` ##### ContextMenu.vue ```vue ``` ##### App.vue ```vue ``` ### Contextual Zoom This example shows how the current zoom level can be used by a node to decide which content to show. Example: examples/interaction/contextual-zoom ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type ZoomNodeType = Node<{ content: string }, 'zoom'>; ``` ##### 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-zoom { font-size: 12px; background: var(--xy-node-background-color-default); border: var(--xy-node-border-default); border-radius: 5px; text-align: center; width: 150px; padding: 10px; line-height: 1.2; } .vue-flow__node-zoom img { pointer-events: none; } .placeholder { display: contents; } .placeholder div { background: var(--xy-theme-muted-bg); width: 100%; height: 10px; margin-bottom: 4px; } .placeholder div:last-child { margin-bottom: 0; } ``` ##### ZoomNode.vue ```vue ``` ##### App.vue ```vue ``` ### Copy and Paste This example demonstrates how to copy and paste nodes and edges within a Vue Flow graph. Try using Shift + click + drag to select multiple nodes to copy. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Drag and Drop In these examples, we use a custom Sidebar component to create new nodes when dragging from the sidebar into the Vue Flow pane. #### Drag and Drop with HTML Drag and Drop API The HTML Drag and Drop API is a native API that is supported by all major browsers. It is a simple API that allows you to drag and drop elements between different elements on the page. **Note:** HTML Drag and Drop API is not properly supported on touch devices. See the example below for an alternative approach using pointer events. Example: examples/interaction/drag-and-drop ##### useDnD.ts ```ts import type { InjectionKey, Ref } from 'vue'; import { inject, provide, shallowRef } from 'vue'; // the node type currently being dragged from the sidebar, shared between the sidebar and the flow const DnDKey: InjectionKey> = Symbol('dnd-type'); export function provideDnD() { const type = shallowRef(null); provide(DnDKey, type); return type; } export function useDnD() { const type = inject(DnDKey); if (!type) { throw new Error( 'useDnD must be used within a component that called provideDnD', ); } return type; } ``` ##### 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; } .dndflow { flex-direction: column; display: flex; flex-grow: 1; height: 100%; } .dndflow aside { border-right: 1px solid var(--xy-theme-subtle-border); padding: 15px 10px; font-size: 12px; background: var(--xy-theme-panel-bg); color: var(--xy-theme-panel-text); } /* Sidebar is outside .vue-flow so it doesn't get theme variables in dark mode. */ @media (prefers-color-scheme: dark) { .dndflow aside { background: #141519; color: #f3f4f6; border-right-color: #3f434c; } .dndflow .dndnode { border-color: #3f434c; background: #1a1b1e; color: #f3f4f6; } } .dndflow aside .description { margin-bottom: 10px; } .dndflow .dndnode { height: 20px; padding: 4px; border: 1px solid; border-radius: 2px; margin-bottom: 10px; display: flex; justify-content: center; align-items: center; cursor: grab; } .dndflow .vue-flow-wrapper { flex-grow: 1; height: 100%; } @media screen and (min-width: 768px) { .dndflow { flex-direction: row; } .dndflow aside { width: 20%; max-width: 250px; } } ``` ##### Sidebar.vue ```vue ``` ##### App.vue ```vue ``` #### Drag and Drop with Pointer Events Another way to implement drag and drop is to use **pointer events**. The Pointer Events API is a modern API that is supported by all major browsers. It is slightly more complex to implement than the HTML Drag and Drop API, but by using pointer events we can make sure that the drag and drop behavior is consistent across all devices, both mouse and touch. Example: examples/interaction/drag-and-drop-custom ##### useDnD.ts ```ts import type { InjectionKey, Ref } from 'vue'; import type { XYPosition } from '@xyflow/vue'; import { inject, onMounted, onUnmounted, provide, shallowRef, watch, } from 'vue'; import { useVueFlow } from '@xyflow/vue'; export type OnDropAction = (params: { position: XYPosition }) => void; interface DnDContext { isDragging: Ref; dropAction: Ref; } const DnDKey: InjectionKey = Symbol('dnd-custom'); // Wrap the flow subtree so the sidebar can start dragging a node without registering any callback on the // flow itself. export function provideDnD() { provide(DnDKey, { isDragging: shallowRef(false), dropAction: shallowRef(null), }); } export function useDnD() { const context = inject(DnDKey); if (!context) { throw new Error( 'useDnD must be used within a component tree that called provideDnD', ); } const { isDragging, dropAction } = context; const { screenToFlowPosition } = useVueFlow(); // start dragging a new node into the flow (used by the sidebar entries) function onDragStart(event: PointerEvent, onDrop: OnDropAction) { event.preventDefault(); (event.target as HTMLElement).setPointerCapture(event.pointerId); isDragging.value = true; dropAction.value = onDrop; } function onDragEnd(event: PointerEvent) { if (!isDragging.value) { return; } (event.target as HTMLElement).releasePointerCapture(event.pointerId); event.preventDefault(); // only drop when the pointer is released over the flow const elementUnderPointer = document.elementFromPoint( event.clientX, event.clientY, ); if (elementUnderPointer?.closest('.vue-flow')) { dropAction.value?.({ position: screenToFlowPosition({ x: event.clientX, y: event.clientY }), }); } isDragging.value = false; } watch(isDragging, (dragging) => { if (dragging) { document.addEventListener('pointerup', onDragEnd); } else { document.removeEventListener('pointerup', onDragEnd); } }); onUnmounted(() => document.removeEventListener('pointerup', onDragEnd)); return { isDragging, onDragStart }; } export function useDnDPosition() { const position = shallowRef(); function onDrag(event: PointerEvent) { event.preventDefault(); position.value = { x: event.clientX, y: event.clientY }; } onMounted(() => document.addEventListener('pointermove', onDrag)); onUnmounted(() => document.removeEventListener('pointermove', onDrag)); return { position }; } ``` ##### 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; /* Prevent zoom on mobile when tapping */ touch-action: manipulation; -webkit-touch-callout: none; user-select: none; } #app { width: 100vw; height: 100vh; } .dndflow { flex-direction: column; display: flex; flex-grow: 1; height: 100%; } .dndflow aside { border-right: 1px solid #eee; padding: 15px 10px; font-size: 12px; background: #fcfcfc; } .dndflow aside .description { margin-bottom: 10px; } .dndflow .dndnode { height: 20px; padding: 8px; border: 1px solid #1a192b; border-radius: 6px; margin-bottom: 10px; display: flex; justify-content: center; align-items: center; cursor: grab; /* Prevent zoom or scroll when dragging nodes on mobile */ touch-action: none; background: white; font-size: 12px; text-wrap: nowrap; } .dndflow .ghostnode { position: fixed; pointer-events: none; width: 100px; } .dndflow .dndnode:active { cursor: grabbing; } .dndflow .dndnode.input { border-color: #0041d0; } .dndflow .dndnode.output { border-color: #ff0072; } .dndflow .vue-flow-wrapper { flex-grow: 1; height: 100%; } @media screen and (min-width: 768px) { .dndflow { flex-direction: row; } .dndflow aside { width: 20%; max-width: 250px; } } ``` ##### Sidebar.vue ```vue ``` ##### DragGhost.vue ```vue ``` ##### App.vue ```vue ``` #### Drag and Drop with Neodrag [Neodrag](https://github.com/puruvj/neodrag) is a library that provides a simple and easy to use drag and drop API. In a real-world application, you may want to use the Neodrag library to handle the drag and drop behavior in a cross-platform compatible way, compatible with both mouse and touch devices. Example: examples/interaction/drag-and-drop-neodrag ##### 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; /* Prevent zoom on mobile when tapping */ touch-action: manipulation; -webkit-touch-callout: none; user-select: none; } #app { width: 100vw; height: 100vh; } .dndflow { flex-direction: column; display: flex; flex-grow: 1; height: 100%; } .dndflow aside { border-right: 1px solid #eee; padding: 15px 10px; font-size: 12px; background: #fcfcfc; } .dndflow aside .description { margin-bottom: 10px; } .dndflow .dndnode { height: 20px; padding: 8px; border: 1px solid #1a192b; border-radius: 6px; margin-bottom: 10px; display: flex; justify-content: center; align-items: center; cursor: grab; /* Prevent zoom or scroll when dragging nodes on mobile */ touch-action: none; background: white; font-size: 12px; text-wrap: nowrap; } .dndflow .dndnode:active { cursor: grabbing; } .dndflow .dndnode.input { border-color: #0041d0; } .dndflow .dndnode.output { border-color: #ff0072; } .dndflow .vue-flow-wrapper { flex-grow: 1; height: 100%; } @media screen and (min-width: 768px) { .dndflow { flex-direction: row; } .dndflow aside { width: 20%; max-width: 250px; } } ``` ##### Sidebar.vue ```vue ``` ##### DraggableNode.vue ```vue ``` ##### App.vue ```vue ``` ### Helper Lines This example demonstrates how to implement alignment helper lines. As you drag nodes around, these visual guides appear automatically to help align nodes with each other, while a snapping mechanism ensures precise positioning. The implementation handles both horizontal and vertical alignment and works correctly with the viewport's transform and scale, ensuring the guides remain accurate even when zoomed or panned. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Interaction Props Vue Flow's interaction props let you turn features on and off. This example toggles props like `nodes-draggable`, `nodes-connectable`, `elements-selectable`, `pan-on-drag` and `zoom-on-scroll` so you can see how each one changes what's possible on the canvas. Example: examples/interaction/interaction-props ##### 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; } ``` ##### App.vue ```vue ``` ### Preventing Cycles Building on the [validation](/examples/interaction/validation) example, this uses the [`getOutgoers`](/api-reference/utils/get-outgoers) helper inside an `is-valid-connection` check to reject any connection that would create a cycle in the graph. Example: examples/interaction/prevent-cycles ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const nodes: Node[] = [ { id: '1', position: { x: 0, y: 9 }, data: { label: 'A' } }, { id: '2', position: { x: 125, y: 125 }, data: { label: 'B' } }, { id: '3', position: { x: 0, y: 250 }, data: { label: 'C' } }, { id: '4', position: { x: -125, y: 125 }, data: { label: 'C' } }, ]; export const edges: Edge[] = [{ id: 'e1-2', source: '1', target: '2' }]; ``` ##### 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; } ``` ##### App.vue ```vue ``` ### Save and Restore Save and restore a flow with the instance's `toObject()` (or your own `nodes`/`edges` state). Move nodes around, add a few, and save β€” then reload the page and click restore to bring the diagram back. Example: examples/interaction/save-and-restore ##### 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; } ``` ##### App.vue ```vue ``` ### Touch Device You can connect nodes on a touch device by tapping two handles in a row. In this example we increased the size of the handles so that they are better tappable. Example: examples/interaction/touch-device ##### 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.touch-flow .vue-flow__handle { width: 20px; height: 20px; } .touch-flow .vue-flow__handle-right { --translate: translate(50%, -50%); } .touch-flow .vue-flow__handle-left { --translate: translate(-50%, -50%); } @keyframes bounce { 0% { transform: var(--translate) scale(1); } 50% { transform: var(--translate) scale(1.1); } } .vue-flow.touch-flow .vue-flow__handle.connecting { animation: bounce 1600ms infinite ease-in; } ``` ##### App.vue ```vue ``` ### Undo and Redo This example demonstrates how to implement undo and redo functionality for a Vue Flow graph. Users can track and revert changes when moving, adding, or deleting nodes and edges. The implementation uses a snapshot-based approach with the `createUndoRedo` function that manages past and future states, allowing users to navigate through their editing history with button clicks or keyboard shortcuts (Ctrl+Z and Ctrl+Shift+Z). ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Validation A custom node needs at least one [``](/api-reference/components/handle) to be connectable. Pass an `is-valid-connection` function to `` (or a handle) to decide whether a new connection should be allowed before it's created. Example: examples/interaction/validation ##### 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; } .validationflow .vue-flow__node { width: 150px; min-height: 44px; text-align: center; font-size: 12px; } .validationflow .vue-flow__node-customnode { background: var(--xy-theme-muted-bg); } .vue-flow__node-custominput .vue-flow__handle { background: var(--xy-theme-muted-bg); } .validationflow .vue-flow__node-custominput { background: var(--xy-node-background-color-default); } .validationflow .vue-flow__handle.connectingto { background: #ff6060; } .validationflow .vue-flow__handle.valid { background: #55dd99; } ``` ##### CustomNode.vue ```vue ``` ##### CustomInput.vue ```vue ``` ##### App.vue ```vue ``` ### Viewport Transition Example: examples/interaction/viewport-transition ##### useDblClick.ts ```ts import type { InjectionKey, Ref } from 'vue'; import { inject, provide, shallowRef } from 'vue'; // Broadcasts the last double-clicked node id from down to the transition edge. A fresh object // per click means re-clicking the same node still triggers the edge's watcher. export type DblClickSignal = { nodeId: string } | null; const DblClickKey: InjectionKey> = Symbol('dblclick-signal'); export function provideDblClick() { const signal = shallowRef(null); provide(DblClickKey, signal); return (nodeId: string) => { signal.value = { nodeId }; }; } export function useDblClick(): Ref { const signal = inject(DblClickKey); if (!signal) { throw new Error( 'useDblClick() must be used under a component that called provideDblClick()', ); } return signal; } ``` ##### 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; } .transition-flow { background-color: #1a192b; } .transition-dot { fill: #fdd023; } .fade-enter-active, .fade-leave-active { transition: opacity 300ms ease; } .fade-enter-from, .fade-leave-to { opacity: 0; } ``` ##### TransitionEdge.vue ```vue ``` ##### App.vue ```vue ``` ### Zoom Transitions The viewport helpers β€” `fitView`, `zoomTo` and `setViewport` β€” accept a `duration`, so you can smoothly tween between zoom levels and positions instead of jumping straight to them. Example: examples/interaction/zoom-transitions ##### 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; } ``` ##### App.vue ```vue ``` ### Layout Animation Example: examples/layout/animation ##### useRunProcess.ts ```ts import type { MaybeRefOrGetter } from 'vue'; import type { Node } from '@xyflow/vue'; import type { DagreGraph } from './useLayout'; import { shallowRef, toValue } from 'vue'; import { getConnectedEdges, useVueFlow } from '@xyflow/vue'; export enum ProcessStatus { ERROR = 'error', SKIPPED = 'skipped', CANCELLED = 'cancelled', FINISHED = 'finished', RUNNING = 'running', } export type ProcessNodeData = { status: ProcessStatus | null }; export type ProcessNodeType = Node; interface RunProcessOptions { graph: MaybeRefOrGetter; cancelOnError?: MaybeRefOrGetter; } /** * Simulates running a process tree: it walks the graph, pretends to run an async task on each node and * updates the node's `status`. When a node finishes it starts its children (in parallel), optionally * cancelling everything downstream on error. */ export function useRunProcess({ graph, cancelOnError = true, }: RunProcessOptions) { const { updateNodeData, getNode, getEdge, getEdges } = useVueFlow(); const isRunning = shallowRef(false); /** node id β†’ its scheduled timeout */ const runningTasks = new Map>(); /** node ids that have already run */ const executedNodes = new Set(); /** node ids queued but not yet started */ const upcomingTasks = new Set(); function updateNodeStatus(nodeId: string, status: ProcessStatus | null) { updateNodeData(nodeId, { status }); } async function runNode( nodeId: string, isStart = false, ): Promise { if (executedNodes.has(nodeId)) { return; } upcomingTasks.add(nodeId); const node = getNode(nodeId); const connectedEdges = node ? getConnectedEdges([node], [...getEdges.value]) : []; const incomers = connectedEdges.filter((edge) => edge.target === nodeId); // wait for incoming edge animations to finish; re-read the edge each poll since updates replace it await Promise.all( incomers.map((incomer) => until(() => !getEdge(incomer.id)?.data?.isAnimating), ), ); upcomingTasks.clear(); if (!isRunning.value) { return; } executedNodes.add(nodeId); updateNodeStatus(nodeId, ProcessStatus.RUNNING); const delay = Math.floor(Math.random() * 2000) + 1000; return new Promise((resolve) => { const timeout = setTimeout( async () => { const children = toValue(graph).successors(nodeId) ?? []; // 15% chance of failure (never on the starting node) const willThrowError = Math.random() < 0.15; if (!isStart && willThrowError) { updateNodeStatus(nodeId, ProcessStatus.ERROR); if (toValue(cancelOnError)) { await skipDescendants(nodeId); runningTasks.delete(nodeId); resolve(true); return; } } updateNodeStatus(nodeId, ProcessStatus.FINISHED); runningTasks.delete(nodeId); if (children.length > 0) { await Promise.all(children.map((child) => runNode(child))); } resolve(true); }, isStart ? 0 : delay, ); runningTasks.set(nodeId, timeout); }); } async function run(nodes: Node[]) { if (isRunning.value) { return; } reset(nodes); isRunning.value = true; const startingNodes = nodes.filter( (node) => (toValue(graph).predecessors(node.id) ?? []).length === 0, ); await Promise.all(startingNodes.map((node) => runNode(node.id, true))); clear(); } function reset(nodes: Node[]) { clear(); for (const node of nodes) { updateNodeStatus(node.id, null); } } async function skipDescendants(nodeId: string) { const children = toValue(graph).successors(nodeId) ?? []; for (const child of children) { updateNodeStatus(child, ProcessStatus.SKIPPED); await skipDescendants(child); } } async function stop() { isRunning.value = false; for (const nodeId of [...upcomingTasks, ...runningTasks.keys()]) { clearTimeout(runningTasks.get(nodeId)); runningTasks.delete(nodeId); updateNodeStatus(nodeId, ProcessStatus.CANCELLED); await skipDescendants(nodeId); } executedNodes.clear(); upcomingTasks.clear(); } function clear() { isRunning.value = false; executedNodes.clear(); runningTasks.clear(); } return { run, stop, reset, isRunning }; } function until(condition: () => boolean) { return new Promise((resolve) => { const interval = setInterval(() => { if (condition()) { clearInterval(interval); resolve(); } }, 100); }); } ``` ##### useLayout.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import { shallowRef } from 'vue'; import dagre from '@dagrejs/dagre'; import { Position, useVueFlow } from '@xyflow/vue'; export type DagreGraph = InstanceType; /** * Runs a dagre layout over the current graph. The resulting `graph` ref is shared with `useRunProcess`, which * walks its successors/predecessors to drive the simulated process. * * @see https://github.com/dagrejs/dagre/wiki */ export function useLayout() { const { getNode } = useVueFlow(); const graph = shallowRef(new dagre.graphlib.Graph()); function layout( nodes: NodeType[], edges: Edge[], direction: 'LR' | 'TB', ): NodeType[] { // build a fresh graph each run so removed nodes/edges don't linger const dagreGraph = new dagre.graphlib.Graph(); graph.value = dagreGraph; dagreGraph.setDefaultEdgeLabel(() => ({})); dagreGraph.setGraph({ rankdir: direction }); const isHorizontal = direction === 'LR'; for (const node of nodes) { // measured dimensions come from the InternalNode once it has been rendered const internal = getNode(node.id); dagreGraph.setNode(node.id, { width: internal?.measured?.width ?? 150, height: internal?.measured?.height ?? 50, }); } for (const edge of edges) { dagreGraph.setEdge(edge.source, edge.target); } dagre.layout(dagreGraph); return nodes.map((node) => { const { x, y } = dagreGraph.node(node.id); return { ...node, targetPosition: isHorizontal ? Position.Left : Position.Top, sourcePosition: isHorizontal ? Position.Right : Position.Bottom, position: { x, y }, }; }); } return { graph, layout }; } ``` ##### initial-elements.ts ```ts import type { Edge } from '@xyflow/vue'; import type { ProcessNodeType } from './useRunProcess'; // dagre positions every node on `nodes-initialized`, so the initial positions are just placeholders. // Each node gets its own `data` object (not a shared reference). export const initialNodes: ProcessNodeType[] = [ '1', '2', '2a', '2b', '2c', '2d', '3', '4', '5', '6', '7', ].map((id) => ({ id, type: 'process', position: { x: 0, y: 0 }, data: { status: null }, })); export const initialEdges: Edge[] = [ { id: 'e1-2', source: '1', target: '2' }, { id: 'e1-3', source: '1', target: '3' }, { id: 'e2-2a', source: '2', target: '2a' }, { id: 'e2-2b', source: '2', target: '2b' }, { id: 'e2-2c', source: '2', target: '2c' }, { id: 'e2c-2d', source: '2c', target: '2d' }, { id: 'e3-4', source: '3', target: '4' }, { id: 'e4-5', source: '4', target: '5' }, { id: 'e5-6', source: '5', target: '6' }, { id: 'e5-7', source: '5', target: '7' }, ]; ``` ##### 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; } .layout-flow { background-color: #1a192b; } /* Panel */ .process-panel, .layout-panel { display: flex; gap: 10px; } .process-panel { flex-direction: column; background-color: #2d3748; padding: 10px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); } .process-panel button { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: none; border-radius: 8px; cursor: pointer; background-color: #4a5568; color: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); } .process-panel button svg { display: block; width: 20px; height: 20px; } .process-panel button:hover, .layout-panel button:hover { background-color: #2563eb; transition: background-color 0.2s; } .process-panel label { color: white; font-size: 12px; } .checkbox-panel { display: flex; align-items: center; gap: 10px; } .stop-btn svg { display: none; } .stop-btn:hover svg { display: block; } .stop-btn:hover .spinner { display: none; } .spinner { width: 10px; height: 10px; border: 3px solid #f3f3f3; border-top: 3px solid #2563eb; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } /* Process node */ .process-node { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 10px; border-radius: 99px; } .process-node .vue-flow__handle { width: unset; height: unset; border: none; background: transparent; font-size: 12px; } /* Truck travelling along the animated edge */ .animation-truck { position: absolute; z-index: 1; offset-path: var(--offset-path); offset-rotate: 0deg; offset-anchor: center; } .animation-truck .truck { position: relative; display: inline-block; transform: scaleX(-1); } .animation-truck .box { position: absolute; top: -10px; } ``` ##### ProcessNode.vue ```vue ``` ##### Icon.vue ```vue ``` ##### App.vue ```vue ``` ##### AnimationEdge.vue ```vue ``` ### Auto Layout This example demonstrates how to automatically arrange nodes. It introduces a reusable `runAutoLayout` function and showcases three popular layout engines that you can switch between at runtime: [dagre](https://github.com/dagrejs/dagre), [d3-hierarchy](https://github.com/d3/d3-hierarchy), and [elk](https://github.com/kieler/elkjs). ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [@dagrejs/dagre](https://www.npmjs.com/package/@dagrejs/dagre), [d3-hierarchy](https://www.npmjs.com/package/d3-hierarchy), [elkjs](https://www.npmjs.com/package/elkjs) * Provides a comparison of different layout algorithms with interactive controls * Note: In your own applications, you typically only need to choose one layout engine * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Dagre Tree Example: examples/layout/dagre ##### useDagreLayout.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import dagre from '@dagrejs/dagre'; import { Position } from '@xyflow/vue'; const nodeWidth = 172; const nodeHeight = 36; export function useDagreLayout() { const dagreGraph = new dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({})); return ( nodes: Node[], edges: Edge[], direction: 'TB' | 'LR' = 'TB', ): { nodes: Node[]; edges: Edge[] } => { const isHorizontal = direction === 'LR'; dagreGraph.setGraph({ rankdir: direction }); nodes.forEach((node) => { dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight }); }); edges.forEach((edge) => { dagreGraph.setEdge(edge.source, edge.target); }); dagre.layout(dagreGraph); const layoutedNodes = nodes.map((node) => { const nodeWithPosition = dagreGraph.node(node.id); return { ...node, targetPosition: isHorizontal ? Position.Left : Position.Top, sourcePosition: isHorizontal ? Position.Right : Position.Bottom, // shift the dagre node position (anchor=center) to the top-left so it matches Vue Flow's anchor position: { x: nodeWithPosition.x - nodeWidth / 2, y: nodeWithPosition.y - nodeHeight / 2, }, }; }); return { nodes: layoutedNodes, edges }; }; } ``` ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; const position = { x: 0, y: 0 }; const edgeType = 'smoothstep'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'input' }, position }, { id: '2', data: { label: 'node 2' }, position }, { id: '2a', data: { label: 'node 2a' }, position }, { id: '2b', data: { label: 'node 2b' }, position }, { id: '2c', data: { label: 'node 2c' }, position }, { id: '2d', data: { label: 'node 2d' }, position }, { id: '3', data: { label: 'node 3' }, position }, { id: '4', data: { label: 'node 4' }, position }, { id: '5', data: { label: 'node 5' }, position }, { id: '6', type: 'output', data: { label: 'output' }, position }, { id: '7', type: 'output', data: { label: 'output' }, position }, ]; export const initialEdges: Edge[] = [ { id: 'e12', source: '1', target: '2', type: edgeType, animated: true }, { id: 'e13', source: '1', target: '3', type: edgeType, animated: true }, { id: 'e22a', source: '2', target: '2a', type: edgeType, animated: true }, { id: 'e22b', source: '2', target: '2b', type: edgeType, animated: true }, { id: 'e22c', source: '2', target: '2c', type: edgeType, animated: true }, { id: 'e2c2d', source: '2c', target: '2d', type: edgeType, animated: true }, { id: 'e45', source: '4', target: '5', type: edgeType, animated: true }, { id: 'e56', source: '5', target: '6', type: edgeType, animated: true }, { id: 'e57', source: '5', target: '7', type: edgeType, animated: true }, ]; ``` ##### 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; } ``` ##### App.vue ```vue ``` ### Dynamic Layouting This example creates a self-organizing graph where nodes position themselves automatically in a tree-like structure. Key features include: * **Node creation**: Instead of manually placing or connecting nodes, users click on placeholder elements to add new nodes * **Multiple interaction points**: Add children by clicking on nodes, convert placeholders into nodes, or insert nodes between existing ones using the "+" button on edges * **Smart layout algorithm**: When the graph changes, a `useLayout` composable powered by `d3-hierarchy` recalculates all positions * **Smooth transitions**: Nodes animate to their new positions, maintaining visual clarity even as complexity increases ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [d3-hierarchy](https://www.npmjs.com/package/d3-hierarchy), [d3-timer](https://www.npmjs.com/package/d3-timer) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Elkjs Multiple Handles Example: examples/layout/elkjs-multiple-handles ##### useLayoutNodes.ts ```ts import type { Edge } from '@xyflow/vue'; import type { ElkNode as ElkLayoutNode } from 'elkjs/lib/elk-api'; import type { ElkNode } from './nodes'; import { watch } from 'vue'; import { useNodesInitialized, useVueFlow } from '@xyflow/vue'; import ELK from 'elkjs/lib/elk.bundled.js'; // elk layouting options: https://www.eclipse.org/elk/reference/algorithms/org-eclipse-elk-layered.html const layoutOptions = { 'elk.algorithm': 'layered', 'elk.direction': 'RIGHT', 'elk.layered.spacing.edgeNodeBetweenLayers': '40', 'elk.spacing.nodeNode': '40', 'elk.layered.nodePlacement.strategy': 'SIMPLE', }; const elk = new ELK(); // uses elkjs to give each node a layouted position export async function getLayoutedNodes( nodes: ElkNode[], edges: readonly Edge[], ): Promise { const graph: ElkLayoutNode = { id: 'root', layoutOptions, children: nodes.map((n) => { const targetPorts = n.data.targetHandles.map((t) => ({ id: t.id, // ⚠️ it's important to tell elk which side the port is on β€” targets are on the // left (WEST) and sources on the right (EAST) properties: { side: 'WEST' }, })); const sourcePorts = n.data.sourceHandles.map((s) => ({ id: s.id, properties: { side: 'EAST' }, })); return { id: n.id, width: n.width ?? 150, height: n.height ?? 50, // ⚠️ tell elk the ports are fixed, to reduce edge crossings properties: { 'org.eclipse.elk.portConstraints': 'FIXED_ORDER' }, // pass the node id too, so we can handle edges without a source/target handle ports: [{ id: n.id }, ...targetPorts, ...sourcePorts], }; }), edges: edges.map((e) => ({ id: e.id, sources: [e.sourceHandle || e.source], targets: [e.targetHandle || e.target], })), }; const layoutedGraph = await elk.layout(graph); return nodes.map((node) => { const layoutedNode = layoutedGraph.children?.find( (lgNode) => lgNode.id === node.id, ); return { ...node, position: { x: layoutedNode?.x ?? 0, y: layoutedNode?.y ?? 0, }, }; }); } export default function useLayoutNodes() { const nodesInitialized = useNodesInitialized(); const { getNodes, getEdges, setNodes, fitView } = useVueFlow(); watch( nodesInitialized, async (initialized) => { if (!initialized) { return; } const layoutedNodes = await getLayoutedNodes( getNodes.value as unknown as ElkNode[], getEdges.value, ); setNodes(layoutedNodes); fitView(); }, { immediate: true }, ); } ``` ##### nodes.ts ```ts import type { Node } from '@xyflow/vue'; export type ElkNodeData = { label: string; sourceHandles: { id: string }[]; targetHandles: { id: string }[]; }; export type ElkNode = Node; export const nodes: ElkNode[] = [ { id: 'a', data: { label: 'A', // we need unique ids for the handles (called 'ports' in elkjs) for the layouting // an id is structured like: nodeId-source/target-id sourceHandles: [{ id: 'a-s-a' }, { id: 'a-s-b' }, { id: 'a-s-c' }], targetHandles: [], }, position: { x: 0, y: 0 }, type: 'elk', }, { id: 'b', data: { label: 'B', sourceHandles: [{ id: 'b-s-a' }, { id: 'b-s-b' }], targetHandles: [{ id: 'b-t-a' }, { id: 'b-t-b' }, { id: 'b-t-c' }], }, position: { x: 0, y: 0 }, type: 'elk', }, { id: 'c', data: { label: 'C', sourceHandles: [{ id: 'c-s-a' }, { id: 'c-s-b' }], targetHandles: [{ id: 'c-t-a' }, { id: 'c-t-b' }, { id: 'c-t-c' }], }, position: { x: 0, y: 0 }, type: 'elk', }, { id: 'd', data: { label: 'D', sourceHandles: [{ id: 'd-s-a' }], targetHandles: [{ id: 'd-t-a' }, { id: 'd-t-b' }, { id: 'd-t-c' }], }, position: { x: 0, y: 0 }, type: 'elk', }, { id: 'e', data: { label: 'E', sourceHandles: [{ id: 'e-s-a' }], targetHandles: [{ id: 'e-t-a' }], }, position: { x: 0, y: 0 }, type: 'elk', }, { id: 'f', data: { label: 'F', sourceHandles: [{ id: 'f-s-a' }], targetHandles: [{ id: 'f-t-a' }, { id: 'f-t-b' }], }, position: { x: 0, y: 0 }, type: 'elk', }, { id: 'g', data: { label: 'G', sourceHandles: [{ id: 'g-s-a' }], targetHandles: [{ id: 'g-t-a' }, { id: 'g-t-b' }], }, position: { x: 0, y: 0 }, type: 'elk', }, ]; ``` ##### 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; } .handles { position: absolute; display: flex; flex-direction: column; justify-content: space-around; } .handles.sources { right: 0; top: 0; height: 100%; transform: translate(50%, 0); } .handles.targets { left: 0; top: 0; height: 100%; transform: translate(-50%, 0); } .handles .vue-flow__handle { position: relative; top: 0; left: 0; transform: none; } ``` ##### edges.ts ```ts import type { Edge } from '@xyflow/vue'; export const edges: Edge[] = [ { id: 'a-b', source: 'a', sourceHandle: 'a-s-a', target: 'b', targetHandle: 'b-t-a', }, { id: 'a-c', source: 'a', sourceHandle: 'a-s-c', target: 'c', targetHandle: 'c-t-c', }, { id: 'a-d', source: 'a', sourceHandle: 'a-s-b', target: 'd', targetHandle: 'd-t-b', }, { id: 'b-e', source: 'b', sourceHandle: 'b-s-a', target: 'e', targetHandle: 'e-t-a', }, { id: 'd-e', source: 'd', sourceHandle: 'd-s-a', target: 'e', targetHandle: 'e-t-a', }, { id: 'e-f', source: 'e', sourceHandle: 'e-s-a', target: 'f', targetHandle: 'f-t-b', }, { id: 'e-g', source: 'e', sourceHandle: 'e-s-a', target: 'g', targetHandle: 'g-t-a', }, ]; ``` ##### ElkNode.vue ```vue ``` ##### App.vue ```vue ``` ### Elkjs Tree Example: examples/layout/elkjs ##### useElkjsLayout.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import type { ElkExtendedEdge, ElkNode } from 'elkjs/lib/elk-api'; import { Position } from '@xyflow/vue'; import ELK from 'elkjs/lib/elk.bundled'; export function useElkjsLayout() { const elk = new ELK(); return async ( nodes: Node[], edges: Edge[], options: Record = {}, ): Promise<{ nodes: Node[]; edges: Edge[] }> => { const isHorizontal = options['elk.direction'] === 'RIGHT'; const graph: ElkNode = { id: 'root', layoutOptions: options, children: nodes.map((node) => ({ ...node, // adjust the target/source handle positions to the layout direction targetPosition: isHorizontal ? Position.Left : Position.Top, sourcePosition: isHorizontal ? Position.Right : Position.Bottom, // hardcode a width/height for elk to lay out with width: 150, height: 50, })) as unknown as ElkNode[], edges: edges as unknown as ElkExtendedEdge[], }; const layoutedGraph = await elk.layout(graph); return { nodes: (layoutedGraph.children ?? []).map((node) => ({ ...(node as unknown as Node), // Vue Flow expects a `position` property instead of elk's `x`/`y` position: { x: node.x ?? 0, y: node.y ?? 0 }, })), edges: (layoutedGraph.edges ?? []) as unknown as Edge[], }; }; } ``` ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; const position = { x: 0, y: 0 }; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'input' }, position }, { id: '2', data: { label: 'node 2' }, position }, { id: '2a', data: { label: 'node 2a' }, position }, { id: '2b', data: { label: 'node 2b' }, position }, { id: '2c', data: { label: 'node 2c' }, position }, { id: '2d', data: { label: 'node 2d' }, position }, { id: '3', data: { label: 'node 3' }, position }, { id: '4', data: { label: 'node 4' }, position }, { id: '5', data: { label: 'node 5' }, position }, { id: '6', type: 'output', data: { label: 'output' }, position }, { id: '7', type: 'output', data: { label: 'output' }, position }, ]; export const initialEdges: Edge[] = [ { id: 'e12', source: '1', target: '2', type: 'smoothstep' }, { id: 'e13', source: '1', target: '3', type: 'smoothstep' }, { id: 'e22a', source: '2', target: '2a', type: 'smoothstep' }, { id: 'e22b', source: '2', target: '2b', type: 'smoothstep' }, { id: 'e22c', source: '2', target: '2c', type: 'smoothstep' }, { id: 'e2c2d', source: '2c', target: '2d', type: 'smoothstep' }, { id: 'e45', source: '4', target: '5', type: 'smoothstep' }, { id: 'e56', source: '5', target: '6', type: 'smoothstep' }, { id: 'e57', source: '5', target: '7', type: 'smoothstep' }, ]; ``` ##### 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; } ``` ##### App.vue ```vue ``` ### Entitree Flex Example: examples/layout/entitree-flex ##### layout-elements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import type { TreeNodeData } from './initialElements'; import { Position } from '@xyflow/vue'; import { layoutFromMap } from 'entitree-flex'; export type EntitreeNodeData = { label: string; direction: string; isRoot?: boolean; isSpouse?: boolean; isSibling?: boolean; children?: string[]; siblings?: string[]; spouses?: string[]; }; export type EntitreeNode = Node; const nodeWidth = 150; const nodeHeight = 36; const Orientation = { Vertical: 'vertical', Horizontal: 'horizontal', } as const; const entitreeSettings = { clone: true, // returns a copy of the input, if your application does not allow editing the original object enableFlex: true, // has slightly better performance if turned off (node.width, node.height will not be read) firstDegreeSpacing: 100, // spacing between nodes belonging to the same source, e.g. children with same parent nextAfterAccessor: 'spouses', // the side node prop used to go sideways, AFTER the current node nextAfterSpacing: 100, // the spacing of the "side" nodes AFTER the current node nextBeforeAccessor: 'siblings', // the side node prop used to go sideways, BEFORE the current node nextBeforeSpacing: 100, // the spacing of the "side" nodes BEFORE the current node nodeHeight, // default node height in px nodeWidth, // default node width in px orientation: Orientation.Vertical, // "vertical" = parents top / children bottom, "horizontal" = parents left rootX: 0, // set root position if other than 0 rootY: 0, // set root position if other than 0 secondDegreeSpacing: 100, // spacing between nodes not belonging to the same parent, e.g. "cousin" nodes sourcesAccessor: 'parents', // the prop used as the array of ancestor ids sourceTargetSpacing: 100, // the "vertical" spacing between nodes in vertical orientation, horizontal otherwise targetsAccessor: 'children', // the prop used as the array of children ids }; const { Top, Bottom, Left, Right } = Position; export function layoutElements( tree: Record, rootId: string | number, direction: 'TB' | 'LR' = 'TB', ) { const isTreeHorizontal = direction === 'LR'; const { nodes: entitreeNodes, rels: entitreeEdges } = layoutFromMap( rootId, tree, { ...entitreeSettings, orientation: isTreeHorizontal ? Orientation.Horizontal : Orientation.Vertical, }, ); const nodes: EntitreeNode[] = []; const edges: Edge[] = []; entitreeEdges.forEach((edge) => { const sourceNode = edge.source.id; const targetNode = edge.target.id; // check if the target node is a spouse or a sibling to pick which handles to connect const isTargetSpouse = !!edge.target.isSpouse; const isTargetSibling = !!edge.target.isSibling; let sourceHandle: Position; let targetHandle: Position; if (isTargetSpouse) { sourceHandle = isTreeHorizontal ? Bottom : Right; targetHandle = isTreeHorizontal ? Top : Left; } else if (isTargetSibling) { sourceHandle = isTreeHorizontal ? Top : Left; targetHandle = isTreeHorizontal ? Bottom : Right; } else { sourceHandle = isTreeHorizontal ? Right : Bottom; targetHandle = isTreeHorizontal ? Left : Top; } edges.push({ id: `e${sourceNode}${targetNode}`, source: sourceNode, target: targetNode, type: 'smoothstep', animated: true, sourceHandle, targetHandle, }); }); entitreeNodes.forEach((node) => { const isSpouse = !!node.isSpouse; const isSibling = !!node.isSibling; let sourcePosition: Position; let targetPosition: Position; if (isSpouse) { sourcePosition = isTreeHorizontal ? Bottom : Right; targetPosition = isTreeHorizontal ? Top : Left; } else if (isSibling) { sourcePosition = isTreeHorizontal ? Top : Left; targetPosition = isTreeHorizontal ? Bottom : Right; } else { sourcePosition = isTreeHorizontal ? Right : Bottom; targetPosition = isTreeHorizontal ? Left : Top; } nodes.push({ id: node.id, type: 'custom', position: { x: node.x, y: node.y }, width: nodeWidth, height: nodeHeight, sourcePosition, targetPosition, // `isRoot` (and isSpouse/isSibling/children/…) come from the spread entitree node data: { label: node.name, direction, ...node }, }); }); return { nodes, edges }; } ``` ##### initialElements.ts ```ts export const treeRootId = 1; export interface TreeNodeData { id: string; name: string; type?: string; children?: string[]; siblings?: string[]; spouses?: string[]; isSpouse?: boolean; isSibling?: boolean; } export const initialTree: Record = { 1: { id: '1', name: 'root', type: 'input', children: ['2', '3'], siblings: ['8'], spouses: ['10'], }, 2: { id: '2', name: 'child2' }, 3: { id: '3', name: 'child3', children: ['4', '5'], siblings: ['9'], spouses: ['6'], }, 4: { id: '4', name: 'grandChild4' }, 5: { id: '5', name: 'grandChild5' }, 6: { id: '6', name: 'spouse of child 3', isSpouse: true }, 8: { id: '8', name: 'root sibling', isSibling: true }, 9: { id: '9', name: 'child3 sibling', isSibling: true }, 10: { id: '10', name: 'root spouse', isSpouse: true }, }; ``` ##### 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; } ``` ##### CustomNode.vue ```vue ``` ##### App.vue ```vue ``` ### Expand and Collapse This example demonstrates how to implement expandable and collapsible nodes in a hierarchical tree structure. Nodes with children can be expanded or collapsed by clicking on them, revealing or hiding their descendants. The implementation maintains the complete graph structure while only rendering the currently visible portions. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [@dagrejs/dagre](https://www.npmjs.com/package/@dagrejs/dagre) * Demonstrates dynamic node addition with automatic layout recalculation * Uses node data properties to track expanded/collapsed state * Provides interactive controls to expand/collapse nodes and add children * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Force Layout This example shows how you can integrate a [d3 force layout](https://github.com/d3/d3-force) with Vue Flow. You can customize the layout by setting the strength of the force and the distance between the nodes. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [d3-force](https://www.npmjs.com/package/d3-force) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Horizontal Flow Example: examples/layout/horizontal ##### 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__edge-textbg { fill: #f7f9fb; } ``` ##### App.vue ```vue ``` ### Node Collisions Example: examples/layout/node-collisions ##### resolve-collisions.ts ```ts import type { Node } from '@xyflow/vue'; export type CollisionAlgorithmOptions = { maxIterations: number; overlapThreshold: number; margin: number; }; export type CollisionAlgorithm = ( nodes: Node[], options: CollisionAlgorithmOptions, ) => Node[]; type Box = { x: number; y: number; width: number; height: number; moved: boolean; node: Node; }; function getBoxesFromNodes(nodes: Node[], margin = 0): Box[] { const boxes: Box[] = Array.from({ length: nodes.length }); for (let i = 0; i < nodes.length; i++) { const node = nodes[i]; boxes[i] = { x: node.position.x - margin, y: node.position.y - margin, width: (node.width ?? node.measured?.width ?? 0) + margin * 2, height: (node.height ?? node.measured?.height ?? 0) + margin * 2, node, moved: false, }; } return boxes; } export const resolveCollisions: CollisionAlgorithm = ( nodes, { maxIterations = 50, overlapThreshold = 0.5, margin = 0 }, ) => { const boxes = getBoxesFromNodes(nodes, margin); for (let iter = 0; iter <= maxIterations; iter++) { let moved = false; for (let i = 0; i < boxes.length; i++) { for (let j = i + 1; j < boxes.length; j++) { const A = boxes[i]; const B = boxes[j]; // center positions const centerAX = A.x + A.width * 0.5; const centerAY = A.y + A.height * 0.5; const centerBX = B.x + B.width * 0.5; const centerBY = B.y + B.height * 0.5; // distance between centers const dx = centerAX - centerBX; const dy = centerAY - centerBY; // overlap along each axis const px = (A.width + B.width) * 0.5 - Math.abs(dx); const py = (A.height + B.height) * 0.5 - Math.abs(dy); // resolve if there's significant overlap if (px > overlapThreshold && py > overlapThreshold) { A.moved = B.moved = moved = true; // resolve along the smallest overlap axis if (px < py) { // move along the x-axis const sx = dx > 0 ? 1 : -1; const moveAmount = (px / 2) * sx; A.x += moveAmount; B.x -= moveAmount; } else { // move along the y-axis const sy = dy > 0 ? 1 : -1; const moveAmount = (py / 2) * sy; A.y += moveAmount; B.y -= moveAmount; } } } } // early exit if no overlaps were found if (!moved) { break; } } return boxes.map((box) => { if (box.moved) { return { ...box.node, position: { x: box.x + margin, y: box.y + margin, }, }; } return box.node; }); }; ``` ##### nodes-and-edges.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', position: { x: 624, y: 449 }, data: { label: 'πŸ‘' } }, { id: '2', position: { x: 661, y: 519 }, data: { label: 'πŸ‘' } }, { id: '3', position: { x: 554, y: 413 }, data: { label: 'πŸ‘' } }, { id: '4', position: { x: 700, y: 380 }, data: { label: 'πŸ‘' } }, { id: '5', position: { x: 637, y: 309 }, data: { label: 'πŸ‘' } }, { id: '6', position: { x: 630, y: 379 }, data: { label: 'πŸ‘' } }, { id: '7', position: { x: 770, y: 435 }, data: { label: 'πŸ‘' } }, { id: '8', position: { x: 694, y: 449 }, data: { label: 'πŸ‘' } }, { id: '9', position: { x: 707, y: 310 }, data: { label: 'πŸ‘' } }, { id: '10', position: { x: 560, y: 343 }, data: { label: 'πŸ‘' } }, { id: '11', position: { x: 522, y: 487 }, data: { label: 'πŸ‘' } }, { id: '12', position: { x: 591, y: 518 }, data: { label: 'πŸ‘' } }, { id: '13', position: { x: 701, y: 589 }, data: { label: 'πŸ‘' } }, { id: '14', position: { x: 731, y: 519 }, data: { label: 'πŸ‘' } }, { id: '15', position: { x: 801, y: 505 }, data: { label: 'πŸ‘' } }, { id: '16', position: { x: 250, y: 450 }, data: { label: '🐢' } }, ]; export const initialEdges: 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; } html, body, #app { height: 100%; } .vue-flow__node { display: flex; height: 50px; width: 50px; align-items: center; justify-content: center; border-radius: 0.5rem; background-color: var(--xy-node-background-color-default); border: var(--xy-node-border-default); padding: 1rem; box-shadow: var(--xy-node-boxshadow-default); } .vue-flow__handle { opacity: 0; pointer-events: none !important; } ``` ##### App.vue ```vue ``` ### Download Image Example: examples/misc/download-image ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'β–²' }, position: { x: 0, y: 50 }, sourcePosition: Position.Right, style: { backgroundColor: '#BEE3F8' }, }, { id: '2', type: 'custom', data: {}, position: { x: 200, y: 50 }, style: { backgroundColor: '#90CDF4' }, }, { id: '3', data: { label: 'β–²' }, position: { x: 400, y: 0 }, targetPosition: Position.Left, sourcePosition: Position.Right, style: { backgroundColor: '#63B3ED' }, }, { id: '4', data: { label: 'β–²' }, position: { x: 400, y: 100 }, targetPosition: Position.Left, sourcePosition: Position.Right, style: { backgroundColor: '#63B3ED' }, }, { id: '5', type: 'output', data: { label: 'β–²' }, position: { x: 600, y: 0 }, targetPosition: Position.Left, style: { backgroundColor: '#4299E1' }, }, { id: '6', type: 'output', data: { label: 'β–²' }, position: { x: 600, y: 100 }, targetPosition: Position.Left, style: { backgroundColor: '#4299E1' }, }, ]; export const initialEdges: Edge[] = [ { id: 'e1-2', source: '1', target: '2' }, { id: 'e2a-3', source: '2', target: '3', sourceHandle: 'a' }, { id: 'e2b-4', source: '2', target: '4', sourceHandle: 'b' }, { id: 'e3a-5', source: '3', target: '5' }, { id: 'e4b-6', source: '4', target: '6' }, ]; ``` ##### 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; } ``` ##### DownloadButton.vue ```vue ``` ##### CustomNode.vue ```vue ``` ##### App.vue ```vue ``` ### Pinia Example: examples/misc/pinia ##### store.ts ```ts import type { Connection, Edge, Node } from '@xyflow/vue'; import { shallowRef } from 'vue'; import { addEdge } from '@xyflow/vue'; import { defineStore } from 'pinia'; const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, class: 'light', }, { id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 }, class: 'light', }, { id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 }, class: 'light', }, { id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 }, class: 'light', }, ]; const initialEdges: Edge[] = [ { id: 'e1-2', source: '1', target: '2' }, { id: 'e1-3', source: '1', target: '3' }, { id: 'e3-4', source: '3', target: '4' }, ]; export const useStore = defineStore('vue-flow-pinia', () => { const nodes = shallowRef(initialNodes); const edges = shallowRef(initialEdges); function connect(connection: Connection) { edges.value = addEdge(connection, edges.value); } function reset() { nodes.value = initialNodes; edges.value = initialEdges; } function log() { console.log('nodes', nodes.value, 'edges', edges.value); } function toggleClass() { nodes.value = nodes.value.map((node) => ({ ...node, class: node.class === 'dark' ? 'light' : 'dark', })); } function updatePositions() { nodes.value = nodes.value.map((node) => ({ ...node, position: { x: Math.random() * 400, y: Math.random() * 400 }, })); } return { nodes, edges, connect, reset, log, toggleClass, updatePositions }; }); ``` ##### 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; } /* the store toggles these classes on every node */ .pinia-flow .vue-flow__node.light { background-color: #fefefe; color: #1a192b; border: 1px solid #1a192b; } .pinia-flow .vue-flow__node.dark { background-color: #1a192b; color: #fefefe; border: 1px solid #fefefe; } .pinia-flow .vue-flow__panel button svg { display: block; } ``` ##### Icon.vue ```vue ``` ##### App.vue ```vue ``` ### Server Side Image Creation This example demonstrates how to create static images of Vue Flow graphs on the server side. The application lets you interact with nodes on the left side of the screen while automatically generating and displaying the corresponding flow image on the right. The backend uses Puppeteer to render the flow on a standalone preview page and capture it as an image. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [express](https://www.npmjs.com/package/express), [puppeteer](https://www.npmjs.com/package/puppeteer), [cors](https://www.npmjs.com/package/cors) * Includes a complete backend implementation for image generation * Provides Dockerfile configuration for containerized deployment * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Add Node On Edge Drop You can create a new node when you drop the connection line on the pane by using the `@connect-start` and `@connect-end` events. Example: examples/nodes/add-node-on-edge-drop ##### 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; } .wrapper { height: 100%; } ``` ##### App.vue ```vue ``` ### Connection Limit This is an example of a custom node with a custom handle that can limit the amount of connections a handle can have using the `isConnectable` prop. Example: examples/nodes/connection-limit ##### 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-custom .vue-flow__handle.connectable { border-color: var(--xy-theme-selected); background: var(--xy-theme-selected); &:hover { background: var(--xy-theme-selected); } } ``` ##### CustomNode.vue ```vue ``` ##### CustomHandle.vue ```vue ``` ##### App.vue ```vue ``` ### Custom Nodes Creating a custom node is as easy as building a regular Vue component and registering it with a `#node-` slot. You can render any content and add any behavior you need, with full access to the node's props. For more, see the [Custom Nodes guide](/learn/customization/custom-nodes). Example: examples/nodes/custom-node ##### types.ts ```ts import type { BuiltInNode, Node, NodeProps } from '@xyflow/vue'; export type ColorSelectorNodeData = { color: string; }; export type ColorSelectorNode = Node; export type ColorSelectorNodeProps = NodeProps; export type CustomNodeExampleNode = ColorSelectorNode | BuiltInNode; ``` ##### initial-elements.ts ```ts import type { Edge } from '@xyflow/vue'; import type { CustomNodeExampleNode } from './types'; import { Position } from '@xyflow/vue'; export const initColor = '#ff0071'; export const nodes: CustomNodeExampleNode[] = [ { id: '1', type: 'input', data: { label: 'An input node' }, position: { x: 0, y: 50 }, sourcePosition: Position.Right, }, { id: '2', type: 'selectorNode', data: { color: initColor }, position: { x: 300, y: 50 }, }, { id: '3', type: 'output', data: { label: 'Output A' }, position: { x: 650, y: 25 }, targetPosition: Position.Left, }, { id: '4', type: 'output', data: { label: 'Output B' }, position: { x: 650, y: 100 }, targetPosition: Position.Left, }, ]; export const edges: Edge[] = [ { id: 'e1-2', source: '1', target: '2', animated: true }, { id: 'e2a-3', source: '2', target: '3', animated: true }, { id: 'e2b-4', source: '2', target: '4', animated: true }, ]; ``` ##### 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; } .color-input { width: 40px; height: 24px; margin-top: 6px; padding: 0; border: 0; background: transparent; appearance: none; cursor: pointer; } .color-input::-webkit-color-swatch-wrapper { padding: 0; } .color-input::-webkit-color-swatch { border: 0; border-radius: 999px; } .color-input::-moz-color-swatch { border: 0; border-radius: 999px; } .color-panel { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--xy-controls-button-border-color, #ddd); border-radius: 8px; background: var(--xy-controls-button-background-color, #fff); } .color-swatch { width: 16px; height: 16px; border: 1px solid rgba(0, 0, 0, 0.2); border-radius: 999px; } .color-value { font-family: monospace; font-variant-numeric: tabular-nums; } ``` ##### ColorSelectorNode.vue ```vue ``` ##### App.vue ```vue ``` ### Delete Middle Node This example shows how to keep a chain connected when you delete a node from the middle. If three nodes are linked `a β†’ b β†’ c` and you delete `b`, you end up with `a β†’ c`. It leans on a few helpers: the `@nodes-delete` event tells us which nodes were removed, [`getConnectedEdges`](/api-reference/utils/get-connected-edges) returns the edges touching a node, and [`getIncomers`](/api-reference/utils/get-incomers) / [`getOutgoers`](/api-reference/utils/get-outgoers) return the nodes connected to it as source or target. For each deleted node we drop its edges, then reconnect every incomer to every outgoer. Example: examples/nodes/delete-middle-node ##### initial-elements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; export const initialNodes: Node[] = [ { id: '1', type: 'input', data: { label: 'Start here...' }, position: { x: -150, y: 0 }, }, { id: '2', type: 'input', data: { label: '...or here!' }, position: { x: 150, y: 0 }, }, { id: '3', data: { label: 'Delete me.' }, position: { x: 0, y: 100 } }, { id: '4', data: { label: 'Then me!' }, position: { x: 0, y: 200 } }, { id: '5', type: 'output', data: { label: 'End here!' }, position: { x: 0, y: 300 }, }, ]; export const initialEdges: Edge[] = [ { id: '1->3', source: '1', target: '3' }, { id: '2->3', source: '2', target: '3' }, { id: '3->4', source: '3', target: '4' }, { id: '4->5', source: '4', target: '5' }, ]; ``` ##### 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; } ``` ##### App.vue ```vue ``` ### Detached Handle Example: examples/nodes/detached-handle ##### types.ts ```ts import type { BuiltInNode, Node, NodeProps } from '@xyflow/vue'; export type DetachedHandleNodeData = { label: string }; export type DetachedHandleNode = Node; export type DetachedHandleNodeProps = NodeProps; export type DetachedFlowNode = DetachedHandleNode | BuiltInNode; ``` ##### 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; } .detached-handle { position: absolute; top: 50%; left: 1rem; transform: translateY(-50%); width: 2rem; height: 2rem; border: none; border-radius: 50%; cursor: crosshair; } ``` ##### DetachedHandleNode.vue ```vue ``` ##### App.vue ```vue ``` ### Drag Handle You can restrict dragging to a specific part of a node, by specifying a class that acts as a [`dragHandle`](/api-reference/types/node). To stop elements inside the drag handle from starting a drag, add the [`nodrag`](/learn/customization/utility-classes) class to them. Example: examples/nodes/drag-handle ##### 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; } .drag-handle__label { display: flex; align-items: center; } .drag-handle__custom { display: inline-block; width: 20px; height: 20px; background-color: teal; margin-left: 15px; border-radius: 50%; } ``` ##### DragHandleNode.vue ```vue ``` ##### App.vue ```vue ``` ### Easy Connect Fed up with tiny little connection handles? Make your whole node act as one! Keep in mind though that you need to define separate drag handles in this case to still be able to drag the node. Example: examples/nodes/easy-connect ##### utils.ts ```ts import type { InternalNode } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; // returns the intersection point of the line between the center of intersectionNode and the target node // https://math.stackexchange.com/questions/1724792 function getNodeIntersection( intersectionNode: InternalNode, targetNode: InternalNode, ) { const intersectionNodeWidth = intersectionNode.measured.width ?? 0; const intersectionNodeHeight = intersectionNode.measured.height ?? 0; const intersectionNodePosition = intersectionNode.internals.positionAbsolute; const targetPosition = targetNode.internals.positionAbsolute; const w = intersectionNodeWidth / 2; const h = intersectionNodeHeight / 2; const x2 = intersectionNodePosition.x + w; const y2 = intersectionNodePosition.y + h; const x1 = targetPosition.x + (targetNode.measured.width ?? 0) / 2; const y1 = targetPosition.y + (targetNode.measured.height ?? 0) / 2; const xx1 = (x1 - x2) / (2 * w) - (y1 - y2) / (2 * h); const yy1 = (x1 - x2) / (2 * w) + (y1 - y2) / (2 * h); const a = 1 / (Math.abs(xx1) + Math.abs(yy1) || 1); const xx3 = a * xx1; const yy3 = a * yy1; const x = w * (xx3 + yy3) + x2; const y = h * (-xx3 + yy3) + y2; return { x, y }; } // returns the position (Top, Right, Bottom or Left) of the node relative to the intersection point function getEdgePosition( node: InternalNode, intersectionPoint: { x: number; y: number }, ) { const pos = node.internals.positionAbsolute; const nx = Math.round(pos.x); const ny = Math.round(pos.y); const px = Math.round(intersectionPoint.x); const py = Math.round(intersectionPoint.y); const width = node.measured.width ?? 0; const height = node.measured.height ?? 0; if (px <= nx + 1) { return Position.Left; } if (px >= nx + width - 1) { return Position.Right; } if (py <= ny + 1) { return Position.Top; } if (py >= ny + height - 1) { return Position.Bottom; } return Position.Top; } // returns the params (sx, sy, tx, ty, sourcePos, targetPos) needed to draw a floating edge between two nodes export function getEdgeParams(source: InternalNode, target: InternalNode) { const sourceIntersectionPoint = getNodeIntersection(source, target); const targetIntersectionPoint = getNodeIntersection(target, source); const sourcePos = getEdgePosition(source, sourceIntersectionPoint); const targetPos = getEdgePosition(target, targetIntersectionPoint); return { sx: sourceIntersectionPoint.x, sy: sourceIntersectionPoint.y, tx: targetIntersectionPoint.x, ty: targetIntersectionPoint.y, sourcePos, targetPos, }; } ``` ##### types.ts ```ts import type { Node, NodeProps } from '@xyflow/vue'; // The whole node acts as a handle (see CustomNode + index.css), so it carries no data of its own. export type EasyConnectNode = Node, 'custom'>; export type CustomNodeProps = NodeProps; ``` ##### 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; } .customNodeBody { width: 150px; height: 80px; position: relative; border-radius: 10px; display: flex; justify-content: center; align-items: center; font-weight: bold; } div.customHandle { width: 100%; height: 100%; background: blue; position: absolute; top: 0; left: 0; border-radius: 0; transform: none; border: none; opacity: 0; } ``` ##### FloatingEdge.vue ```vue ``` ##### CustomNode.vue ```vue ``` ##### CustomConnectionLine.vue ```vue ``` ##### App.vue ```vue ``` ### Hidden Example: examples/nodes/hidden ##### 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__panel { padding-left: 0.5rem; padding-top: 0.5rem; padding-bottom: 0.5rem; border-radius: 8px; background-color: light-dark( rgba(207, 182, 255, 0.4), rgba(123, 107, 148, 0.22) ); color: light-dark(black, white); } .vue-flow__panel label { width: 100%; display: flex; align-items: center; gap: 0.5rem; } ``` ##### App.vue ```vue ``` ### Intersections [`useVueFlow`](/api-reference/composables/use-vue-flow) exposes helpers to check whether nodes intersect with other nodes or with an area. Drag a node here to see it highlight when it overlaps another. Example: examples/nodes/intersections ##### 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.highlight { background-color: #918fbe; color: white; } .intersection-flow .vue-flow__handle { display: none; } ``` ##### App.vue ```vue ``` ### Node Position Animation This example demonstrates how to create fluid, animated transitions between different graph layouts. When you click the "toggle layout" button, nodes smoothly animate to their new positions, creating a visually appealing way to switch between different arrangements. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [d3-timer](https://www.npmjs.com/package/d3-timer) * Implements a reusable `createAnimatedNodes` function for smooth transitions * Uses linear interpolation to animate node positions * Demonstrates position tweening between horizontal and vertical layouts * Provides a simple toggle control to switch between different layouts * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Node Resizer The [``](/api-reference/components/node-resizer) component adds a resize UI to a custom node. Vue Flow also exports [``](/api-reference/components/node-resize-control) for building a custom resize control, as shown here. Example: examples/nodes/node-resizer ##### types.ts ```ts import type { Node } from '@xyflow/vue'; /** Every node in this example carries the same data; only the (visual) node type differs. */ export type NodeResizerExampleNode = Node<{ label: string }>; ``` ##### 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; } ``` ##### ResizableNodeSelected.vue ```vue ``` ##### ResizableNode.vue ```vue ``` ##### CustomResizerNode.vue ```vue ``` ##### App.vue ```vue ``` ### Node Toolbar For many types of applications, having a toolbar or set of controls appear when a node is selected can be quite useful. Content in the toolbar is not scaled as you zoom your flow in and out: this means it should always be visible. Example: examples/nodes/node-toolbar ##### types.ts ```ts import type { Align, Node, Position } from '@xyflow/vue'; export type NodeWithToolbarData = { label: string; toolbarPosition?: Position; align?: Align; forceToolbarVisible?: boolean; }; export type NodeWithToolbarNode = Node< NodeWithToolbarData, 'node-with-toolbar' >; ``` ##### 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; } ``` ##### NodeWithToolbar.vue ```vue ``` ##### App.vue ```vue ``` ### Proximity Connect This example shows how to automatically create edges when a node is dropped in close proximity to another one. While dragging, a dotted connection line is displayed to show which edge will be created if you drop the node. Example: examples/nodes/proximity-connect ##### initial-elements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; const nodeDefaults = { sourcePosition: Position.Right, targetPosition: Position.Left, }; export const initialNodes: Node[] = [ { id: '1', position: { x: 0, y: 0 }, data: { label: '⬛️' }, ...nodeDefaults }, { id: '2', position: { x: 250, y: -100 }, data: { label: '🟩' }, ...nodeDefaults, }, { id: '3', position: { x: 250, y: 100 }, data: { label: '🟧' }, ...nodeDefaults, }, { id: '4', position: { x: 500, y: 0 }, data: { label: '🟦' }, ...nodeDefaults, }, ]; export const initialEdges: Edge[] = [ { id: 'e1-2', source: '1', target: '2' }, { id: 'e1-3', source: '1', target: '3' }, ]; ``` ##### 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; } .temp .vue-flow__edge-path { stroke: #bbb; stroke-dasharray: 5 5; } .vue-flow__node { border-radius: 100%; background-color: var(--xy-node-background-color-default); border: var(--xy-node-border-default); width: 50px; height: 50px; display: flex; align-items: center; justify-content: center; } ``` ##### App.vue ```vue ``` ### Rotatable Node This example shows how to implement a [custom node](/learn/customization/custom-nodes) that can be rotated using CSS transforms. Dragging the small handle above the node updates its `rotation` and calls `updateNodeInternals` so the edges keep following the handles. Example: examples/nodes/rotatable-node ##### initialElements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; import { Position } from '@xyflow/vue'; export type RotatableNodeData = { label: string }; export type RotatableNode = Node; export const initialNodes: RotatableNode[] = [ { id: '1', type: 'rotatableNode', position: { x: 0, y: 0 }, data: { label: 'Rotate Me!' }, targetPosition: Position.Left, sourcePosition: Position.Right, }, { id: '2', type: 'rotatableNode', position: { x: 300, y: 0 }, data: { label: 'Rotate Me!' }, targetPosition: Position.Left, sourcePosition: Position.Right, }, ]; export const initialEdges: Edge[] = [ { id: '1->2', source: '1', target: '2', type: 'smoothstep' }, ]; ``` ##### 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__node-rotatableNode { border: 0; box-shadow: none; } .rotatable-node { transform-origin: center center; box-sizing: border-box; } .rotatable-node__handle { position: absolute; width: 10px; height: 10px; background: #3367d9; left: 50%; top: -30px; border-radius: 100%; transform: translate(-50%, -50%); cursor: alias; } .rotatable-node__handle:after { content: ''; display: block; position: absolute; width: 1px; height: 30px; background: #3367d9; left: 4px; top: 5px; } ``` ##### RotatableNode.vue ```vue ``` ##### App.vue ```vue ``` ### Shapes This example shows how to render [Custom Nodes](/learn/customization/custom-nodes) with different shapes commonly used in flow charts like circles, diamonds, or hexagons. It also showcases how to create a sidebar component, custom minimap nodes, and a node toolbar for changing the color of the shapes. The example uses a centralized Shape component that renders different SVG paths based on the shape type. By defining node data with `{ type: 'shape', data: { type: 'diamond', color: '#ff0071' }}`, you can control which shape gets rendered and how it appears, all while using a single node type implementation. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Stress Test This example shows how Vue Flow performs when rendering hundreds of nodes and edges. Example: examples/nodes/stress ##### initial-elements.ts ```ts import type { Edge, Node } from '@xyflow/vue'; // px strings on `style` (Vue's `:style` doesn't px-ify numeric values) export function initialElements( xNodes = 10, yNodes = 10, ): { nodes: Node[]; edges: Edge[] } { const nodes: Node[] = []; const edges: Edge[] = []; let nodeId = 1; let recentNodeId: number | null = null; for (let y = 0; y < yNodes; y++) { for (let x = 0; x < xNodes; x++) { const position = { x: x * 100, y: y * 50 }; const data = { label: `Node ${nodeId}` }; nodes.push({ id: `stress-${nodeId}`, style: { width: '50px', fontSize: '11px' }, data, position, }); if (recentNodeId && nodeId <= xNodes * yNodes) { edges.push({ id: `${x}-${y}`, source: `stress-${recentNodeId}`, target: `stress-${nodeId}`, }); } recentNodeId = nodeId; nodeId++; } } return { nodes, edges }; } ``` ##### 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; } /* The demo theme's default node shadow is a heavy 3-layer, 18px-blur drop shadow. At stress-test scale Chrome re-rasterizes every node's blurred shadow on each pan/zoom frame, which tanks the frame rate (Firefox rasters it far more cheaply). Use a light single-layer shadow here so pan/zoom stays smooth; the fancy shadow is kept in the other (small) examples. */ .vue-flow { --xy-node-boxshadow-default: 0 1px 4px 1px rgba(0, 0, 0, 0.12); } ``` ##### App.vue ```vue ``` ### Teleport Example: examples/nodes/teleport ##### useTeleport.ts ```ts import type { Node } from '@xyflow/vue'; import { nextTick, shallowRef } from 'vue'; import { getConnectedEdges, useVueFlow } from '@xyflow/vue'; export type TeleportNodeData = { label?: string; /** the selector the node is currently teleported into, or null when it lives in the graph */ destination?: string | null; }; export type TeleportNode = Node; type Animation = 'fade' | 'shrink'; /** * Drives a single teleportable node: it stays a graph node (edges still track its position) but its DOM is * moved into another element via Vue's ``. Animations that resize the node call * `updateNodeInternals` so the handle positions β€” and therefore the connected edges β€” stay correct. */ export function useTeleport(id: string) { const animation = shallowRef('fade'); const transition = shallowRef(false); const target = shallowRef(null); const { updateNodeInternals, updateNodeData, getNode, getEdges, setEdges } = useVueFlow(); // hide an edge while either of its endpoints is teleported out of the graph function syncHiddenEdges(connectedEdgeIds: string[]) { setEdges((edges) => edges.map((edge) => connectedEdgeIds.includes(edge.id) ? { ...edge, hidden: !!getNode(edge.source)?.data.destination || !!getNode(edge.target)?.data.destination, } : edge, ), ); } function fade(destination: string | null, onFinish: () => void) { setTimeout(() => { target.value = destination; setTimeout(() => { transition.value = false; // when returning to the graph, defer hiding edges until the node is back if (!destination) { onFinish(); } }, 500); }, 500); } function shrink(destination: string | null, onFinish: () => void) { setTimeout(() => { target.value = destination; setTimeout(() => { transition.value = false; if (!destination) { setTimeout(() => { updateNodeInternals([id]); nextTick(onFinish); }, 500); } }, 500); }, 500); } function onClick(destination: string | null) { const node = getNode(id); if (!node) { return; } transition.value = true; // remember where the node went so `syncHiddenEdges` can check both endpoints updateNodeData(id, { destination }); const connectedEdgeIds = getConnectedEdges([node], [...getEdges.value]).map( (edge) => edge.id, ); // hide edges immediately when leaving the graph if (destination) { syncHiddenEdges(connectedEdgeIds); } const onFinish = () => syncHiddenEdges(connectedEdgeIds); if (animation.value === 'shrink') { shrink(destination, onFinish); } else { fade(destination, onFinish); } } return { animation, transition, target, onClick }; } ``` ##### 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; } .teleportflow { display: flex; flex-direction: column; height: 100%; } .teleportflow .vue-flow { flex-grow: 1; } .teleportflow aside { display: flex; flex-direction: column; gap: 5px; color: white; font-weight: 700; border-right: 1px solid #eee; padding: 10px; font-size: 12px; background: rgba(16, 185, 129, 0.75); box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.3); } .teleportflow aside .description { margin-bottom: 10px; } .teleportflow aside .port > * { position: relative; margin-bottom: 10px; cursor: grab; font-weight: 500; box-shadow: 5px 5px 10px 2px rgba(0, 0, 0, 0.25); } @media screen and (min-width: 640px) { .teleportflow { flex-direction: row; } .teleportflow aside { min-width: 25%; } } @media screen and (max-width: 639px) { .teleportflow aside .port { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; } } .vue-flow__node-teleportable { padding: 0; border: none; background: transparent; box-shadow: none; } .vue-flow__node-teleportable.selectable.selected { box-shadow: none; } .vue-flow__node-teleportable:empty { display: none; } .teleportable { padding: 10px; background: white; border: 1px solid black; border-radius: 10px; color: black; } .buttons { display: flex; flex-direction: column; justify-content: center; align-items: center; margin-top: 5px; gap: 5px; } .buttons .button { background-color: whitesmoke; cursor: pointer; padding: 5px 10px; border: 1px solid black; border-radius: 10px; color: black; font-weight: 700; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); } .buttons .button:hover { background: black; color: white; } .fade-enter-active, .fade-leave-active { transition: opacity 0.5s ease; } .fade-enter-from, .fade-leave-to { opacity: 0; } .shrink-leave-active { animation: shrink 0.5s; } .shrink-enter-active { animation: grow 0.5s; } @keyframes grow { from { transform: scale(0.1); } to { transform: scale(1); } } @keyframes shrink { from { transform: scale(1); } to { transform: scale(0.1); } } ``` ##### TeleportableNode.vue ```vue ``` ##### Sidebar.vue ```vue ``` ##### App.vue ```vue ``` ### Updating Nodes You can update properties of nodes and edges freely as long as you pass a newly created `nodes` or `edges` array to `VueFlow`. Example: examples/nodes/update-node ##### 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; } ``` ##### App.vue ```vue ``` ### Base Style Example: examples/styling/base-style ##### index.css ```css @import url('@xyflow/vue/dist/base.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ### Dark Mode Example: examples/styling/dark-mode ##### index.css ```css @import url('@xyflow/vue/xy-theme.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ### Default Style Example: examples/styling/default-style ##### index.css ```css @import url('@xyflow/vue/xy-theme.css'); html, body { margin: 0; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } ``` ##### App.vue ```vue ``` ### Tailwind Example: examples/styling/tailwind ##### types.ts ```ts import type { Node } from '@xyflow/vue'; export type PersonNodeData = { name: string; job: string; emoji: string; }; export type PersonNode = Node; ``` ##### index.css ```css @layer theme, base, xyflow, components, utilities; @import 'tailwindcss'; @import '@xyflow/vue/xy-theme.css'; html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } ``` ##### CustomNode.vue ```vue ``` ##### App.vue ```vue ``` ### Turbo Flow Example: examples/styling/turbo-flow ##### types.ts ```ts import type { Component } from 'vue'; import type { Node } from '@xyflow/vue'; export type TurboNodeData = { title: string; icon?: Component; subtitle?: string; }; export type TurboNodeType = Node; ``` ##### index.css ```css @import url('@xyflow/vue/dist/base.css'); html, body { margin: 0; font-family: sans-serif; box-sizing: border-box; } #app { width: 100vw; height: 100vh; } .vue-flow { --bg-color: rgb(17, 17, 17); --text-color: rgb(243, 244, 246); --node-border-radius: 10px; --node-box-shadow: 10px 0 15px rgba(42, 138, 246, 0.3), -10px 0 15px rgba(233, 42, 103, 0.3); background-color: var(--bg-color); color: var(--text-color); } .vue-flow__node-turbo { border-radius: var(--node-border-radius); display: flex; height: 70px; min-width: 150px; font-family: 'Fira Mono', Monospace; font-weight: 500; letter-spacing: -0.2px; box-shadow: var(--node-box-shadow); } .vue-flow__node-turbo .wrapper { overflow: hidden; display: flex; padding: 2px; position: relative; border-radius: var(--node-border-radius); flex-grow: 1; } .gradient:before { content: ''; position: absolute; padding-bottom: calc(100% * 1.41421356237); width: calc(100% * 1.41421356237); background: conic-gradient( from -160deg at 50% 50%, #e92a67 0deg, #a853ba 120deg, #2a8af6 240deg, #e92a67 360deg ); left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 100%; } .vue-flow__node-turbo.selected .wrapper.gradient:before { content: ''; background: conic-gradient( from -160deg at 50% 50%, #e92a67 0deg, #a853ba 120deg, #2a8af6 240deg, rgba(42, 138, 246, 0) 360deg ); animation: spinner 4s linear infinite; transform: translate(-50%, -50%) rotate(0deg); z-index: -1; } @keyframes spinner { 100% { transform: translate(-50%, -50%) rotate(-360deg); } } .vue-flow__node-turbo .inner { background: var(--bg-color); padding: 16px 20px; border-radius: var(--node-border-radius); display: flex; flex-direction: column; justify-content: center; flex-grow: 1; position: relative; } .vue-flow__node-turbo .icon { margin-right: 8px; } .vue-flow__node-turbo .body { display: flex; } .vue-flow__node-turbo .title { font-size: 16px; margin-bottom: 2px; line-height: 1; } .vue-flow__node-turbo .subtitle { font-size: 12px; color: #777; } .vue-flow__node-turbo .cloud { border-radius: 100%; width: 30px; height: 30px; right: 0; position: absolute; top: 0; transform: translate(50%, -50%); display: flex; transform-origin: center center; padding: 2px; overflow: hidden; box-shadow: var(--node-box-shadow); z-index: 1; } .vue-flow__node-turbo .cloud div { background-color: var(--bg-color); flex-grow: 1; border-radius: 100%; display: flex; justify-content: center; align-items: center; position: relative; } .vue-flow__handle { opacity: 0; } .vue-flow__handle.source { right: -10px; } .vue-flow__handle.target { left: -10px; } .vue-flow__node:focus { outline: none; } .vue-flow__edge .vue-flow__edge-path { stroke: url(#edge-gradient); stroke-width: 2; stroke-opacity: 0.75; } .vue-flow__controls button { background-color: var(--bg-color); color: var(--text-color); border: 1px solid #95679e; border-bottom: none; } .vue-flow__controls button:hover { background-color: rgb(37, 37, 37); } .vue-flow__controls button:first-child { border-radius: 5px 5px 0 0; } .vue-flow__controls button:last-child { border-bottom: 1px solid #95679e; border-radius: 0 0 5px 5px; } .vue-flow__controls button path { fill: var(--text-color); } .vue-flow__attribution { background: rgba(200, 200, 200, 0.2); } .vue-flow__attribution a { color: #95679e; } ``` ##### TurboNode.vue ```vue ``` ##### TurboEdge.vue ```vue ``` ##### FunctionIcon.vue ```vue ``` ##### FileIcon.vue ```vue ``` ##### App.vue ```vue ``` ### Eraser Tool 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 ``` ### Freehand Draw This example demonstrates how to implement freehand drawing capabilities in your Vue Flow application. Users can draw smooth curves on the pane, which can be useful for annotations or sketching around existing nodes. Drawings get converted into custom nodes that can be styled and manipulated like regular nodes. ! THIS IS A PRO EXAMPLE. SUBSCRIBE TO TO ACCESS PRO EXAMPLES ! ##### About this Pro Example * Dependencies: [@xyflow/vue](https://www.npmjs.com/package/@xyflow/vue), [perfect-freehand](https://www.npmjs.com/package/perfect-freehand) * License: [xyflow Pro License](https://xyflow.com/pro-license) ### Lasso Selection 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 ``` ### Rectangle 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 ``` ## API Reference ### API Reference This reference attempts to document every function, composable, component, and type exported by Vue Flow. If you are looking for guides, please refer to our [learn section](/learn). #### How to use this reference We think that documentation should answer two broad questions: "what is this thing?" and "how do I use it?" To that end, our API reference aims to **concisely** answer that first question, while guides go into more detail on the second. If you find yourself clicking around the reference wondering what the heck any of this means, maybe we have a guide that can help you out! #### A note for JavaScript users Vue Flow is written in TypeScript, but we know that not everyone uses it. We encourage developers to use the technology that works best for them, and throughout our documentation there is a blend of TypeScript and JavaScript examples. For our API reference, however, we use TypeScript's syntax to document the types of props and functions. Here's a quick crash course on how to read it: β€’ `?` means that the field or argument is optional. β€’ `` in a type definition represents a generic type parameter. Like a function argument but for types! The definition `type Array = ...` means a type called `Array` that takes a generic type parameter `T`. β€’ `` when referring to a type is like "filling in" a generic type parameter. It's like calling a function but for types! The type `Array` is the type `Array` with the generic type parameter `T` filled in with the type `number`. β€’ `T | U` means that the type is either `T` or `U`: this is often called a *union*. β€’ `T & U` means that the type is both `T` and `U`: this is often called an *intersection*. The TypeScript folks have their own [handy guide for reading types](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html) that you might find useful. If you're still stuck on something, feel free to drop by our [Discord](https://discord.com/invite/RVmnytFmGW) and ask for help! ### The VueFlowProvider component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/container/VueFlowProvider/VueFlowProvider.vue) The `` component creates a Vue Flow store and `provide`s it to everything it wraps, so components rendered *outside* of [``](/api-reference/vue-flow) β€” a sidebar, a toolbar β€” can still read and drive the flow through [`useVueFlow()`](/api-reference/composables/use-vue-flow) and the other composables. ```vue ``` ```vue ``` Prefer the composable [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) when you own the surrounding component β€” it creates and provides the same store from ` ``` This component takes a lot of different props, most of which are optional. We've tried to document them in groups that make sense to help you find your way. #### Common props These are the props you will most commonly use when working with Vue Flow. * `id?: string` An optional id for the flow. Useful when you render multiple flows on one page. * `nodes?: Node, string | undefined>[]` An array of nodes to render in a controlled flow. * `edges?: Edge, string>[]` An array of edges to render in a controlled flow. * `edgeTypes?: EdgeTypesObject, string>>` Custom edge types to be available in a flow. Vue Flow matches an edge's type to a component in the `edgeTypes` object. Alternatively, register edge components with the `#edge-` slots. * `nodeTypes?: NodeTypesObject, string | undefined>>` Custom node types to be available in a flow. Vue Flow matches a node's type to a component in the `nodeTypes` object. Alternatively, register node components with the `#node-` slots. * `forceColorMode?: ColorMode` Forces a color scheme on the flow container via class name, overriding the system default. Page-level theming is typically done by setting `data-theme` on ``. * `proOptions?: ProOptions` By default, we render a small attribution in the corner of your flows that links back to the project. Anyone is free to remove this attribution whether they're a Pro subscriber or not but we ask that you take a quick look at our removing attribution guide before doing so. * `ariaLabelConfig?: Partial` Customize the aria labels / a11y descriptions (node/edge descriptions, the aria-live move message, and the Controls/MiniMap/Handle labels). Merged over the defaults. * `debug?: boolean` When `true`, Vue Flow logs its events to the console as they fire (high-frequency ones like move/drag are skipped) β€” handy for debugging which events run. * `...props: HTMLAttributes` #### Viewport props * `width: unknown` * `height: unknown` * `defaultViewport?: Partial` Sets the initial position and zoom of the viewport. If a default viewport is provided but `fitView` is enabled, the default viewport will be ignored. * `fitView?: boolean` When `true`, the flow will be zoomed and panned to fit all the nodes initially provided. * `fitViewOptions?: { padding?: Padding; includeHiddenNodes?: boolean; minZoom?: number; maxZoom?: number; duration?: number; ease?: (t: number) => number; interpolate?: 'smooth' | 'linear'; nodes?: (NodeType | { id: string; })[]; }` When you typically call `fitView` on a `VueFlowInstance`, you can provide an object of options to customize its behavior. This prop lets you do the same for the initial `fitView` call. * `minZoom?: number` Minimum zoom level. * `maxZoom?: number` Maximum zoom level. * `snapGrid?: SnapGrid` If `snapToGrid` is enabled, this prop configures the grid that nodes will snap to. * `onlyRenderVisibleElements?: boolean` You can enable this optimisation to instruct Vue Flow to only render nodes and edges that would be visible in the viewport. This might improve performance when you have a large number of nodes and edges but also adds an overhead. * `translateExtent?: CoordinateExtent` By default, the viewport extends infinitely. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right. * `preventScrolling?: boolean` Disabling this prop will allow the user to scroll the page even when their pointer is over the flow. * `attributionPosition?: PanelPosition` Set position of the attribution * `viewport?: Viewport` Controlled viewport (`v-model:viewport`) β€” keeps the flow's transform in sync with the bound value. #### Node props * `nodeOrigin?: NodeOrigin` The origin of the node to use when placing it in the flow or looking up its `x` and `y` position. An origin of `[0, 0]` means that a node's top left corner will be placed at the `x` and `y` position. * `nodesDraggable?: boolean` Controls whether all nodes should be draggable or not. Individual nodes can override this setting by setting their `draggable` prop. * `nodesConnectable?: boolean` Controls whether all nodes should be connectable or not. Individual nodes can override this setting by setting their `connectable` prop. * `nodesFocusable?: boolean` When `true`, focus between nodes can be cycled with the `Tab` key and selected with the `Enter` key. This option can be overridden by individual nodes by setting their `focusable` prop. * `nodeDragThreshold?: number` With a threshold greater than zero you can delay node drag events. If threshold equals 1, you need to drag the node 1 pixel before a drag event is fired. * `nodeExtent?: CoordinateExtent` By default, nodes can be placed on an infinite flow. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right. * `elevateNodesOnSelect?: boolean` Enabling this option will raise the z-index of nodes when they are selected. #### Edge props * `edgesFocusable?: boolean` When `true`, focus between edges can be cycled with the `Tab` key and selected with the `Enter` key. This option can be overridden by individual edges by setting their `focusable` prop. * `edgesReconnectable?: EdgeReconnectable` Whether edges can be updated once they are created. When both this prop is `true` and an `onReconnect` handler is provided, the user can drag an existing edge to a new source or target. Individual edges can override this value with their `reconnectable` property. * `reconnectRadius?: number` The radius around an edge connection that can trigger an edge reconnection. * `elevateEdgesOnSelect?: boolean` Enabling this option will raise the z-index of edges when they are selected. * `defaultMarkerColor?: string | null` Color of edge markers. You can pass `null` to use the CSS variable `--xy-edge-stroke` for the marker color. * `defaultEdgeOptions?: DefaultEdgeOptions` Defaults to be applied to all new edges that are added to the flow. Properties on a new edge will override these defaults if they exist. Does not apply to the `addEdge` utility. #### Event handlers ##### General Events * `init: [paneEvent: VueFlowInstance, string | undefined>, Edge, string>>]` * `error: [error: VueFlowError]` * `nodesChange: NodeChangeset, string | undefined>>` * `edgesChange: EdgeChangeset, string>>` * `delete: [event: { nodes: Node, string | undefined>[]; edges: Edge, string>[]; }]` * `nodesDelete: [nodes: Node, string | undefined>[]]` * `edgesDelete: [edges: Edge, string>[]]` * `onBeforeDelete?: OnBeforeDelete, string | undefined>, Edge, string>> | null` This handler is called before nodes or edges are deleted, allowing the deletion to be aborted by returning `false` or modified by returning updated nodes and edges. * `updateNodeInternals: []` ##### Viewport Events * `moveStart: [moveEvent: { event: MouseTouchEvent | null; viewport: Viewport; }]` * `move: [moveEvent: { event: MouseTouchEvent | null; viewport: Viewport; }]` * `moveEnd: [moveEvent: { event: MouseTouchEvent | null; viewport: Viewport; }]` * `viewportChangeStart: [viewport: Viewport]` * `viewportChange: [viewport: Viewport]` * `viewportChangeEnd: [viewport: Viewport]` ##### Node Events * `nodeClick: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `nodeDoubleClick: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `nodeMouseEnter: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `nodeMouseMove: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `nodeMouseLeave: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `nodeContextMenu: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `nodeDragStart: [nodeDragEvent: NodeDragEvent, string | undefined>>]` * `nodeDrag: [nodeDragEvent: NodeDragEvent, string | undefined>>]` * `nodeDragStop: [nodeDragEvent: NodeDragEvent, string | undefined>>]` * `nodesInitialized: [nodes: Node, string | undefined>[]]` * `miniMapNodeClick: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `miniMapNodeDoubleClick: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `miniMapNodeMouseEnter: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `miniMapNodeMouseMove: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` * `miniMapNodeMouseLeave: [nodeMouseEvent: NodeMouseEvent, string | undefined>>]` ##### Edge Events * `edgeContextMenu: [edgeMouseEvent: EdgeMouseEvent, string>>]` * `edgeMouseEnter: [edgeMouseEvent: EdgeMouseEvent, string>>]` * `edgeMouseMove: [edgeMouseEvent: EdgeMouseEvent, string>>]` * `edgeMouseLeave: [edgeMouseEvent: EdgeMouseEvent, string>>]` * `edgeDoubleClick: [edgeMouseEvent: EdgeMouseEvent, string>>]` * `edgeClick: [edgeMouseEvent: EdgeMouseEvent, string>>]` * `reconnectStart: [edgeReconnectEvent: EdgeReconnectStartEvent, string>>]` * `reconnect: [reconnectEvent: EdgeReconnectEvent, string>>]` * `reconnectEnd: [edgeReconnectEvent: EdgeReconnectEndEvent, string | undefined>, Edge, string>>]` ##### Selection Events * `selectionChange: [selectionEvent: SelectionChangeEvent, string | undefined>, Edge, string>>]` * `selectionContextMenu: [selectionEvent: { event: MouseEvent; nodes: Node, string | undefined>[]; }]` * `selectionDragStart: [selectionEvent: NodeDragEvent, string | undefined>>]` * `selectionDrag: [selectionEvent: NodeDragEvent, string | undefined>>]` * `selectionDragStop: [selectionEvent: NodeDragEvent, string | undefined>>]` * `selectionStart: [selectionEvent: MouseEvent]` * `selectionEnd: [selectionEvent: MouseEvent]` ##### Pane Events * `paneClick: [paneEvent: MouseEvent]` * `paneContextMenu: [paneEvent: MouseEvent]` * `paneMouseEnter: [paneEvent: MouseEvent]` * `paneMouseMove: [paneEvent: MouseEvent]` * `paneMouseLeave: [paneEvent: MouseEvent]` * `paneScroll: [paneEvent: WheelEvent | undefined]` ##### Connection Events * `connect: [connectionEvent: Connection]` * `connectStart: [connectionEvent: { event?: MouseEvent; } & OnConnectStartParams]` * `connectEnd: [connectionEvent: ConnectEndEvent, string | undefined>>]` * `isValidConnection?: IsValidConnection | null` This callback can be used to validate a new connection. If you return `false`, the edge will not be added to your flow. If you have custom connection logic it is preferred to use this callback over the `isValidConnection` prop on the handle component for performance reasons. * `clickConnectStart: [connectionEvent: { event?: MouseEvent; } & OnConnectStartParams]` * `clickConnectEnd: [connectionEvent: ConnectEndEvent, string | undefined>>]` #### Connection line props * `connectionRadius?: number` The radius around a handle where you drop a connection line to create a new edge. * `connectionDragThreshold?: number` The threshold in pixels that the pointer must move before a connection line starts to drag. This is useful to prevent accidental connections when clicking on a handle. * `connectionLineType?: ConnectionLineType` The path shape drawn while dragging a new connection, see ConnectionLineType . Edges can be of any type once created, but the connection line has to know which path to draw before that. * `connectionLineStyle?: CSSProperties` Inline style applied to the connection line itself. * `connectionLineContainerStyle?: CSSProperties` Inline style applied to the `` the connection line is drawn in. * `connectionLineClass?: ClassValue` Additional class names applied to the connection line. * `connectionLineMarkerStart?: EdgeMarkerType` Marker rendered at the start (source handle) of the connection line. * `connectionLineMarkerEnd?: EdgeMarkerType` Marker rendered at the end (pointer side) of the connection line. #### Interaction props * `elementsSelectable?: boolean` When `true`, elements (nodes and edges) can be selected by clicking on them. This option can be overridden by individual elements by setting their `selectable` prop. * `autoPanOnConnect?: boolean` When `true`, the viewport will pan automatically when the cursor moves to the edge of the viewport while creating a connection. * `autoPanOnNodeDrag?: boolean` When `true`, the viewport will pan automatically when the cursor moves to the edge of the viewport while dragging a node. * `autoPanOnSelection?: boolean` Pan the viewport automatically when the cursor reaches the edge of the viewport while dragging a selection box. * `autoPanOnNodeFocus?: boolean` Pan the viewport to a node when it receives keyboard focus (Tab) and isn't currently within the viewport β€” keeps keyboard navigation from landing on off-screen nodes. * `autoPanSpeed?: number` The speed at which the viewport pans while dragging a node or a selection box. * `selectNodesOnDrag?: boolean` If `true`, nodes get selected on drag. * `panOnDrag?: boolean | number[]` Enabling this prop allows users to pan the viewport by clicking and dragging. You can also set this prop to an array of numbers to limit which mouse buttons can activate panning. * `selectionOnDrag?: boolean` Draw a selection box on a plain pane drag (no key held). Pair it with `panOnDrag` set to a non-left button (e.g. `[1, 2]`) or `false` so a left-drag selects instead of panning. Has no effect when the left mouse button pans the viewport (`panOnDrag` is `true` or includes `0`). * `selectionMode?: SelectionMode` When set to `"partial"`, when the user creates a selection box by click and dragging nodes that are only partially in the box are still selected. * `panOnScroll?: boolean` Controls if the viewport should pan by scrolling inside the container. Can be limited to a specific direction with `panOnScrollMode`. * `panOnScrollMode?: PanOnScrollMode` This prop is used to limit the direction of panning when `panOnScroll` is enabled. The `"free"` option allows panning in any direction. * `panOnScrollSpeed?: number` Controls how fast viewport should be panned on scroll. Use together with `panOnScroll` prop. * `zoomOnScroll?: boolean` Controls if the viewport should zoom by scrolling inside the container. * `zoomOnPinch?: boolean` Controls if the viewport should zoom by pinching on a touch screen. * `zoomOnDoubleClick?: boolean` Controls if the viewport should zoom by double-clicking somewhere on the flow. * `connectionMode?: ConnectionMode` A loose connection mode will allow you to connect handles with differing types, including source-to-source connections. However, it does not support target-to-target connections. Strict mode allows only connections between source handles and target handles. * `connectOnClick?: boolean` The `connectOnClick` option lets you click or tap on a source handle to start a connection and then click on a target handle to complete the connection. If you set this option to `false`, users will need to drag the connection line to the target handle to create a connection. * `snapToGrid?: boolean` When enabled, nodes will snap to the grid when dragged. * `paneDragThreshold?: number` Distance in pixels the pointer has to move before dragging the pane starts panning or a selection. If the pointer moves less, the gesture is treated as a click: `paneClick` (or `paneContextMenu` when panning with the right mouse button) is emitted and the viewport does not move. This applies to every mouse button that is enabled via `panOnDrag` and to `selectionOnDrag`. * `zIndexMode?: ZIndexMode` controls how the z-index of nodes and edges is calculated. * `basic` (default): z-index is derived from the element's `zIndex`, parentage and selection state * `auto`: same as `basic`, but parented nodes are always lifted above their parent * `manual`: the element's explicit `zIndex` is used verbatim (no elevation) #### Keyboard props * `deleteKeyCode?: KeyFilter | null` If set, pressing the key or chord will delete any selected nodes and edges. Passing an array represents multiple keys that can be pressed. * `selectionKeyCode?: KeyFilter | null` If set, holding this key will let you click and drag to draw a selection box around multiple nodes and edges. Passing an array represents multiple keys that can be pressed. * `multiSelectionKeyCode?: KeyFilter | null` Pressing down this key you can select multiple elements by clicking. * `zoomActivationKeyCode?: KeyFilter | null` If a key is set, you can zoom the viewport while that key is held down even if `panOnScroll` is set to `false`. Setting this prop to `null` disables the functionality. * `panActivationKeyCode?: KeyFilter | null` If a key is set, you can pan the viewport while that key is held down even if `panOnScroll` is set to `false`. Setting this prop to `null` disables the functionality. * `disableKeyboardA11y?: boolean` You can use this prop to disable keyboard accessibility features such as selecting nodes or moving selected nodes with the arrow keys. #### Style props Applying certain classes to elements rendered inside the canvas will change how interactions are handled. These props let you configure those class names if you need to. * `noPanClassName?: string` If an element in the canvas does not stop mouse events from propagating, clicking and dragging that element will pan the viewport. Adding the `"nopan"` class prevents this behavior and this prop allows you to change the name of that class. * `noDragClassName?: string` If a node is draggable, clicking and dragging that node will move it around the canvas. Adding the `"nodrag"` class prevents this behavior and this prop allows you to change the name of that class. * `noWheelClassName?: string` Typically, scrolling the mouse wheel when the mouse is over the canvas will zoom the viewport. Adding the `"nowheel"` class to an element in the canvas will prevent this behavior and this prop allows you to change the name of that class. #### Notes * The props of this component get exported as `VueFlowProps` and its events as `VueFlowEmits`. * With `v-model:nodes` / `v-model:edges` Vue Flow applies node and edge changes for you. With a one-way `:nodes` / `:edges` binding the flow is controlled: handle `@nodes-change` / `@edges-change` and apply the [`NodeChangeset`](/api-reference/types/node-changeset) / [`EdgeChangeset`](/api-reference/types/edge-changeset) yourself. ### The Background component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Background/Background.vue) The `` component makes it convenient to render different types of backgrounds common in node-based UIs. It comes with three variants: `lines`, `dots` and `cross`. ```vue ``` #### Props The type for props of `` component is exported as `BackgroundProps`. * `id?: string` `` component id This is necessary when you have multiple flows with backgrounds visible at the same time. If no id is explicitly assigned, an auto-generated one is used. * `variant?: BackgroundVariant` The background pattern variant BackgroundVariant * `gap?: number | number[]` The background pattern gap Can be either a number or \[xGap: number, yGap: number], defining the gap on the X and Y axis respectively * `size?: number` The radius of each dot or the size of each rectangle if the `dots` or `cross` variant is used. Defaults to 1 or 6 respectively, and is ignored by the `lines` variant. * `lineWidth?: number` The stroke thickness used when drawing the pattern. * `color?: string` The background pattern color This only changes the color of the *pattern*, not the background color itself - use BackgroundProps.bgColor for that. * `bgColor?: string` The background color * `patternClassName?: string` Class applied to the pattern * `x?: number` Background x-coordinate (offset x) * `y?: number` Background y-coordinate (offset y) * `offset?: number | [number, number]` Background pattern offset #### Examples ##### Multiple backgrounds It is possible to render multiple `` components by giving each one a distinct `id`. Combining variants β€” for example a fine `dots` grid over a wider `lines` grid β€” makes for a nice layered effect. ```vue ``` ### The BaseEdge component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Edges/BaseEdge.vue) The `` component is used internally by all the built-in edges. It can be used inside a [custom edge](/learn/customization/custom-edges) and handles the invisible interaction path and the edge label for you. ```vue ``` #### Props The type for props of `` component is exported as `BaseEdgeProps`. * `id?: string` Unique id of an edge. * `labelX?: number` The x position of edge label. * `labelY?: number` The y position of edge label. * `path: string` The SVG path string that defines the edge. This should look something like `'M 0 0 L 100 100'` for a simple line. * `label?: string | VNode | Component` * `markerStart?: string` The id of the SVG marker to use at the start of the edge. This should be defined in a `` element. Use the format "url(#markerId)" where markerId is the id of your marker definition. * `markerEnd?: string` The id of the SVG marker to use at the end of the edge. This should be defined in a `` element. Use the format "url(#markerId)" where markerId is the id of your marker definition. * `interactionWidth?: number` The width of the invisible area around the edge that the user can interact with. This is useful for making the edge easier to click or hover over. * `labelStyle?: CSSProperties` Custom styles to apply to the label. * `labelShowBg?: boolean` Render a background rectangle behind the label. * `labelBgStyle?: CSSProperties` Inline style applied to the label background rectangle. * `labelBgPadding?: [number, number]` Padding around the label inside its background, as `[x, y]` in pixels. * `labelBgBorderRadius?: number` Border radius of the label background, in pixels. #### Notes * If you want to use a marker, pass the marker id to the `markerStart` or `markerEnd` props β€” the same values you'd set on an edge's `markerStart` / `markerEnd`. ### The ControlButton component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Controls/ControlButton.vue) The `` component adds a button to the [``](/api-reference/components/controls) panel, styled to match the built-in zoom and fit-view buttons. ```vue ``` #### Props * `disabled?: boolean` Whether the button is disabled. * `label?: string` Accessible label for the button, used as both `aria-label` and `title`. * `onClick?: ((event: MouseEvent) => any) | undefined` #### Notes * The button content is provided through the default slot, so you can drop in any icon or element. * `` emits `click` with the native `MouseEvent`. ### The Controls component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Controls/Controls.vue) The `` component renders a small panel with convenient buttons to zoom in, zoom out, fit the view, and lock the viewport. ```vue ``` #### Props The type for props of `` component is exported as `ControlProps`. * `showZoom?: boolean` Show the zoom control buttons (zoom-in and zoom-out) * `showFitView?: boolean` Show the fit view control button * `showInteractive?: boolean` Show the interactivity toggle control button * `fitViewOptions?: { padding?: Padding; includeHiddenNodes?: boolean; minZoom?: number; maxZoom?: number; duration?: number; ease?: (t: number) => number; interpolate?: 'smooth' | 'linear'; nodes?: (NodeType | { id: string; })[]; }` FitViewOptionsBase Options to use when the fit view control button is pressed * `position?: PanelPosition` The PanelPosition position of the `` panel * `ariaLabel?: string | null` Accessible label for the controls panel; falls back to `ariaLabelConfig['controls.ariaLabel']`. * `orientation?: "horizontal" | "vertical"` The direction the control buttons are laid out in * `onZoomIn?: (() => any) | undefined` * `onZoomOut?: (() => any) | undefined` * `onFitView?: (() => any) | undefined` * `onInteractionChange?: ((isInteractive: boolean) => any) | undefined` #### Notes * To extend or customize the controls, add your own buttons with the [``](/api-reference/components/control-button) component in the `` default slot. * `` emits `zoom-in`, `zoom-out`, `fit-view`, and `interaction-change` so you can react to the built-in buttons. ### The EdgeLabelRenderer component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Edges/EdgeLabelRenderer.vue) Edges are rendered as SVG paths, which makes it awkward to put interactive HTML in a label. The `` teleports its slot content into a single HTML container that sits above the edges, so you can render fully interactive labels (with inputs, buttons, etc.) inside a custom edge. ```vue
``` #### Notes * `` renders its default slot and takes no props. * Because the labels are absolutely positioned in one container, position each label yourself with a `transform` (see the example above), and add the `nodrag nopan` classes so interacting with the label doesn't pan the pane. * This is the Vue Flow equivalent of rendering into the viewport layer β€” for non-label content anchored to the transformed pane, use the `#zoom-pane` slot on [``](/api-reference/vue-flow) instead. ### The EdgeText component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Edges/EdgeText.vue) The `` component renders a label with an optional background at a given position. It is used by [``](/api-reference/components/base-edge) to draw edge labels, and you can use it directly in a custom edge. ```vue ``` #### Props The type for props of `` component is exported as `EdgeTextProps`. * `x: number` The x position where the label should be rendered. * `y: number` The y position where the label should be rendered. * `label?: string | VNode | Component` The label or custom element to render along the edge. This is commonly a text label or some custom controls. * `labelStyle?: CSSProperties` Custom styles to apply to the label. * `labelShowBg?: boolean` Render a background rectangle behind the label. * `labelBgStyle?: CSSProperties` Inline style applied to the label background rectangle. * `labelBgPadding?: [number, number]` Padding around the label inside its background, as `[x, y]` in pixels. * `labelBgBorderRadius?: number` Border radius of the label background, in pixels. ### The EdgeToolbar component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/EdgeToolbar/EdgeToolbar.vue) The `` component renders a toolbar positioned on an edge β€” the edge counterpart to [``](/api-reference/components/node-toolbar), handy for per-edge actions like deleting or editing a connection. It is a Vue Flow addition with no React/Svelte Flow equivalent. ```vue ``` #### Props The type for props of `` component is exported as `EdgeToolbarProps`. * `x: number` The `x` position of the edge toolbar. * `y: number` The `y` position of the edge toolbar. * `isVisible?: boolean` If `true`, edge toolbar is visible even if edge is not selected. * `alignX?: "left" | "center" | "right"` Align the vertical toolbar position relative to the passed x position. * `alignY?: "center" | "top" | "bottom"` Align the horizontal toolbar position relative to the passed y position. * `edgeId: string` The id of the edge the toolbar belongs to. #### Notes * Position the toolbar with `x` / `y` (typically the edge's label coordinates from a path helper) and fine-tune with `alignX` / `alignY`. ### The Handle component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Handle/Handle.vue) The `` component is used in your [custom nodes](/learn/customization/custom-nodes) to define connection points. ```vue ``` #### Props The type for props of `` component is exported as `HandleProps`. * `id?: string` Id of the handle. * `type?: 'source' | 'target'` Type of the handle. * `position?: Position` The position of the handle relative to the node. In a horizontal flow source handles are typically `Position.Right` and in a vertical flow they are typically `Position.Top`. * `isValidConnection?: IsValidConnection` Called when a connection is dragged to this handle. You can use this callback to perform some custom validation logic based on the connection target and source, for example. Where possible, we recommend you move this logic to the `isValidConnection` prop on the `` component for performance reasons. * `isConnectable?: HandleConnectable` Should you be able to connect to/from this handle. * `isConnectableStart?: boolean` Dictates whether a connection can start from this handle. * `isConnectableEnd?: boolean` Dictates whether a connection can end on this handle. #### Examples ##### Custom handle with validation You can build your own handle by wrapping ``. This example only allows a connection when the connection source matches a given id. ```vue ``` ##### Styling handles while connecting A handle receives the class `connecting` while the connection line is above it, and `valid` when the connection is valid β€” use these to color handles during a connection. See the [validation example](/examples/interaction/validation). ##### Multiple handles If you need more than one source or target handle, give each handle an `id`. Edges then target a specific handle via `sourceHandle` / `targetHandle` β€” e.g. a node `node-1` with a handle `handle-1` is reached by an edge with `source: 'node-1', sourceHandle: 'handle-1'`. ##### Dynamic handles If you programmatically change the position or number of handles in a custom node, call `updateNodeInternals` (from [`useVueFlow()`](/api-reference/composables/use-vue-flow)) for that node so Vue Flow re-measures its handles. ### Components ### The MiniMap component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/MiniMap/MiniMap.vue) The `` component renders an overview of your flow. It renders each node as an SVG element and visualizes where the current viewport is in relation to the rest of the flow. ```vue ``` #### Props The type for props of `` component is exported as `MiniMapProps`. * `nodeColor?: string | MiniMapNodeFunc` Color of nodes on minimap. * `nodeStrokeColor?: string | MiniMapNodeFunc` Stroke color of nodes on minimap. * `nodeClassName?: string | MiniMapNodeFunc` Class name applied to nodes on minimap. * `nodeBorderRadius?: number` Border radius of nodes on minimap. * `nodeStrokeWidth?: number` Stroke width of nodes on minimap. * `bgColor?: string` Background color of minimap. * `maskColor?: string` The color of the mask that covers the portion of the minimap not currently visible in the viewport. * `maskStrokeColor?: string` Stroke color of mask representing viewport. * `maskStrokeWidth?: number` Stroke width of mask representing viewport. Scaled by the minimap's view scale, so the mask border keeps a constant on-screen thickness. * `position?: PanelPosition` Position of minimap on pane, see PanelPosition . * `pannable?: boolean` Determines whether you can pan the viewport by dragging inside the minimap. * `zoomable?: boolean` Determines whether you can zoom the viewport by scrolling inside the minimap. * `width?: number` Width of the mini map, in pixels. * `height?: number` Height of the mini map, in pixels. * `ariaLabel?: string | null` Accessible label for the mini map. Pass `null` to render no label. Defaults to the flow's configured mini map aria-label. * `inversePan?: boolean` Invert direction when panning the minimap viewport. * `zoomStep?: number` Step size for zooming in/out on minimap. * `offsetScale?: number` Offset the viewport on the minimap, acts like a padding. * `maskBorderRadius?: number` Border radius of the viewport mask, in pixels. * `onClick?: ((params: { event: MouseEvent; position: XYPosition; }) => any) | undefined` * `onNodeClick?: ((params: NodeMouseEvent, string | undefined>>) => any) | undefined` * `onNodeDblclick?: ((params: NodeMouseEvent, string | undefined>>) => any) | undefined` * `onNodeMouseenter?: ((params: NodeMouseEvent, string | undefined>>) => any) | undefined` * `onNodeMousemove?: ((params: NodeMouseEvent, string | undefined>>) => any) | undefined` * `onNodeMouseleave?: ((params: NodeMouseEvent, string | undefined>>) => any) | undefined` #### Examples ##### Making the mini map interactive By default the mini map is non-interactive. Set either or both of `pannable` and `zoomable` to `true` to let users pan and zoom the viewport from the mini map. ```vue ``` ##### Customizing mini map node color `nodeColor`, `nodeStrokeColor`, and `nodeClassName` each accept a function that receives a [`Node`](/api-reference/types/node) and returns the value for that node β€” handy for coloring mini map nodes by type. ```vue ``` #### Notes * `` emits `node-click`, `node-double-click`, and the `node-mouse-*` events, each with the corresponding [`Node`](/api-reference/types/node). * To render a custom shape per node, use the per-type `#node-*` slots (e.g. `#node-input`), typed by `MiniMapNodeProps`. ### The NodeResizeControl component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/NodeResizer/ResizeControl.vue) The `` component renders a single resize control, so you can place and style resize handles individually β€” as opposed to [``](/api-reference/components/node-resizer), which renders the full set at once. ```vue ``` #### Props The type for props of `` component is exported as `ResizeControlProps`. * `nodeId?: string` Id of the node it is resizing. * `color?: string` Color of the resize handle. * `minWidth?: number` Minimum width of node. * `minHeight?: number` Minimum height of node. * `maxWidth?: number` Maximum width of node. * `maxHeight?: number` Maximum height of node. * `position?: ControlLinePosition | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'` Position of the control. * `variant?: ResizeControlVariant` Variant of the control. * `resizeDirection?: 'horizontal' | 'vertical'` The direction the user can resize the node in. When left unset the node can be resized in any direction. * `shouldResize?: (event: ResizeDragEvent, params: ResizeParamsWithDirection) => boolean` Callback to determine if node should resize. * `keepAspectRatio?: number | boolean` Keep aspect ratio when resizing. * `autoScale?: boolean` Scale the controls with the zoom level. * `handleClassName?: string` Class name applied to handle. * `handleStyle?: CSSProperties` Style applied to handle. * `lineClassName?: string` Class name applied to line. * `lineStyle?: CSSProperties` Style applied to line. * `isVisible?: boolean` Are the controls visible. * `onResize?: ((resizeEvent: OnResize) => any) | undefined` * `onResizeStart?: ((resizeEvent: OnResizeStart) => any) | undefined` * `onResizeEnd?: ((resizeEvent: OnResizeEnd) => any) | undefined` #### Notes * Use the `position` prop to choose which corner or edge the control sits on, and `variant` to switch between a handle and a line control. * Like ``, it emits `resize-start`, `resize`, and `resize-end`. ### The NodeResizer component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/NodeResizer/NodeResizer.vue) The `` component renders draggable controls around a node so users can resize it. Drop it into a [custom node](/learn/customization/custom-nodes). ```vue ``` #### Props The type for props of `` component is exported as `NodeResizerProps`. * `nodeId?: string` Id of the node it is resizing. * `color?: string` Color of the resize handle. * `handleClassName?: string` Class name applied to handle. * `handleStyle?: CSSProperties` Style applied to handle. * `lineClassName?: string` Class name applied to line. * `lineStyle?: CSSProperties` Style applied to line. * `isVisible?: boolean` Are the controls visible. * `minWidth?: number` Minimum width of node. * `minHeight?: number` Minimum height of node. * `maxWidth?: number` Maximum width of node. * `maxHeight?: number` Maximum height of node. * `shouldResize?: (event: ResizeDragEvent, params: ResizeParamsWithDirection) => boolean` Callback to determine if node should resize. * `keepAspectRatio?: number | boolean` Keep aspect ratio when resizing. * `autoScale?: boolean` Scale the controls with the zoom level. * `onResize?: ((resizeEvent: OnResize) => any) | undefined` * `onResizeStart?: ((resizeEvent: OnResizeStart) => any) | undefined` * `onResizeEnd?: ((resizeEvent: OnResizeEnd) => any) | undefined` #### Notes * `` emits `resize-start`, `resize`, and `resize-end` throughout a resize interaction. * Constrain resizing with `minWidth` / `minHeight` / `maxWidth` / `maxHeight`, or keep proportions with `keepAspectRatio`. * For a single resize control (e.g. only the bottom-right corner) use [``](/api-reference/components/node-resize-control). ### The NodeToolbar component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/NodeToolbar/NodeToolbar.vue) The `` component renders a toolbar attached to a node β€” handy for per-node actions or a tooltip. It stays in place as you pan and zoom. ```vue ``` #### Props The type for props of `` component is exported as `NodeToolbarProps`. * `nodeId?: string | string[]` By passing in an array of node id's you can render a single tooltip for a group or collection of nodes. * `isVisible?: boolean` If `true`, node toolbar is visible even if node is not selected. * `position?: Position` Position of the toolbar relative to the node. * `offset?: number` The space between the node and the toolbar, measured in pixels. * `align?: "center" | "start" | "end"` Align the toolbar relative to the node. #### Notes * By default the toolbar is only visible when its node is selected. When multiple nodes are selected it hides to avoid overlapping toolbars β€” override this with the `isVisible` prop. * Pass `nodeId` to render the toolbar for a specific node (or an array of ids) from outside that node's component. ### The Panel component ### \ [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Panel/Panel.vue) The `` component helps you position content above the viewport. It is used internally by the [``](/api-reference/components/minimap) and [``](/api-reference/components/controls) components. ```vue ``` #### Props The type for props of `` component is exported as `PanelProps`. * `position?: PanelPosition` The position of the panel. * `label?: string | null` accessible label for the panel container, applied as `aria-label` (used by ``) ### Composables ### setupVueFlow() ### setupVueFlow() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/setupVueFlow.ts) The `setupVueFlow` composable creates a Vue Flow store, `provide`s it to the current component's subtree, and returns the flow instance (the same shape as [`useVueFlow()`](/api-reference/composables/use-vue-flow)). It is the composable alternative to the [``](/api-reference/vue-flow-provider) component β€” use it when you own the surrounding component and want to set up and access the flow from one ` ``` #### Signature Create a VueFlow store, `provide` it to the current component's subtree, and return the instance β€” the same API as {@link useVueFlow}. The Vue-native alternative to wrapping in ``: call it in the component that renders `` and you get the store's actions/getters/hooks in that same `setup`, while the rendered `` (and any `useVueFlow()`/`useVueFlowStore()` below it) reuse the provided store instead of creating their own. Must run in a component `setup` (it calls `provide`). Delegates to the same store factory as ``, so one call scopes one store β€” host a single `` per setup. ###### Parameters * `options?: VueFlowProps` initial flow options (`id`, initial nodes/edges, defaults, …) ###### Returns `VueFlowInstance` #### Notes * Call `setupVueFlow` in a component `setup` β€” it relies on Vue's `provide`, so the store is only available to that component and its descendants. * Child components then reach the same store with `useVueFlow()` / `useVueFlowStore()`, without passing anything down. * You can pass initial options (the same props as ``) to seed the store. ### storeToRefs() ### storeToRefs() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/storeToRefs.ts) The `storeToRefs` helper destructures the reactive state returned by [`useVueFlowStore()`](/api-reference/composables/use-vue-flow-store) into refs without losing reactivity β€” the same pattern as Pinia's `storeToRefs`. Destructuring the store object directly would break reactivity on its value fields; `storeToRefs` keeps each field reactive. ```vue ``` #### Signature ```ts function storeToRefs( store: VueFlowState, ): ToRefs>; ``` It takes the reactive state from [`useVueFlowStore()`](/api-reference/composables/use-vue-flow-store) and returns an object of refs β€” one per state field β€” so you can destructure without losing reactivity. #### Notes * Use `storeToRefs` for value and array fields. The map-like lookups (`nodeLookup`, `edgeLookup`, `parentLookup`, `connectionLookup`) are reference types and can be destructured straight off `useVueFlowStore()`. ### useConnection() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useConnection.ts) The `useConnection` composable returns the current connection while there is an active connection interaction. When no connection is in progress it reports `inProgress: false` with `null` fields. A typical use is to colorize handles based on whether the connection is valid. ```vue ``` #### Signature Returns the current connection when there is an active connection interaction. When idle, every field is null (`inProgress: false`). A typical use case is to colorize handles based on whether the connection is valid. The store holds the raw {@link ConnectionState } from `@xyflow/system`; here the `to` endpoint is converted into flow coordinates (viewport-dependent). This function does not accept any parameters. ###### Returns `ComputedRef>>` #### Notes * The returned value is a computed ref β€” read it as `connection.value` in script, or bind it directly in a template. * The `to` endpoint is given in flow coordinates. ### useEdge() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useEdge.ts) The `useEdge` composable returns the [`Edge`](/api-reference/types/edge) for a given id along with its DOM element. Inside a [custom edge](/learn/customization/custom-edges) the `id` defaults to the current edge, so you can call it with no arguments. ```vue ``` #### Signature Composable that provides access to an edge object and it's dom element If no edge id is provided, the edge id is injected from context If you do not provide an id, this composable has to be called in a child of your custom edge component, or it will throw ###### Parameters * `id?: string` The id of the edge to access ###### Returns * `id: string` * `edge: ComputedRef` * `edgeEl: ShallowRef` #### Notes * `edgeEl` is only populated when `useEdge` runs **inside a custom edge** (or a descendant of one) β€” it's injected from the surrounding edge's component. Called from anywhere else, the `edge` data still resolves by `id`, but `edgeEl` stays `null`. Note it always refers to the edge you're rendered in, not the edge the `id` argument points at. ### useEdgesData() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useEdgesData.ts) The `useEdgesData` composable returns the `data` of one or more edges by id, along with each edge's `id` and `type`. Like [`useNodesData()`](/api-reference/composables/use-nodes-data), it is shallow-compared and only re-runs when the referenced edges' data changes. ```vue ``` #### Signature Composable that lets you subscribe to changes of a specific edge's `data` object. ###### Parameters * `edgeId: MaybeRefOrGetter` The id (or ids) of the edge to get the data from ###### Returns `ComputedRef | null>` #### Notes * Pass a single id to get an object (or `null`); pass an array to get an array. * The result is read-only. ### useHandle() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useHandle.ts) The `useHandle` composable exposes the low-level connect logic β€” both drag-to-connect and click-to-connect β€” that powers the [``](/api-reference/components/handle) component. It returns `handlePointerDown` and `handleClick` handlers you wire to your own element. Most of the time you should use ``; reach for `useHandle` only when you need a fully custom handle element. ```vue ``` #### Signature Composable powering drag- and click-to-connect. Drag-to-connect delegates to `@xyflow/system`'s `XYHandle`; click-to-connect is handled here (it validates via `XYHandle.isValid` and builds the `clickConnect*` payloads itself). Generally it's recommended to use the `` component instead of this composable. ###### Parameters * `[0].handleId: MaybeRefOrGetter` * `[0].nodeId: MaybeRefOrGetter` * `[0].type: MaybeRefOrGetter` * `[0].isValidConnection?: MaybeRefOrGetter` * `[0].reconnectHandleType?: MaybeRefOrGetter` * `[0].onReconnectStart?: (event: MouseTouchEvent) => void` * `[0].onReconnect?: (event: MouseTouchEvent, connection: Connection) => void` * `[0].onReconnectEnd?: (event: MouseTouchEvent, connectionState: FinalConnectionState, string | undefined>>>) => void` ###### Returns * `handlePointerDown: (event: MouseTouchEvent) => void` * `handleClick: (event: MouseEvent) => void` ### useInternalNode() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useInternalNode.ts) The `useInternalNode` composable returns the [`InternalNode`](/api-reference/types/internal-node) for a given id β€” the enriched representation Vue Flow maintains internally, with `measured` size, absolute position, and handle bounds under `internals`. Inside a custom node the `id` defaults to the current node. ```vue ``` #### Signature Access the enriched {@link InternalNode} (store-computed `internals.{positionAbsolute, z, handleBounds}` + authoritative `measured`) for an id, as a `computed` that re-resolves whenever the store re-adopts the node. If no id is given it is read from node context (call inside a custom node). Use {@link useNode} for the user-facing node + dom element + connected edges. The id accepts a ref/getter so it can track a reactive source β€” e.g. a custom edge resolving its endpoint with `useInternalNode(() => props.source)` stays correct after a reconnect changes the source. ###### Parameters * `id?: string | Ref | ShallowRef | WritableComputedRef | ComputedRef<...> | (() => string | undefined)` The id of the node to access (a value, ref, or getter; defaults to the node context id) ###### Returns `ComputedRef | undefined>` #### Notes * Returns a computed ref that is `undefined` when the node doesn't exist. * The `id` argument accepts a ref or getter, so the result stays reactive. * For the plain user-facing node, use [`useNode()`](/api-reference/composables/use-node). ### useKeyPress() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useKeyPress.ts) The `useKeyPress` composable returns a reactive boolean that tracks whether a given key or key combination is currently pressed. It is the same key-filter mechanism Vue Flow uses internally for shortcuts like selection and deletion. ```vue ``` #### Signature Composable that returns a boolean value if a key is pressed ###### Parameters * `keyFilter: string | boolean | string[] | KeyPredicate | Ref | ShallowRef | WritableComputedRef<...> | ComputedRef<...> | (() => false | ... 1 more ... | null)` Can be a boolean, a string, an array of strings or a function that returns a boolean. If it's a boolean, it will act as if the key is always pressed. If it's a string, it will return true if a key matching that string is pressed. If it's an array of strings, it will return true if any of the strings match a key being pressed, or a combination (e.g. \['ctrl+a', 'ctrl+b']) * `options.target?: MaybeRefOrGetter` The DOM element the key listeners are attached to. * `options.actInsideInputWithModifier?: MaybeRefOrGetter` A key press is normally ignored while a text input, textarea, or contentEditable element is focused. When `true`, key combinations that include a modifier (Ctrl/Meta/Shift/Alt) are still detected inside those elements β€” so a shortcut like `Meta+a` keeps working while the user is typing. * `options.preventDefault?: MaybeRefOrGetter` Whether to call `preventDefault()` on a matched key event (skipped for a button/link pressed without a modifier). Set to `false` to leave the event's default behaviour untouched and handle it yourself. ###### Returns `ShallowRef` #### Notes * The key filter accepts a single key, an array of keys/combinations, a boolean, or `null` β€” and can be a ref or getter so it stays reactive. * Options let you scope the listener to a target element, react to combinations while typing in inputs, and control `preventDefault`. ### useNodeConnections() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useNodeConnections.ts) The `useNodeConnections` composable returns the [connections](/api-reference/types/node-connection) of a node, optionally filtered by handle type (`source` / `target`) and handle id. It can also run `onConnect` / `onDisconnect` callbacks as connections come and go. Inside a custom node the id defaults to the current node. ```vue ``` #### Signature Hook to retrieve all edges connected to a node. Can be filtered by handle type and id. ###### Parameters * `params?: UseNodeConnectionsParams` ###### Returns `ComputedRef` #### Notes * The parameters are reactive (each accepts a ref or getter). Passing `handleId` requires `handleType`. * Returns a computed ref to an array of connections. ### useNodeId() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useNodeId.ts) The `useNodeId` composable returns the id of the node a component is rendered in. It reads the node context that Vue Flow provides around every custom node, so it only returns a value when called inside a [custom node](/learn/customization/custom-nodes) (or one of its descendants) β€” otherwise it returns `null`. ```vue ``` #### Signature This composable returns the current node id from the ctx. It should be used inside a (custom-)node components ctx as the id is provided by the internal `NodeWrapper` component. This function does not accept any parameters. ###### Returns `string | null` ### useNode() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useNode.ts) The `useNode` composable returns the user-facing [`Node`](/api-reference/types/node) for a given id, along with its DOM element, parent node, and connected edges. Inside a [custom node](/learn/customization/custom-nodes) the `id` defaults to the current node, so you can call it with no arguments. ```vue ``` #### Signature Composable that provides access to a node object, its parent node, connected edges and its dom element. Returns the user-facing {@link Node} β€” use {@link useInternalNode} for the enriched `InternalNode`. If no id is given it is read from node context (call inside a custom node, or it will throw). The id accepts a ref/getter so it can track a reactive source. ###### Parameters * `id?: string | Ref | ShallowRef | WritableComputedRef | ComputedRef<...> | (() => string | undefined)` The id of the node to access (a value, ref, or getter; defaults to the node context id) ###### Returns * `id: string` * `nodeEl: ShallowRef` * `node: ComputedRef` * `parentNode: ComputedRef` * `connectedEdges: ComputedRef, string>[]>` #### Notes * The `id` argument is reactive β€” pass a ref or getter and the result tracks it. * For the enriched internal node (measured size, absolute position, handle bounds) use [`useInternalNode()`](/api-reference/composables/use-internal-node) instead. * `nodeEl` is only populated when `useNode` runs **inside a custom node** (or a descendant of one) β€” it's injected from the surrounding node's component. Called from anywhere else (a sidebar, a toolbar, a provider-scoped component), the `node` data still resolves by `id`, but `nodeEl` stays `null`. Note it always refers to the node you're rendered in, not the node the `id` argument points at. ### useNodesData() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useNodesData.ts) The `useNodesData` composable returns the `data` of one or more nodes by id, along with each node's `id` and `type`. It is shallow-compared, so it only re-runs when the referenced nodes' data actually changes β€” handy for reading upstream nodes' data inside a custom node without re-rendering on unrelated updates. ```vue ``` #### Signature Composable that lets you subscribe to changes of a specific node's `data` object. ###### Parameters * `nodeId: MaybeRefOrGetter` The id (or ids) of the node to get the data from ###### Returns `ComputedRef | null>` #### Notes * Pass a single id to get an object (or `null`); pass an array to get an array. * The result is read-only. ### useNodesInitialized() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useNodesInitialized.ts) The `useNodesInitialized` composable returns a reactive boolean that becomes `true` once every node has been measured β€” i.e. its dimensions and handle bounds are known. It's the signal to wait for before doing work that needs the real, measured node sizes, such as running your own layout. ```vue ``` #### Signature Composable for getting the initialized state of all nodes. When a new node is added to the graph, it is not immediately initialized. That's because the node's bounds are not yet known. This composable will return false and then true when all nodes are initialized, i.e. when their bounds are known. ###### Parameters * `options.includeHiddenNodes?: boolean` Whether hidden nodes must also be measured before the flow counts as initialized. When `false`, hidden nodes are ignored (the result can be `true` while some hidden nodes are still unmeasured). ###### Returns `ComputedRef` #### Notes * Hidden nodes are ignored unless you pass `{ includeHiddenNodes: true }`. * `fitView()` already waits for measurement internally, so you often don't need this composable just to fit the view β€” reach for it when you have your own layout or measurement-dependent logic. ### useVueFlowStore() ### useVueFlowStore() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useVueFlowStore.ts) The `useVueFlowStore` composable returns the **raw reactive state** of the flow. Where [`useVueFlow()`](/api-reference/composables/use-vue-flow) gives you a curated set of actions and getters, `useVueFlowStore` gives you the underlying reactive fields directly β€” `nodes`, `edges`, `transform`, `nodeLookup`, `connectionLookup`, and so on. Read them straight off the returned object (no `.value`), the same way you'd read a Pinia store. ```vue ``` #### Signature Access the raw reactive state of the surrounding flow β€” every {@link VueFlowState} field plus the lookups, read directly (`store.nodes`, `store.transform`, `store.nodeLookup`, …; no `.value`, like `xyflow/svelte`'s store). Mirrors `useVueFlowStore` in `xyflow/react`+`svelte`. Reading a field inside a `computed`/`watch`/template tracks it reactively; reading it in a plain callback is just a current-value read. To destructure scalar/array fields as refs, wrap the result in `storeToRefs`; reference-type lookups (`nodeLookup`, …) can be destructured directly. For actions, getters, and event hooks use {@link useVueFlow} instead. Throws if called outside a provider (or outside a component `setup`). This function does not accept any parameters. ###### Returns `VueFlowState` #### Notes * Prefer [`useVueFlow()`](/api-reference/composables/use-vue-flow) for most work β€” reach for `useVueFlowStore` only when you need a raw store field that isn't exposed as a getter. * To destructure value fields into refs without losing reactivity, pass the store through [`storeToRefs()`](/api-reference/composables/store-to-refs). The map-like lookups (`nodeLookup`, `edgeLookup`, `parentLookup`, `connectionLookup`) can be destructured directly. * Like the other composables, `useVueFlowStore` throws when used outside a flow provider. ### useVueFlow() ### useVueFlow() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/composables/useVueFlow.ts) The `useVueFlow` composable returns the **Vue Flow instance**: a curated set of actions (`setNodes`, `addEdges`, `updateNodeData`, `deleteElements`, …), computed getters (`getNodes`, `getEdges`, `getSelectedNodes`, `viewport`), the viewport helpers (`fitView`, `zoomIn`, `setCenter`, `screenToFlowPosition`, …), and the `on*` event hooks (`onConnect`, `onNodeDragStop`, `onInit`, …). It must run inside a flow provided by [``](/api-reference/vue-flow), [``](/api-reference/vue-flow-provider), or [`setupVueFlow()`](/api-reference/composables/setup-vue-flow) β€” otherwise it throws. ```vue ``` #### Signature Access the VueFlow instance for the surrounding flow β€” actions, computed getters, and event hooks. For the raw reactive state (`nodes`, `transform`, lookups, …) use {@link useVueFlowStore} (and `storeToRefs` to destructure it). Pure context consumer β€” resolves the instance provided by the nearest `` / `` / `setupVueFlow()` ancestor. It takes **no arguments**: there is no global registry, no lookup-by-id, and no store creation here. To create/own a store, render a `` (or ``, which provides its own); to share one across components, wrap them in a common `` / `setupVueFlow()` call. Throws if called outside a provider (or outside a component `setup`, where `inject` is unavailable). This function does not accept any parameters. ###### Returns `VueFlowInstance` #### Notes * `useVueFlow` returns the curated instance, not raw state. To read the reactive store directly (e.g. `nodeLookup`, `transform`), use [`useVueFlowStore()`](/api-reference/composables/use-vue-flow-store) β€” optionally with [`storeToRefs()`](/api-reference/composables/store-to-refs). * Several things that are standalone hooks in React/Svelte Flow are methods on this instance in Vue Flow β€” e.g. `updateNodeInternals`, `getViewport`/`setViewport`, and the selection/viewport event hooks (`onSelectionChange`, `onViewportChange`). ### Align ### Align The `Align` type is the alignment options for a [``](/api-reference/components/node-toolbar) relative to its node: `center`, `start`, or `end`. #### Type ```ts type Align = 'center' | 'start' | 'end'; ``` ### AriaLabelConfig ### AriaLabelConfig The `AriaLabelConfig` type is the full set of accessibility labels and live-region messages Vue Flow uses (for nodes, edges, controls, the minimap, and keyboard hints). Override any of them with the `ariaLabelConfig` prop to localize or reword them. #### Fields * `node.a11yDescription.default: string` * `node.a11yDescription.keyboardDisabled: string` * `node.a11yDescription.ariaLiveMessage: ({ direction, x, y }: { direction: string; x: number; y: number; }) => string` * `edge.a11yDescription.default: string` * `controls.ariaLabel: string` * `controls.zoomIn.ariaLabel: string` * `controls.zoomOut.ariaLabel: string` * `controls.fitView.ariaLabel: string` * `controls.interactive.ariaLabel: string` * `minimap.ariaLabel: string` * `handle.ariaLabel: string` ### BackgroundVariant ### BackgroundVariant The `BackgroundVariant` type is the set of pattern styles the [``](/api-reference/components/background) component can render: `dots`, `lines` or `cross`. #### Type ```ts type BackgroundVariant = 'dots' | 'lines' | 'cross'; ``` ### BaseEdgeProps ### BaseEdgeProps The `BaseEdgeProps` type is the set of props accepted by the [``](/api-reference/components/base-edge) component β€” the SVG `path`, the label and its position, markers, and the interaction width. #### Fields BaseEdge component props. * `id?: string` Unique id of an edge. * `labelX?: number` The x position of edge label. * `labelY?: number` The y position of edge label. * `path: string` The SVG path string that defines the edge. This should look something like `'M 0 0 L 100 100'` for a simple line. * `label?: string | VNode | Component` * `markerStart?: string` The id of the SVG marker to use at the start of the edge. This should be defined in a `` element. Use the format "url(#markerId)" where markerId is the id of your marker definition. * `markerEnd?: string` The id of the SVG marker to use at the end of the edge. This should be defined in a `` element. Use the format "url(#markerId)" where markerId is the id of your marker definition. * `interactionWidth?: number` The width of the invisible area around the edge that the user can interact with. This is useful for making the edge easier to click or hover over. * `labelStyle?: CSSProperties` Custom styles to apply to the label. * `labelShowBg?: boolean` Render a background rectangle behind the label. * `labelBgStyle?: CSSProperties` Inline style applied to the label background rectangle. * `labelBgPadding?: [number, number]` Padding around the label inside its background, as `[x, y]` in pixels. * `labelBgBorderRadius?: number` Border radius of the label background, in pixels. ### ColorMode ### ColorMode The `ColorMode` type is the resolved color theme of a flow: `light` or `dark`. (The `forceColorMode` prop additionally accepts `'system'` to follow the OS preference, which resolves to one of these.) #### Type ```ts type ColorMode = 'light' | 'dark'; ``` ### ConnectEndEvent ### ConnectEndEvent The `ConnectEndEvent` type is the payload of the `@connect-end` event, fired when a connection interaction finishes (whether or not it produced a connection). It carries the native `event` and the final connection state, so you can react even when no edge was created β€” e.g. to add a node where the connection was dropped. #### Fields Payload for `connectEnd`/`clickConnectEnd` β€” the pointer event plus the {@link FinalConnectionState } (whether the connection was valid, the from/to handles and nodes). * `event: MouseTouchEvent` The DOM event that ended the connection attempt. * `connectionState: FinalConnectionState>` The final connection state β€” validity plus the from/to handles and nodes. ### ConnectionLineProps ### ConnectionLineProps The `ConnectionLineProps` type is the set of props Vue Flow passes to a custom connection line through the `#connection-line` slot β€” the `from*` / `to*` coordinates and positions, the source node and handle, the pointer, and the connection status. #### Fields If you want to render a custom component for connection lines, you can pass it to the `connection-line` slot. These props are passed to your custom component. * `fromX: number` X start position of the connection line * `fromY: number` Y start position of the connection line * `fromPosition: Position` the side of the start handle * `toX: number` X end position of the connection line (the current pointer) * `toY: number` Y end position of the connection line (the current pointer) * `toPosition: Position` the side of the end handle * `fromNode: InternalNode` the node the connection started from * `fromHandle: HandleBounds | null` the handle the connection started from (not the DOM element) * `toNode: InternalNode | null` the node the connection currently ends on, or `null` * `toHandle: HandleBounds | null` the handle the connection currently ends on (not the DOM element), or `null` * `markerStart?: string` marker url * `markerEnd?: string` marker url * `connectionStatus: ConnectionStatus | null` If there is an `isValidConnection` callback, this prop will be set to `"valid"` or `"invalid"` based on the return value of that callback. Otherwise, it will be `null`. * `pointer: XYPosition` the raw pointer position in flow coordinates (unsnapped, unlike `toX`/`toY`) ### ConnectionLineType ### ConnectionLineType The `ConnectionLineType` enum selects the shape of the temporary line drawn while making a connection β€” bezier, straight, step, or smooth step. Set it via `connectionLineType`. #### Values ```ts enum ConnectionLineType { Bezier = 'default', Straight = 'straight', Step = 'step', SmoothStep = 'smoothstep', SimpleBezier = 'simplebezier', } ``` ### ConnectionMode ### ConnectionMode The `ConnectionMode` enum controls how handles may connect. In `strict` mode a source handle can only connect to a target handle; in `loose` mode any handle can connect to any other. Set it with the `connectionMode` prop. #### Values ```ts enum ConnectionMode { Strict = 'strict', Loose = 'loose', } ``` ### ConnectionState ### ConnectionState The `ConnectionState` type describes an in-progress connection: the `from` / `to` handles and nodes, the `pointer` position, and whether it `isValid`. When no connection is being made, `inProgress` is `false` and the other fields are `null`. Read it with [`useConnection()`](/api-reference/composables/use-connection). #### Fields The `ConnectionState` type bundles all information about an ongoing connection. It is returned by the [`useConnection`](/api-reference/hooks/use-connection) hook. * `inProgress: boolean` Indicates whether a connection is currently in progress. * `isValid: boolean | null` If an ongoing connection is above a handle or inside the connection radius, this will be `true` or `false`, otherwise `null`. * `from: XYPosition | null` Returns the xy start position in flow coordinates or `null` if no connection is in progress. * `fromHandle: HandleBounds | null` Returns the start handle or `null` if no connection is in progress. * `fromPosition: Position | null` Returns the side (called position) of the start handle or `null` if no connection is in progress. * `fromNode: NodeType | null` Returns the start node or `null` if no connection is in progress. * `to: XYPosition | null` Returns the xy end position in flow coordinates or `null` if no connection is in progress. * `toHandle: HandleBounds | null` Returns the end handle or `null` if no connection is in progress. * `toPosition: Position | null` Returns the side (called position) of the end handle or `null` if no connection is in progress. * `toNode: NodeType | null` Returns the end node or `null` if no connection is in progress. * `pointer: XYPosition | null` Returns the pointer position relative to the pane, in screen coordinates, or `null` if no connection is in progress. ### ConnectionStatus ### ConnectionStatus The `ConnectionStatus` type reports the state of the connection being drawn β€” `valid` or `invalid` (or `null` when there is none). It's surfaced on [`ConnectionState`](/api-reference/types/connection-state) and the connection-line slot props, handy for styling handles or the connection line. #### Type ```ts type ConnectionStatus = 'valid' | 'invalid'; ``` ### Connection ### Connection The `Connection` type describes a new connection between two handles: the source and target nodes and, optionally, the specific handles on each. You receive one in the `@connect` event when a user completes a connection, and pass it to [`addEdge`](/api-reference/utils/add-edge) to turn it into an [`Edge`](/api-reference/types/edge). #### Fields The `Connection` type is the basic minimal description of an [`Edge`](/api-reference/types/edge) between two nodes. The [`addEdge`](/api-reference/utils/add-edge) util can be used to upgrade a `Connection` to an [`Edge`](/api-reference/types/edge). * `source: string` The id of the node this connection originates from. * `target: string` The id of the node this connection terminates at. * `sourceHandle: string | null` When not `null`, the id of the handle on the source node that this connection originates from. * `targetHandle: string | null` When not `null`, the id of the handle on the target node that this connection terminates at. ### CoordinateExtent ### CoordinateExtent The `CoordinateExtent` type describes a bounding box as `[[minX, minY], [maxX, maxY]]`. It's used to constrain panning (`translateExtent`) and node movement (`nodeExtent`). #### Type ```ts type CoordinateExtent = [[number, number], [number, number]]; ``` ### DefaultEdgeOptions ### DefaultEdgeOptions The `DefaultEdgeOptions` type is the set of [`Edge`](/api-reference/types/edge) properties applied to every newly created edge β€” `type`, `animated`, `style`, markers, and so on. Pass it via the `defaultEdgeOptions` prop so you don't repeat them on each edge. #### Fields Many properties on an `Edge` are optional. When a new edge is created, the properties that are not provided will be filled in with the default values passed to the `defaultEdgeOptions` prop of the `` component. * `label?: string | VNode | Component` The label or custom element to render along the edge. This is commonly a text label or some custom controls. * `markerStart?: EdgeMarkerType` Set the marker on the beginning of an edge. * `markerEnd?: EdgeMarkerType` Set the marker on the end of an edge. * `reconnectable?: EdgeReconnectable` Determines whether the edge can be updated by dragging the source or target to a new node. This property overrides the default set by the `edgesReconnectable` prop on the `` component. * `focusable?: boolean` Disable/enable focusing edge (a11y) * `class?: ClassValue` Additional class names * `style?: Styles` Additional styles * `domAttributes?: Omit` General escape hatch for adding custom attributes to the edge's DOM element. * `type?: string` Type of edge defined in `edgeTypes`. * `animated?: boolean` * `hidden?: boolean` * `deletable?: boolean` * `selectable?: boolean` * `data?: Record` Arbitrary data passed to an edge. * `zIndex?: number` * `ariaLabel?: string` * `interactionWidth?: number` ReactFlow renders an invisible path around each edge to make them easier to click or tap on. This property sets the width of that invisible path. * `labelStyle?: CSSProperties` Custom styles to apply to the label. * `labelShowBg?: boolean` Render a background rectangle behind the label. * `labelBgStyle?: CSSProperties` Inline style applied to the label background rectangle. * `labelBgPadding?: [number, number]` Padding around the label inside its background, as `[x, y]` in pixels. * `labelBgBorderRadius?: number` Border radius of the label background, in pixels. ### Dimensions ### Dimensions The `Dimensions` type is a simple `{ width, height }` pair, used for measured sizes throughout Vue Flow. #### Fields * `width: number` * `height: number` ### EdgeChange ### EdgeChange The `EdgeChange` type is the union of the individual changes Vue Flow reports for edges β€” selection, add, remove, and replace. The `@edges-change` event delivers them as an [`EdgeChangeset`](/api-reference/types/edge-changeset); in a controlled flow apply them with the changeset's `applyTo(edges)`. #### Fields The `edges-change` event passes an array of `EdgeChange` objects that you should use to update your flow's state. The `EdgeChange` type is a union of the different object types that represent the various ways an edge can change in a flow. * `id: string` * `type: "select" | "remove" | "add"` ### EdgeChangeset ### EdgeChangeset An `EdgeChangeset` is what Vue Flow hands you whenever edges change: both the `@edges-change` event and the `onEdgesChange` hook deliver one. It collects the [`EdgeChange`](/api-reference/types/edge-change) objects queued for that update and knows how to apply them, so you never assemble the next array yourself. [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/changes/index.ts) ```ts import type { Edge, EdgeChangeset } from '@xyflow/vue'; function onEdgesChange(changes: EdgeChangeset) { edges.value = changes.applyTo(edges.value); } ``` You only need this in a **controlled** flow (a one-way `:edges` binding). With `v-model:edges` Vue Flow applies the changeset for you. #### Reading changes A changeset is iterable, and it can hand you changes by type or by edge β€” so inspecting an update doesn't mean scanning an array yourself. ```ts // every change, in order for (const change of changes) { console.log(change.type, change.id); } // just the removals if (changes.getByType('remove').length > 0) { saveUndoSnapshot(); } // everything queued for one edge const changesForEdge = changes.getForEdge('e1-2'); ``` #### Editing before you apply Because the changeset is a real object you can drop or add changes before applying it β€” handy for vetoing an update without rebuilding the array. ```ts function onEdgesChange(changes: EdgeChangeset) { // keep this edge no matter what the interaction asked for changes.removeForEdge('e1-2'); edges.value = changes.applyTo(edges.value); } ``` #### Members | Member | Signature | Description | | --------------- | ---------------------------------------------- | ---------------------------------------------------------------- | | `applyTo` | `(edges: EdgeType[]) => EdgeType[]` | Applies every queued change and returns the next array. | | `add` | `(change: EdgeChange \| EdgeChange[]) => void` | Queues one or more changes. | | `remove` | `(change: EdgeChange) => void` | Removes a queued change by object reference. | | `getByType` | `(type: EdgeChange['type']) => EdgeChange[]` | Every queued change of that type, e.g. `'select'` or `'remove'`. | | `getForEdge` | `(edgeId: string) => EdgeChange[]` | Every queued change for one edge. | | `removeForEdge` | `(edgeId: string) => void` | Drops every queued change for one edge. | | `toArray` | `() => EdgeChange[]` | All queued changes as a flat array. | | `size` | `number` | How many edges the changeset touches. | | `version` | `number` | Bumped on every edit β€” useful as a watch source. | The changeset also implements `Symbol.iterator`, so `[...changes]` and `for…of` work directly. #### Notes * Construct one yourself with `new EdgeChangeset(changes?)` β€” for example to replay recorded changes. * The standalone `applyEdgeChanges(changes, edges)` util is **deprecated** and still array-based, so it cannot take the event payload; use `applyTo` or the instance's `applyEdgeChanges(changeset)`. * Nodes have the mirrored [`NodeChangeset`](/api-reference/types/node-changeset). ### EdgeMarkerType ### EdgeMarkerType The `EdgeMarkerType` type is what an edge's `markerStart` / `markerEnd` accepts β€” either a bare [`MarkerType`](/api-reference/types/marker-type) string or a full [`EdgeMarker`](/api-reference/types/edge-marker) object. #### Type ```ts type EdgeMarkerType = string | EdgeMarker; ``` A bare string is treated as a [`MarkerType`](/api-reference/types/marker-type); pass an [`EdgeMarker`](/api-reference/types/edge-marker) object for full control. ### EdgeMarker ### EdgeMarker The `EdgeMarker` type describes an edge marker in detail: its [`MarkerType`](/api-reference/types/marker-type), size (`width` / `height`), `color`, `strokeWidth`, and orientation. Set it as an edge's `markerStart` / `markerEnd` when you need more than a bare marker type. #### Fields Edges can optionally have markers at the start and end of an edge. The `EdgeMarker` type is used to configure those markers! Check the docs for [`MarkerType`](/api-reference/types/marker-type) for details on what types of edge marker are available. * `type: MarkerType | "arrow" | "arrowclosed"` * `color?: string | null` * `width?: number` * `height?: number` * `markerUnits?: string` * `orient?: string` * `strokeWidth?: number` ### EdgeMouseEvent ### EdgeMouseEvent The `EdgeMouseEvent` type is the payload of the edge pointer events β€” `@edge-click`, `@edge-double-click`, `@edge-context-menu`, and the `@edge-mouse-*` events. It carries the native `event` and the [`Edge`](/api-reference/types/edge) it concerns. #### Fields Payload for the edge pointer events (`edgeClick`, `edgeMouseEnter`, `edgeContextMenu`, …). * `event: MouseTouchEvent` The DOM event that triggered this. * `edge: EdgeType` The edge the event refers to. ### EdgeProps ### EdgeProps The `EdgeProps` type is the set of props Vue Flow passes to a [custom edge](/learn/customization/custom-edges) component β€” `id`, `source` / `target`, the endpoint coordinates (`sourceX` / `sourceY` / `targetX` / `targetY`), positions, `data`, `selected`, and more. Declare it with `defineProps()`. #### Fields When you implement a custom edge it is wrapped in a component that enables some basic functionality. The `EdgeProps` type is the props that are passed to that component. No `sourceNode`/`targetNode` (resolve them with `useInternalNode`); handles are exposed as `sourceHandleId`/`targetHandleId`; markers are pre-resolved to url strings. * `id: string` Unique id of an edge. * `source: string` Id of source node. * `target: string` Id of target node. * `type?: EdgeType["type"]` Type of edge defined in `edgeTypes`. * `label?: string | VNode | Component` The label or custom element to render along the edge. This is commonly a text label or some custom controls. * `style?: CSSProperties` Inline style applied to the edge path. * `selected?: boolean` Whether the edge is currently selected. * `selectable?: boolean` Whether the edge can be selected. * `deletable?: boolean` Whether the edge can be deleted. * `sourceHandleId?: string | null` Id of source handle, only needed if there are multiple handles per node. * `targetHandleId?: string | null` Id of target handle, only needed if there are multiple handles per node. * `animated?: boolean` Whether the edge path is animated. * `reconnectable?: EdgeReconnectable` Whether the edge can be reconnected by dragging an endpoint, see EdgeReconnectable. * `markerStart?: string` Pre-resolved `url(#…)` reference for the start marker, or `undefined` when the edge has none. * `markerEnd?: string` Pre-resolved `url(#…)` reference for the end marker, or `undefined` when the edge has none. * `curvature?: number` Curvature of the default bezier path, between 0 and 1. * `interactionWidth?: number` The width of the invisible area around the edge that the user can interact with. This is useful for making the edge easier to click or hover over. * `data?: EdgeType["data"]` Arbitrary data passed to an edge. * `labelStyle?: CSSProperties` Custom styles to apply to the label. * `labelShowBg?: boolean` Render a background rectangle behind the label. * `labelBgStyle?: CSSProperties` Inline style applied to the label background rectangle. * `labelBgPadding?: [number, number]` Padding around the label inside its background, as `[x, y]` in pixels. * `labelBgBorderRadius?: number` Border radius of the label background, in pixels. * `sourceX: number` * `sourceY: number` * `targetX: number` * `targetY: number` * `sourcePosition: Position` * `targetPosition: Position` #### Notes * Unlike React Flow there is no `sourceNode` / `targetNode` β€” resolve nodes with [`useInternalNode()`](/api-reference/composables/use-internal-node). Handles are given as `sourceHandleId` / `targetHandleId`, and markers arrive pre-resolved as url strings. ### EdgeReconnectEndEvent ### EdgeReconnectEndEvent The `EdgeReconnectEndEvent` type is the payload of the `@reconnect-end` event, fired when an edge reconnection interaction finishes (whether or not it resulted in a reconnection). It carries the native `event`, the [`Edge`](/api-reference/types/edge), the `handleType`, and the final connection state. #### Fields Payload for the `reconnectEnd` event β€” fired when a reconnect gesture ends, whether or not it succeeded. * `event: MouseTouchEvent` The DOM event that ended the reconnect. * `edge: EdgeType` The edge that was being reconnected. * `handleType: 'source' | 'target'` the type of the handle that was reconnected * `connectionState: FinalConnectionState>` the FinalConnectionState at the moment the reconnect ended ### EdgeReconnectEvent ### EdgeReconnectEvent The `EdgeReconnectEvent` type is the payload of the `@reconnect` event, fired when a user finishes dragging an edge endpoint to a new handle. It carries the original [`Edge`](/api-reference/types/edge) and the new [`Connection`](/api-reference/types/connection). Persist it with [`reconnectEdge`](/api-reference/utils/reconnect-edge). #### Fields Payload for the `reconnect` event β€” fired once an edge has been reconnected to a new handle. * `event: MouseTouchEvent` The DOM event that completed the reconnect. * `edge: EdgeType` The edge that was reconnected. * `connection: Connection` The new connection the edge now describes. ### EdgeReconnectStartEvent ### EdgeReconnectStartEvent The `EdgeReconnectStartEvent` type is the payload of the `@reconnect-start` event, fired when a user begins dragging an edge endpoint. It carries the native `event`, the [`Edge`](/api-reference/types/edge), and which `handleType` (source or target) is being reconnected. #### Fields Payload for the `reconnectStart` event β€” fired when the user grabs an edge endpoint to reconnect it. * `event: MouseTouchEvent` The DOM event that started the reconnect. * `edge: EdgeType` The edge being reconnected. * `handleType: 'source' | 'target'` the type of the handle being reconnected (the fixed end, opposite the grabbed anchor) ### EdgeReconnectable ### EdgeReconnectable The `EdgeReconnectable` type controls whether an edge can be reconnected β€” `true` for both ends, `false` for neither, or `'source'` / `'target'` to allow only one end. Set it per edge (`edge.reconnectable`) or globally with the `edgesReconnectable` prop. #### Type ```ts type EdgeReconnectable = boolean | 'source' | 'target'; ``` ### EdgeTypesObject ### EdgeTypesObject The `EdgeTypesObject` type maps custom edge `type` names to the components that render them β€” the shape of the `edgeTypes` prop. In Vue Flow you can also register edge types with the `#edge-` slots instead. #### Fields * `default?: EdgeComponent, string>>` * `straight?: EdgeComponent, string>>` * `simplebezier?: EdgeComponent, string>>` * `step?: EdgeComponent, string>>` * `smoothstep?: EdgeComponent, string>>` ### Edge ### Edge\ An `Edge` is the complete description with everything Vue Flow needs to know in order to render it. #### Fields * `label?: string | VNode | Component` The label or custom element to render along the edge. This is commonly a text label or some custom controls. * `markerStart?: EdgeMarkerType` Set the marker on the beginning of an edge. * `markerEnd?: EdgeMarkerType` Set the marker on the end of an edge. * `reconnectable?: EdgeReconnectable` Determines whether the edge can be updated by dragging the source or target to a new node. This property overrides the default set by the `edgesReconnectable` prop on the `` component. * `focusable?: boolean` Disable/enable focusing edge (a11y) * `class?: ClassValue` Additional class names * `style?: Styles` Additional styles * `domAttributes?: Omit` General escape hatch for adding custom attributes to the edge's DOM element. * `id: string` Unique id of an edge. * `type?: Type | "smoothstep" | "default"` Type of edge defined in `edgeTypes`. * `source: string` Id of source node. * `target: string` Id of target node. * `sourceHandle?: string | null` Id of source handle, only needed if there are multiple handles per node. * `targetHandle?: string | null` Id of target handle, only needed if there are multiple handles per node. * `animated?: boolean` * `hidden?: boolean` * `deletable?: boolean` * `selectable?: boolean` * `data?: Data` Arbitrary data passed to an edge. * `selected?: boolean` * `zIndex?: number` * `ariaLabel?: string` * `interactionWidth?: number` ReactFlow renders an invisible path around each edge to make them easier to click or tap on. This property sets the width of that invisible path. * `labelStyle?: CSSProperties` Custom styles to apply to the label. * `labelShowBg?: boolean` Render a background rectangle behind the label. * `labelBgStyle?: CSSProperties` Inline style applied to the label background rectangle. * `labelBgPadding?: [number, number]` Padding around the label inside its background, as `[x, y]` in pixels. * `labelBgBorderRadius?: number` Border radius of the label background, in pixels. ### FinalConnectionState ### FinalConnectionState The `FinalConnectionState` type describes the connection at the moment an interaction ends β€” the `from` / `to` handles and nodes, the pointer position, and whether it was valid. It's carried by the [`ConnectEndEvent`](/api-reference/types/connect-end-event) and the reconnect-end event, so you can act on connections that were dropped on the pane. #### Fields * `isValid: boolean | null` If an ongoing connection is above a handle or inside the connection radius, this will be `true` or `false`, otherwise `null`. * `from: XYPosition | null` Returns the xy start position in flow coordinates or `null` if no connection is in progress. * `fromHandle: HandleBounds | null` Returns the start handle or `null` if no connection is in progress. * `fromPosition: Position | null` Returns the side (called position) of the start handle or `null` if no connection is in progress. * `fromNode: NodeType | null` Returns the start node or `null` if no connection is in progress. * `to: XYPosition | null` Returns the xy end position in flow coordinates or `null` if no connection is in progress. * `toHandle: HandleBounds | null` Returns the end handle or `null` if no connection is in progress. * `toNode: NodeType | null` Returns the end node or `null` if no connection is in progress. * `pointer: XYPosition | null` Returns the pointer position relative to the pane, in screen coordinates, or `null` if no connection is in progress. * `toPosition: Position | null` ### FitViewOptions ### FitViewOptions The `FitViewOptions` type configures a `fitView` call β€” `padding`, animation `duration`, `minZoom` / `maxZoom`, and which `nodes` to fit. Pass it to the `fitView` action, the `fitViewOptions` prop, or the Controls' fit-view button. #### Fields * `padding?: Padding` * `includeHiddenNodes?: boolean` * `minZoom?: number` * `maxZoom?: number` * `duration?: number` * `ease?: (t: number) => number` * `interpolate?: "smooth" | "linear"` * `nodes?: (NodeType | { id: string; })[]` ### FlowExportObject ### FlowExportObject The `FlowExportObject` type is the serializable snapshot of a flow returned by the instance's `toObject()` β€” its [`nodes`](/api-reference/types/node), [`edges`](/api-reference/types/edge), and [`viewport`](/api-reference/types/viewport). Save it to persist a flow and restore it later. #### Fields * `nodes: Node, string | undefined>[]` exported nodes * `edges: Edge, string>[]` exported edges * `viewport: Viewport` exported viewport (position + zoom) ### HandleBounds ### HandleBounds The `HandleBounds` type describes a single handle as Vue Flow has measured it β€” its position and size relative to its node, plus which node and `HandleType` it belongs to. You get it from [`ConnectionState`](/api-reference/types/connection-state)'s `fromHandle` and `toHandle` while a connection is being drawn, and from a node's `internals.handleBounds` in the store. #### Type ```ts type HandleBounds = { id?: string | null; nodeId: string; x: number; y: number; position: Position; type: HandleType; width: number; height: number; }; ``` ### Types Vue Flow is written in TypeScript and exports the types behind its components, composables, and utilities. Because Vue Flow models flow events as component emits and instance event hooks (rather than callback props), the event payload types below (e.g. `NodeMouseEvent`, `ConnectEndEvent`) take the place of React Flow's `on*` handler types. ### InternalNode ### InternalNode The `InternalNode` type is Vue Flow's enriched representation of a [`Node`](/api-reference/types/node). On top of the user-facing fields it carries `measured` size and an `internals` object with the absolute position, z-index, and handle bounds. Read one with [`useInternalNode()`](/api-reference/composables/use-internal-node). #### Fields The enriched, store-internal node β€” what `nodeLookup`/`getInternalNode(id)`/`useInternalNode(id)` return, once a user-provided `Node` has been processed by the store. Carries the user `Node` (`internals.userNode`) plus the store-computed `internals.{positionAbsolute, z, handleBounds}` and authoritative `measured`. * `width?: NodeType["width"]` * `height?: NodeType["height"]` * `id: NodeType["id"]` Unique id of a node. * `position: NodeType["position"]` Position of a node on the pane. * `type?: NodeType["type"]` Type of node defined in nodeTypes * `data: NodeType["data"]` Arbitrary data passed to a node. * `sourcePosition?: NodeType["sourcePosition"]` Only relevant for default, source, target nodeType. Controls source position. * `targetPosition?: NodeType["targetPosition"]` Only relevant for default, source, target nodeType. Controls target position. * `hidden?: NodeType["hidden"]` Whether or not the node should be visible on the canvas. * `selected?: NodeType["selected"]` * `dragging?: NodeType["dragging"]` Whether or not the node is currently being dragged. * `draggable?: NodeType["draggable"]` Whether or not the node is able to be dragged. * `selectable?: NodeType["selectable"]` * `connectable?: NodeType["connectable"]` * `deletable?: NodeType["deletable"]` * `dragHandle?: NodeType["dragHandle"]` A class name that can be applied to elements inside the node that allows those elements to act as drag handles, letting the user drag the node by clicking and dragging on those elements. * `initialWidth?: NodeType["initialWidth"]` * `initialHeight?: NodeType["initialHeight"]` * `parentId?: NodeType["parentId"]` Parent node id, used for creating sub-flows. * `zIndex?: NodeType["zIndex"]` * `extent?: NodeType["extent"]` Boundary a node can be moved in. * `expandParent?: NodeType["expandParent"]` When `true`, the parent node will automatically expand if this node is dragged to the edge of the parent node's bounds. * `ariaLabel?: NodeType["ariaLabel"]` * `origin?: NodeType["origin"]` Origin of the node relative to its position. * `handles?: NodeType["handles"]` * `resizing?: NodeType["resizing"]` Whether the node is currently being resized. * `class?: NodeType["class"]` Additional class names applied to the node element. * `style?: NodeType["style"]` Additional inline styles applied to the node element. * `focusable?: NodeType["focusable"]` Whether the node can be focused for keyboard interaction (a11y). * `ariaRole?: NodeType["ariaRole"]` The ARIA role attribute for the node element, used for accessibility. * `domAttributes?: NodeType["domAttributes"]` General escape hatch for adding custom attributes to the node's DOM element. * `measured: { width?: number; height?: number; }` * `internals: { positionAbsolute: XYPosition; z: number; rootParentIndex?: number; userNode: NodeType; handleBounds?: NodeHandleBounds; bounds?: NodeBounds; isParent: boolean; }` #### Notes * You don't create `InternalNode`s β€” Vue Flow derives them from your nodes. Treat the `measured` and `internals` fields as read-only. ### IsValidConnection ### IsValidConnection The `IsValidConnection` type is the signature of a function that decides whether an attempted [`Connection`](/api-reference/types/connection) is allowed. Return `true` to permit it. Pass one via the `isValidConnection` prop on `` or on an individual [``](/api-reference/components/handle). #### Fields ###### Parameters * `edge: EdgeType | Connection` ###### Returns `boolean` ### MarkerType ### MarkerType The `MarkerType` enum is the set of built-in edge marker shapes β€” `arrow` (open) and `arrowclosed` (filled). Use it when setting an edge's `markerStart` / `markerEnd`. #### Values ```ts enum MarkerType { Arrow = 'arrow', ArrowClosed = 'arrowclosed', } ``` ### MouseTouchEvent ### MouseTouchEvent The `MouseTouchEvent` type is a native mouse or touch (or pointer) event, used where an interaction can originate from either input β€” for example in connection and reconnection callbacks. #### Type ```ts type MouseTouchEvent = MouseEvent | TouchEvent; ``` ### NoConnection ### NoConnection The `NoConnection` type is the idle variant of [`ConnectionState`](/api-reference/types/connection-state): `inProgress` is `false` and every other field is `null`. It's what [`useConnection()`](/api-reference/composables/use-connection) returns while nothing is being connected. #### Fields * `inProgress: false` * `isValid: null` * `from: null` * `fromHandle: null` * `fromPosition: null` * `fromNode: null` * `to: null` * `toHandle: null` * `toPosition: null` * `toNode: null` * `pointer: null` ### NodeChange ### NodeChange The `NodeChange` type is the union of the individual changes Vue Flow reports for nodes β€” position, dimensions, selection, add, remove, and replace. The `@nodes-change` event delivers them as a [`NodeChangeset`](/api-reference/types/node-changeset); in a controlled flow apply them with the changeset's `applyTo(nodes)`. #### Fields The `nodes-change` event passes an array of `NodeChange` objects that you should use to update your flow's state. The `NodeChange` type is a union of the different object types that represent the various ways a node can change in a flow. * `id: string` * `type: "dimensions" | "position" | "select" | "remove" | "add"` ### NodeChangeset ### NodeChangeset A `NodeChangeset` is what Vue Flow hands you whenever nodes change: both the `@nodes-change` event and the `onNodesChange` hook deliver one. It collects the [`NodeChange`](/api-reference/types/node-change) objects queued for that update and knows how to apply them, so you never assemble the next array yourself. [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/changes/index.ts) ```ts import type { Node, NodeChangeset } from '@xyflow/vue'; function onNodesChange(changes: NodeChangeset) { nodes.value = changes.applyTo(nodes.value); } ``` You only need this in a **controlled** flow (a one-way `:nodes` binding). With `v-model:nodes` Vue Flow applies the changeset for you. #### Reading changes A changeset is iterable, and it can hand you changes by type or by node β€” so inspecting an update doesn't mean scanning an array yourself. ```ts // every change, in order for (const change of changes) { console.log(change.type, change.id); } // just the removals if (changes.getByType('remove').length > 0) { saveUndoSnapshot(); } // everything queued for one node const changesForNode = changes.getForNode('node-1'); ``` #### Editing before you apply Because the changeset is a real object you can drop or add changes before applying it β€” handy for vetoing an update without rebuilding the array. ```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); } ``` #### Members | Member | Signature | Description | | --------------- | ---------------------------------------------- | ------------------------------------------------------------------ | | `applyTo` | `(nodes: NodeType[]) => NodeType[]` | Applies every queued change and returns the next array. | | `add` | `(change: NodeChange \| NodeChange[]) => void` | Queues one or more changes. | | `remove` | `(change: NodeChange) => void` | Removes a queued change by object reference. | | `getByType` | `(type: NodeChange['type']) => NodeChange[]` | Every queued change of that type, e.g. `'position'` or `'remove'`. | | `getForNode` | `(nodeId: string) => NodeChange[]` | Every queued change for one node. | | `removeForNode` | `(nodeId: string) => void` | Drops every queued change for one node. | | `toArray` | `() => NodeChange[]` | All queued changes as a flat array. | | `size` | `number` | How many nodes the changeset touches. | | `version` | `number` | Bumped on every edit β€” useful as a watch source. | The changeset also implements `Symbol.iterator`, so `[...changes]` and `for…of` work directly. #### Notes * Construct one yourself with `new NodeChangeset(changes?)` β€” for example to replay recorded changes. * The standalone `applyNodeChanges(changes, nodes)` util is **deprecated** and still array-based, so it cannot take the event payload; use `applyTo` or the instance's `applyNodeChanges(changeset)`. * Edges have the mirrored [`EdgeChangeset`](/api-reference/types/edge-changeset). ### NodeConnection ### NodeConnection The `NodeConnection` type describes a connection attached to a node β€” the `source` / `target`, the handle ids, and the `edgeId`. It's what [`useNodeConnections()`](/api-reference/composables/use-node-connections) returns. #### Fields The `NodeConnection` type is an extension of a basic [Connection](/api-reference/types/connection) that includes the `edgeId`. * `source: string` The id of the node this connection originates from. * `target: string` The id of the node this connection terminates at. * `sourceHandle: string | null` When not `null`, the id of the handle on the source node that this connection originates from. * `targetHandle: string | null` When not `null`, the id of the handle on the target node that this connection terminates at. * `edgeId: string` ### NodeDragEvent ### NodeDragEvent The `NodeDragEvent` type is the payload of the node drag events β€” `@node-drag-start`, `@node-drag`, and `@node-drag-stop`. It carries the native `event`, the primary [`Node`](/api-reference/types/node), and the full set of `nodes` being dragged. #### Fields Payload for the node drag events (`nodeDragStart`, `nodeDrag`, `nodeDragStop`). * `event: MouseTouchEvent` The DOM event driving the drag. * `node: NodeType` The node being dragged. * `nodes: NodeType[]` All nodes being dragged together (the grabbed node plus any others in the selection). ### NodeMouseEvent ### NodeMouseEvent The `NodeMouseEvent` type is the payload of the node pointer events β€” `@node-click`, `@node-double-click`, `@node-context-menu`, and the `@node-mouse-*` events. It carries the native `event` and the [`Node`](/api-reference/types/node) it concerns. #### Fields Payload for the node pointer events (`nodeClick`, `nodeMouseEnter`, `nodeContextMenu`, …). * `event: MouseTouchEvent` The DOM event that triggered this. * `node: NodeType` The node the event refers to. ### NodeOrigin ### NodeOrigin The `NodeOrigin` type is an `[x, y]` pair (each `0`–`1`) that sets which point of a node its `position` refers to β€” `[0, 0]` is the top-left (the default), `[0.5, 0.5]` centers the node on its position, `[1, 1]` is the bottom-right. #### Type ```ts type NodeOrigin = [number, number]; ``` ### NodeProps ### NodeProps The `NodeProps` type is the set of props Vue Flow passes to a [custom node](/learn/customization/custom-nodes) component β€” `id`, `data`, `type`, `selected`, `dragging`, `positionAbsoluteX` / `positionAbsoluteY`, and more. Declare it in your node with `defineProps()`. #### Fields When you implement a custom node it is wrapped in a component that enables basic functionality like selection and dragging. Your custom node receives `NodeProps` as props. * `id: string` Unique id of a node. * `data: NodeType["data"]` Arbitrary data passed to a node. * `type: NodeType["type"]` Type of node defined in `nodeTypes`. * `selected: boolean` Whether the node is currently selected. * `selectable: boolean` Whether the node can be selected. * `deletable: boolean` Whether the node can be deleted. * `draggable: boolean` Whether or not the node is able to be dragged. * `dragging: boolean` Whether or not the node is currently being dragged. * `zIndex: number` The node's z-index. * `isConnectable: boolean` Whether a node is connectable or not. * `positionAbsoluteX: number` Position absolute x value. * `positionAbsoluteY: number` Position absolute y value. * `width?: NodeType["width"]` The node's width, in pixels. * `height?: NodeType["height"]` The node's height, in pixels. * `sourcePosition?: NodeType["sourcePosition"]` Only relevant for default, source, target nodeType. Controls source position. * `targetPosition?: NodeType["targetPosition"]` Only relevant for default, source, target nodeType. Controls target position. * `dragHandle?: NodeType["dragHandle"]` A class name that can be applied to elements inside the node that allows those elements to act as drag handles, letting the user drag the node by clicking and dragging on those elements. * `parentId?: NodeType["parentId"]` Parent node id, used for creating sub-flows. #### Notes * Vue Flow doesn't pass the whole node object to a custom node. If you need fields that aren't in `NodeProps` (e.g. the parent node or connected edges), resolve them with [`useNode()`](/api-reference/composables/use-node) / [`useInternalNode()`](/api-reference/composables/use-internal-node). ### NodeTypesObject ### NodeTypesObject The `NodeTypesObject` type maps custom node `type` names to the components that render them β€” the shape of the `nodeTypes` prop. In Vue Flow you can also register node types with the `#node-` slots instead. #### Fields * `input?: NodeComponent` * `output?: NodeComponent` * `default?: NodeComponent` * `group?: NodeComponent` ### Node ### Node\ The `Node` type represents everything Vue Flow needs to know about a given node. #### Notes * You shouldn't try to set the `measured.width` or `measured.height` of a node directly. It is measured internally by Vue Flow and used when rendering the node in the viewport. To control a node's size you should use the `width` and `height` attributes. #### Fields The `Node` type represents everything Vue Flow needs to know about a given node. Whenever you want to update a certain attribute of a node, you need to create a new node object. * `id: string` Unique id of a node. * `position: XYPosition` Position of a node on the pane. * `data: NodeData` Arbitrary data passed to a node. * `sourcePosition?: Position` Only relevant for default, source, target nodeType. Controls source position. * `targetPosition?: Position` Only relevant for default, source, target nodeType. Controls target position. * `hidden?: boolean` Whether or not the node should be visible on the canvas. * `selected?: boolean` * `dragging?: boolean` Whether or not the node is currently being dragged. * `draggable?: boolean` Whether or not the node is able to be dragged. * `selectable?: boolean` * `connectable?: boolean` * `deletable?: boolean` * `dragHandle?: string` A class name that can be applied to elements inside the node that allows those elements to act as drag handles, letting the user drag the node by clicking and dragging on those elements. * `width?: number` * `height?: number` * `initialWidth?: number` * `initialHeight?: number` * `parentId?: string` Parent node id, used for creating sub-flows. * `zIndex?: number` * `extent?: CoordinateExtent | "parent" | null` Boundary a node can be moved in. * `expandParent?: boolean` When `true`, the parent node will automatically expand if this node is dragged to the edge of the parent node's bounds. * `ariaLabel?: string` * `origin?: NodeOrigin` Origin of the node relative to its position. * `handles?: NodeHandle[]` * `measured?: { width?: number; height?: number; }` * `resizing?: boolean` Whether the node is currently being resized. * `type?: string | NodeType | (NodeType & undefined)` Type of node defined in nodeTypes * `class?: ClassValue` Additional class names applied to the node element. * `style?: Styles` Additional inline styles applied to the node element. * `focusable?: boolean` Whether the node can be focused for keyboard interaction (a11y). * `ariaRole?: string` The ARIA role attribute for the node element, used for accessibility. * `domAttributes?: Omit` General escape hatch for adding custom attributes to the node's DOM element. ### OnBeforeDelete ### OnBeforeDelete The `OnBeforeDelete` type is the signature of the function you pass to the `onBeforeDelete` prop. It receives the nodes and edges about to be deleted and returns (a promise of) `false` to cancel the deletion, `true` to allow it, or a filtered set of elements to delete a subset. #### Fields Consulted before nodes/edges are deleted (via the delete key or `deleteElements`). Receives the full set about to be removed (the targeted nodes/edges plus connected edges and child nodes). Return `false` to cancel, `true` to delete that set, or `{ nodes, edges }` to delete only a subset. ###### Parameters * `__0: { nodes: NodeType[]; edges: EdgeType[]; }` ###### Returns `Promise` ### OnConnectStartParams ### OnConnectStartParams The `OnConnectStartParams` type describes where a connection interaction started β€” the `nodeId`, `handleId`, and `handleType`. It's part of the `@connect-start` event payload. #### Fields * `nodeId: string | null` * `handleId: string | null` * `handleType: HandleType | null` ### OnDelete ### OnDelete The `OnDelete` type is the payload of the `@delete` event, fired after elements are removed. It carries the [`nodes`](/api-reference/types/node) and [`edges`](/api-reference/types/edge) that were deleted. #### Fields Called after nodes and/or edges have been removed (via the delete key or `deleteElements`), with the removed elements. The `delete` event payload; mirrors xyflow/react's `OnDelete` and xyflow/svelte's `ondelete`. ###### Parameters * `params: { nodes: NodeType[]; edges: EdgeType[]; }` ###### Returns `void` ### Padding [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/types/utils.ts/#L165) You can pass a `Padding` value to define the space around the nodes when fitting the view. It can be a single value applied to all sides, or an object specifying individual sides or axes like you know it from CSS. ```ts const padding: Padding = { top: '10px', right: '5%', bottom: 20, // this would be interpreted as 20px left: '15px', } ``` ### PanOnScrollMode ### PanOnScrollMode The `PanOnScrollMode` enum controls scroll-panning direction when `panOnScroll` is enabled β€” `free`, `horizontal`, or `vertical`. Set it with the `panOnScrollMode` prop. #### Values ```ts enum PanOnScrollMode { Free = 'free', Vertical = 'vertical', Horizontal = 'horizontal', } ``` ### PanelPosition ### PanelPosition The `PanelPosition` type is the set of anchor points a [``](/api-reference/components/panel) β€” and the MiniMap and Controls, which build on it β€” can sit at, e.g. `top-left`, `bottom-right`, `top-center`. #### Type ```ts type PanelPosition = | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-right'; ``` ### Position ### Position The `Position` enum describes the four sides a handle can be placed on. It's used for handle placement (`sourcePosition` / `targetPosition`) and when computing edge paths. #### Values ```ts enum Position { Left = 'left', Top = 'top', Right = 'right', Bottom = 'bottom', } ``` ### ProOptions ### ProOptions The `ProOptions` type configures Pro-related options β€” most commonly `hideAttribution` to remove the Vue Flow attribution (please only do so if you have a [Pro subscription](https://vueflow.dev/pro)). Pass it via the `proOptions` prop. #### Fields Vue Flow is independent and entirely funded by its users. If you hide the attribution, please support our work by subscribing to Vue Flow Pro: * `account?: string` * `hideAttribution: boolean` If you hide the attribution, please support our work with a subscription. ### Rect ### Rect The `Rect` type describes a rectangle by its top-left position (`x`, `y`) and its `width` and `height`. It's returned by helpers like [`getNodesBounds`](/api-reference/utils/get-nodes-bounds). #### Fields * `width: number` * `height: number` * `x: number` * `y: number` ### SelectionChangeEvent ### SelectionChangeEvent The `SelectionChangeEvent` type is the payload of the `@selection-change` event, fired whenever the selection changes. It carries the currently selected [`nodes`](/api-reference/types/node) and [`edges`](/api-reference/types/edge). #### Fields Payload for `selectionChange` β€” the currently selected nodes and edges. * `nodes: NodeType[]` The currently selected nodes. * `edges: EdgeType[]` The currently selected edges. ### SelectionMode ### SelectionMode The `SelectionMode` enum controls how the selection box picks nodes β€” `full` requires a node to be entirely inside the box, `partial` selects nodes it merely overlaps. Set it with the `selectionMode` prop. #### Values ```ts enum SelectionMode { Partial = 'partial', Full = 'full', } ``` ### SnapGrid ### SnapGrid The `SnapGrid` type is an `[x, y]` step pair that nodes snap to while dragging when the `snapToGrid` prop is enabled. #### Type ```ts type SnapGrid = [number, number]; ``` ### UseNodeConnectionsParams ### UseNodeConnectionsParams The options object accepted by the [`useNodeConnections()`](/api-reference/composables/use-node-connections) composable. Every field is optional; each may be a value, ref, or getter. Filter by handle with `handleType` (and `handleId`), and react to changes with `onConnect` / `onDisconnect`. #### Type ```ts type UseNodeConnectionsParams = { // node id β€” defaults to the useNodeId context injection id?: MaybeRefOrGetter; // called when a connection to this node is created onConnect?: (connections: NodeConnection[]) => void; // called when a connection to this node is removed onDisconnect?: (connections: NodeConnection[]) => void; // 'source' or 'target' β€” restrict to connections on that side handleType?: MaybeRefOrGetter; // a specific handle id (only for nodes with multiple same-type handles); requires handleType handleId?: MaybeRefOrGetter; }; ``` #### Notes * `handleId` requires `handleType` to be set. * The callbacks receive an array of [`NodeConnection`](/api-reference/types/node-connection); `handleType` is `'source'` or `'target'`. ### Viewport ### Viewport The `Viewport` type describes the current pan and zoom of the flow as `x`, `y`, and `zoom`. Read it from `useVueFlow().viewport`, bind it with `v-model:viewport`, or set it with the viewport helpers. #### Fields Internally, React Flow maintains a coordinate system that is independent of the rest of the page. The `Viewport` type tells you where in that system your flow is currently being display at and how zoomed in or out it is. * `x: number` * `y: number` * `zoom: number` ### XYPosition ### XYPosition The `XYPosition` type is a simple `{ x, y }` coordinate pair, used throughout Vue Flow β€” most visibly as a node's `position`. #### Fields All positions are stored in an object with x and y coordinates. * `x: number` * `y: number` ### ZIndexMode ### ZIndexMode The `ZIndexMode` type controls how Vue Flow assigns stacking order β€” `basic` uses a fixed order, while other modes raise elements based on selection. Set it with the `zIndexMode` prop. #### Type ```ts type ZIndexMode = 'auto' | 'basic' | 'manual'; ``` ### addEdge() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/utils/edges.ts) The `addEdge` util is a convenience function to add a new [`Edge`](/api-reference/types/edge) to an array of edges. It also validates the edge so you don't add an invalid one or duplicate an existing connection. ```ts import { addEdge } from '@xyflow/vue'; function onConnect(connection) { edges.value = addEdge(connection, edges.value); } ``` #### Signature Adds a `Connection` (or a full `Edge`) to an edges array and returns a new array β€” generating the edge id and skipping the add when an equivalent connection already exists. The pure helper to use in an `@connect` handler against a `v-model:edges` array, e.g. `edges.value = addEdge(connection, edges.value)`, with no store/instance access. ###### Parameters * `edgeParams: EdgeType | Connection` * `edges: EdgeType[]` * `options.getEdgeId?: GetEdgeId` Custom function to generate edge IDs. If not provided, the default `getEdgeId` function is used. * `options.onError?: OnError` Called when edge validation fails. If not provided, a default dev warning is used. ###### Returns `EdgeType[]` #### Notes * If an edge with the same `source` and `target` already exists (and the same `sourceHandle` / `targetHandle` when set), `addEdge` won't add another one β€” even if the `id` differs. ### getBezierPath() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/edges/bezier-edge.ts) The `getBezierPath` util returns the SVG path string for a bezier edge, along with the label coordinates and the edge's center. Use it inside a [custom edge](/learn/customization/custom-edges) to draw the path. ```ts import { BaseEdge, getBezierPath } from '@xyflow/vue'; const [path, labelX, labelY] = getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, }); ``` #### Signature The `getBezierPath` util returns everything you need to render a bezier edge between two nodes. ###### Parameters * `[0].sourceX: number` The `x` position of the source handle. * `[0].sourceY: number` The `y` position of the source handle. * `[0].sourcePosition?: Position` The position of the source handle. * `[0].targetX: number` The `x` position of the target handle. * `[0].targetY: number` The `y` position of the target handle. * `[0].targetPosition?: Position` The position of the target handle. * `[0].curvature?: number` The curvature of the bezier edge. ###### Returns `[path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]` ### getConnectedEdges() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/graph.ts) The `getConnectedEdges` util returns every edge connected to any of the given nodes β€” an edge counts if either its `source` or `target` is one of those nodes. ```ts import { getConnectedEdges } from '@xyflow/vue'; const connected = getConnectedEdges(selectedNodes, edges); ``` #### Signature This utility filters an array of edges, keeping only those where either the source or target node is present in the given array of nodes. ###### Parameters * `nodes: NodeType[]` Nodes you want to get the connected edges for. * `edges: EdgeType[]` All edges. ###### Returns `EdgeType[]` ### getIncomers() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/graph.ts) The `getIncomers` util returns the source nodes directly connected to a given node β€” i.e. the nodes on the other end of every edge whose `target` is that node. ```ts import { getIncomers } from '@xyflow/vue'; const incomers = getIncomers(node, nodes, edges); ``` #### Signature This util is used to tell you what nodes, if any, are connected to the given node as the *source* of an edge. ###### Parameters * `node: NodeType | { id: string; }` The node to get the connected nodes from. * `nodes: NodeType[]` The array of all nodes. * `edges: EdgeType[]` The array of all edges. ###### Returns `NodeType[]` #### Notes * See [`getOutgoers`](/api-reference/utils/get-outgoers) for the nodes on the outgoing side. ### getNodesBounds() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/graph.ts) The `getNodesBounds` util returns the bounding [`Rect`](/api-reference/types/rect) that contains all of the given nodes β€” handy for centering the view on a subset of nodes or measuring a group. ```ts import { getNodesBounds, useVueFlow } from '@xyflow/vue'; const { getNodes } = useVueFlow(); const bounds = getNodesBounds(getNodes.value); ``` #### Signature Returns the bounding box that contains all the given nodes in an array. This can be useful when combined with [`getViewportForBounds`](/api-reference/utils/get-viewport-for-bounds) to calculate the correct transform to fit the given nodes in a viewport. ###### Parameters * `nodes: (string | NodeType | InternalNodeBase)[]` Nodes to calculate the bounds for. * `params.nodeOrigin?: NodeOrigin` Origin of the nodes: `[0, 0]` for top-left, `[0.5, 0.5]` for center. * `params.nodeLookup?: NodeLookup>` ###### Returns `Rect` ### getOutgoers() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/graph.ts) The `getOutgoers` util returns the target nodes directly connected to a given node β€” i.e. the nodes on the other end of every edge whose `source` is that node. ```ts import { getOutgoers } from '@xyflow/vue'; const outgoers = getOutgoers(node, nodes, edges); ``` #### Signature This util is used to tell you what nodes, if any, are connected to the given node as the *target* of an edge. ###### Parameters * `node: NodeType | { id: string; }` The node to get the connected nodes from. * `nodes: NodeType[]` The array of all nodes. * `edges: EdgeType[]` The array of all edges. ###### Returns `NodeType[]` #### Notes * See [`getIncomers`](/api-reference/utils/get-incomers) for the nodes on the incoming side. ### getSimpleBezierPath() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/components/Edges/SimpleBezierEdge.ts) The `getSimpleBezierPath` util returns the SVG path string for a simple bezier edge β€” a smoother curve than the default bezier, without control-point handles β€” along with the label coordinates. ```ts import { BaseEdge, getSimpleBezierPath } from '@xyflow/vue'; const [path, labelX, labelY] = getSimpleBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, }); ``` #### Signature Get a simple bezier path from source to target handle (no curvature) ###### Parameters * `[0].sourceX: number` * `[0].sourceY: number` * `[0].sourcePosition?: Position` * `[0].targetX: number` * `[0].targetY: number` * `[0].targetPosition?: Position` ###### Returns `[path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]` ### getSmoothStepPath() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/edges/smoothstep-edge.ts) The `getSmoothStepPath` util returns the SVG path string for a smooth-step edge, along with the label coordinates. Set `borderRadius` to `0` for a sharp step edge. ```ts import { BaseEdge, getSmoothStepPath } from '@xyflow/vue'; const [path, labelX, labelY] = getSmoothStepPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, }); ``` #### Signature The `getSmoothStepPath` util returns everything you need to render a stepped path between two nodes. The `borderRadius` property can be used to choose how rounded the corners of those steps are. ###### Parameters * `[0].sourceX: number` The `x` position of the source handle. * `[0].sourceY: number` The `y` position of the source handle. * `[0].sourcePosition?: Position` The position of the source handle. * `[0].targetX: number` The `x` position of the target handle. * `[0].targetY: number` The `y` position of the target handle. * `[0].targetPosition?: Position` The position of the target handle. * `[0].borderRadius?: number` * `[0].centerX?: number` * `[0].centerY?: number` * `[0].offset?: number` * `[0].stepPosition?: number` Controls where the bend occurs along the path. 0 = at source, 1 = at target, 0.5 = midpoint ###### Returns `[path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]` ### getStraightPath() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/edges/straight-edge.ts) The `getStraightPath` util returns the SVG path string for a straight edge, along with the label coordinates. ```ts import { BaseEdge, getStraightPath } from '@xyflow/vue'; const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY }); ``` #### Signature Calculates the straight line path between two points. ###### Parameters * `[0].sourceX: number` The `x` position of the source handle. * `[0].sourceY: number` The `y` position of the source handle. * `[0].targetX: number` The `x` position of the target handle. * `[0].targetY: number` The `y` position of the target handle. ###### Returns `[path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]` ### getViewportForBounds() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/system/src/utils/general.ts) The `getViewportForBounds` util computes the [`Viewport`](/api-reference/types/viewport) (`x`, `y`, `zoom`) needed to fit a given bounding rectangle into the flow area, respecting the min/max zoom and padding. It's the math behind `fitView` / `fitBounds`. ```ts import { getViewportForBounds } from '@xyflow/vue'; const viewport = getViewportForBounds(bounds, width, height, minZoom, maxZoom, padding); ``` #### Signature Returns a viewport that encloses the given bounds with padding. ###### Parameters * `bounds: Rect` Bounds to fit inside viewport. * `width: number` Width of the viewport. * `height: number` Height of the viewport. * `minZoom?: number` Minimum zoom level of the resulting viewport. * `maxZoom?: number` Maximum zoom level of the resulting viewport. * `padding?: Padding` Padding around the bounds. ###### Returns * `x: number` * `y: number` * `zoom: number` ### Utils ### isEdge() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/utils/graph.ts) The `isEdge` util is a type guard that returns `true` when a flow element is an [`Edge`](/api-reference/types/edge), narrowing its type for TypeScript. ```ts import { isEdge } from '@xyflow/vue'; const edgesOnly = elements.filter(isEdge); ``` #### Signature Test whether an object is usable as an `Edge`. In TypeScript this is a type guard that narrows the type of whatever you pass in to `Edge` if it returns `true`. ###### Parameters * `element: unknown` The element to test. ###### Returns `boolean` #### Notes * See [`isNode`](/api-reference/utils/is-node) for the node counterpart. ### isNode() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/utils/graph.ts) The `isNode` util is a type guard that returns `true` when a flow element is a [`Node`](/api-reference/types/node), narrowing its type for TypeScript. ```ts import { isNode } from '@xyflow/vue'; const nodesOnly = elements.filter(isNode); ``` #### Signature Test whether an object is usable as a `Node`. In TypeScript this is a type guard that narrows the type of whatever you pass in to `Node` if it returns `true`. ###### Parameters * `element: unknown` The element to test. ###### Returns `boolean` #### Notes * See [`isEdge`](/api-reference/utils/is-edge) for the edge counterpart. ### reconnectEdge() [Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/vue/src/utils/edges.ts) The `reconnectEdge` util takes an existing [`Edge`](/api-reference/types/edge), a new [`Connection`](/api-reference/types/connection), and the current edges, and returns a new array with that edge reconnected to the new source/target. Use it from the `@reconnect` handler to persist a reconnection. ```ts import { reconnectEdge } from '@xyflow/vue'; function onReconnect(oldEdge, newConnection) { edges.value = reconnectEdge(oldEdge, newConnection, edges.value); } ``` #### Signature Reconnects an existing edge to a new `Connection`, returning a new edges array. The pure, controlled counterpart to the store action `useVueFlow().reconnectEdge` β€” use it in an `@reconnect` handler against a `v-model:edges` array, e.g. `edges.value = reconnectEdge(oldEdge, newConnection, edges.value)`. ###### Parameters * `oldEdge: EdgeType` * `newConnection.source: string` The id of the node this connection originates from. * `newConnection.target: string` The id of the node this connection terminates at. * `newConnection.sourceHandle: string | null` When not `null`, the id of the handle on the source node that this connection originates from. * `newConnection.targetHandle: string | null` When not `null`, the id of the handle on the target node that this connection terminates at. * `edges: EdgeType[]` * `options.shouldReplaceId?: boolean` Should the id of the old edge be replaced with the new connection id. * `options.getEdgeId?: GetEdgeId` Custom function to generate edge IDs. If not provided, the default `getEdgeId` function is used. * `options.onError?: OnError` Called when edge validation fails. If not provided, a default dev warning is used. ###### Returns `EdgeType[]` #### Notes * By default the edge keeps its `id`. Pass `shouldReplaceId` to derive a new id from the new connection instead.