Image

An image with a preview overlay, a fallback for a broken source and a placeholder for one still loading.

Code

Image installs into your project as a file you own. It takes the same props as Ant Design's Image. It changes one default: a preview.actionsRender that draws the six toolbar icons from your icon pack, on Image and on Image.PreviewGroup. Your own actionsRender receives that toolbar and info.icons with the pack glyphs in place, and preview={false} still turns the viewer off.

Install

npx antuikit@latest init
npx antuikit@latest add image
The first command sets up AntuikitProvider and the theme tokens, and the second adds Image.

Import

Import from @/components/ui/image, not from antd. Once installed, the file lives in your project.
import { Image } from "@/components/ui/image"

The axes

Image has no variant props. You configure it with a URL, a node or a config object, and round its corners with a class like rounded-lg on classNames.root.
The one choice from a list is preview.cover's placement: top, bottom or center (the default), which places the hover overlay on the thumbnail.

Flags

Every switch is inside preview, which is the first of them. preview={false} turns the viewer off and removes the tab stop, and preview={true} is the default.
  • preview.movable and preview.wheel (both on by default) are drag to pan and wheel to zoom. Turn the wheel off where people expect it to scroll the page.
  • preview.focusTrap defaults to true and keeps Tab inside the open viewer. Leave it on.
  • preview.mask takes a boolean or { enabled, blur, closable }. The backdrop is on and closes on click by default, and the blur is off.
  • preview.open controls the viewer, paired with preview.onOpenChange. Pass both, or the viewer will not close.
preview.forceRender and preview.destroyOnClose were removed and do nothing. The viewer always renders once it has opened.

Slots

The props that take a node. Only placeholder is top-level, and the rest are in the preview config.
  • placeholder shows while the image loads. A node is replaced by the image, and { progress } shows a progress box instead of the image.
  • preview.cover is the hover overlay on the thumbnail, a node or { coverNode, placement }. The backdrop behind the viewer is preview.mask.
  • preview.closeIcon is the close icon, which AntuikitProvider sets from your icon pack.
  • preview.imageRender wraps the image in the open viewer and receives the current transform, for a caption, a watermark or content that is not an image.
  • preview.actionsRender renders the toolbar and preview.countRender the group's counter. Both receive the finished nodes, so clone and swap rather than rebuild them.
  • placeholder.progress.render renders the loading box, with the progress bar and the percent.

Events

  • onError
  • preview.onOpenChange
  • preview.onTransform

Image.PreviewGroup

Part of the same import. It gives a set of images one viewer, with previous and next buttons, arrow keys and a counter. Images inside a group use the group's viewer, so the kit sets actionsRender on the group too.
1
import { Image } from "@/components/ui/image"
2
3
// The page and the viewer show the same set.
4
<Image.PreviewGroup>
5
{shots.map((shot) => (
6
<Image key={shot.src} src={shot.src} alt={shot.alt} width={160} />
7
))}
8
</Image.PreviewGroup>
9
10
// One thumbnail on the page, the whole set in the viewer.
11
<Image.PreviewGroup items={shots.map((shot) => shot.src)}>
12
<Image src={shots[0].src} alt={shots[0].alt} width={160} />
13
</Image.PreviewGroup>
The group's preview config adds current, onChange and an onOpenChange with the index. Its mask only takes the backdrop config, so a node is a type error there.

Styling

classNames and styles take the same keys. Use them before a descendant selector.
1
<Image
2
classNames={{
3
root: "…",
4
image: "…",
5
cover: "…",
6
placeholder: {
7
progress: "…",
8
},
9
popup: {
10
root: "…",
11
mask: "…",
12
body: "…",
13
footer: "…",
14
actions: "…",
15
close: "…",
16
},
17
}}
18
/>

API Reference

Image
Image's props.
PlaceholderType
The fields of the object form of placeholder.
ImageProgressConfig
The fields of the object form of placeholder.progress.
PreviewType
The fields of the object form of preview. Rows marked antuikit in the Version column are added by the kit.
Image.PreviewGroup
Image.PreviewGroup's props.
PreviewGroupType
The fields of the object form of Image.PreviewGroup's preview. Rows marked antuikit in the Version column are added by the kit.