# Flowchart

> Lay out an agent workflow as a sequence of steps joined by connectors.

Source: https://www.honestui.com/docs/ai/flowchart

```tsx
import { Flowchart, FlowStep } from "@/components/ai/flowchart"

export function FlowchartDemo() {
  return (
    <div className="w-full max-w-md min-w-0">
      <Flowchart label="Invoice follow-up workflow">
        <FlowStep
          kind="Trigger"
          title="Invoice becomes overdue"
          caption="Runs once for each invoice, the day after its due date."
        />
        <FlowStep
          kind="Condition"
          title="If the amount is over 1,000"
          caption="Larger invoices go to a person before any email is sent."
        />
        <FlowStep kind="Action" title="Draft a reminder email" caption="Waits for approval." />
      </Flowchart>
    </div>
  )
}

```

## Overview [#overview]

Flowchart shows a workflow from top to bottom: a trigger, a condition, an action. Each step is a card with a kind, a title, and a caption, and any controls you put inside it.

It is a layout, not an editor. The steps are in the order you render them and cannot be dragged. The Beautiful UI original let cards be dragged around a canvas, which has no keyboard equivalent and stores nothing, so it is left out.

## Anatomy [#anatomy]

<Anatomy title="Flowchart">
  <AnatomyItem name="Flowchart" description="The canvas and the ordered list of steps" />

  <AnatomyItem name="FlowStep" description="One step: a card that opens with its kind, and the connector above it" />

  <AnatomyItem name="Children" description="Your controls for the step" />
</Anatomy>

`flowchart` has no registry dependencies.

## Behavior [#behavior]

### Order [#order]

Steps are stacked in the order you render them, with a connector above every step but the first. Each connector ends in an arrowhead pointing at the step it leads to. Flowchart draws a single path; it does not draw branches, so name a condition step for what it checks, such as "If the amount is over 1,000".

### Step content [#step-content]

`title` and `caption` are optional. A step's children are placed in its card under them, for a condition's fields or a summary of what an action will do.

## Accessibility [#accessibility]

The flow is an ordered list named by `label`, so the sequence is available without the connectors, which are decoration. Each step's kind is text.

Flowchart has no keyboard interaction of its own. Controls you place in a step keep theirs.

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;@honestai/flowchart&#x22;]" />
  

  
    
      
        Copy and paste this file into your project.
      

      ### components/ai/flowchart.tsx

```tsx
import * as React from "react"

import { cn } from "@/lib/utils"

export type FlowchartProps = React.ComponentProps<"ol"> & {
  /** Names the workflow for screen readers. */
  label: string
}

/**
 * A workflow as a top-to-bottom sequence of steps joined by connectors. The
 * steps are an ordered list, so the order is available without the lines.
 */
function Flowchart({ label, className, ...props }: FlowchartProps) {
  return (
    <ol
      role="list"
      aria-label={label}
      data-slot="flowchart"
      className={cn(
        "m-0 flex w-full min-w-0 list-none flex-col items-center gap-[var(--hui-space-8)] p-0",
        className
      )}
      {...props}
    />
  )
}

export type FlowStepProps = Omit<React.ComponentProps<"li">, "title"> & {
  /** The step's role in the flow, such as "Trigger", "Condition", or "Action". */
  kind: string
  title?: React.ReactNode
  /** One line under the title. */
  caption?: React.ReactNode
}

/** One step. Put controls for the step, such as a condition's fields, in its children. */
function FlowStep({ kind, title, caption, className, children, ...props }: FlowStepProps) {
  return (
    <li
      data-slot="flow-step"
      className={cn(
        // A connector with an arrowhead is drawn above every step but the
        // first, pointing into the step it leads to. It stays 1px wide: at
        // the surface hairline width it would disappear on the canvas.
        "relative flex w-full max-w-sm min-w-0 flex-col before:absolute before:bottom-full before:left-1/2 before:mb-px before:h-[calc(var(--hui-space-8)-2px)] before:w-px before:-translate-x-1/2 before:bg-[var(--hui-color-border-base-emphasis)] after:absolute after:bottom-full after:left-1/2 after:mb-[3px] after:size-[7px] after:-translate-x-1/2 after:rotate-45 after:border-e after:border-b after:border-[var(--hui-color-border-base-emphasis)] first:before:hidden first:after:hidden forced-colors:before:bg-[CanvasText] forced-colors:after:border-[CanvasText]",
        className
      )}
      {...props}
    >
      <div className="flex min-w-0 flex-col gap-[var(--hui-space-3)] rounded-[var(--hui-radius-4)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-primary)] p-[var(--hui-space-4)] text-[var(--hui-color-foreground-base-primary)] shadow-[var(--hui-shadow-feather)] [font-size:var(--hui-font-size-regular)] [letter-spacing:var(--hui-letter-spacing-regular)] [line-height:var(--hui-line-height-regular)]">
        <div className="flex min-w-0 flex-col gap-[var(--hui-space-1)]">
          <p className="m-0 text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)]">
            {kind}
          </p>
          {title && <p className="m-0 break-words [font-weight:var(--hui-font-weight-medium)]">{title}</p>}
          {caption && (
            <p className="m-0 break-words text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)]">
              {caption}
            </p>
          )}
        </div>
        {children}
      </div>
    </li>
  )
}

export { Flowchart, FlowStep }

```

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
import { Flowchart, FlowStep } from "@/components/ai/flowchart"

<Flowchart label="Invoice follow-up workflow">
  {workflow.steps.map((step) => (
    <FlowStep key={step.id} kind={step.kind} title={step.title} caption={step.summary} />
  ))}
</Flowchart>
```

## Examples [#examples]

### A step with controls [#a-step-with-controls]

The condition step holds a Select. Its value is yours to store.

```tsx
"use client"

import * as React from "react"

import { Flowchart, FlowStep } from "@/components/ai/flowchart"
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/components/honest-ui/ui/select"

const fields = [
  { value: "amount", label: "Amount" },
  { value: "region", label: "Region" },
  { value: "age", label: "Days overdue" },
]

export function FlowchartControlsExample() {
  const [field, setField] = React.useState("amount")

  return (
    <div className="w-full max-w-md min-w-0">
      <Flowchart label="Condition editor">
        <FlowStep kind="Trigger" title="Invoice becomes overdue" />
        <FlowStep kind="Condition" title="Branch on a field">
          <Select
            items={fields}
            value={field}
            onValueChange={(next) => {
              if (typeof next === "string") setField(next)
            }}
          >
            <SelectTrigger size="sm" aria-label="Field to branch on" className="w-full">
              <SelectValue />
            </SelectTrigger>
            <SelectPopup>
              {fields.map((item) => (
                <SelectItem key={item.value} value={item.value}>
                  {item.label}
                </SelectItem>
              ))}
            </SelectPopup>
          </Select>
        </FlowStep>
      </Flowchart>
    </div>
  )
}

```

## API reference [#api-reference]

### Flowchart [#flowchart]

Accepts native ol props beyond those listed. Its children are the steps.

| Prop    | Type   | Default  | Description         |
| ------- | ------ | -------- | ------------------- |
| `label` | string | Required | Names the workflow. |

### FlowStep [#flowstep]

Accepts native li props beyond those listed.

| Prop      | Type      | Default  | Description                  |
| --------- | --------- | -------- | ---------------------------- |
| `kind`    | string    | Required | The step's role in the flow. |
| `title`   | ReactNode | None     | What the step does.          |
| `caption` | ReactNode | None     | One line under the title.    |
