# Task progress

> For work that takes minutes: phases, a live timer, stats, cancel, and the result when it’s done.

Deep research, long builds and batch jobs need more than a spinner. Phases fill left to right with the current one sweeping, the timer and stats roll as they change, and a line tells people they can leave. One status line names the phase and morphs from "Searching" to "Reading" to "Finished in 4m 12s" as a check draws itself. The button is one surface too: Cancel grows into "Open report" when it’s done, or turns into Retry when it fails.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/task-progress.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/task-progress
- Registry item (source): https://hairlineui.com/r/task-progress.json

## Usage

```tsx
import { TaskProgress } from "@/components/task-progress";

<TaskProgress
  title="Researching waffle cone suppliers"
  status="running"
  phases={["Searching", "Reading", "Writing"]}
  phase={1}
  startedAt={startedAt}
  stats={[{ label: "sources", value: 42 }, { label: "read", value: 12 }]}
  message="You can close this tab. We’ll keep going."
  onCancel={stop}
/>
```

## With the AI SDK

```tsx
// Server (inside createUIMessageStream): report progress as a data part with a fixed id,
// so each write updates the same card instead of adding a new one.
writer.write({ type: "data-research", id: "research", data: { phase: 1, sources: 42, read: 12 } });

// Client
import { useChat } from "@ai-sdk/react";
import type { UIMessage } from "ai";
import { TaskProgress } from "@/components/task-progress";

function Research({ message, startedAt }: { message: UIMessage; startedAt: number }) {
  const { status, stop } = useChat();
  const part = message.parts.find((p) => p.type === "data-research");
  if (!part) return null;
  const { phase, sources, read } = part.data as { phase: number; sources: number; read: number };
  return (
    <TaskProgress
      title="Deep research"
      status={status === "streaming" ? "running" : status === "error" ? "error" : "done"}
      phases={["Searching", "Reading", "Writing"]}
      phase={phase}
      startedAt={startedAt}
      stats={[{ label: "sources", value: sources }, { label: "read", value: read }]}
      onCancel={stop}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` | – | What the task is doing. |
| `status` | `"running" \| "done" \| "error" \| "cancelled"` | – | Where the task is. |
| `phases / phase` | `string[] / number` | – | The stages and the index of the current one. |
| `startedAt / duration` | `number` | – | Start time for the live timer, or the total once known (ms). |
| `stats` | `{ label; value }[]` | – | Live numbers, e.g. sources found and read. |
| `message` | `string` | – | A line while running, e.g. that it’s safe to leave. |
| `onCancel / onOpen / openLabel` | `() => void / () => void / string` | `"Open result"` | Cancel while running; open the result when done. |
| `errorText / onRetry` | `string / () => void` | – | Why it failed, and a Retry. |

## States

- **running**: Finished phases fill from the left (620ms); the current one sweeps. The status line names the phase under a sweep of light and morphs as it moves on. Timer and numeric stats roll; the message and Cancel sit below.
- **done**: The last bar fills, the message folds away, a check draws itself and the line morphs to "Finished in 4m 12s". Cancel turns blue and grows into "Open report →".
- **error**: The failed phase fills red, the reason opens in, an alert swaps in and the line reads "Stopped at reading". The button morphs into Retry.
- **cancelled**: "Cancelled after 1m 02s"; the button folds away and focus stays on the card.

## What it handles

Deep research, long builds and batch jobs need more than a spinner. This shows where the work is, how long it has taken and what happens when it finishes or fails.

- **Phases that fill**: Finished phases fill from the left and the current one sweeps.
- **A timer and live numbers**: The elapsed time and your stats, such as sources found and read, roll as they change.
- **One status line**: It names the phase and morphs from “Searching” to “Reading” to “Finished in 4m 12s” as a check draws.
- **One button for every state**: Cancel while running becomes “Open report” when done, or Retry when it fails.
- **Failures say where**: The failed phase fills red and the line reads “Stopped at reading”, with the reason opening in.
- **Safe to leave**: A line can tell people they may close the tab. The current phase and the outcome are announced politely.

## Replaces

a spinner, a phase stepper, an elapsed timer, live stats, Cancel and Retry buttons, a result button

## Where it fits

- **Deep research agents**: Work that takes minutes, with a report at the end.
- **Builds, exports and batch jobs**: A job with named stages and a time estimate people can see.
- **Imports and migrations**: A long move of data that people can leave and come back to.
- **Report and media generation**: AI-generated documents, images or video that take a while.

## Notes

- The current phase and the outcome are announced politely; the bars, rolling digits and status line are decorative copies of that text.
- The timer ticks once a second and stops when the task settles or unmounts. Stats that are numbers roll; anything else renders as you pass it.
- Installs Number roll and Text morph. With reduced motion nothing sweeps, fills or rolls; states change in place.

License: MIT (https://hairlineui.com/license#components)
