Image
vig-image
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.
Your own image, e.g. NgOptimizedImage
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"]
| Part | Element | data-state |
|---|---|---|
root | — | |
image | <img> it renders from src (not a projected one). | — |
error | labels.errorLabel ); the host gets data-state="error" too. | error |
trigger | preview : the button around the image. | — |
indicator | — | |
viewer | <dialog> ; its ::backdrop is --color-backdrop-strong . | open, closed |
viewer-toolbar | — | |
viewer-zoom-level | — | |
viewer-status | — | |
viewer-zoom-out | aria-disabled when fitted). | — |
viewer-zoom-in | aria-disabled at 400%). | — |
viewer-rotate | — | |
viewer-reset | — | |
viewer-close | — | |
viewer-stage | fitted, zoomed | |
viewer-image | — | |
viewer-caption | — |
| Attribute | Meaning |
|---|---|
data-opening | <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities. |
data-closing | data-closing: utilities. |
Accessibility
altis 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-disabledand 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-imageAn 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.
<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
| Name | Type | Default | Description |
|---|---|---|---|
alt | string | undefined | undefined | Text alternative; required. |
height | number | undefined | undefined | — |
labels | Partial<ImageLabels> | — | Texts (i18n) over the locale defaults. |
loading | ImageLoading | 'lazy' |
|
open | boolean | false | Two-way: whether the preview is open. |
preview | boolean | false | Makes the image a button that opens the full-screen viewer. |
previewSrc | string | undefined | undefined | Larger image for the viewer; defaults to |
priority | boolean | false | The page's main (LCP) image: loads eagerly with |
sizes | string | undefined | undefined |
|
src | string | undefined | undefined | Image URL. Leave unset to project your own |
srcset | string | undefined | undefined | Candidate sources for |
width | number | undefined | undefined | Intrinsic width in pixels; with |
| Name | Payload | Description |
|---|---|---|
openChange | boolean | Two-way: whether the preview is open. |