Ant Design Svelte

Image

Images with loading, fallback, transformations and general viewing of the series.

When to use

Image displays a thumbnail with interactive viewing: scaling, rotating, flipping and moving. ImagePreviewGroup groups images into a series. For a regular illustration without preview, set preview:false or use a native img.

CSS Image Prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. Image.previewPrefixCls - The full viewer prefix, including the explicit empty string. undefined adds -preview to the thumbnail prefix. For PreviewGroup this is the basic Image prefix: viewer adds -preview; group thumbnails choose their namespace independently.

Miniature, loading and spare source

src refers to a miniature, preview.src may indicate an original of higher resolution. width/height reserve a place in advance. placeholder — boolean or snippet before loading; fallback substitutes a fallback file in case of error.

Problem Opportunity Example
Open image src, preview Main View
Show preview content placeholder Loading
Substitute backup file fallback Source error
Separate the original from the miniature preview.src Other source
View episode ImagePreviewGroup Group
Open a series of one picture explicit items One miniature

onLoad and onError report image load and failure. Pass your progress value in placeholder.progress. The application supplies the percentage. Image events still determine whether the request loads or fails.

Group opening and indexes

Preview:true uses local state. With preview.open, the owner must accept the new value in onOpenChange and pass it back. For the group, also update the current via onChange. current starts from zero, but countRender gets its number from one.

The group uses explicit items or registered child Images. An explicit array, including an empty one, takes precedence. Therefore, you can show one thumbnail, transfer the entire series to items, or open the view with an external button without thumbnails at all.

mask separately specifies the presence of darkening, blur, and background closure. focusTrap holds focus inside the viewer; example in Modal checks for returning to the original action after closing.

Transformations and own content

scaleStep, minScale/maxScale limit the scale, wheel controls wheel scaling, movable controls movement. onTransform communicates the transform and action via requestAnimationFrame. In the group actions.onActive(offset) takes a relative step.

actionsRender gets the original actionbar and viewer context. imageRender receives an image snippet and transform. Keep the original snippets if you supplement standard operations with a signature or button, as in action bars.

Transformations change the CSS, not the source file. The download link in the example preserves the original. Creating a rotated file requires separate Canvas processing and a CORS enabled source.

API design and boundaries

Alt describes the image; preview opens by pressing or Enter. For a decorative picture, do not duplicate adjacent text. Own controls viewer should remain buttons with accessible names.

class/style refers to the img, styles.root refers to the thumbnail wrapper. classNames.popup.root styles the root of a single or group view. The remaining semantic slots are not yet available in the official version. Six Image design tokens apply to the thumbnail and viewer, including PreviewGroup; preview.zIndex allows you to override the preview level. Native nodes are accessible via nativeElement/imageElement.

Examples

Action: no. Scale: 100%.

View Image

Pressing or Enter opens a view with zoom, rotation and flip.

Loading…

Preload

Snippet with blurry illustration is displayed before the main file is loaded.

Original image available

Backup image

fallback substitutes a fallback file in case of decoding error; button restores the source.

General view

ImagePreviewGroup combines child Images. Saved review example with three images.

Series of one miniature

items specifies a complete series, although one image is shown on the page.

Separate viewing source

preview.src is different from the thumbnail src; in the application this is how they connect the original of a higher resolution.

Image: 2. Open: no.

Guided View

The owner stores open and current, processes callbacks and configures the counter.

Own action bar

actionsRender retains standard operations and adds reset and download of the original.

View content

imageRender saves the original image and adds a caption with the current scale.

View background

Dimming, blurring, no background and separate background closure control.

Label on thumbnail

coverNode and placement specify the content and location of the caption on hover or focus.

Thumbnail and viewing
General viewing of the series

Semantic styles

styles.root designs the thumbnail wrapper, class/style - img, classNames.popup.root - individual or group viewing. The remaining semantic slots have not yet been transferred.

Image inside Modal

Open view. Escape first closes the image and returns focus to the thumbnail.

View inside Modal

Opens on top of a modal window and returns focus after closing the view.

Single image
Group of two images

Component tokens

Local thumbnail theme and viewer, ImagePreviewGroup, CSS variables and priority preview.zIndex.

Open the image to scale, rotate and move.

Landscape from review

Saved example with local data URL.

Scale: 100%
General: suite; local: project-image

Image.previewPrefixCls - The full viewer prefix, including the explicit empty string. Undefined adds -preview to the thumbnail prefix. For PreviewGroup this is the basic Image prefix: viewer adds -preview; group thumbnails choose their namespace independently.

CSS prefixes Image

Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.

API

Example themes verified against ant.design 6.7.0; Svelte API - with installed package based on 6.6.8. Full definitions of Props belong to @woodger/antd. All example images are stored locally.

Topics of official examples
ThemeExample or limitation
Basic UsageView with keyboard and mouse.
Progressive Loadingplaceholder accepts a Snippet or progress supplied by the application.
Fault tolerantSpare file and src recovery.
Multiple image previewRegistration of child Images.
Preview from one imageExplicit items, one thumbnail.
Custom preview imageIndependent preview.src.
Controlled Previewopen/current, callbacks, countRender.
Custom toolbar renderSnippet actionsRender, reset and download original. Converted Canvas export has not been added.
Custom preview renderimageRender preserving original.
preview maskmask.enabled, blur and closable.
Custom semantic dom stylingPartially: styles.root for Image and classNames.popup.root for Image/PreviewGroup. The remaining slots are not yet available.
nestedView over Modal.

Image

PropertyDescriptionTypeDefault
previewPrefixClsFull viewer prefix; undefined adds -preview to resolved Image.prefixCls. The explicit empty string is retained. Namespace styles are included by the library.stringImage prefixCls + "-preview"
prefixClsFull CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and undefined inherit ConfigProvider. The namespace of the topic is set separately.stringConfigProvider.prefixCls + "-image"
srcThumbnail URL; native srcset, sizes, loading and referrerpolicy are also available.string—
altDescription of the picture and name of the view button.string—
widthThumbnail width.number | string—
heightThumbnail height.number | string—
previewView settings; false leaves the normal image.boolean | ImagePreviewConfigtrue
placeholdertrue enables the built-in placeholder background. Show a Snippet or progress while loading.boolean | Snippet | { progress? }—
fallbackFallback URL for thumbnail and preview in case of error.string—
onErrorError loading or decoding thumbnail.(event: Event) => void—
onLoadLoading a thumbnail, including fallback.(event: Event) => void—
stylesCSS string for the root wrapper of the thumbnail.{ root?: string }—
classNamesSeparate view root class. For general viewing, it is set to ImagePreviewGroup.{ popup?: { root?: string } }—
styleStyle img; class also applies to img.string—
nativeElementbind:nativeElement - thumbnail container.HTMLElementafter mount
imageElementbind:imageElement - native img.HTMLImageElementafter mount

preview for Image

PropertyDescriptionTypeDefault
srcIndependent viewer URL.stringsrc Image
altDescribes the image in the viewer. A nonempty value also gives the dialog an accessible name.stringalt Image
getContainerViewer container. The getter runs in the browser without arguments.GetContainerConfigProvider.getPopupContainer
openControlled visibility. Update it in onOpenChange.booleanlocal state
onOpenChangeRequest to change visibility.(open: boolean) => void—
afterOpenChangeReports visibility after the animation finishes.(open: boolean) => void—
onTransformState after conversion; callback is delivered via requestAnimationFrame.({ transform, action }) => void—
scaleStepSingle step multiplier: 1 + scaleStep.number0.5
minScaleMinimum scale.number1
maxScaleMaximum scale.number50
wheelZooming with the mouse wheel.booleantrue
movableDrag and drop the enlarged image.booleantrue
focusTrapModal dialog with focus holding.booleantrue
maskBackground and closing based on it.boolean | { enabled?, blur?, closable? }true
coverThumbnail label, false hides it.boolean | Snippet | { coverNode?, placement? }standard area
actionsRenderAction bar and context with transform, image and actions.Snippet<[original, info]>standard actions
imageRenderView content; original preserves the built-in transformations.Snippet<[original, info]>image
zIndexExplicit dialog layer.number1080

ImagePreviewGroup

PropertyDescriptionTypeDefault
previewPrefixClsBasic Image prefix for general viewing: viewer adds -preview. The empty string/undefined inherits the common Image prefix. Does not rename thumbnails.stringConfigProvider.prefixCls + "-image"
classNamesGeneral view root class.{ popup?: { root?: string } }—
itemsURL strings or objects with native img fields. Even an empty array has priority over child registration.readonly ImagePreviewGroupItem[]child Image
previewGeneral viewing settings; false disables opening.boolean | ImagePreviewGroupConfigtrue
fallbackSpare file for the general viewer.string—

Additions preview group

PropertyDescriptionTypeDefault
currentManaged index from scratch.number0
onChangeImage change request; save the new index.(current, previous) => void—
onOpenChangeVisibility with image index.(open, { current }) => void—
countRenderUnlike current, the number in countRender starts with one.Snippet<[current, total]>number / total

Use Image.PreviewGroup or the named ImagePreviewGroup export to preview a series. preview.getContainer selects the viewer container, and preview.alt describes the open image.

Semantic DOM

Thumbnail - native button with img; at preview={false} container becomes div. The view uses dialog, image, background, close and transform buttons. The button opens with Enter or a spacebar; Escape closes the view and returns focus.

In upstream, root, image, cover and popup.root/mask/body/footer/actions/close are available. In Svelte styles.root designs the miniature wrapper, and classNames.popup.root specifies the class of the view root. These fields accept objects; callbacks and other slots are not yet available. style and class refer to img, rootClassName - to the wrapper.

actionsRender and imageRender receive the original content as a Snippet. Challenge original() saves inline actions or image with transformations.

Registration tokens

theme.components.Image applies six tokens to the thumbnail and viewer, including ImagePreviewGroup. The example shows action sizes and colors, a custom zIndexPopup, and named CSS variables. Explicit preview.zIndex takes precedence over the topic token.

progressAnimationDuration specifies a CSS duration variable. Object placeholder.progress has not yet been ported, so there is no separate example of a progress animation yet.

Component tokens Image
TokenPurpose
zIndexPopupView layer.
previewOperationSizeSize of action icons.
previewOperationColorAction color.
previewOperationHoverColorHover action color.
previewOperationColorDisabledColor of unavailable actions.
progressAnimationDurationLoading animation duration; progress API has not yet been migrated.
Common tokens of the current topic
TokenMeaning
colorBgMaskrgba(0,0,0,0.45)
colorTextLightSolid#fff
colorTextSecondaryrgba(0,0,0,0.65)
colorPrimaryBorder#adc6ff
fontSize14
marginXL32
motionDurationSlow0.3s

FAQ

How to open a series without all the miniatures?

Set items to ImagePreviewGroup. A child Image or external button with controlled open will open the overall series.

Why doesn't the view close with controlled open?

Update open in onOpenChange. For a managed index, handle onChange in the same way.

Is the rotated image downloaded?

No. The example downloads the source file; CSS transform doesn't change its content.

How to show loading and error?

placeholder is visible before loading, fallback replaces the failed source. Reserve your thumbnail sizes in advance.