Image
图片

可预览的图片。

何时使用

  • 需要展示图片时使用。
  • 加载显示大图或加载失败时容错处理。

代码演示

预览

单击图像可以放大显示。

expand codeexpand code
预览

加载失败显示图像占位符。

expand codeexpand code
预览

大图使用 placeholder 渐进加载。

expand codeexpand code
预览
预览

点击左右切换按钮可以预览多张图片。

expand codeexpand code
预览

从一张图片点开相册。

expand codeexpand code
预览

可以设置不同的预览图片。

expand codeexpand code
scaleStep:

可以使预览受控。

expand codeexpand code
预览

可以自定义工具栏并添加下载原图或翻转旋转后图片的按钮。

expand codeexpand code
预览

可以自定义预览内容。

expand codeexpand code

API

通用属性参考:通用属性

Image

参数说明类型默认值版本
alt图像描述string-4.6.0
fallback加载失败容错地址string-4.6.0
height图像高度string | number-4.6.0
placeholder加载占位, 为 true 时使用默认占位ReactNode-4.6.0
preview预览参数,为 false 时禁用boolean | PreviewTypetrue4.6.0 PreviewType:4.7.0
src图片地址string-4.6.0
width图像宽度string | number-4.6.0
onError加载错误回调(event: Event) => void-4.12.0

其他属性见 <img>

PreviewType

参数说明类型默认值版本
visible是否显示boolean--
src自定义预览 srcstring-4.10.0
getContainer指定预览挂载的节点,但依旧为全屏展示,false 为挂载在当前位置string | HTMLElement | (() => HTMLElement) | false-4.8.0
movable是否可移动booleantrue5.8.0
mask缩略图遮罩ReactNode-4.9.0
maskClassName缩略图遮罩类名string-4.11.0
rootClassName预览图的根 DOM 类名string-5.4.0
scaleStep1 + scaleStep 为缩放放大的每步倍数number0.5-
minScale最小缩放倍数number15.7.0
maxScale最大放大倍数number505.7.0
closeIcon自定义关闭 IconReact.ReactNode-5.7.0
forceRender强制渲染预览图boolean--
toolbarRender自定义工具栏(originalNode: React.ReactNode, info: Omit<ToolbarRenderInfoType, 'current' | 'total'>) => React.ReactNode-5.7.0
imageRender自定义预览内容(originalNode: React.ReactNode, info: { transform: TransformType }) => React.ReactNode-5.7.0
onTransform预览图 transform 变化的回调{ transform: TransformType, action: TransformAction }-5.7.0
onVisibleChangevisible 发生改变时的回调(visible: boolean, prevVisible: boolean) => void--

PreviewGroup

参数说明类型默认值版本
preview预览参数,为 false 时禁用boolean | PreviewGroupTypetrue4.6.0 PreviewGroupType:4.7.0
items预览数组string[] | { src: string, crossOrigin: string, ... }[]-5.7.0
fallback加载失败容错地址string-5.7.0

PreviewGroupType

参数说明类型默认值版本
visible是否显示boolean--
getContainer指定预览挂载的节点,但依旧为全屏展示,false 为挂载在当前位置string | HTMLElement | (() => HTMLElement) | false-4.8.0
movable是否可移动booleantrue5.8.0
current当前预览图的 indexnumber-4.12.0
mask缩略图遮罩ReactNode-4.9.0
maskClassName缩略图遮罩类名string-4.11.0
rootClassName预览图的根 DOM 类名string-5.4.0
scaleStep1 + scaleStep 为缩放放大的每步倍数number0.5-
minScale最小缩放倍数number15.7.0
maxScale最大放大倍数number505.7.0
closeIcon自定义关闭 IconReact.ReactNode-5.7.0
forceRender强制渲染预览图boolean--
countRender自定义预览计数内容(current: number, total: number) => React.ReactNode-4.20.0
toolbarRender自定义工具栏(originalNode: React.ReactNode, info: ToolbarRenderInfoType) => React.ReactNode-5.7.0
imageRender自定义预览内容(originalNode: React.ReactNode, info: { transform: TransformType, current: number }) => React.ReactNode-5.7.0
onTransform预览图 transform 变化的回调{ transform: TransformType, action: TransformAction }-5.7.0
onChange切换预览图的回调(current: number, prevCurrent: number) => void-5.3.0
onVisibleChangevisible 发生改变时的回调(visible: boolean, prevVisible: boolean, current: number) => void-current 参数 5.3.0

Interface

TransformType

{
x: number;
y: number;
rotate: number;
scale: number;
flipX: boolean;
flipY: boolean;
}

TransformAction

type TransformAction =
| 'flipY'
| 'flipX'
| 'rotateLeft'
| 'rotateRight'
| 'zoomIn'
| 'zoomOut'
| 'close'
| 'prev'
| 'next'
| 'wheel'
| 'doubleClick'
| 'move'
| 'dragRebound';

ToolbarRenderInfoType

{
icons: {
flipYIcon: React.ReactNode;
flipXIcon: React.ReactNode;
rotateLeftIcon: React.ReactNode;
rotateRightIcon: React.ReactNode;
zoomOutIcon: React.ReactNode;
zoomInIcon: React.ReactNode;
};
actions: {
onFlipY: () => void;
onFlipX: () => void;
onRotateLeft: () => void;
onRotateRight: () => void;
onZoomOut: () => void;
onZoomIn: () => void;
};
transform: TransformType,
current: number;
total: number;
}

Design Token

组件 Token

全局 Token

  • Empty空状态List列表