# Live activity

> One pill for whatever is happening now: it updates in place, tap it and it grows into a panel, done blurs into a check.

Background work in web apps usually means a toast that vanishes or a spinner nobody notices. This is one pill for whatever is happening now, the way a phone shows a call or a timer at the top. It opens out of nothing when work starts; while it runs, its label morphs letter by letter ("Planning the change" becomes "Editing 3 files"), its ring fills and its figure rolls; a different activity blurs in over the last while the pill reshapes to fit it. Tap it and the pill itself grows into a panel, size and corners easing together: a title, a progress bar, steps that tick themselves off, and actions. When it’s done the spinner blurs into a check that draws itself, and once you clear it the pill folds away.

## Install

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

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

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

## Usage

```tsx
import { LiveActivity } from "@/components/live-activity";

<LiveActivity
  activity={{
    id: "export",
    label: "Editing 3 files",
    progress: 0.52,
    steps: [{ label: "Plan the change", done: true }, { label: "Edit 3 files" }, { label: "Run the tests" }],
  }}
/>
```

## For an agent running in the background

Map the run’s status onto one activity; clear it a few seconds after it finishes.

```tsx
"use client";
import { useEffect, useState } from "react";
import { LiveActivity, type LiveActivityData } from "@/components/live-activity";
import { useRun } from "@/lib/runs";

export function RunPill({ runId }: { runId: string }) {
  const run = useRun(runId); // { phase, progress, steps, filesChanged, status }
  const [cleared, setCleared] = useState(false);
  useEffect(() => {
    if (run.status !== "done") return;
    const t = setTimeout(() => setCleared(true), 4000);
    return () => clearTimeout(t);
  }, [run.status]);

  const activity: LiveActivityData | null = cleared
    ? null
    : {
        id: runId,
        label: run.status === "done" ? `${run.filesChanged} files changed` : run.phase,
        status: run.status,
        progress: run.progress,
        steps: run.steps,
        actions: run.status === "done" ? [{ label: "View changes", primary: true, onClick: () => open(run.diffUrl) }] : undefined,
      };
  return <LiveActivity activity={activity} className="fixed left-1/2 top-3 -translate-x-1/2" />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `activity` | `LiveActivityData \| null` | – | { id, label, status?, progress?, count?, icon?, title?, detail?, steps?, actions? }; null folds the pill away. |
| `expanded / defaultExpanded / onExpandedChange` | `boolean / boolean / (open) => void` | – | Whether the panel is open; controlled or not. |
| `panelWidth` | `number` | `320` | The panel’s width. |

## States

- **arrive / leave**: Setting an activity opens the pill from nothing (width, opacity, scale 0.85→1, 480ms); setting null folds it away, keeping its last content while it goes.
- **update**: Same id: the label morphs, the 16px ring eases to the new progress (500ms) and count rolls.
- **switch**: A new id: the pill’s face rises in out of a 5px blur (360ms) while its width eases to the new label.
- **expand**: Tap: width, height and corners ease from the pill to the panel (480ms) while the pill’s face blurs out and the panel’s fades in after it. Escape (focus returns to the pill) or a tap outside folds it back.
- **done / error**: The spinner blurs into a check that draws itself (420ms), or an alert; the bar turns emerald or red; steps tick as they finish.

## What it handles

Background work in web apps usually means a toast that vanishes or a spinner nobody notices. This is one pill for whatever is happening now, the way a phone shows a call or a timer at the top.

- **One pill for the work in progress**: It opens from nothing when work starts and folds away when you set the activity to null.
- **It updates in place**: The label morphs, the ring eases to the new progress and the figure rolls.
- **A new activity replaces the old**: The new face rises in out of a blur while the pill reshapes to fit its label.
- **Tap for the details**: The pill itself grows into a panel with a title, a progress bar, steps that tick off and actions.
- **Done is visible**: The spinner blurs into a drawn check, or an alert on failure, and the bar turns emerald or red.
- **Quiet for screen readers**: A polite status announces the label and when it is done or failed, never the progress figure.

## Replaces

a toast, a spinner, a status popover, a progress bar, a step checklist

## Where it fits

- **Agents working in the background**: A pill that reads “Editing 3 files” while the agent works, with the steps a tap away.
- **Uploads, imports and exports**: Show a long job’s progress without a toast that vanishes.
- **Deploys and builds**: A running deploy with its steps ticking off.
- **Syncs and backups**: Work that happens quietly and should show when it finishes.

## Notes

- The pill is a button with aria-expanded controlling the panel, a labelled group; Escape returns focus to the pill.
- A polite status region announces the label and when it’s done or failed, never the progress or the rolling figure.
- The spinner only spins while an activity runs; green and red always come with a check or an alert and words.
- Installs Number roll and Text morph. With reduced motion the pill changes size and content in place.

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