# Workflow canvas

> Connected steps you can move, inspect and follow as work flows through them.

A compact canvas for showing how work gets done. Nodes sit on a quiet dot grid, connected by rounded paths. Drag a node and its connections follow in the same coordinate space; drag the background to pan, zoom around the centre, or fit the whole workflow. Select a node to inspect its details. Execution states come from your application: completed steps leave a coloured trail, running steps receive travelling pulses, and failures stay visible with their context.

## Install

```bash
npx shadcn@latest add @hairline/workflow-canvas
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/workflow-canvas
- Registry item (source): https://hairlineui.com/r/workflow-canvas.json

## Usage

```tsx
import { WorkflowCanvas } from "@/components/workflow-canvas";

<WorkflowCanvas width={460} height={180}
  nodes={[
    { id: "input", title: "Receive brief", x: 20, y: 50, status: "complete" },
    { id: "draft", title: "Create draft", x: 270, y: 50, status: "running", detail: "Preparing a first draft from the brief." },
  ]}
  edges={[{ id: "input-draft", from: "input", to: "draft" }]}
/>
```

## Drive it from your application

The component displays the state you provide. Connect your runner or event stream to node statuses, and persist positions after a drag.

```tsx
"use client";

import { useState } from "react";
import { WorkflowCanvas, type WorkflowNode } from "@/components/workflow-canvas";

export function Workflow() {
  const [nodes, setNodes] = useState<WorkflowNode[]>([
    { id: "brief", title: "Receive brief", x: 20, y: 50, status: "idle" },
    { id: "draft", title: "Create proposal", x: 270, y: 50, status: "queued" },
  ]);
  return (
    <WorkflowCanvas nodes={nodes} width={460} height={180}
      edges={[{ id: "brief-draft", from: "brief", to: "draft" }]}
      onNodeMove={(id, position) => setNodes((current) => current.map((node) => node.id === id ? { ...node, ...position } : node))}
      onNodeSelect={(id) => console.log("Inspect", id)}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `nodes` | `WorkflowNode[]` | – | Unique id, title and x/y canvas coordinates. Optional subtitle, icon, status and detail. Nodes measure 164 × 78px. |
| `edges` | `{ id: string; from: string; to: string }[]` | – | Unique connection IDs and source/destination node IDs. Missing endpoints are ignored. |
| `width / height` | `number` | `660 / 340` | Canvas bounds in CSS pixels before zoom. Viewport height is 300px. |
| `label` | `string` | `Workflow` | Region label and visible canvas heading. |
| `onNodeMove` | `(id: string, position: { x: number; y: number }) => void` | – | Final coordinates after a committed drag. Persist these in your application. |
| `onNodeSelect` | `(id: string \| null) => void` | – | The inspected node ID, or null when its details close. |
| `className` | `string` | – | Additional root classes. Standard div attributes are forwarded. |

## States

- **ready / queued**: Each node shows its title, subtitle and state indicator. Connections stay quiet until their source has completed.
- **running**: The node’s outline gains colour and a pulse travels down incoming connections from completed steps. Pulses pause offscreen and in hidden tabs.
- **complete / error**: Completion resolves to a check and leaves a fine coloured connection. Failure uses an error indicator and keeps the node’s details available.
- **move**: Dragging updates a node and all attached SVG paths directly, in canvas coordinates. The final position is reported on release; cancellation restores it.
- **pan / zoom**: Nodes and paths share one transform. Zoom stays centred on the viewport; Fit shows the full canvas with padding.
- **inspect**: A details panel opens below the canvas and measures its content height. Selecting another node updates the panel without shifting the canvas.

## What it handles

How work flows through steps is hard to show in a table. This draws the steps on a canvas and shows each one’s state as it runs. It is a viewer, not an editor: your application owns the execution.

- **Nodes you can move**: Dragging a node moves its connections with it, and the final position is reported so you can save it.
- **Pan, zoom and fit**: Drag the background to pan, zoom about the centre, or press Fit to see the whole workflow.
- **State from your application**: Queued, running, complete and error. Running steps receive travelling pulses and failures stay visible with their context.
- **Inspect any node**: Select a node and a details panel opens below the canvas without shifting it.
- **Keyboard and screen readers**: Tab reaches every node, arrows move focus, Alt with the arrows moves a node, and status changes are announced.
- **A viewer by design**: It does not run or edit the workflow. Your application owns execution, retries and validation.

## Replaces

a node graph library, pan and zoom, connection paths, status pulses, a node inspector

## Where it fits

- **Automation run views**: Show a workflow’s steps and which one is running.
- **AI agent pipelines**: Draw the stages of an agent’s work, with failures kept visible.
- **Data pipeline status**: Sources, transforms and destinations with their current state.
- **Process maps**: Explain how a process works in docs and dashboards.

## Notes

- Nodes are real buttons. Tab reaches every node and control; arrows move focus in supplied reading order. Alt + arrows move a node by 12 canvas pixels. Enter or Space opens details; Escape closes details or cancels a drag.
- Status uses text and icons as well as colour. Running, completion and error updates are announced in a polite live region.
- Reduced motion removes connection pulses, spinning indicators and eased viewport/panel transitions. Direct manipulation stays attached to the pointer.
- The canvas owns touch gestures inside its bounds. The initial zoom stays at least 85% for legibility; on narrow screens, pan to reach other nodes or use Fit for an overview. Focusing a node brings it into view.
- Node positions are remembered locally after dragging. onNodeMove lets you persist them. Remount with a new key to reset a moved layout.
- This is a workflow viewer, not a graph execution engine or connection editor. Your application owns execution, retries and data validation.

License: MIT (https://hairlineui.com/license#components)
