GitHub

Image

An image with loading and failure states, and an optional fullscreen preview with zoom, rotation and a gallery.

Loading example…

Installation

pnpm dlx shadcn@latest add @sui/image

Install with the shadcn CLI or use the shared @workspace/ui package. Follow the installation guide to configure the registry, load styles, and choose import aliases.

Image installs as components/ui/image/index.tsx. If you installed it from SUI 5.4 or earlier, delete the old components/ui/image.tsx after updating: a file beside the folder wins over its index, so imports would keep the old version. See Update installed source.

Usage

import { Image, ImageGroup } from "@workspace/ui/components/image";

// One image that opens a fullscreen preview
<Image src="/photos/cover.jpg" alt="Cover" width={240} height={160} preview />

// A gallery: clicking any image previews them all
<ImageGroup>
  {photos.map((photo) => (
    <Image key={photo.id} src={photo.thumb} alt={photo.name} preview={{ src: photo.full }} />
  ))}
</ImageGroup>

Image

Image renders a picture in a box sized by width and height (numbers are pixels) or by className. fit sets object-fit and defaults to cover. While loading, a pulsing placeholder fills the box; if loading fails, fallback replaces it, or a default icon and the error label. The box exposes data-state as loading, ready or error. Other <img> attributes such as loading="lazy" pass through.

Preview

preview is off by default, so an image stays a plain picture. preview turns the image into a button that opens a fullscreen preview; its accessible name comes from labels.preview(alt). Pass an object to preview a larger src, or to control the preview with open, defaultOpen and onOpenChange. container chooses the Portal container.

Inside the preview, wheel and pinch gestures zoom, dragging pans, and the toolbar zooms, rotates and resets. Arrow keys navigate, +/- zoom and 0 resets. Loading failures offer a retry. The preview uses the shared Dialog for focus management and dismissal.

Loading example…

Gallery

ImageGroup turns the Images inside it into one gallery, without rendering a wrapper element. Clicking an image opens the preview on that image, with navigation and thumbnails in document order. Images take part unless they set preview={false}, and each one's preview.src is used when present. Control the group's preview through preview={{ open, onOpenChange, index, onIndexChange }}, with zero-based indexes.

Preview without thumbnails

ImagePreview is the fullscreen viewer on its own, for opening images from other controls. It takes images (one or more URLs, or { src, alt } items), open, onOpenChange, and an optional controlled index with onIndexChange or an uncontrolled initialIndex. Opening an uncontrolled preview restores initialIndex. An empty list renders nothing.

Loading example…

Labels and glass

labels customizes the preview button, toolbar, navigation, thumbnail and position announcements; pass imageLabelsZhCN for Chinese. Function labels receive one-based positions. glass and frosted on Image, ImageGroup or ImagePreview apply only to the preview's controls; the dialog, images and thumbnails keep their normal styles.

API reference

Image

PropTypeDefault / behavior
src, altstringRequired.
width, heightnumber | stringBox size; numbers are pixels.
fitCSSProperties["objectFit"]"cover".
fallbackReactNodeIcon and labels.error.
previewboolean | { src, open, defaultOpen, onOpenChange, container }false; inside ImageGroup, on unless false.
labelsPartial<ImageLabels>English labels.
glass, frostedboolean | GlassConfig, booleanfalse; preview controls only.

ImageGroup

PropTypeDefault / behavior
preview{ open, onOpenChange, index, onIndexChange, container }Uncontrolled.
altstringAlt text for images without their own.
labels, glass, frostedAs ImageApplied to the shared preview.

ImagePreview

PropTypeDefault / behavior
imagesImagePreviewItem | ImagePreviewItem[]Required URL(s) or { src, alt } items.
open / onOpenChangeboolean / (open: boolean) => voidRequired.
index / initialIndexnumberControlled / 0.
onIndexChange(index: number) => voidReports the zero-based index.
altstringlabels.defaultAlt.
containerPortal containerOptional.

The module exports ImageProps, ImageGroupProps, ImagePreviewProps, ImagePreviewItem and ImageLabels. The modal behavior is documented in the Base UI Dialog API.