Content
Image Lightbox
A full-screen image viewer with zoom, rotate, download and keyboard shortcuts, rendered into a portal.
A controlled, full-screen image viewer rendered into a portal on document.body. It supports zoom, rotate, download and keyboard shortcuts (Esc to close, + / - to zoom, R to rotate). It's the viewer that ContentImage opens on click, but you can drive it yourself for any image: hold the open state and pass isOpen / onClose.
The dialog traps keyboard focus, sets aria-modal="true", restores focus after closing, and locks background scrolling while open. Set the optional label prop to provide the dialog's accessible name; by default it uses alt, then the host's content translation (“Image preview”).
Import
tsx1 line
import { ImageLightbox } from "@yuhuanowo/yunui/content";Example
ImageLightbox
Usage
tsx9 lines
const [open, setOpen] = useState(false);
<button onClick={() => setOpen(true)}>View</button><ImageLightbox src={imageUrl} alt="Generated image" isOpen={open} onClose={() => setOpen(false)}/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| alt | string | — | |
| children | ReactNode | — | Custom zoomable content instead of an `<img src>` — e.g. an inline SVG diagram. Download is only offered when `src` is set. |
| isOpen* | boolean | — | |
| label | string | — | Accessible dialog name; defaults to alt or the host's content translation. |
| onClose* | () => void | — | |
| src | string | — | Image URL to view. Omit when providing custom `children` (e.g. an SVG). |