JGuang

Image

Image · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

Image

Show and preview pictures.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: When you need to view a picture, simply set the src property to get a component with picture preview function.
  • Show caption: By setting title and description, the title and description of the picture can be displayed inside or at the bottom of the picture. The display position is controlled by footerPosition.
  • Extra operations: The extra operations are set by actions and arranged horizontally by default. If you have more operation buttons, we also provide the simple mode to put the buttons in a drop-down box. Note that in the simple mode, the description will be unable to display.
  • Error state: Content displayed when the image fails to load.
  • Loading: There is no loading effect by default. Default loading effect can be enabled with loader=true. If the default loading effect does not meet the requirements, you can also set the loading style through loaderClassName. Loading
  • Progressive Loading: When you need to display a large image, you can pass a smaller image to loader to display it when the original image is not successfully loaded to simulate progressive loading.
  • Preview control bar: The function buttons on the control preview control bar can be sorted and filtered through actionLayout. Among them, extra represents the buttons in actions, and the key in actions also supports separate sorting.
  • Multi-image preview: Use <Image.PreviewGroup> to wrap the <Image> component to preview multiple images.
  • Use Preview alone: Image.Preview can be used alone, you need to set src and control visible.
  • Use PreviewGroup alone: Image.PreviewGroup can be used alone, with visible and onVisibleChange to control its visibility. The image display is divided into two scenes. One is to specify the first image to be displayed by defaultCurrent. The other one is to control which image is currently displayed by current and onChange.
  • Popup container: Use getPopupContainer to specify the parent node where the preview should mount to.
  • lazyload: Set slazyload to enable lazy loading, and the image will only be loaded when it appears in the viewport The lazyload attribute is implemented based on IntersectionObserver API

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

<div class="image-demo-props">

Image

PropertyDescriptionTypeDefaultValueVersion
previewWhether to enable previewbooleantrue-
simpleWhether to enable simple modeboolean--
indexUse Image.PreviewGroup to wrap the preview index. Generally, you don't need to specify it. When there is a problem with the preview order of multiple images, you can manually specify the preview order of the current imagenumber-2.23.0
descriptionImage descriptionstring--
srcImage pathstring--
titleImage titlestring--
footerPositionThe position of footer'inner' | 'outer'inner-
errorContent displayed in error stateReactNode--
loaderLoad transition effect, set true to show the default loading effectboolean | ReactNode--
actionsExtra operationsReactNode[]--
classNameAdditional css classstring | string[]--
heightImage heightstring | number--
lazyloadlazyload loading Intersection_Observerboolean | IntersectionObserverInit-2.47.0
loaderClassNameThe style of the loader, will override the default transition effectstring | string[]--
onErrorTriggered when image loading fails(ev: SyntheticEvent<HTMLImageElement>) => void--
onLoadTriggered when the image is loaded(ev: SyntheticEvent<HTMLImageElement>) => void--
previewPropsPreview options (all options are optional) ImagePreviewPropsPartialImagePreviewProps--
styleAdditional styleCSSProperties--
widthImage widthstring | number--

Image.Preview

PropertyDescriptionTypeDefaultValueVersion
closableWhether display close buttonbooleantrue2.16.0
defaultVisibleWhether visible by defaultboolean--
escToExitWhether to enable pressing ESC to close the preview.booleantrue2.24.0
maskClosableWhether click mask to closebooleantrue-
resetTranslateEnable position correctionbooleantrue2.61.0
visibleWhether is visibleboolean--
breakPointThe width that triggers the toolbar to switch to simple modenumber316-
srcImage path, The default in Image is the src of Imagestring (Required)--
imgAttributesImage props, passthrough to the img tag in the preview modalOmit<ImgHTMLAttributes<HTMLImageElement>, 'src'>-2.39.0
extraAdditional nodes add to the image preview areaReactNode-2.53.0
actionsExtra operations, ImagePreviewActionPropsImagePreviewActionProps[]--
actionsLayoutThe layout of the control barstring[]['fullScreen', 'rotateRight', 'rotateLeft', 'zoomIn', 'zoomOut', 'originalSize', 'extra']-
classNameAdditional css classstring | string[]--
scalesThe zoom percentage in the current array is used when previewing zooms. If 100% is not included, the 100% scale will be automatically added in the most adjacent position.number[][25, 33, 50, 67, 75, 80, 90, 100, 110, 125, 150, 175, 200, 250, 300, 400, 500];2.30.0
styleAdditional styleCSSProperties--
getPopupContainerGet popup's parent node() => HTMLElement() => document.body2.16.0
imageRenderRendering of custom IMG elements(originalNode: ReactElement) => ReactNode-2.58.0
onVisibleChangeCallback when visibility changes(visible: boolean, preVisible: boolean) => void--

Image.PreviewGroup

Start from v2.14.0

PropertyDescriptionTypeDefaultValueVersion
closableWhether display close buttonbooleantrue2.16.0
defaultVisibleWhether visible by defaultboolean--
escToExitWhether to enable pressing ESC to close the preview.booleantrue2.24.0
forceRenderWhether to render the image list for loading images in advanceboolean-2.58.0
infiniteWhether to loop infinitelyboolean--
maskClosableWhether click mask to closebooleantrue-
resetTranslateEnable position correctionbooleantrue2.61.0
visibleWhether is visibleboolean--
breakPointThe width that triggers the toolbar to switch to simple modenumber316-
currentThe index of current image (controlled prop)number--
defaultCurrentThe default index of first imagenumber--
imgAttributesImage props, passthrough to the img tag in the preview modalOmit<ImgHTMLAttributes<HTMLImageElement>, 'src'>-2.39.0
extraAdditional nodes add to the image preview areaReactNode-2.53.0
actionsExtra operations, ImagePreviewActionPropsImagePreviewActionProps[]--
actionsLayoutThe layout of the control barstring[]['fullScreen', 'rotateRight', 'rotateLeft', 'zoomIn', 'zoomOut', 'originalSize', 'extra']-
classNameAdditional css classstring | string[]--
scalesThe zoom percentage in the current array is used when previewing zooms. If 100% is not included, the 100% scale will be automatically added in the most adjacent position.number[][25, 33, 50, 67, 75, 80, 90, 100, 110, 125, 150, 175, 200, 250, 300, 400, 500];2.30.0
srcListImage path list(After setting this property, the information of the Image sub-component will no longer be collected)string[]--
styleAdditional styleCSSProperties--
getPopupContainerGet popup's parent node() => HTMLElement() => document.body2.16.0
imageRenderRendering of custom IMG elements(originalNode: ReactElement) => ReactNode-2.58.0
onChangeCallback when image switches(index: number) => void--
onVisibleChangeCallback when visibility changes(visible: boolean, preVisible: boolean) => void--

ImagePreviewActionProps

Detailed parameters of type ImagePreviewActionProps in <Image.Preview>.

PropertyDescriptionTypeDefaultValue
disabledWhether disabledboolean-
keyUnique identifierstring (Required)-
namenamestring-
contentcontentReactNode (Required)-
classNameAdditional css classstring | string[]-
styleAdditional styleCSSProperties-
getContainerBecause content can only specify content, this function is provided to support custom peripheral elements.Note that if getContainer is set, the Tooltip displaying name will be invalid(actionElement: ReactNode) => ReactNode-
</div>