Skip to content
nexubDesign System
v11.9.0

Components · Diagram

Diagram Canvas

AlphaAdded v11.6.0

Nodes and edges on a themed, keyboard-accessible canvas: workflows and mind maps, with automatic layout and a "Show as list" text alternative. From `@nexub/diagram`, on React Flow.

import { DiagramCanvas } from '@nexub/diagram';
import '@nexub/diagram/styles.css';

Install: npm install @nexub/diagram @xyflow/react. @xyflow/react (React Flow) is a peer dependency: install it next to @nexub/diagram. Load the stylesheet after @nexub/react’s.

View as Markdown

Usage

Use it for
  • Free-form graphs people build or edit: workflow editors, automations, pipelines.

  • Mind maps: one idea in the middle, branches around it (`layout="mind-map"`).

  • Read-only maps of how things connect, where the shape matters (`readOnly`).

Use something else for
  • Reporting lines and other strict hierarchies people scan by name: use OrgChart or TreeView.

  • Steps in a fixed order: use Stepper or a list.

  • An app that can’t take React Flow as a dependency (about 50 kB gzip): DiagramCanvas needs `@xyflow/react` installed next to it.

Playground

Props

layout
Show as list
  • New sign-up
    • Connects to: Enrich profile, Send welcome email
  • Enrich profile
    • Connects to: Score lead
    • Connected from: New sign-up
  • Send welcome email (Good)
    • Connected from: New sign-up
  • Score lead (Warning)
    • Connects to: Create CRM record
    • Connected from: Enrich profile
  • Create CRM record
    • Connected from: Score lead
TSX
<DiagramCanvas aria-label="Lead onboarding workflow" nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} minZoom={0.3} layout="left-right" fitView />

Examples

Workflow, left to right

Controlled nodes and edges with `layout="left-right"`. Tab to a node, then try the arrow keys, Alt+arrows, C and Delete.

Show as list
  • New sign-up
    • Connects to: Enrich profile, Send welcome email
  • Enrich profile
    • Connects to: Score lead
    • Connected from: New sign-up
  • Send welcome email (Good)
    • Connected from: New sign-up
  • Score lead (Warning)
    • Connects to: Create CRM record
    • Connected from: Enrich profile
  • Create CRM record
    • Connected from: Score lead

Mind map

`layout="mind-map"` and `readOnly`: a radial tree to look at, not edit.

Mini Map
Show as list
  • Product launch
    • Connects to: Audience, Channels, Timeline
  • Timeline
    • Connects to: Beta in March
    • Connected from: Product launch
  • Beta in March
    • Connected from: Timeline
  • Audience
    • Connects to: Small teams, Enterprise
    • Connected from: Product launch
  • Small teams
    • Connected from: Audience
  • Enterprise
    • Connected from: Audience
  • Channels
    • Connects to: Email, Events
    • Connected from: Product launch
  • Events
    • Connected from: Channels
  • Email
    • Connected from: Channels

States

  • Show as list
    • New sign-up
      • Connects to: Enrich profile, Send welcome email
    • Enrich profile
      • Connects to: Score lead
      • Connected from: New sign-up
    • Send welcome email (Good)
      • Connected from: New sign-up
    • Score lead (Warning)
      • Connects to: Create CRM record
      • Connected from: Enrich profile
    • Create CRM record
      • Connected from: Score lead
    default
  • Show as list
    • New sign-up
      • Connects to: Enrich profile, Send welcome email
    • Enrich profile
      • Connects to: Score lead
      • Connected from: New sign-up
    • Send welcome email (Good)
      • Connected from: New sign-up
    • Score lead (Warning)
      • Connects to: Create CRM record
      • Connected from: Enrich profile
    • Create CRM record
      • Connected from: Score lead
    readOnly

Props

Props
PropTypeDefaultDescription
aria-labelrequiredstring—Names the canvas (role="application"). Required.
nodes / onNodesChangeNode[]—React Flow’s controlled nodes. type: 'nexub' renders the Nexub card (DiagramNode) from data: { title, description, icon, tone }.
edges / onEdgesChangeEdge[]—React Flow’s controlled edges.
defaultNodes / defaultEdgesNode[] / Edge[]—Uncontrolled instead: the canvas keeps the state, and layout applies once.
onConnect(connection: Connection) => void—Called when a handle is dragged to another node, or a node is picked in the "Connect to…" menu (C). Without it, nodes can’t be connected.
layout'left-right' | 'mind-map' | 'none''none'left-right: a layered workflow (a tidy tree when the graph is a tree). mind-map: a radial tree with edges between facing sides. Runs again when node ids, sizes or links change; moves made since are kept until then.
readOnlyboolean—View only: no dragging, connecting, deleting or selecting. Arrow keys still move focus between nodes.
minimapbooleanfalseShow the minimap.
controlsbooleantrueShow the zoom in, zoom out and fit view buttons.
listViewbooleantrueShow the "Show as list" text alternative under the canvas: every node with its connections by name.
labelsPartial<DiagramLabels>—Every string the canvas shows or announces, English by default. Pass translations here.
keyboardStepnumber—Grid step for Alt+Arrow moves, in flow units; Shift moves four steps. Defaults to snapGrid[0], else 16.
nodeTypesNodeTypes—Extra node types; nexub (DiagramNode) is always there.
fitViewboolean—React Flow’s: fit the nodes into view on first render. Animation is skipped under reduced motion.
classNamestring—Sizes the canvas box (24rem tall by default), e.g. h-96.

Accessibility

ARIA roles

application (the canvas, named by `aria-label`)group with `aria-roledescription="node"` for each node, named by its title, with the keyboard hint as its descriptionlistbox and option (the "Connect to…" menu)Native `<details>` for "Show as list"

Keyboard

  • Tab

    Moves into the canvas onto one node (roving tabindex: the last focused, else the first in reading order), then on to the zoom controls.

  • Arrow keys

    Move focus to the nearest node in that direction.

  • Home / End

    First or last node in reading order (top to bottom, then by line direction; mirrored in RTL).

  • Alt (Option) + Arrow

    Moves the focused node one grid step (`keyboardStep`); with Shift, four. The new position is announced. Off in `readOnly`.

  • C

    Opens the "Connect <node> to…" menu, the keyboard alternative to dragging a handle. Only with `onConnect`.

  • Up / Down, Home / End, a letter

    In the Connect menu: move through the nodes it can connect to; typing a letter jumps to the next title starting with it.

  • Enter / Space

    In the Connect menu: connects to the active node and announces it.

  • Escape / Tab

    Closes the Connect menu; focus returns to the node.

  • Delete / Backspace

    Removes the selection, or the focused node; focus moves to the next node in reading order and the count is announced.

Focus

  • One node is in the Tab order at a time; focus follows arrow keys, not the DOM order of React Flow’s nodes.

  • After a delete, focus goes to the next node (or the previous one at the end), never to the page.

  • Focus rings and the 24px handle hit area come from the tokens.

Screen reader

  • Each node is read by its title, then its tone ("Warning") as text, then how the keyboard works.

  • Connections, moves and deletes are announced in a polite live region.

  • "Show as list" lists every node with what it connects to and is connected from, by name: the text alternative to the drawing.

Notes

  • Tone is never colour alone: a dot plus text for screen readers and the list view, and a border in forced colours.

  • Fit view and animated edges respect reduced motion.

  • Every string (`labels`) is English by default: they are not in `@nexub/core` messages yet, so pass translations.

On iOS & Android