# Mist reveal

> The calm wait for a generated image: a slow band of colour drifts while it works, then the mist moves off and the picture sharpens into place.

Waiting for an image model is the moment a product looks either alive or stuck. While your generation runs, Mist reveal fills the frame with a slow band of your theme’s chart colours drifting through a quiet well, enough to say it is working without a spinner. It never guesses: it waits on your status, and only once the image is ready and has actually loaded does the mist move off towards a corner while the picture sharpens out of a soft blur in the same move. If your API reports progress, a small figure rolls in the corner; if it fails, the frame says so and offers Try again. The calm one of the four, for consumer apps.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/mist-reveal.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`
- Docs and live preview: https://hairlineui.com/ui/mist-reveal
- Registry item (source): https://hairlineui.com/r/mist-reveal.json

## Usage

```tsx
import { MistReveal } from "@/components/mist-reveal";

<MistReveal
  src={image?.url}
  status={job.status}
  alt={prompt}
  onRetry={regenerate}
  className="aspect-square w-80"
/>
```

## Polling your generation API

Start a generation, poll its status, and hand the component the real state. Any API that reports generating, ready and failed works the same way.

```tsx
"use client";
import * as React from "react";
import { MistReveal } from "@/components/mist-reveal";

type Job = { id: string; status: "generating" | "ready" | "error"; url?: string; progress?: number };

export function Generation({ prompt }: { prompt: string }) {
  const [job, setJob] = React.useState<Job | null>(null);

  async function generate() {
    const { id } = await fetch("/api/generate", { method: "POST", body: JSON.stringify({ prompt }) }).then((r) => r.json());
    setJob({ id, status: "generating" });
    const poll = window.setInterval(async () => {
      const next: Job = await fetch(`/api/generate/${id}`).then((r) => r.json());
      setJob(next);
      if (next.status !== "generating") window.clearInterval(poll);
    }, 1000);
  }

  return (
    <div className="grid gap-3">
      <MistReveal
        src={job?.url}
        status={job?.status ?? "generating"}
        alt={prompt}
        onRetry={generate}
        className="aspect-square w-80"
      />
      <button onClick={generate}>Generate</button>
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `src` | `string` | – | The generated image. It can arrive before or with status "ready"; the reveal waits until it has loaded and decoded. |
| `status` | `"generating" \| "ready" \| "error"` | – | Your generation’s real state. Nothing plays on a timer. |
| `progress` | `number` | – | 0 to 1, if your API reports it. Shown as a small rolling figure; without it, no number is shown. |
| `alt` | `string` | – | The image’s text alternative, usually its prompt. |
| `crossOrigin` | `"anonymous" \| "use-credentials"` | – | Set it when your image host sends CORS headers. |
| `onReady` | `() => void` | – | Called once the reveal has played, or the image is shown without one. |
| `onRetry` | `() => void` | – | Shows Try again when the generation fails. |
| `labels` | `{ generating?, ready?, failed?, retry? }` | – | Words for the progress tag, the announcements and the failure. |
| `className` | `string` | – | Size the frame here, e.g. "aspect-square w-72". |

## States

- **waiting**: A band of --chart-1, --chart-2 and --chart-4, blurred 28px, drifts 16% each way over 4.6s in the muted well. aria-busy is set.
- **arriving**: Once status is "ready" and the image has decoded: the mist fades over 0.9s while moving 32% towards the bottom-right corner, and the image goes from blur(14px) and scale(1.06) to sharp in 1.1s.
- **shown**: The plain image, its alt text intact. onReady fires.
- **failed**: The well with “This image couldn’t be created.” and Try again when onRetry is passed.

## What it handles

Most image products show a spinner or a skeleton, then swap the image in with a hard cut, and many fake a progress bar that finishes before the image does.

- **Follows the real state**: It waits on your status and on the image actually decoding, so it never finishes early or shows a half-loaded picture.
- **Calm while it works**: A slow band of your chart colours drifts at a pace you can ignore; nothing spins or pulses.
- **One move to arrive**: The mist leaves for a corner as the picture sharpens out of a blur, in one 1.1s move.
- **Honest progress**: A rolling percentage only when your API gives one; otherwise no number at all.
- **Failure designed**: A failed generation says so in the frame with Try again, instead of an empty box.
- **Already there, already shown**: An image that was ready on page load appears without replaying the reveal.

## Replaces

loading spinner, skeleton loader, fake progress bar, blur-up placeholder

## Where it fits

- **Image generators**: The frame a prompt’s result appears in.
- **Chat with images**: An image a model is drawing inside a reply.
- **Avatars and covers**: A generated profile picture or cover photo arriving.
- **Product photos**: A background removal or a restyle being processed.

## Notes

- It follows your status: it waits while "generating", and plays only once status is "ready" and the image has loaded and decoded (img.decode), so it can never finish before the picture does. An image that was already there when the page loaded is simply shown.
- The figure has aria-busy while it waits, and a status line announces Generating, Image ready or the failure; the image keeps its alt text.
- The mist is one blurred layer moved by a CSS animation, so it costs no script while it waits.
- Under reduced motion the image appears in place, with no drift while waiting.

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