Menu
Navigation

Quick Start

Install a diagram as source code. Use the default widgets or replace any part, just like a Flitter chart.

1. Initialize

npm install flitterjs @flitterjs/adapter-react
npx @flitterjs/cli@latest init

2. Add a flow diagram

npx @flitterjs/cli@latest add flow-diagram

This copies the preset's widget source into your project:

components/diagram/flow-diagram/
├── index.ts          # FlowDiagram — import this
├── base/             # Structural defaults and geometry helpers
└── style/
    ├── config.ts     # Style settings and defaults
    └── parts/        # Widgets you can edit or replace
        ├── node.ts
        ├── handle.ts
        ├── controls.ts
        └── context-menu.ts

The runtime in @flitterjs/diagram owns gestures, state and geometry. The files you install provide the UI.

3. Use the diagram

import Widget from "@flitterjs/adapter-react";
import { layeredLayout, type FlowDiagramData } from "@flitterjs/diagram";
import FlowDiagram from "@/components/diagram/flow-diagram";
 
const data: FlowDiagramData = {
  nodes: [
    {
      id: "draft",
      type: "input",
      position: { x: 0, y: 0 },
      data: { label: "Draft" },
    },
    { id: "review", position: { x: 0, y: 0 }, data: { label: "Review" } },
    {
      id: "publish",
      type: "output",
      position: { x: 0, y: 0 },
      data: { label: "Publish" },
    },
  ],
  edges: [
    { id: "a", source: "draft", target: "review" },
    { id: "b", source: "review", target: "publish" },
  ],
};
 
const diagram = FlowDiagram({
  data,
  layout: layeredLayout,
  viewport: { fitView: true },
  config: { minimap: { visible: false } },
});
 
export default function App() {
  return <Widget widget={diagram} width="100%" height="480px" />;
}

Drag a node, connect a handle, select an edge or press ⌘Z / Ctrl+Z. Those interactions are supplied by the engine.

4. Customize

config adjusts the installed preset. custom replaces widgets.

import {
  Border,
  BorderRadius,
  BoxDecoration,
  Container,
  EdgeInsets,
} from "flitterjs";
 
FlowDiagram({
  data,
  custom: {
    node: ({ label, isHovered, isSelected }) =>
      Container({
        width: 180,
        padding: EdgeInsets.all(16),
        decoration: new BoxDecoration({
          color: "#ffffff",
          borderRadius: BorderRadius.circular(16),
          border: Border.all({
            color: isHovered || isSelected ? "#8b5cf6" : "#d4d4d8",
            width: 2,
          }),
        }),
        child: label,
      }),
  },
});

label is an existing child widget. The engine attaches drag, hover and selection to your returned node. You only replace its appearance.

Parent widgets work the same way:

import { MainAxisSize, Row } from "flitterjs";
 
FlowDiagram({
  data,
  custom: {
    controls: ({ zoomIn, zoomOut, fitView }) =>
      Row({
        mainAxisSize: MainAxisSize.min,
        children: [zoomOut, fitView, zoomIn],
      }),
  },
});

Each button already has its action. Change the row into a column, omit a button, or replace custom.controlButton to change the button itself.

How far can customization go?

You can replace the widget itself, including its children and layout. The gallery contains full applications that use the same engine:

ChangeExtension point
Colors, spacing, sizesconfig
Node body, ports, connection labels, buttons, workspacecustom widget builders
Port geometry and edge routinggetHandles, getEdgePath, nodeOptions
Connection rules and enabled gesturesinteraction, can
Selection details, add-step actions, simulationon, controller methods, your StatefulWidget

The engine still owns the core gesture state machine. Replacing a node widget does not replace dragging or undo; it gives those interactions a different UI. Use your own StatefulWidget for product state and GestureDetector for additional buttons. Dispose controllers and timers when the example unmounts.

Understand the widget tree

The Widget Structure guide explains each replaceable part, its children, and how the engine attaches behavior. Follow it from a node body to the viewport and workspace.

Next: Widget Structure · Gallery · Flow Diagram API