Shehryar Ali

Flowchart

Component 5

About

Workflow canvas with a trigger, an editable If/Else condition card and labelled branches on a dotted grid; cards are draggable and selectable.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Flowchart to your project and fits it to your theme.

Code

How Flowchart is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import type { ReactNode } from "react";
import Flowchart, { type FlowEdge, type FlowStep } from "@/components/ui/flowchart";

/* all content lives here; the component only renders what it is given */

function Icon({ children, size = 16 }: { children: ReactNode; size?: number }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      {children}
    </svg>
  );
}

const TicketIcon = ({ size }: { size?: number }) => (
  <Icon size={size}>
    <path d="M4 7a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v2a2 2 0 0 0 0 4v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-2a2 2 0 0 0 0-4z" />
    <path d="M10 5v12" strokeDasharray="2 2" />
  </Icon>
);

const PROPERTIES = [{ name: "priority" }, { name: "plan" }, { name: "region" }, { name: "channel" }];

const STEPS: FlowStep[] = [
  {
    id: "trigger",
    row: 0,
    x: 0.5,
    w: 300,
    kind: { label: "Trigger", tone: "violet" },
    icon: <TicketIcon />,
    title: "New support ticket",
    caption: "Runs when a customer opens a ticket",
  },
  {
    id: "route",
    row: 1,
    x: 0.5,
    w: 372,
    kind: { label: "If / Else", tone: "amber" },
    clauses: [
      {
        joiner: "If",
        source: { label: "ticket", icon: <TicketIcon size={12} /> },
        property: { value: "priority", options: PROPERTIES },
        operator: "is",
        value: {
          value: "Urgent",
          dot: true,
          options: [
            { name: "Urgent", tag: "P0" },
            { name: "High", tag: "P1" },
            { name: "Normal", tag: "P2" },
            { name: "Low", tag: "P3" },
          ],
        },
      },
      {
        joiner: "and",
        source: { label: "ticket", icon: <TicketIcon size={12} /> },
        property: { value: "plan", options: PROPERTIES },
        operator: "is",
        value: {
          value: "Enterprise annual contract",
          dot: true,
          options: [{ name: "Enterprise annual contract" }, { name: "Team monthly" }, { name: "Starter" }, { name: "Free trial" }],
        },
      },
    ],
  },
  {
    id: "page",
    row: 2,
    x: 0.27,
    w: 252,
    kind: { label: "Then", tone: "emerald" },
    icon: <Icon><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" /><path d="M10.3 21a1.9 1.9 0 0 0 3.4 0" /></Icon>,
    title: "Page on-call engineer",
    caption: "Escalate in #incidents",
  },
  {
    id: "queue",
    row: 2,
    x: 0.73,
    w: 252,
    kind: { label: "Else", tone: "sky" },
    icon: <Icon><path d="M4 6h16M4 12h16M4 18h10" /></Icon>,
    title: "Add to support queue",
    caption: "Auto-reply within 4 hours",
  },
];

const EDGES: FlowEdge[] = [
  { from: "trigger", to: "route" },
  { from: "route", to: "page", label: "true" },
  { from: "route", to: "queue", label: "false" },
];

export default function FlowchartDemo() {
  return (
    <div className="flex min-h-[520px] w-full items-center justify-center bg-background p-8">
      <div className="w-full max-w-[640px]">
        <Flowchart
          steps={STEPS}
          edges={EDGES}
          onSelect={(id) => console.log("select:", id)}
          onClauseChange={(step, clause, field, value) => console.log("change:", step, clause, field, value)}
        />
      </div>
    </div>
  );
}

More by Shehryar Ali

View all
  • Loading State

    Loading State

    20
  • Insight Cards

    Insight Cards

    10
  • Streaming Text

    Streaming Text

    9
  • Murmur Ember Silk

    Murmur Ember Silk

    3
  • Thinking State

    Thinking State

    2
  • Selection Actions

    Selection Actions

    2
  • Filter Table

    Filter Table

    2
  • Murmur Ember Tide

    Murmur Ember Tide

    1