# Grid reveal

A reserved frame for a generated still image or static diagram, with a quiet grid while it is made.

Live variants: https://design.arcadia.is/components/grid-reveal

```tsx
import { GridReveal } from "@arcadia/ui";
```

```tsx
import { useState, useEffect } from "react";
import { Button, GridReveal } from "@arcadia/ui";

function Generation() {
  const [attempt, setAttempt] = useState(0);
  const [instant, setInstant] = useState(false);
  const [state, setState] = useState<GridRevealState>(result);
  useEffect(() => {
    if (state.phase !== "waiting") return;
    const timer = setTimeout(() => setState(result), 1800);
    return () => clearTimeout(timer);
  }, [attempt, state.phase]);
  const pending = state.phase === "waiting";
  return (
    <div data-instant={instant ? "" : undefined} {...sx(null, styles.stage)}>
      <div {...sx(null, styles.actions)}>
        <Button size="sm" variant="secondary" onClick={event => {
          setAttempt(attempt + 1);
          setInstant(event.detail === 0);
          setState({ phase: "waiting" });
        }}>Generate image</Button>
        <Button size="sm" variant="ghost" onClick={() => {
          if (pending) setState({ phase: "cancelled" });
        }} disabled={!pending} focusableWhenDisabled>Cancel generation</Button>
      </div>
      <GridReveal key={attempt} kind="image" {...picture} state={state} live={attempt > 0} announce />
    </div>
  )
```

## Accessibility

The image has its own `alt` and the grid is decorative. Describe what the image shows. For a static diagram, name the relationship in the alt text, such as "A request branches to two workers". Place a full text equivalent nearby when needed. The frame is not a focus stop. Keep cancellation and recovery outside the frame and reachable from the keyboard.

Reduced motion keeps the grid still and shows the entire image at once. Use `announce` only if the surrounding conversation does not announce the outcome. A wait and its failure are written out, never carried by the grid or colour alone.

## API reference

### GridReveal

- `state` (`GridRevealState`, required): The product owns generation, cancellation and retry. Key the component by attempt.
- `kind` (`"image" | "diagram"`, required): Only generated still images or self-contained, static diagram images.
- `width` (`number`, required): Positive dimensions agreed before generation. They must not change within an attempt.
- `height` (`number`, required)
- `alt` (`string`, required): Describe the finished visual. Provide a longer text equivalent separately for a complex diagram.
- `live` (`boolean`, default `false`): Opt in for a new result, never for history or a restored view. Only one live indicator per region.
- `announce` (`boolean`, default `false`): Politely announce outcomes only if the surrounding conversation does not already do so.
- `onImageError` (`() => void`): Report a load or decode failure so the caller can offer recovery.
- `rootStyle` (`RootStyle`): Typed StyleX layout override.
