2020-08-22 22:02:20 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: Data Display
|
2020-08-22 22:02:20 +08:00
|
|
|
|
title: Image
|
2024-03-22 14:22:42 +08:00
|
|
|
|
description: Preview-able image.
|
2020-08-22 22:02:20 +08:00
|
|
|
|
cols: 2
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*FbOCS6aFMeUAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*LVQ3R5JjjJEAAAAAAAAAAAAADrJ8AQ/original
|
2020-08-22 22:02:20 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## When To Use
|
|
|
|
|
|
|
|
|
|
- When you need to display pictures.
|
|
|
|
|
- Display when loading a large image or fault tolerant handling when loading fail.
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## Examples
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">Basic Usage</code>
|
|
|
|
|
<code src="./demo/fallback.tsx">Fault tolerant</code>
|
|
|
|
|
<code src="./demo/placeholder.tsx">Progressive Loading</code>
|
|
|
|
|
<code src="./demo/preview-group.tsx">Multiple image preview</code>
|
|
|
|
|
<code src="./demo/preview-group-visible.tsx">Preview from one image</code>
|
|
|
|
|
<code src="./demo/previewSrc.tsx">Custom preview image</code>
|
|
|
|
|
<code src="./demo/controlled-preview.tsx">Controlled Preview</code>
|
2023-06-21 19:58:28 +08:00
|
|
|
|
<code src="./demo/toolbarRender.tsx">Custom toolbar render</code>
|
|
|
|
|
<code src="./demo/imageRender.tsx">Custom preview render</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/preview-mask.tsx" debug>Custom preview mask</code>
|
2023-11-24 16:17:52 +08:00
|
|
|
|
<code src="./demo/nested.tsx">nested</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/preview-group-top-progress.tsx" debug>Top progress customization when previewing multiple images</code>
|
2023-06-02 15:48:18 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>Custom component token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2020-08-22 22:02:20 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
Common props ref:[Common props](/docs/react/common-props)
|
|
|
|
|
|
2023-06-21 19:58:28 +08:00
|
|
|
|
### Image
|
|
|
|
|
|
2020-08-22 22:02:20 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| alt | Image description | string | - | 4.6.0 |
|
|
|
|
|
| fallback | Load failure fault-tolerant src | string | - | 4.6.0 |
|
|
|
|
|
| height | Image height | string \| number | - | 4.6.0 |
|
|
|
|
|
| placeholder | Load placeholder, use default placeholder when set `true` | ReactNode | - | 4.6.0 |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| preview | preview config, disabled when `false` | boolean \| [PreviewType](#previewtype) | true | 4.6.0 [PreviewType](#previewtype):4.7.0 |
|
2020-08-22 22:02:20 +08:00
|
|
|
|
| src | Image path | string | - | 4.6.0 |
|
|
|
|
|
| width | Image width | string \| number | - | 4.6.0 |
|
2021-02-02 13:35:37 +08:00
|
|
|
|
| onError | Load failed callback | (event: Event) => void | - | 4.12.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
|
|
|
|
|
Other attributes [<img>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#Attributes)
|
|
|
|
|
|
|
|
|
|
### PreviewType
|
|
|
|
|
|
2023-11-05 10:30:29 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| visible | Whether the preview dialog is visible or not | boolean | - | - |
|
|
|
|
|
| src | Custom preview src | string | - | 4.10.0 |
|
|
|
|
|
| getContainer | The mounted node for preview dialog but still display at fullScreen | string \| HTMLElement \| (() => HTMLElement) \| false | - | 4.8.0 |
|
2023-07-26 16:28:49 +08:00
|
|
|
|
| movable | whether can be moved | boolean | true | 5.8.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| mask | Thumbnail mask | ReactNode | - | 4.9.0 |
|
|
|
|
|
| maskClassName | The className of the mask | string | - | 4.11.0 |
|
|
|
|
|
| rootClassName | The classname of the preview root DOM | string | - | 5.4.0 |
|
|
|
|
|
| scaleStep | `1 + scaleStep` is the step to increase or decrease the scale | number | 0.5 | - |
|
|
|
|
|
| minScale | Min scale | number | 1 | 5.7.0 |
|
|
|
|
|
| maxScale | Max scale | number | 50 | 5.7.0 |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| closeIcon | Custom close icon | React.ReactNode | - | 5.7.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| forceRender | Force render preview dialog | boolean | - | - |
|
2023-08-09 11:52:35 +08:00
|
|
|
|
| toolbarRender | Custom toolbar render | (originalNode: React.ReactElement, info: Omit<[ToolbarRenderInfoType](#toolbarrenderinfotype), 'current' \| 'total'>) => React.ReactNode | - | 5.7.0 |
|
|
|
|
|
| imageRender | Custom preview content | (originalNode: React.ReactElement, info: { transform: [TransformType](#transformtype) }) => React.ReactNode | - | 5.7.0 |
|
2024-05-08 19:05:50 +08:00
|
|
|
|
| destroyOnClose | Destroy child elements when closing preview | boolean | false | |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| onTransform | Callback when the transform of image changed | { transform: [TransformType](#transformtype), action: [TransformAction](#transformaction) } | - | 5.7.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| onVisibleChange | Callback when `visible` changed | (visible: boolean, prevVisible: boolean) => void | - | - |
|
|
|
|
|
|
|
|
|
|
## PreviewGroup
|
|
|
|
|
|
2023-11-05 10:30:29 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| --- | --- | --- | --- | --- |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| preview | Preview config, `disabled` when false | boolean \| [PreviewGroupType](#previewgrouptype) | true | 4.6.0 [PreviewGroupType](#previewgrouptype):4.7.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| items | Preview items | string[] \| { src: string, crossOrigin: string, ... }[] | - | 5.7.0 |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| fallback | Load failure fault-tolerant src | string | - | 5.7.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
|
|
|
|
|
### PreviewGroupType
|
|
|
|
|
|
2023-11-05 10:30:29 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| visible | Whether the preview dialog is visible or not | boolean | - | - |
|
|
|
|
|
| getContainer | The mounted node for preview dialog but still display at fullScreen | string \| HTMLElement \| (() => HTMLElement) \| false | - | 4.8.0 |
|
2023-07-26 16:28:49 +08:00
|
|
|
|
| movable | whether can be moved | boolean | true | 5.8.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| current | The index of the current preview | number | - | 4.12.0 |
|
|
|
|
|
| mask | Thumbnail mask | ReactNode | - | 4.9.0 |
|
|
|
|
|
| maskClassName | The className of the mask | string | - | 4.11.0 |
|
|
|
|
|
| rootClassName | The classname of the preview root DOM | string | - | 5.4.0 |
|
|
|
|
|
| scaleStep | `1 + scaleStep` is the step to increase or decrease the scale | number | 0.5 | - |
|
|
|
|
|
| minScale | Min scale | number | 1 | 5.7.0 |
|
|
|
|
|
| maxScale | Max scale | number | 50 | 5.7.0 |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| closeIcon | Custom close icon | React.ReactNode | - | 5.7.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| forceRender | Force render preview dialog | boolean | - | - |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| countRender | Custom preview count content | (current: number, total: number) => React.ReactNode | - | 4.20.0 |
|
2023-08-09 11:52:35 +08:00
|
|
|
|
| toolbarRender | Custom toolbar render | (originalNode: React.ReactElement, info: [ToolbarRenderInfoType](#toolbarrenderinfotype)) => React.ReactNode | - | 5.7.0 |
|
|
|
|
|
| imageRender | Custom preview content | (originalNode: React.ReactElement, info: { transform: [TransformType](#transformtype), current: number }) => React.ReactNode | - | 5.7.0 |
|
2023-07-07 09:54:19 +08:00
|
|
|
|
| onTransform | Callback when the transform of image changed | { transform: [TransformType](#transformtype), action: [TransformAction](#transformaction) } | - | 5.7.0 |
|
2023-06-21 19:58:28 +08:00
|
|
|
|
| onChange | Callback when switch preview image | (current: number, prevCurrent: number) => void | - | 5.3.0 |
|
2023-11-05 10:30:29 +08:00
|
|
|
|
| onVisibleChange | Callback when `visible` changed | (visible: boolean, prevVisible: boolean, current: number) => void | - | current Property 5.3.0 |
|
2020-08-22 22:02:20 +08:00
|
|
|
|
|
2023-06-21 19:58:28 +08:00
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
|
|
### TransformType
|
2020-09-28 14:15:23 +08:00
|
|
|
|
|
2023-02-21 21:21:51 +08:00
|
|
|
|
```typescript
|
2020-09-28 14:15:23 +08:00
|
|
|
|
{
|
2023-06-21 19:58:28 +08:00
|
|
|
|
x: number;
|
|
|
|
|
y: number;
|
|
|
|
|
rotate: number;
|
|
|
|
|
scale: number;
|
|
|
|
|
flipX: boolean;
|
|
|
|
|
flipY: boolean;
|
2020-09-28 14:15:23 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-21 19:58:28 +08:00
|
|
|
|
### TransformAction
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
type TransformAction =
|
|
|
|
|
| 'flipY'
|
|
|
|
|
| 'flipX'
|
|
|
|
|
| 'rotateLeft'
|
|
|
|
|
| 'rotateRight'
|
|
|
|
|
| 'zoomIn'
|
|
|
|
|
| 'zoomOut'
|
|
|
|
|
| 'close'
|
|
|
|
|
| 'prev'
|
|
|
|
|
| 'next'
|
|
|
|
|
| 'wheel'
|
|
|
|
|
| 'doubleClick'
|
|
|
|
|
| 'move'
|
|
|
|
|
| 'dragRebound';
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### ToolbarRenderInfoType
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
```
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
## Design Token
|
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Image"></ComponentTokenTable>
|