# Image

A generated or attached image, with what to show while it loads or if it fails.

- **Use it for**: A generated or attached image with loading and failure states.
- **Not for**: Attached files of any type. Try [Attachment](https://unseenui.com/components/attachment/).

## Installation

```bash
npm install @stackunseen/ui
```

## Usage

```tsx
import { Image } from '@stackunseen/ui/media';
import '@stackunseen/ui/styles.css';

<Image src={url} alt="Weekly signups chart" />
```

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `alt` (required) | `string` | Required description; use "" only for purely decorative images. |
| `base64` | `string` |  |
| `caption` | `string` |  |
| `className` | `string` |  |
| `error` | `string` | What went wrong, shown with state "failed". |
| `height` | `number` |  |
| `mediaType` | `"image/png" \| "image/jpeg" \| "image/webp" \| "image/gif"` |  |
| `onRetry` | `(() => void)` | Offers a retry with state "failed". |
| `preview` | `string` | A partial image the model has streamed so far (URL), shown softened while loading. |
| `progress` | `number` | Host-measured progress from 0 to 1 while loading. |
| `src` | `string` | Host-supplied image URL (http(s), blob:) or a base64 payload with mediaType. |
| `state` | `"ready" \| "loading" \| "failed" \| "queued"` | "queued" before generation starts, "loading" while the host generates or fetches it, "failed" when it could not; "ready" shows the image. |
| `width` | `number` |  |

## Keyboard

Tab reaches controls; Enter or Space activates buttons. Accordions use arrow keys, Home and End. Select menus support arrows and typeahead; Escape closes menus and dialogs and restores focus.

## Works with

[CodeTabs](https://unseenui.com/components/code-tabs/), [Snippet](https://unseenui.com/components/snippet/), [Commit](https://unseenui.com/components/commit/), [EnvironmentVariables](https://unseenui.com/components/environment-variables/), [PackageInfo](https://unseenui.com/components/package-info/), [SchemaDisplay](https://unseenui.com/components/schema-display/), [StackTrace](https://unseenui.com/components/stack-trace/), [WebPreview](https://unseenui.com/components/web-preview/), [FileExplorer](https://unseenui.com/components/file-explorer/), [CodeDiff](https://unseenui.com/components/code-diff/), [TerminalOutput](https://unseenui.com/components/terminal-output/), [TestResults](https://unseenui.com/components/test-results/)

Page: https://unseenui.com/components/image/
