# Flowchart

An agent workflow drawn as a trigger and its conditions on a canvas.

An agent workflow on a dotted canvas: a trigger node joined by a connector to an If / Else node. The trigger card opens a menu of triggers; each condition row reads as a sentence whose property and value are ghost sm selects. Rows reorder and delete through the row handle's menu (Move up, Move down, Remove), so reordering never needs a drag. Adding a condition reveals the new row once; nothing else animates. Composes select, menu and button; their behaviour comes from Zag in every target.

Kind: block · Category: Agent · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add flowchart
```

It writes the folder `flowchart/` into the project's ui folder (`index.ts`, `flowchart.tsx`, `Flowchart.vue`, `Flowchart.svelte`, `flowchart.recipe.ts`), and what it is built from: [Select](/components/select.md), [Menu](/components/menu.md), [Button](/components/button.md), [Tooltip](/components/tooltip.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Flowchart } from "@/components/ui/flowchart";
```

```vue
import { Flowchart } from "@/components/ui/flowchart";
```

```svelte
import { Flowchart } from "$lib/components/ui/flowchart";
```

## Parts

In the DOM the root carries `data-slot="flowchart"` and each part `data-slot="flowchart-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `flowchart` |  | The dotted canvas |
| `node` | `div` | `flowchart-node` | repeats | Kind pill above a card; its kind (trigger or condition) is a recipe variant |
| `kind` | `span` | `flowchart-kind` |  | Kind pill, tinted by the kind variant |
| `card` | `button \| div` | `flowchart-card` |  | Trigger: the button that is its Menu trigger (data-state=open\|closed, marked data-menu="trigger"). Condition: role=group, labelled Conditions |
| `icon` | `span` | `flowchart-icon` |  | Tinted 36px icon box of the trigger card |
| `text` | `span` | `flowchart-text` |  |  |
| `title` | `span` | `flowchart-title` |  | Trigger label; wraps, never truncates |
| `caption` | `span` | `flowchart-caption` | optional |  |
| `caret` | `span` | `flowchart-caret` |  | Says the card opens a menu; does not rotate |
| `edge` | `div` | `flowchart-edge` |  | Connector between the nodes, drawn in CSS from color.line-strong; aria-hidden |
| `conditions` | `ol` | `flowchart-conditions` |  |  |
| `row` | `li` | `flowchart-row` | repeats | Handle, joiner, clause. data-entering (set and cleared by the shared helper) while a row the pointer added is revealed; data-collapsed for its first frame (0fr) |
| `handle` | `button` | `flowchart-handle` |  | Grip; the trigger of the row Menu (Move up, Move down, Remove; marked data-menu="trigger") and of our Tooltip with the same text. aria-label Condition N options |
| `joiner` | `span` | `flowchart-joiner` |  | 'If' on the first row, 'and' after |
| `clause` | `span` | `flowchart-clause` |  | Source, property select, operator, value select; wraps under itself |
| `source` | `span` | `flowchart-source` |  | The record the condition reads (e.g. order); title carries the full name |
| `source-icon` | `span` | `flowchart-source-icon` |  |  |
| `source-text` | `span` | `flowchart-source-text` |  | Truncates; the full name is the source's title |
| `operator` | `span` | `flowchart-operator` |  |  |
| `add` | `button` | `flowchart-add` |  | The real Button (ghost sm) Add condition, marked data-flowchart="add" |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `triggers` | `{ value: string; label: string; caption?: string }[]` |  | What can start the workflow. |
| `trigger` | `string` |  | Bindable (React: `defaultTrigger` and `onTriggerChange`; Vue: `v-model:trigger`; Svelte: `bind:trigger`). Value of the chosen trigger. |
| `source` | `string` | `"record"` | Name of the record the conditions read. |
| `properties` | `{ value: string; label: string }[]` |  | Properties a condition can test. |
| `choices` | `object` |  | Values per property: { [property]: { value, label, meta? }[] }. |
| `conditions` | `{ id: string; property: string; value: string }[]` |  | Bindable (React: `defaultConditions` and `onConditionsChange`; Vue: `v-model:conditions`; Svelte: `bind:conditions`). The If / Else rows in order. |
| `labels` | `object` |  | The fixed strings, partial: { trigger, condition, conditions, if, and, is, addCondition, rowOptions, rowProperty, rowValue, moveUp, moveDown, remove }. {n} in rowOptions / rowProperty / rowValue is the row's number. |
| `kind` | `"trigger" \| "condition"` |  | Set per node; tints the kind pill and picks the card. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `triggerChange` | (value: string) |
| `conditionsChange` | (conditions: { id, property, value }[]) after a value or property change, an add, a move or a removal |

## States

`hover`, `press`, `focus-visible`, `open`, `disabled`

## Keyboard and accessibility

Role: group of conditions (ordered list) under a trigger menu button.

Keyboard:

- Tab order: trigger card, then per row the handle, the property select and the value select, then Add condition
- Trigger card: Enter / Space / ArrowDown open the trigger menu (menu contract); picking a trigger updates the card and closes the menu; focus returns to the card
- Row handle: Enter / Space / ArrowDown open Move up / Move down / Remove; after a move focus follows the row's handle, after a removal it lands on the next row's handle (or Add condition)
- Property and value: the select contract; a new property resets the value to that property's first choice
- Add condition: Enter / Space add a row and move focus to its property select; from the keyboard the row appears without the reveal

Notes:

- Reordering never needs a drag: the handle's menu moves the row.
- Every select and handle is labelled with its row number ('Condition 2 value').
- The connector is decoration (aria-hidden); order is carried by the DOM.

## Motion

- added row: it opens its room (its one grid row 0fr → 1fr over duration.reveal, easing.out-strong, clipped while it opens, so the card grows with it instead of snapping) while it fades up (fndn-fade-up over duration.enter, easing.out-strong), once (data-entering is removed when it ends, so a reorder cannot replay it); keyboard adds are instant
- nothing else animates: no node drag, no connector draw, no caret rotation; reorders and removals are instant
- trigger card and handle: colour / shadow feedback at duration.fast and duration.base; the selects, menus and button keep their own motion

## Tokens

`color.page`, `color.surface`, `color.hover`, `color.hover-2`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.line-strong`, `color.accent`, `color.orange`, `shadow.hairline`, `shadow.card`, `shadow.raised`, `shadow.btn`, `radius.chip`, `radius.control`, `radius.card`, `radius.window`, `text.xs`, `text.sm`, `duration.fast`, `duration.base`, `duration.enter`, `easing.out-strong`

## Dependencies

- [Select](/components/select.md)
- [Menu](/components/menu.md)
- [Button](/components/button.md)
- [Tooltip](/components/tooltip.md)

## Examples

### Onboard new Business workspaces

React · `default.tsx`

```tsx
import type { ComponentProps } from "react";
import { Flowchart } from "@/components/ui/flowchart";

type Props = ComponentProps<typeof Flowchart>;

const triggers: Props["triggers"] = [
  {
    value: "workspace-created",
    label: "Workspace created",
    caption: "Runs when a customer signs up",
  },
  {
    value: "trial-ending",
    label: "Trial ends in 3 days",
    caption: "Runs three days before a trial ends",
  },
  {
    value: "first-booking",
    label: "First booking made",
    caption: "Runs on a workspace's first booking",
  },
];

const properties: Props["properties"] = [
  { value: "plan", label: "plan" },
  { value: "industry", label: "industry" },
  { value: "team-size", label: "team size" },
  { value: "source", label: "signup source" },
];

const choices: Props["choices"] = {
  plan: [
    { value: "starter", label: "Starter", meta: "$19 / seat" },
    { value: "team", label: "Team", meta: "$49 / seat" },
    { value: "business", label: "Business", meta: "$99 / seat" },
    { value: "enterprise", label: "Enterprise", meta: "Custom" },
  ],
  industry: [
    { value: "dental", label: "Dental" },
    { value: "healthcare", label: "Healthcare" },
    { value: "logistics", label: "Logistics" },
    { value: "real-estate", label: "Real estate" },
  ],
  "team-size": [
    { value: "1-5", label: "1–5 people" },
    { value: "6-25", label: "6–25 people" },
    { value: "26-100", label: "26–100 people" },
    { value: "100+", label: "More than 100" },
  ],
  source: [
    { value: "search", label: "Search" },
    { value: "referral", label: "Customer referral" },
    { value: "partner", label: "Partner: Dental Association of Oregon" },
  ],
};

export default function OnboardBusinessWorkspaces() {
  return (
    <Flowchart
      triggers={triggers}
      defaultTrigger="workspace-created"
      source="workspace"
      properties={properties}
      choices={choices}
      defaultConditions={[{ id: "c1", property: "plan", value: "business" }]}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Flowchart } from "@/components/ui/flowchart";

const triggers = [
  {
    value: "workspace-created",
    label: "Workspace created",
    caption: "Runs when a customer signs up",
  },
  {
    value: "trial-ending",
    label: "Trial ends in 3 days",
    caption: "Runs three days before a trial ends",
  },
  {
    value: "first-booking",
    label: "First booking made",
    caption: "Runs on a workspace's first booking",
  },
];

const properties = [
  { value: "plan", label: "plan" },
  { value: "industry", label: "industry" },
  { value: "team-size", label: "team size" },
  { value: "source", label: "signup source" },
];

const choices = {
  plan: [
    { value: "starter", label: "Starter", meta: "$19 / seat" },
    { value: "team", label: "Team", meta: "$49 / seat" },
    { value: "business", label: "Business", meta: "$99 / seat" },
    { value: "enterprise", label: "Enterprise", meta: "Custom" },
  ],
  industry: [
    { value: "dental", label: "Dental" },
    { value: "healthcare", label: "Healthcare" },
    { value: "logistics", label: "Logistics" },
    { value: "real-estate", label: "Real estate" },
  ],
  "team-size": [
    { value: "1-5", label: "1–5 people" },
    { value: "6-25", label: "6–25 people" },
    { value: "26-100", label: "26–100 people" },
    { value: "100+", label: "More than 100" },
  ],
  source: [
    { value: "search", label: "Search" },
    { value: "referral", label: "Customer referral" },
    { value: "partner", label: "Partner: Dental Association of Oregon" },
  ],
};

const trigger = ref("workspace-created");

const conditions = ref([{ id: "c1", property: "plan", value: "business" }]);
</script>

<template>
  <Flowchart
    :triggers="triggers"
    v-model:trigger="trigger"
    source="workspace"
    :properties="properties"
    :choices="choices"
    v-model:conditions="conditions"
    style="width: 420px"
  />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { Flowchart } from "$lib/components/ui/flowchart";

  const triggers = [
    {
      value: "workspace-created",
      label: "Workspace created",
      caption: "Runs when a customer signs up",
    },
    {
      value: "trial-ending",
      label: "Trial ends in 3 days",
      caption: "Runs three days before a trial ends",
    },
    {
      value: "first-booking",
      label: "First booking made",
      caption: "Runs on a workspace's first booking",
    },
  ];

  const properties = [
    { value: "plan", label: "plan" },
    { value: "industry", label: "industry" },
    { value: "team-size", label: "team size" },
    { value: "source", label: "signup source" },
  ];

  const choices = {
    plan: [
      { value: "starter", label: "Starter", meta: "$19 / seat" },
      { value: "team", label: "Team", meta: "$49 / seat" },
      { value: "business", label: "Business", meta: "$99 / seat" },
      { value: "enterprise", label: "Enterprise", meta: "Custom" },
    ],
    industry: [
      { value: "dental", label: "Dental" },
      { value: "healthcare", label: "Healthcare" },
      { value: "logistics", label: "Logistics" },
      { value: "real-estate", label: "Real estate" },
    ],
    "team-size": [
      { value: "1-5", label: "1–5 people" },
      { value: "6-25", label: "6–25 people" },
      { value: "26-100", label: "26–100 people" },
      { value: "100+", label: "More than 100" },
    ],
    source: [
      { value: "search", label: "Search" },
      { value: "referral", label: "Customer referral" },
      { value: "partner", label: "Partner: Dental Association of Oregon" },
    ],
  };

  let trigger = $state("workspace-created");

  let conditions = $state([{ id: "c1", property: "plan", value: "business" }]);
</script>

<Flowchart
  triggers={triggers}
  bind:trigger={trigger}
  source="workspace"
  properties={properties}
  choices={choices}
  bind:conditions={conditions}
  style="width: 420px"
/>
```

### Send partner dental groups to guided setup

React · `guided-setup.tsx`

```tsx
import type { ComponentProps } from "react";
import { Flowchart } from "@/components/ui/flowchart";

type Props = ComponentProps<typeof Flowchart>;

const triggers: Props["triggers"] = [
  {
    value: "workspace-created",
    label: "Workspace created",
    caption: "Runs when a customer signs up",
  },
  {
    value: "trial-ending",
    label: "Trial ends in 3 days",
    caption: "Runs three days before a trial ends",
  },
  {
    value: "first-booking",
    label: "First booking made",
    caption: "Runs on a workspace's first booking",
  },
];

const properties: Props["properties"] = [
  { value: "plan", label: "plan" },
  { value: "industry", label: "industry" },
  { value: "team-size", label: "team size" },
  { value: "source", label: "signup source" },
];

const choices: Props["choices"] = {
  plan: [
    { value: "starter", label: "Starter", meta: "$19 / seat" },
    { value: "team", label: "Team", meta: "$49 / seat" },
    { value: "business", label: "Business", meta: "$99 / seat" },
    { value: "enterprise", label: "Enterprise", meta: "Custom" },
  ],
  industry: [
    { value: "dental", label: "Dental" },
    { value: "healthcare", label: "Healthcare" },
    { value: "logistics", label: "Logistics" },
    { value: "real-estate", label: "Real estate" },
  ],
  "team-size": [
    { value: "1-5", label: "1–5 people" },
    { value: "6-25", label: "6–25 people" },
    { value: "26-100", label: "26–100 people" },
    { value: "100+", label: "More than 100" },
  ],
  source: [
    { value: "search", label: "Search" },
    { value: "referral", label: "Customer referral" },
    { value: "partner", label: "Partner: Dental Association of Oregon" },
  ],
};

const conditions: Props["defaultConditions"] = [
  { id: "c1", property: "plan", value: "business" },
  { id: "c2", property: "industry", value: "dental" },
  { id: "c3", property: "team-size", value: "26-100" },
  { id: "c4", property: "source", value: "partner" },
];

export default function GuidedSetupForDentalGroups() {
  return (
    <Flowchart
      triggers={triggers}
      defaultTrigger="workspace-created"
      source="workspace"
      properties={properties}
      choices={choices}
      defaultConditions={conditions}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `guided-setup.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Flowchart } from "@/components/ui/flowchart";

const triggers = [
  {
    value: "workspace-created",
    label: "Workspace created",
    caption: "Runs when a customer signs up",
  },
  {
    value: "trial-ending",
    label: "Trial ends in 3 days",
    caption: "Runs three days before a trial ends",
  },
  {
    value: "first-booking",
    label: "First booking made",
    caption: "Runs on a workspace's first booking",
  },
];

const properties = [
  { value: "plan", label: "plan" },
  { value: "industry", label: "industry" },
  { value: "team-size", label: "team size" },
  { value: "source", label: "signup source" },
];

const choices = {
  plan: [
    { value: "starter", label: "Starter", meta: "$19 / seat" },
    { value: "team", label: "Team", meta: "$49 / seat" },
    { value: "business", label: "Business", meta: "$99 / seat" },
    { value: "enterprise", label: "Enterprise", meta: "Custom" },
  ],
  industry: [
    { value: "dental", label: "Dental" },
    { value: "healthcare", label: "Healthcare" },
    { value: "logistics", label: "Logistics" },
    { value: "real-estate", label: "Real estate" },
  ],
  "team-size": [
    { value: "1-5", label: "1–5 people" },
    { value: "6-25", label: "6–25 people" },
    { value: "26-100", label: "26–100 people" },
    { value: "100+", label: "More than 100" },
  ],
  source: [
    { value: "search", label: "Search" },
    { value: "referral", label: "Customer referral" },
    { value: "partner", label: "Partner: Dental Association of Oregon" },
  ],
};

const trigger = ref("workspace-created");

const conditions = ref([
  { id: "c1", property: "plan", value: "business" },
  { id: "c2", property: "industry", value: "dental" },
  { id: "c3", property: "team-size", value: "26-100" },
  { id: "c4", property: "source", value: "partner" },
]);
</script>

<template>
  <Flowchart
    :triggers="triggers"
    v-model:trigger="trigger"
    source="workspace"
    :properties="properties"
    :choices="choices"
    v-model:conditions="conditions"
    style="width: 420px"
  />
</template>
```

Svelte · `guided-setup.svelte`

```svelte
<script lang="ts">
  import { Flowchart } from "$lib/components/ui/flowchart";

  const triggers = [
    {
      value: "workspace-created",
      label: "Workspace created",
      caption: "Runs when a customer signs up",
    },
    {
      value: "trial-ending",
      label: "Trial ends in 3 days",
      caption: "Runs three days before a trial ends",
    },
    {
      value: "first-booking",
      label: "First booking made",
      caption: "Runs on a workspace's first booking",
    },
  ];

  const properties = [
    { value: "plan", label: "plan" },
    { value: "industry", label: "industry" },
    { value: "team-size", label: "team size" },
    { value: "source", label: "signup source" },
  ];

  const choices = {
    plan: [
      { value: "starter", label: "Starter", meta: "$19 / seat" },
      { value: "team", label: "Team", meta: "$49 / seat" },
      { value: "business", label: "Business", meta: "$99 / seat" },
      { value: "enterprise", label: "Enterprise", meta: "Custom" },
    ],
    industry: [
      { value: "dental", label: "Dental" },
      { value: "healthcare", label: "Healthcare" },
      { value: "logistics", label: "Logistics" },
      { value: "real-estate", label: "Real estate" },
    ],
    "team-size": [
      { value: "1-5", label: "1–5 people" },
      { value: "6-25", label: "6–25 people" },
      { value: "26-100", label: "26–100 people" },
      { value: "100+", label: "More than 100" },
    ],
    source: [
      { value: "search", label: "Search" },
      { value: "referral", label: "Customer referral" },
      { value: "partner", label: "Partner: Dental Association of Oregon" },
    ],
  };

  let trigger = $state("workspace-created");

  let conditions = $state([
    { id: "c1", property: "plan", value: "business" },
    { id: "c2", property: "industry", value: "dental" },
    { id: "c3", property: "team-size", value: "26-100" },
    { id: "c4", property: "source", value: "partner" },
  ]);
</script>

<Flowchart
  triggers={triggers}
  bind:trigger={trigger}
  source="workspace"
  properties={properties}
  choices={choices}
  bind:conditions={conditions}
  style="width: 420px"
/>
```

### Remind every trial before it ends

React · `no-conditions.tsx`

```tsx
import type { ComponentProps } from "react";
import { Flowchart } from "@/components/ui/flowchart";

type Props = ComponentProps<typeof Flowchart>;

const triggers: Props["triggers"] = [
  {
    value: "workspace-created",
    label: "Workspace created",
    caption: "Runs when a customer signs up",
  },
  {
    value: "trial-ending",
    label: "Trial ends in 3 days",
    caption: "Runs three days before a trial ends",
  },
  {
    value: "first-booking",
    label: "First booking made",
    caption: "Runs on a workspace's first booking",
  },
];

const properties: Props["properties"] = [
  { value: "plan", label: "plan" },
  { value: "industry", label: "industry" },
  { value: "team-size", label: "team size" },
  { value: "source", label: "signup source" },
];

const choices: Props["choices"] = {
  plan: [
    { value: "starter", label: "Starter", meta: "$19 / seat" },
    { value: "team", label: "Team", meta: "$49 / seat" },
    { value: "business", label: "Business", meta: "$99 / seat" },
    { value: "enterprise", label: "Enterprise", meta: "Custom" },
  ],
  industry: [
    { value: "dental", label: "Dental" },
    { value: "healthcare", label: "Healthcare" },
    { value: "logistics", label: "Logistics" },
    { value: "real-estate", label: "Real estate" },
  ],
  "team-size": [
    { value: "1-5", label: "1–5 people" },
    { value: "6-25", label: "6–25 people" },
    { value: "26-100", label: "26–100 people" },
    { value: "100+", label: "More than 100" },
  ],
  source: [
    { value: "search", label: "Search" },
    { value: "referral", label: "Customer referral" },
    { value: "partner", label: "Partner: Dental Association of Oregon" },
  ],
};

export default function EveryTrialGetsAReminder() {
  return (
    <Flowchart
      triggers={triggers}
      defaultTrigger="trial-ending"
      source="workspace"
      properties={properties}
      choices={choices}
      defaultConditions={[]}
      style={{ width: 420 }}
    />
  );
}
```

Vue · `no-conditions.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Flowchart } from "@/components/ui/flowchart";

const triggers = [
  {
    value: "workspace-created",
    label: "Workspace created",
    caption: "Runs when a customer signs up",
  },
  {
    value: "trial-ending",
    label: "Trial ends in 3 days",
    caption: "Runs three days before a trial ends",
  },
  {
    value: "first-booking",
    label: "First booking made",
    caption: "Runs on a workspace's first booking",
  },
];

const properties = [
  { value: "plan", label: "plan" },
  { value: "industry", label: "industry" },
  { value: "team-size", label: "team size" },
  { value: "source", label: "signup source" },
];

const choices = {
  plan: [
    { value: "starter", label: "Starter", meta: "$19 / seat" },
    { value: "team", label: "Team", meta: "$49 / seat" },
    { value: "business", label: "Business", meta: "$99 / seat" },
    { value: "enterprise", label: "Enterprise", meta: "Custom" },
  ],
  industry: [
    { value: "dental", label: "Dental" },
    { value: "healthcare", label: "Healthcare" },
    { value: "logistics", label: "Logistics" },
    { value: "real-estate", label: "Real estate" },
  ],
  "team-size": [
    { value: "1-5", label: "1–5 people" },
    { value: "6-25", label: "6–25 people" },
    { value: "26-100", label: "26–100 people" },
    { value: "100+", label: "More than 100" },
  ],
  source: [
    { value: "search", label: "Search" },
    { value: "referral", label: "Customer referral" },
    { value: "partner", label: "Partner: Dental Association of Oregon" },
  ],
};

const trigger = ref("trial-ending");

const conditions = ref([]);
</script>

<template>
  <Flowchart
    :triggers="triggers"
    v-model:trigger="trigger"
    source="workspace"
    :properties="properties"
    :choices="choices"
    v-model:conditions="conditions"
    style="width: 420px"
  />
</template>
```

Svelte · `no-conditions.svelte`

```svelte
<script lang="ts">
  import { Flowchart } from "$lib/components/ui/flowchart";

  const triggers = [
    {
      value: "workspace-created",
      label: "Workspace created",
      caption: "Runs when a customer signs up",
    },
    {
      value: "trial-ending",
      label: "Trial ends in 3 days",
      caption: "Runs three days before a trial ends",
    },
    {
      value: "first-booking",
      label: "First booking made",
      caption: "Runs on a workspace's first booking",
    },
  ];

  const properties = [
    { value: "plan", label: "plan" },
    { value: "industry", label: "industry" },
    { value: "team-size", label: "team size" },
    { value: "source", label: "signup source" },
  ];

  const choices = {
    plan: [
      { value: "starter", label: "Starter", meta: "$19 / seat" },
      { value: "team", label: "Team", meta: "$49 / seat" },
      { value: "business", label: "Business", meta: "$99 / seat" },
      { value: "enterprise", label: "Enterprise", meta: "Custom" },
    ],
    industry: [
      { value: "dental", label: "Dental" },
      { value: "healthcare", label: "Healthcare" },
      { value: "logistics", label: "Logistics" },
      { value: "real-estate", label: "Real estate" },
    ],
    "team-size": [
      { value: "1-5", label: "1–5 people" },
      { value: "6-25", label: "6–25 people" },
      { value: "26-100", label: "26–100 people" },
      { value: "100+", label: "More than 100" },
    ],
    source: [
      { value: "search", label: "Search" },
      { value: "referral", label: "Customer referral" },
      { value: "partner", label: "Partner: Dental Association of Oregon" },
    ],
  };

  let trigger = $state("trial-ending");

  let conditions = $state([]);
</script>

<Flowchart
  triggers={triggers}
  bind:trigger={trigger}
  source="workspace"
  properties={properties}
  choices={choices}
  bind:conditions={conditions}
  style="width: 420px"
/>
```

## Recipe

`flowchart.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* flowchart — a trigger node and an If / Else node on a dotted canvas, joined by a connector.
 * Each node is a kind pill above a card. The trigger card is a Menu's own trigger; condition rows
 * hold a Menu handle (inside a Tooltip) and two sm ghost Selects, and the card ends with a ghost
 * sm Add Button. Their popups live in portals and keep their own styling. The nodes stack above
 * the connector (z-index 1); the portaled popups sit on their own layers (--fndn-z-popup), so they
 * paint above the nodes without the canvas isolating them.
 *
 * Nothing here animates except the one-shot reveal of a row the pointer added (data-entering and
 * data-collapsed, set and cleared by the shared helper flowchart.logic.ts): it opens its room and fades up. The trigger card and the handles are Menu
 * triggers (marked data-menu="trigger"); the Add Button is marked data-flowchart="add".
 * The menu engine stamps dir="ltr" on its triggers; the trigger card and the handles follow the
 * page's direction instead, so they mirror right-to-left.
 *
 * The Add button keeps the button's own ink. */

export const flowchart = tv({
  slots: {
    base: [
      "relative flex flex-col items-center w-full min-w-0 py-6 px-4 rounded-card shadow-hairline text-ink",
      "bg-page bg-[image:radial-gradient(var(--fndn-line-strong)_1px,transparent_1.25px)] bg-size-[22px_22px] bg-center",
    ],
    /* the kind pill above the card; the Menu around the trigger card fills the node */
    node: "relative z-1 flex flex-col items-start gap-1.5 w-full min-w-0 [&>[data-slot=menu]]:flex [&>[data-slot=menu]]:w-full",
    kind: "inline-flex items-center h-[22px] px-2 rounded-chip text-[11.5px] font-medium leading-none whitespace-nowrap",
    card: "w-full min-w-0 rounded-window bg-surface shadow-card",
    icon: [
      "flex shrink-0 items-center justify-center size-9 rounded-control text-accent text-[16px]",
      "bg-[color-mix(in_srgb,var(--fndn-accent)_12%,var(--fndn-surface))] shadow-[0_0_0_1px_color-mix(in_srgb,var(--fndn-accent)_20%,var(--fndn-surface))]",
    ],
    text: "flex flex-1 flex-col gap-0.5 min-w-0",
    /* wraps rather than truncates: trigger names often carry numbers */
    title: "wrap-anywhere text-sm font-semibold leading-[1.25]",
    caption: "text-xs leading-[1.4] text-ink-2 wrap-anywhere",
    caret: "flex shrink-0 text-[12px] text-ink-3",
    /* connector: runs from the trigger card's bottom to the condition card's top, behind its pill */
    edge: "relative z-0 shrink-0 w-[1.25px] h-16 -mb-7 bg-line-strong",
    conditions: "flex flex-col self-stretch gap-1 min-w-0 m-0 p-0 list-none empty:hidden",
    /* handle · joiner · clause; a clause that wraps continues under itself, not under the handle */
    /* a row the pointer added makes its room as it fades up, so the card grows with it instead of
     * snapping: flowchart.logic.ts sets data-entering and, for one frame, data-collapsed (0fr: the minimum is 0, so the 28px handle cannot hold it open), then the
     * one row track opens to 1fr over duration.reveal (the collapsible's reveal), clipped meanwhile.
     * fndn-check-ok: grid-template-rows is the sanctioned way to open room; the track is the row's own */
    row: [
      "grid grid-cols-[auto_28px_minmax(0,1fr)] grid-rows-[minmax(0,1fr)] [align-items:start] gap-x-1 min-w-0",
      "data-entering:animate-fade-up data-entering:overflow-hidden data-entering:motion-size-reveal",
      "data-collapsed:grid-rows-[minmax(0,0fr)]",
    ],
    /* a narrow grip still gets a 30px-wide target */
    handle: [
      "relative flex shrink-0 items-center justify-center w-[18px] h-7 rounded-chip text-ink-3 text-[14px] [direction:inherit]",
      "after:content-[''] after:absolute after:inset-y-0 after:inset-x-[-6px]",
      "motion-colors-fast hover:bg-hover hover:text-ink-2 active:bg-hover-2 active:text-ink data-[state=open]:bg-hover-2 data-[state=open]:text-ink",
    ],
    joiner: "flex items-center h-7 text-dense text-ink-2 whitespace-nowrap",
    operator: "flex items-center h-7 text-dense text-ink-2 whitespace-nowrap",
    clause: "flex flex-wrap items-center gap-x-1 gap-y-0 min-w-0",
    source: [
      "inline-flex shrink-0 items-center gap-1 max-w-full h-6 px-1.5 rounded-chip bg-surface shadow-btn",
      "text-xs font-medium leading-none whitespace-nowrap",
    ],
    sourceIcon: "flex shrink-0 text-[12px] text-ink-2",
    sourceText: "min-w-0 overflow-hidden text-ellipsis",
    /* the Button */
    add: "ms-[22px]",
  },
  variants: {
    kind: {
      trigger: {
        node: "max-w-[300px]",
        kind: "bg-[color-mix(in_srgb,var(--fndn-accent)_14%,var(--fndn-page))] text-[color-mix(in_srgb,var(--fndn-accent)_80%,var(--fndn-ink))]",
        card: [
          "flex shrink-0 items-center gap-2.5 p-2.5 text-start [direction:inherit]",
          "motion-shadow-base motion-colors-fast hover:shadow-raised active:bg-hover-2",
          "data-[state=open]:shadow-[0_0_0_1.5px_var(--fndn-accent),var(--fndn-shadow-card)]",
        ],
      },
      condition: {
        node: "max-w-[356px]",
        kind: "bg-[color-mix(in_srgb,var(--fndn-orange)_14%,var(--fndn-page))] text-[color-mix(in_srgb,var(--fndn-orange)_80%,var(--fndn-ink))]",
        card: "flex flex-col items-start gap-1 py-2 ps-2 pe-3",
      },
    },
  },
});

export type FlowchartRecipeProps = VariantProps<typeof flowchart>;
```
