Image

An image that loads lazily without shifting the layout, and can open a full-screen preview to zoom, pan and rotate.

  • vig-image
Import
import { Image } from '@vigdx/ui/image';

Basic and preview

src and alt are all it needs; width and height reserve the space before it loads, and it renders with loading="lazy" and decoding="async" ( priority loads the page's main image eagerly with fetchpriority="high" ). preview turns it into a button that opens the viewer; previewSrc shows a larger file there. If the file fails to load, a labelled error state ( labels.errorLabel , data-state="error" ) replaces it and no preview is offered.

Crater lake, Eastern Anatolia region

Your own image, e.g. NgOptimizedImage

Leave src unset and put your own <img> inside: it is shown untouched, so ngSrc , priority and srcset of NgOptimizedImage keep working. The preview follows its src , srcset and alt as they change and shows the largest srcset candidate; set previewSrc for a dedicated file (a load error of a projected image is yours to handle). The kit cannot apply NgOptimizedImage for you (it needs your image loader), but srcset , sizes , width , height and loading pass through when it renders the image.

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="image"][data-part="root"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="image"]

Image styling hooks
Part Element data-state
root The host, an inline block. —
image The <img> it renders from src (not a projected one). —
error Shown instead of an image that failed to load ( labels.errorLabel ); the host gets data-state="error" too. error
trigger With preview : the button around the image. —
indicator The zoom glyph shown over the image on hover and focus. —
viewer The full-screen native modal <dialog> ; its ::backdrop is --color-backdrop-strong . open, closed
viewer-toolbar The row of viewer controls. —
viewer-zoom-level The visible zoom percentage (hidden from screen readers). —
viewer-status Visually hidden polite status with the zoom level, debounced for wheel and pinch. —
viewer-zoom-out Zoom out button ( aria-disabled when fitted). —
viewer-zoom-in Zoom in button ( aria-disabled at 400%). —
viewer-rotate Rotate a quarter turn clockwise (R; Shift+R back). —
viewer-reset Back to fitted and upright (0). —
viewer-close Close button; takes focus when the viewer opens. —
viewer-stage The area around the image: pinch, wheel and drag; a press on it closes. fitted, zoomed
viewer-image The image, transformed by zoom, rotation and panning. —
viewer-caption The caption under the image (hidden when empty). —
Image data attributes
Attribute Meaning
data-opening On the overlay element (panel or <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities.
data-closing On the overlay element while its exit transition plays, before it closes; removed once it settles (2s at most). Style the closed look with data-closing: utilities.

Accessibility

  • alt is required; dev mode warns when it is missing, and when an image with a preview has an empty one (its alt names the button: "Open preview: Crater lake").
  • The viewer is the native modal <dialog>: the page behind is inert, focus starts on Close and returns to the image, Escape closes. A press beside the image closes too.
  • Every control is a labelled button (zoom out, zoom in, rotate, reset, close), and has a key: + and − zoom, 0 resets, R rotates (Shift+R back), the arrow keys pan a zoomed image. The zoom level is announced politely: at once for a button or key, once a wheel or pinch comes to rest. Controls that cannot act are aria-disabled and stay focusable.
  • Pointer extras: wheel and pinch zoom (Safari trackpad pinches too, instead of zooming the page), drag to pan, double click toggles 200%. The page behind never scrolls. Transitions run only without prefers-reduced-motion.

API

Image

vig-image component

An image that can open a full-screen preview. It renders its own <img> (src, alt, width/height against layout shift, srcset/sizes, loading="lazy" and decoding="async" by default; priority for the page's main image) or shows an <img> you project, such as one with NgOptimizedImage's ngSrc, untouched.

Example :
<vig-image src="/photos/lake.jpg" alt="Lake at dawn" width="800" height="533" preview />

<vig-image preview previewSrc="/photos/lake-full.jpg">
  <img ngSrc="/photos/lake.jpg" alt="Lake at dawn" width="800" height="533" />
</vig-image>

With preview, the image is a button that opens the kit's image viewer, a native modal <dialog>: zoom, rotation, panning, keyboard (+ − 0 R, arrows, Escape) and focus returning to the image. While the viewer plays its entrance or exit transition, its <dialog> carries data-opening or data-closing (stable hooks for styling and for waiting in tests; see the theming guide). data-opening data-closing

Image props
Name Type Default Description
altstring | undefinedundefined

Text alternative; required. "" marks a decorative image, which cannot have a preview (its button would have no name). Dev mode warns when it is missing.

heightnumber | undefinedundefined
—
labelsPartial<ImageLabels>—

Texts (i18n) over the locale defaults.

loadingImageLoading'lazy'

lazy (default) or eager.

open model booleanfalse

Two-way: whether the preview is open.

previewbooleanfalse

Makes the image a button that opens the full-screen viewer.

previewSrcstring | undefinedundefined

Larger image for the viewer; defaults to src (or the projected image).

prioritybooleanfalse

The page's main (LCP) image: loads eagerly with fetchpriority="high".

sizesstring | undefinedundefined

sizes for srcset width descriptors.

srcstring | undefinedundefined

Image URL. Leave unset to project your own <img> (e.g. with ngSrc).

srcsetstring | undefinedundefined

Candidate sources for srcset, e.g. "lake-480.jpg 480w, lake-960.jpg 960w".

widthnumber | undefinedundefined

Intrinsic width in pixels; with height it reserves the space before loading.

Are you sure?