# Pipeline

Where an opportunity is in its pipeline: a circle per stage, the current one open into a pill with its name. Every stage is a button with a rich tooltip saying what it means and how long was spent there. With onStageChange, pressing a stage moves there and an unreached stage previews its colours on hover.

- Beta: ready to use; its API can still change in a minor release.
- Category: Patterns · Workspace & pipeline

```tsx
import { Pipeline } from "@leap-crm/design-system";
```

## Best practices

- Do: Put the ways out of the run, like Lost and Disqualified, in `endings`, so they sit after a divider and the stages read forward.
- Do: Name stages in the region's terms (Enquiry or Lead, Agreement or Engagement) and give each a `description` and `time`, so its tooltip says what the stage means and how long was spent there.
- Do: Pass `onStageChange` only where the lawyer may move the opportunity. Without it the pipeline only shows where things are.
- Do: Set `aria-label`, like “Opportunity stage”, so screen readers know what the stages belong to.
- Don't: Use it for the steps of a setup flow. Use `StepHeader`; Pipeline shows where an opportunity stands.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | Moves from stage to stage; a stage's tooltip shows when focus reaches it. |
| Enter, Space | Choose the focused stage. |
| Escape | Closes the stage's tooltip. |

## Related

- [Step Header](./step-header.md)
- [Progress](./progress.md)
- [Opportunity Card](./opportunity-card.md)
- [Next Action Banner](./next-action-banner.md)

## Examples

What the examples import:

```tsx
import { BadgeX, Ban, BookOpenCheck, Calendar, DoorClosedLocked, FileSignature, MessageCircleMore, ShieldCheck } from "lucide-react";
import { useState } from "react";
import { Pipeline, type PipelineStage } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const stages: PipelineStage[] = [
  {
    id: "enquiry",
    label: "Enquiry",
    icon: <MessageCircleMore />,
    tone: "info",
    description: "New enquiry, awaiting qualification",
    time: "2d 4h",
  },
  {
    id: "qualifying",
    label: "Qualifying",
    icon: <ShieldCheck />,
    tone: "warning",
    description: "Checking conflicts and whether the firm can take the matter",
    time: "1d 2h",
  },
  {
    id: "scheduled",
    label: "Scheduled",
    icon: <Calendar />,
    tone: "success",
    description: "Initial consultation booked",
    time: "21d 6h",
  },
  {
    id: "agreement",
    label: "Agreement",
    icon: <FileSignature />,
    tone: "teal",
    description: "Costs agreement sent for signing",
  },
  {
    id: "active",
    label: "Active",
    icon: <BookOpenCheck />,
    tone: "purple",
    description: "Client engaged the firm, work on the matter has started",
  },
  {
    id: "closed",
    label: "Closed",
    icon: <DoorClosedLocked />,
    tone: "default",
    description: "The matter is finished",
  },
];

const endings: PipelineStage[] = [
  {
    id: "lost",
    label: "Lost",
    icon: <BadgeX />,
    tone: "destructive",
    description: "The client went elsewhere",
  },
  {
    id: "disqualified",
    label: "Disqualified",
    icon: <Ban />,
    tone: "plum",
    description: "The firm can't take the matter",
  },
];

function MovablePipeline() {
  const [current, setCurrent] = useState("scheduled");
  return (
    <Pipeline
      stages={stages}
      endings={endings}
      current={current}
      onStageChange={setCurrent}
    />
  );
}
```

### Movable

Press a stage to move there: the pill closes and the new one opens while the connectors between them fill with colour one after another, or drain back when you move back. Hover an unreached stage to preview its colours; Tab through for the tooltips.

```tsx
<MovablePipeline />
```

### Each stage current

Every stage up to the current one is visited, in its own colour, and the connectors between two visited stages fade from one colour to the next.

```tsx
<div className="flex flex-col gap-4">
  {stages.map(stage => (
    <Pipeline
      key={stage.id}
      stages={stages}
      endings={endings}
      current={stage.id}
    />
  ))}
</div>
```

### Lost and disqualified

An opportunity that leaves the run keeps the stages it reached, and the way out opens into the pill.

```tsx
<div className="flex flex-col gap-4">
  <Pipeline
    stages={stages}
    endings={endings}
    current="lost"
    visited={["enquiry", "qualifying"]}
  />
  <Pipeline
    stages={stages}
    endings={endings}
    current="disqualified"
    visited={["enquiry"]}
  />
</div>
```

### Read only

Without onStageChange the stages only show where things are: no hover preview, no Click to change hint.

```tsx
<Pipeline stages={stages} endings={endings} current="agreement" />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `stages` (required) | `unknown` |  | The run of stages, joined by connectors, in order. |
| `endings` | `unknown` | `[]` | Ways out of the run, like Lost and Disqualified: after a 16 px gap, split by a divider. |
| `current` | `string \| null` | `null` | The stage it's at now. It opens into a pill with its name. |
| `visited` | `unknown` |  | Stages reached. By default every stage up to the current one. |
| `onStageChange` | `(id: string) => void` |  | Makes every other stage pressable, to move there. Without it the pipeline only shows where things are. |
| `aria-label` | `string` | `"Pipeline"` | Names the pipeline for screen readers. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
