Image
带有加载、回退、转换和该系列的一般视图的图像。
何时使用
图像以交互式查看方式显示缩略图:缩放、旋转、翻转和移动。 ImagePreviewGroup 将图像分组为一系列。对于没有预览的常规插图,请设置 preview:false 或使用原生 img。
CSS 图像前缀 显示全局 ConfigProvider.prefixCls 和本地 prefixCls,无需重置状态。 Image.previewPrefixCls - 完整的查看器前缀,包括显式的空字符串。 undefined 将 -preview 添加到缩略图前缀中。对于 PreviewGroup,这是基本的图像前缀:查看器添加 -preview;组缩略图独立选择其名称空间。
缩略图、加载和备用源
src 指的是缩影,preview.src 可能表示更高分辨率的原件。width/height 提前预留位置。 placeholder — 加载前的 boolean 或片段;发生错误时,fallback 会替换后备文件。
| 问题 | 机会 | 示例 |
|---|---|---|
| 打开图片 | src、preview |
主视图 |
| 显示预览内容 | placeholder |
加载中 |
| 替换备份文件 | fallback |
来源错误 |
| 将原件与微型件分开 | preview.src |
其他来源 |
| 查看剧集 | ImagePreviewGroup |
团体 |
| 打开一系列一张图片 | 显式 items |
一个微型 |
onLoad 和 onError 分别报告图片加载成功或失败。通过 placeholder.progress 传入进度值。百分比由应用提供,加载状态和错误状态仍由图片事件决定。
组开盘和索引
预览:true 使用本地状态。使用 preview.open,所有者必须接受 onOpenChange 中的新值并将其传回。对于组,还通过 onChange 更新 current。 current 从零开始,但 countRender 从 1 开始获取其编号。
该组使用显式 items 或注册的子图像。显式数组(包括空数组)优先。因此,您可以显示一个缩略图,将整个系列转移到 items 中,或者使用外部按钮打开根本没有缩略图的视图。
mask 分别指定是否存在变暗、blur 和背景闭合。 focusTrap 将焦点保持在查看器内; 模态中的示例 检查关闭后是否返回到原始操作。
转换和自己的内容
scaleStep、minScale/maxScale 限制缩放比例,wheel 控制滚轮缩放,movable 控制移动。 onTransform 通过 requestAnimationFrame 传达变换和操作。在组 actions.onActive(offset) 中采取相对步骤。
actionsRender 获取原始操作栏和查看器上下文。 imageRender 接收图像片段并进行转换。如果您使用签名或按钮补充标准操作(如 操作栏 中),请保留原始片段。
转换更改的是 CSS,而不是源文件。示例中的下载链接保留了原始链接。创建旋转文件需要单独的 Canvas 处理和启用 CORS 的源。
API 的设计和边界
Alt 描述图像;按 或 Enter 键即可打开 preview。对于装饰图片,请勿重复相邻的文本。自己的控件查看器应保留具有可访问名称的按钮。
class/style 指的是 img,styles.root 指的是缩略图包装器。 classNames.popup.root 设置单个视图或组视图的根的样式。其余语义槽在正式版本中尚未提供。六个图像设计令牌(design tokens)适用于缩略图和查看器,包括 PreviewGroup; preview.zIndex 允许您覆盖预览级别。本机节点可通过 nativeElement/imageElement 访问。
示例
行动: 不。规模: 100%.
查看图片
按或 Enter 键可打开缩放、旋转和翻转视图。
<script lang="ts">
import { Image, type ImageTransformAction } from '@woodger/antd';
let action = $state<ImageTransformAction | "不">(("不"));
let scale = $state(1);
</script>
<Image
src="/examples/image/landscape.svg"
alt={("山风景")}
width={240}
preview={{
onTransform: info => {
action = info.action;
scale = info.transform.scale;
}
}}
/>
<p
role="status"
aria-label={("图像转换")}
>{("\n 行动: ")}{action}{("。规模: ")}{(Math.round(
scale * 100
))}%.
</p>
预载
在加载主文件之前会显示带有模糊插图的片段。
<script lang="ts">
import { Button, Image } from '@woodger/antd';
let revision = $state(0);
let loaded = $state(false);
function reload() {
loaded = false;
revision++;
}
</script>
<style>
.placeholder {
position: relative;
height: 160px;
overflow: hidden;
}
.placeholder span {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: #fff;
background: rgb(0 0 0 / 35%);
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-top: 16px;
}
</style>
{#snippet placeholder()}
<div class="placeholder">
<Image
src="/examples/image/coast.svg"
alt={("")}
width={240}
height={160}
preview={false}
style="filter:blur(8px)"
/>
<span>{("加载图片...")}</span>
</div>
{/snippet}
<Image
src={`/examples/image/landscape.svg?demo=progressive&revision=${revision}`}
alt={("带预载的景观")}
width={240}
height={160}
placeholder={(placeholder)}
onLoad={() => { loaded = true; }}
/>
<div class="actions">
<Button onclick={reload}>{("再次上传")}</Button>
<span role="status" aria-label={("加载图片")}>{(loaded ? "准备好" : "加载中…")}</span>
</div>
备份图像
fallback 在解码错误的情况下替换回退文件;按钮恢复源。
<script lang="ts">
import { Button, Image } from '@woodger/antd';
let source = $state('data:image/png;base64,AA==');
let failed = $state(false);
function restore() {
failed = false;
source = '/examples/image/landscape.svg';
}
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-top: 16px;
}
</style>
<Image
src={source}
fallback="/examples/image/geometry.svg"
alt={("带有备份插图的图像")}
width={240}
onError={() => { failed = true; }}
/>
<div class="actions">
<Button onclick={restore}>{("恢复源")}</Button>
<span role="status" aria-label={("图像源状态")}>
{(failed ? "显示备份插图" : "可用原始图像")}
</span>
</div>
一般观赏
ImagePreviewGroup 组合子图像。保存了包含三张图像的评论示例。
<script lang="ts">
import { Image, ImagePreviewGroup } from '@woodger/antd';
const images = ['#1677ff', '#722ed1', '#13c2c2'].map(
(color, index) =>
({
src: 'data:image/svg+xml,' + encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="${color}"/><circle cx="450" cy="300" r="160" fill="white" opacity="0.6"/><text x="450" y="335" text-anchor="middle" font-size="100">${index
+ 1}</text></svg>`
),
alt: `图库图片 ${index + 1}`
})
);
</script>
<div style="
display: flex;
gap: 12px;
flex-wrap: wrap;
"><ImagePreviewGroup>{#each images as image}<Image
{...image}
width={140}
/>{/each}</ImagePreviewGroup></div>
微型系列
items 指定一个完整的系列,尽管页面上仅显示一张图像。
<script lang="ts">
import { Image, ImagePreviewGroup } from '@woodger/antd';
const items = [
{ src: '/examples/image/landscape.svg', alt: "系列中的山" },
{ src: '/examples/image/coast.svg', alt: "系列中的海岸" },
{ src: '/examples/image/geometry.svg', alt: "系列中的几何" }
];
</script>
<ImagePreviewGroup items={(items)}>
<Image src={items[0].src} alt={("打开一系列三张图像")} width={240} />
</ImagePreviewGroup>
单独查看源码
preview.src 与缩略图 src 不同;在应用程序中,这就是他们连接更高分辨率的原始图像的方式。
<script lang="ts">
import { Image } from '@woodger/antd';
</script>
<Image
src="/examples/image/coast.svg"
alt={("海岸的缩影,山峦尽收眼底")}
width={240}
preview={{ src: '/examples/image/landscape.svg' }}
/>
引导视图
所有者存储 open 的和 current 的、处理回调并配置计数器。
<script lang="ts">
import { Button, ImagePreviewGroup, Select } from '@woodger/antd';
let open = $state(false);
let current = $state(1);
const items = [
{ src: '/examples/image/landscape.svg', alt: "引导视图中的山脉" },
{ src: '/examples/image/coast.svg', alt: "引导视图中的海岸" },
{ src: '/examples/image/geometry.svg', alt: "头视图中的几何图形" }
];
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.field { width: 180px; }
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet counter(index: number, total: number)}{("\n 图像 ")}{(index)}{(" 从 ")}{(total)}
{/snippet}
<ImagePreviewGroup
items={(items)}
preview={{
open,
current,
countRender: counter,
onOpenChange: (next, info) => {
open = next;
current = info.current;
},
onChange: next => { current = next; }
}}
>
<div class="controls">
<div class="field">
<Select
aria-label={("初始图像")}
bind:value={current}
options={(items.map((item, value) => ({ value, label: item.alt })))}
/>
</div>
<Button onclick={() => { open = true; }}>{("视野开阔")}</Button>
</div>
</ImagePreviewGroup>
<output aria-label={("引导视图")}>{("图像: ")}{(current + 1)}{("。打开: ")}{(open ? "是的" : "不")}.</output>
自定义操作栏
actionsRender 保留了标准操作并添加了原始操作的重置和下载。
<script lang="ts">
import { Image, type ImagePreviewRenderInfo } from '@woodger/antd';
import type { Snippet } from 'svelte';
</script>
<style>
.toolbar {
display: grid;
justify-items: center;
gap: 12px;
max-width: calc(100vw - 24px);
}
.custom-actions {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 12px;
}
.custom-actions a,
.custom-actions button {
padding: 8px 12px;
border: 1px solid #fff;
border-radius: 6px;
color: #fff;
background: #262626;
font: inherit;
text-decoration: none;
}
.custom-actions a:focus-visible,
.custom-actions button:focus-visible {
outline: 2px solid #fff;
outline-offset: 2px;
}
</style>
{#snippet actions(original: Snippet, info: ImagePreviewRenderInfo)}
<div class="toolbar">
{@render original()}
<div class="custom-actions">
<button
type="button"
onclick={info.actions.onReset}
>{("重置转换")}</button>
<a href={(info.image.url)} download="landscape.svg">
{("下载原版")}
</a>
</div>
</div>
{/snippet}
<Image
src="/examples/image/landscape.svg"
alt={("具有附加动作的景观")}
width={240}
preview={{ actionsRender: actions }}
/>
查看内容
imageRender 保存原始图像并以当前比例添加标题。
<script lang="ts">
import { Image, type ImageInfo, type ImageTransform } from '@woodger/antd';
import type { Snippet } from 'svelte';
</script>
<style>
figure { display: contents; }
figcaption {
position: absolute;
top: 24px;
left: 50%;
width: min(70vw, 440px);
transform: translateX(-50%);
padding: 8px;
border-radius: 8px;
color: #fff;
background: rgb(0 0 0 / 65%);
pointer-events: none;
}
</style>
{#snippet renderImage(
original: Snippet,
info: { transform: ImageTransform; image: ImageInfo; current?: number }
)}
<figure>
{@render original()}
<figcaption>
{(info.image.alt)}{(" · 规模: ")}{(Math.round(
info.transform.scale * 100
))}%
</figcaption>
</figure>
{/snippet}
<Image
src="/examples/image/coast.svg"
alt={("海岸与签名")}
width={240}
preview={{ imageRender: renderImage }}
/>
查看背景
调光、模糊、无背景和单独的背景关闭控制。
<script lang="ts">
import { Checkbox, Image, Select } from '@woodger/antd';
let mode = $state<'dimmed' | 'blur' | 'none'>('blur');
let closable = $state(true);
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 20px;
}
.field { width: 180px; }
</style>
<div class="controls">
<div class="field">
<Select
aria-label={("查看背景图片")}
bind:value={mode}
options={([
{ value: 'blur', label: "模糊" },
{ value: 'dimmed', label: "停电" },
{ value: 'none', label: "无背景" }
])}
/>
</div>
<Checkbox bind:checked={closable}>{("靠近背景")}</Checkbox>
</div>
<Image
src="/examples/image/geometry.svg"
alt={("具有背景定制的几何图形")}
width={240}
preview={{ mask: { enabled: mode !== 'none', blur: mode === 'blur', closable } }}
/>
微型签名
coverNode 和 placement 指定悬停或焦点时标题的内容和位置。
<script lang="ts">
import { Image } from '@woodger/antd';
</script>
{#snippet cover()}<span>{("打开图片 ↗")}</span>{/snippet}
<Image
src="/examples/image/coast.svg"
alt={("带有悬停标题的海岸")}
width={240}
preview={{ cover: { coverNode: cover, placement: 'bottom' } }}
/>
语义风格
styles.root 设计缩略图包装器,class/style - img,classNames.popup.root - 个人或组查看。剩余的语义槽尚未转移。
<script lang="ts">
import { Image, ImagePreviewGroup } from '@woodger/antd';
const items = [
{ src: '/examples/image/landscape.svg', alt: "形成群山" },
{ src: '/examples/image/coast.svg', alt: "在正式团体中海岸" }
];
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
align-items: start;
gap: 24px;
}
figure {
display: grid;
gap: 8px;
margin: 0;
}
figcaption { color: var(--ant-color-text-secondary); }
:global(.image-semantic-single) {
outline: 3px solid var(--ant-color-success);
outline-offset: -3px;
}
:global(.image-semantic-group) {
outline: 3px solid var(--ant-color-primary);
outline-offset: -3px;
}
</style>
<div class="examples">
<figure>
<Image
src="/examples/image/landscape.svg"
alt={("具有不同样式的图像")}
width={160}
rootClassName="image-semantic-thumbnail"
class="image-semantic-image"
style="border-radius:4px"
styles={{ root: `
border: 2px dashed var(--ant-color-success);
border-radius: 12px;
` }}
classNames={{ popup: { root: 'image-semantic-single' } }}
/>
<figcaption>{("缩略图并查看")}</figcaption>
</figure>
<figure>
<ImagePreviewGroup items={(items)} classNames={{
popup: {
root: 'image-semantic-group'
}
}}>
<Image src="/examples/image/landscape.svg" alt={("组团观看设计")} width={160} />
</ImagePreviewGroup>
<figcaption>{("该系列的一般观看")}</figcaption>
</figure>
</div>
查看模态内部
在模式窗口顶部打开并在关闭视图后返回焦点。
<script lang="ts">
import { Button, Image, Modal } from '@woodger/antd';
let open = $state(false);
</script>
<Button onclick={() => { open = true; }}>{("打开图像窗口")}</Button>
<Modal bind:open title={("模态内的图像")} footer={null}>
<p>{("视野开阔。 Escape 首先关闭图像并将焦点返回到缩略图。")}</p>
<Image
src="/examples/image/coast.svg"
alt={("莫代尔内的海岸")}
width={240}
/>
</Modal>
组件代币
本地缩略图主题和查看器、ImagePreviewGroup、CSS 变量和 preview.zIndex 优先级。
<script lang="ts">
import { Checkbox, ConfigProvider, Image, ImagePreviewGroup } from '@woodger/antd';
let named = $state(false);
let explicitLayer = $state(false);
const items = [
{ src: '/examples/image/landscape.svg', alt: "主题组中的山脉" },
{ src: '/examples/image/coast.svg', alt: "主题组中的海岸" }
];
</script>
<style>
.settings {
display: grid;
justify-items: start;
gap: 12px;
margin-bottom: 20px;
}
.images {
display: flex;
flex-wrap: wrap;
align-items: start;
gap: 20px;
}
figure {
display: grid;
gap: 8px;
margin: 0;
}
figcaption { color: var(--ant-color-text-secondary); }
</style>
<div class="settings">
<Checkbox bind:checked={named}>{("命名 CSS 图像变量")}</Checkbox>
<Checkbox bind:checked={explicitLayer}>{("显式预览.zIndex=2300")}</Checkbox>
</div>
<ConfigProvider theme={{
cssVar: named ? { key: 'image-tokens-demo', prefix: 'image-tokens-demo' } : undefined,
components: {
Image: {
previewOperationSize: 30,
previewOperationColor: '#722ed1',
previewOperationHoverColor: '#fa8c16',
previewOperationColorDisabled: '#595959',
zIndexPopup: 2100,
progressAnimationDuration: '9s'
}
}
}}>
<div class="images">
<figure>
<Image
src="/examples/image/landscape.svg"
alt={("当地主题图片")}
width={160}
preview={{ zIndex: explicitLayer ? 2300 : undefined }}
/>
<figcaption>{("单幅图像")}</figcaption>
</figure>
<figure>
<ImagePreviewGroup items={(items)} preview={{
zIndex: explicitLayer ? 2300 : undefined
}}>
<Image
src="/examples/image/landscape.svg"
alt={("本地群组主题")}
width={160}
/>
</ImagePreviewGroup>
<figcaption>{("两个图像组")}</figcaption>
</figure>
</div>
</ConfigProvider>
打开图像进行缩放、旋转和移动。
评论中的景观
使用本地数据 URL 保存示例。
<script lang="ts">
import { Image } from '@woodger/antd';
const source = 'data:image/svg+xml,' + encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800"><rect width="1200" height="800" fill="#1677ff"/><circle cx="850" cy="220" r="90" fill="#fff"/><path d="M0 800 400 300 700 700 950 400 1200 800" fill="#0958d9"/></svg>'
);
</script>
<Image src={source} alt={("风景可观赏")} width={240} />
<p>{("打开图像进行缩放、旋转和移动。")}</p>
Image.previewPrefixCls - 完整的查看器前缀,包括显式的空字符串。 Undefined 将 -preview 添加到缩略图前缀中。对于 PreviewGroup,这是基本的图像前缀:查看器添加 -preview;组缩略图独立选择其名称空间。
CSS 图像前缀
通用命名空间ConfigProvider和本地 prefixCls;当名称更改时,组件的状态将被保留。
<script lang="ts">
import { Checkbox, ConfigProvider, Image, ImagePreviewGroup } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-image' : '');
let independent = $state(true);
let scale = $state(1);
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("通用前缀图像套件")}</Checkbox>
<Checkbox bind:checked={local}>{("本地前缀图片")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'image-theme' } }}>
<div class="prefix-stage">
<Checkbox
bind:checked={independent}
>{("独立视图前缀图像")}</Checkbox>
<Image prefixCls={localPrefix} previewPrefixCls={independent ? 'project-viewer' : undefined}
src="/examples/image/landscape.svg" alt={("带前缀的风景")} width={200}
preview={{ onTransform: info => scale = info.transform.scale }} />
<ImagePreviewGroup previewPrefixCls={local ? 'project-gallery' : undefined}>
<Image src="/examples/image/landscape.svg" alt={("带前缀的画廊,第一帧")} width={120} />
<Image src="/examples/image/coast.svg" alt={("带前缀的画廊,第二帧")} width={120} />
</ImagePreviewGroup>
<output
aria-label={("带前缀的图像比例")}
>{("规模: ")}{(Math.round(scale * 100))}%</output>
</div>
</ConfigProvider>
<output
aria-label={("CSS 前缀图像")}
>{("一般的: ")}{prefix}{(";当地的: ")}{(localPrefix
|| ("来自提供商"))}</output>
<p>
{("Image.previewPrefixCls - 完整的查看器前缀,包括显式的空字符串。 Undefined 将 -preview 添加到缩略图前缀中。对于 PreviewGroup,这是基本的图像前缀:查看器添加 -preview;组缩略图独立选择其名称空间。")}
</p>
</div>
API
示例主题已针对 ant.design 6.7.0 进行验证; Svelte API - 带有基于 6.6.8 的安装包。 Props 的完整定义属于 @woodger/antd。所有示例图像都存储在本地。
| 主题 | 示例或限制 |
|---|---|
| Basic Usage | 使用键盘和鼠标查看。 |
| Progressive Loading | placeholder 接受 Snippet 或由应用提供的 progress。 |
| Fault tolerant | 备用文件和 src 恢复。 |
| Multiple image preview | 注册儿童图像。 |
| Preview from one image | 明确的 items,一张缩略图。 |
| Custom preview image | 独立 preview.src。 |
| Controlled Preview | open/current, callbacks, countRender. |
| Custom toolbar render | 片段 actionsRender、重置和下载原始片段。尚未添加转换后的画布导出。 |
| Custom preview render | 保留原始 imageRender。 |
| preview mask | mask.enabled、blur 和 closable。 |
| Custom semantic dom styling | 部分:Image 的 styles.root 和 Image/PreviewGroup 的 classNames.popup.root。剩余的插槽尚未可用。 |
| nested | 查看模态。 |
Image
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
previewPrefixCls | 完整的查看者前缀; undefined 将 -preview 添加到已解析的 Image.prefixCls 中。保留显式空字符串。命名空间样式包含在库中。 | string | Image prefixCls + "-preview" |
prefixCls | 组件及其部件的完整 CSS 前缀。非空本地 prop 优先;空字符串和 undefined 继承ConfigProvider。主题的命名空间是单独设置的。 | string | ConfigProvider.prefixCls + "-image" |
src | 缩略图网址;本机 srcset、大小、loading 和 referrerpolicy 也可用。 | string | — |
alt | 视图按钮的图片和名称的描述。 | string | — |
width | 缩略图宽度。 | number | string | — |
height | 缩略图高度。 | number | string | — |
preview | 查看设置; false 留下正常图像。 | boolean | ImagePreviewConfig | true |
placeholder | true 启用内置占位背景。加载时可显示 Snippet 或 progress。 | boolean | Snippet | { progress? } | — |
fallback | 发生错误时缩略图和预览的后备 URL。 | string | — |
onError | 加载或解码缩略图时出错。 | (event: Event) => void | — |
onLoad | 加载缩略图,包括 fallback。 | (event: Event) => void | — |
styles | 缩略图根包装 CSS 字符串。 | { root?: string } | — |
classNames | 个人视图根类。对于一般查看,将其设置为 ImagePreviewGroup。 | { popup?: { root?: string } } | — |
style | img 风格;class 也适用于 img。 | string | — |
nativeElement | bind:nativeElement - 缩略图容器。 | HTMLElement | 安装后 |
imageElement | bind:imageElement - 原生 img。 | HTMLImageElement | 安装后 |
图像预览
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
src | 独立查看器 URL。 | string | src Image |
alt | 描述预览中的图片。非空文本还会设置对话框的无障碍名称。 | string | alt Image |
getContainer | 预览容器。函数在浏览器中调用,不接收参数。 | GetContainer | ConfigProvider.getPopupContainer |
open | 控制能见度。在 onOpenChange 中更新它。 | boolean | 当地国家 |
onOpenChange | 请求更改可见性。 | (open: boolean) => void | — |
afterOpenChange | 动画结束后报告可见状态。 | (open: boolean) => void | — |
onTransform | 变换后的状态;回调是通过 requestAnimationFrame 传递的。 | ({ transform, action }) => void | — |
scaleStep | 单步乘数:1+scaleStep。 | number | 0.5 |
minScale | 最小规模。 | number | 1 |
maxScale | 最大规模。 | number | 50 |
wheel | 用鼠标滚轮缩放。 | boolean | true |
movable | 拖动放大的图像。 | boolean | true |
focusTrap | 具有焦点保持的模态对话框。 | boolean | true |
mask | 背景和关闭它。 | boolean | { enabled?, blur?, closable? } | true |
cover | 缩略图标题, false 隐藏它。 | boolean | Snippet | { coverNode?, placement? } | 标准面积 |
actionsRender | 操作栏和带有变换、image 和操作的上下文。 | Snippet<[original, info]> | 标准动作 |
imageRender | 查看内容;原始保留了内置的转换。 | Snippet<[original, info]> | 图像 |
zIndex | 显式图层对话框。 | number | 1080 |
ImagePreviewGroup
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
previewPrefixCls | 用于一般查看的基本图像前缀:查看器添加 -preview。空字符串/undefined 继承了常见的Image前缀。不重命名缩略图。 | string | ConfigProvider.prefixCls + "-image" |
classNames | 一般视图根类。 | { popup?: { root?: string } } | — |
items | URL 字符串或具有本机 img 字段的对象。即使是空数组也优先于子注册。 | readonly ImagePreviewGroupItem[] | 儿童图片 |
preview | 一般查看设置; false 禁用打开。 | boolean | ImagePreviewGroupConfig | true |
fallback | 通用查看器备份文件。 | string | — |
预览组添加
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
current | 从头开始管理索引。 | number | 0 |
onChange | 要求更改图像;保存新索引。 | (current, previous) => void | — |
onOpenChange | 具有图像索引的可见性。 | (open, { current }) => void | — |
countRender | 与 current 不同,countRender 中的数字从 1 开始。 | Snippet<[current, total]> | 数量/总计 |
使用 Image.PreviewGroup 或具名导出的 ImagePreviewGroup 预览一组图片。preview.getContainer 选择预览容器,preview.alt 描述打开的图片。
Semantic DOM
缩略图 - 带 img 的原生按钮;在 preview={false} 容器变成了一个div。该视图使用对话框、图像、背景、关闭和转换按钮。使用 Enter 或空格键打开该按钮; Escape 关闭视图并返回焦点。
在上游,root、image、cover 和 popup.root/mask/body/footer/actions/close 可用。苗条的 styles.root 设计微型包装纸,并且 classNames.popup.root
指定视图根的类。这些字段接受对象;回调和其他插槽尚不可用。
style 和 class 参考 img, rootClassName - 到包装纸。
actionsRender 和 imageRender 接收片段形式的原始内容。称呼 original() 保存内联操作或带有转换的图像。
注册令牌
theme.components.Image 将六个标记应用于缩略图和查看器,包括 ImagePreviewGroup。该示例显示了操作大小和颜色、自定义 zIndexPopup 以及命名的 CSS 变量。显式的 preview.zIndex
优先于主题标记。
progressAnimationDuration 指定 CSS 持续时间变量。目的
placeholder.progress 尚未传输,因此还没有单独的进度动画示例。
| 代币 | 目的 |
|---|---|
zIndexPopup | 视图层。 |
previewOperationSize | 操作图标大小。 |
previewOperationColor | 动作颜色。 |
previewOperationHoverColor | 悬停动作颜色。 |
previewOperationColorDisabled | 不可用操作的颜色。 |
progressAnimationDuration | 加载动画持续时间;进度 API 尚未迁移。 |
| 代币 | 意义 |
|---|---|
colorBgMask | rgba(0,0,0,0.45) |
colorTextLightSolid | #fff |
colorTextSecondary | rgba(0,0,0,0.65) |
colorPrimaryBorder | #adc6ff |
fontSize | 14 |
marginXL | 32 |
motionDurationSlow | 0.3s |
FAQ
如何在没有所有微缩模型的情况下打开一个系列?
将 items 设置为 ImagePreviewGroup。具有受控打开功能的子图像或外部按钮将 open 整个系列。
为什么控制 open 时视图不关闭?
更新在 onOpenChange 中 open。对于托管索引,以相同的方式处理 onChange。
旋转后的图片会下载吗?
否。示例下载源文件; CSS 转换不会改变其内容。
如何显示加载和错误?
placeholder 在加载前可见,fallback 替换失败的源。提前保留缩略图尺寸。