AttachmentPreview
Previews browser-owned images with localized loading, error and unsupported-file fallbacks.
See it and copy it
Framework example
Choose Astro, React, or Elements to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
Vista previa no disponible para este archivo.
View AttachmentPreview code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.---
import { AttachmentPreview, Button, Link } from '@santi020k/lumen-astro'
---
<AttachmentPreview src="/logo.svg" contentType="image/svg+xml" alt="Lumen logo">
<span slot="caption">Example image attachment</span>
<Link slot="actions" href="/logo.svg" download>Download</Link>
<Button slot="actions" type="button">Replace</Button>
</AttachmentPreview>
<AttachmentPreview contentType="application/pdf" alt="Example report" labels={{ unavailable: 'Vista previa no disponible para este archivo.' }}>
<span slot="caption">Example PDF · unsupported preview</span>
</AttachmentPreview>import { AttachmentPreview, Button } from '@santi020k/lumen-react'
<AttachmentPreview src="/logo.svg" contentType="image/svg+xml" alt="Lumen logo"
caption="Example attachment" actions={<Button type="button">Replace</Button>} /><script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-attachment-preview aria-label="Logo attachment" content-type="image/svg+xml" error-label="Could not load the preview.">
<div data-slot="attachment-preview-media"><img data-ui-attachment-preview-image src="/logo.svg" alt="Lumen logo"></div>
<p data-slot="attachment-preview-fallback" data-ui-attachment-preview-message role="status"></p>
<p>Example image attachment</p>
<div data-slot="attachment-preview-actions"><a href="/logo.svg" download>Download</a></div>
</lumen-attachment-preview>Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astropnpm add @santi020k/lumen-astrolumen add AttachmentPreviewlumen add AttachmentPreviewpnpm add @santi020k/lumen-reactpnpm add @santi020k/lumen-reactlumen add AttachmentPreview --target reactlumen add AttachmentPreview --target reactpnpm add @santi020k/lumen-elementspnpm add @santi020k/lumen-elementslumen add AttachmentPreview --target elementslumen add AttachmentPreview --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| src | string | - | Browser-owned image URL; the application owns authorization and object URL cleanup. |
| alt | string | required | Accessible description of the image. |
| contentType / content-type | string | - | Non-image MIME types use a fallback instead of rendering an image. |
| state | "ready" | "loading" | "error" | "unavailable" | derived | Explicit loading, error and unavailable states override automatic image status. |
| labels | Partial<LumenAttachmentPreviewLabels> | English labels | Localizes fallback messages. Elements uses error-label, loading-label and unavailable-label. |
| retryKey / retry-key | string | number | - | Changes the retry identity for the current image. Retry remains application controlled. |
| caption / actions | React nodes / Astro named slots | - | Composes a caption and independent download, replace or remove actions. |
| onStateChange | (state) => void | - | React callback for transitions after the initial render; DOM adapters emit ui:attachment-preview-change with { state }. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:attachment-preview-change | AttachmentPreview root | { state: "error" | "loading" | "ready" | "unavailable" } | Fires after a preview state changes. The event never includes the file URL. |