Content Image
A lazy, fade-in image that defers loading until near the viewport and opens a zoomable lightbox on click.
A lazy, flicker-free image for rendered content. It defers loading until it scrolls near the viewport (via IntersectionObserver), shows a spinner placeholder, fades in on load, and — by default — opens a full-screen, zoomable lightbox by click or keyboard activation. It extends the native <img> props, so src, alt, className, loading, etc. all pass straight through; A standalone ContentImage uses the supplied URL as-is. When used by MarkdownRenderer, the renderer may rewrite the URL with urlTransform and then filters the result through its safe-protocol rules. Inside MarkdownRenderer, every image is rendered through this component.
Loading begins when the image approaches the viewport; if IntersectionObserver is unavailable, it loads eagerly. With the default enableLightbox, a loaded image can open the lightbox by click, Enter, or Space. Images inside a link keep the link's behavior and do not open the lightbox. Set enableLightbox={false} to disable zoom. Changing src or srcSet resets the image loading state. Turning enableLightbox off and back on does not reopen an earlier preview. The optional zoomLabel overrides the zoom action name; by default it uses the host's content.zoomImage translation (fallback “Zoom image”) plus the image alt text.
Native image props are forwarded. onLoad, onError, onClick, and onKeyDown callbacks run when their events occur; calling preventDefault() in the click or key handler prevents the default lightbox action.
Import
import { ContentImage } from "@yuhuanowo/yunui/content";Example
Click the image to open the lightbox.
ContentImage
Props
Beyond the prop below, ContentImage forwards all native <img> attributes (src, alt, className, loading, onLoad, onError, …).
| Prop | Type | Default | Description |
|---|---|---|---|
| enableLightbox | boolean | — | Open a zoom/rotate/download lightbox on click or keyboard activation. |
| zoomLabel | string | — | Accessible name for the zoom action. Defaults to a translated label plus the image alt text. |