Workflow
An example of how to use the AI Elements Vue to build a workflow visualization.
An example of how to use the AI Elements Vue to build a workflow visualization with interactive nodes and animated connections, built with Vue Flow.
Tutorial
Let's walk through how to build a workflow visualization using AI Elements Vue. Our example will include custom nodes with headers, content, and footers, along with animated and temporary edge types.
Setup
First, set up a new Vue.js repo by running the following command:
Follow this guide to setup shadcn/vue and Tailwind.
Run the following command to install AI Elements:
Now, install the required dependencies:
Now let's build the workflow step by step: create the component structure, define our nodes and edges, and configure the canvas.
Import the components
Import the necessary AI Elements Vue components in your src/App.vue:
Define node IDs
Create a constant object to manage node identifiers. This makes it easier to reference nodes when creating edges:
Create mock nodes
Define the nodes array with position, type, and data for each node in your workflow:
Create mock edges
Define the connections between nodes. Use animated for active paths and temporary for conditional or error paths:
Create the node types
Create a custom node component:
Define the node types to use the custom Node component:
Create the edge types
Map the edge type names to the Edge components:
Create the template
Finally, create the template that combines the Canvas with all nodes, edges, controls, and custom UI panels:
Key Features
The workflow visualization demonstrates several powerful features:
- Custom Node Components: Each node uses the compound components (
NodeHeader,NodeTitle,NodeDescription,NodeContent,NodeFooter) for consistent, structured layouts. - Node Toolbars: The
Toolbarcomponent attaches contextual actions (like Edit and Delete buttons) to individual nodes, appearing when hovering or selecting them. - Handle Configuration: Nodes can have source and/or target handles, controlling which connections are possible.
- Multiple Edge Types: The
animatedtype shows active data flow, whiletemporaryindicates conditional or error paths. - Custom Connection Lines: The
Connectioncomponent provides styled bezier curves when dragging new connections between nodes. - Interactive Controls: The
Controlscomponent adds zoom in/out and fit view buttons with a modern, themed design. - Custom UI Panels: The
Panelcomponent allows you to position custom UI elements (like buttons, filters, or legends) anywhere on the canvas. - Automatic Layout: The
Canvascomponent auto-fits the view and provides pan/zoom controls out of the box.
You now have a working workflow visualization! Feel free to explore dynamic workflows by connecting this to AI-generated process flows, or extend it with interactive editing capabilities using Vue Flow's built-in features.