Image
提供经典 rounded、polaroid 与 circle 样式以及无障碍语义和加载状态追踪的 Duostrap 图像组件。
Duostrap Image 保留归档版本的 .img-rounded、.img-polaroid 与 .img-circle 视觉修饰,同时通过 Base Image 协议统一管理资源地址、填充模式、无障碍语义与实时加载状态。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="grid max-w-2xl grid-cols-4 gap-4">
<wc-duostrap-image-root
source="/images/base-image/portrait.svg"
alternative-text="Default image"
fit="cover"
appearance="default"
></wc-duostrap-image-root>
<wc-duostrap-image-root
source="/images/base-image/portrait.svg"
alternative-text="Rounded image"
fit="cover"
appearance="rounded"
></wc-duostrap-image-root>
<wc-duostrap-image-root
source="/images/base-image/portrait.svg"
alternative-text="Polaroid image"
fit="cover"
appearance="polaroid"
></wc-duostrap-image-root>
<wc-duostrap-image-root
source="/images/base-image/portrait.svg"
alternative-text="Circle image"
fit="cover"
appearance="circle"
></wc-duostrap-image-root>
</div>将于 0.3.0-rc.1 及后续版本中提供。可直接从 @proto.ui/prototypes-duostrap/image 导入 imageRoot(别名 duostrapImageRoot)与 DuostrapImageRootProps。
import * as React from 'react';import { createReactAdapter } from '@proto.ui/adapter-react';import { duostrapImageRoot } from '@proto.ui/prototypes-duostrap/image';
const BootstrapImage = createReactAdapter(React)(duostrapImageRoot);
export function FramedPortrait() { return ( <BootstrapImage source="/images/base-image/portrait.svg" a11yMode="informative" alternativeText="经典拍立得边框人像插图" fit="cover" appearance="polaroid" surfaceStyle={{ width: '160px', height: '160px' }} /> );}- 外观变体(
appearance):default:响应式无边框图像(max-w-full h-auto align-middle border-0)。rounded:经典6px圆角(.img-rounded)。polaroid:4px白色内边距、1px rgba(0, 0, 0, 0.2)外框与柔和投影(.img-polaroid)。circle:历史版本500px圆角(.img-circle),建议配合 1:1 正方形尺寸呈现正圆效果。
- 无障碍与加载状态:
a11yMode、alternativeText、fit、loadingStatus与loadingStatusChange均继承自 Base Image。
搭配 appearance="rounded" 对比 contain、cover 与 fill。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="grid max-w-2xl grid-cols-3 gap-4">
<wc-duostrap-image-root
source="/images/base-image/landscape.svg"
alternative-text="Mountain ridge (contain)"
fit="contain"
appearance="rounded"
></wc-duostrap-image-root>
<wc-duostrap-image-root
source="/images/base-image/landscape.svg"
alternative-text="Mountain ridge (cover)"
fit="cover"
appearance="rounded"
></wc-duostrap-image-root>
<wc-duostrap-image-root
source="/images/base-image/landscape.svg"
alternative-text="Mountain ridge (fill)"
fit="fill"
appearance="rounded"
></wc-duostrap-image-root>
</div>分别使用 polaroid 展示信息性配图、使用 1:1 circle 展示装饰性缩略图。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex max-w-xl flex-col gap-4">
<wc-duostrap-image-root
source="/images/base-image/landscape.svg"
a11y-mode="informative"
alternative-text="Sunlit mountain ridge"
fit="cover"
appearance="polaroid"
></wc-duostrap-image-root>
<wc-duostrap-image-root
source="/images/base-image/portrait.svg"
a11y-mode="decorative"
fit="cover"
appearance="circle"
></wc-duostrap-image-root>
</div>加载与错误回退
Section titled “加载与错误回退”结合 Duostrap 按钮切换资源地址,并在加载失败或清空时显示应用层回退提示与重试按钮。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex max-w-lg flex-col gap-4">
<wc-duostrap-image-root
source="/images/base-image/landscape.svg"
a11y-mode="informative"
alternative-text="Selected landscape scene"
fit="cover"
appearance="polaroid"
></wc-duostrap-image-root>
<div class="flex flex-wrap gap-2">
<wc-duostrap-button variant="primary" size="small">
Landscape
</wc-duostrap-button>
<wc-duostrap-button variant="default" size="small">
Portrait
</wc-duostrap-button>
<wc-duostrap-button variant="danger" size="small">
Broken URL
</wc-duostrap-button>
</div>
</div>Root Props
Section titled “Root Props”| 属性 | 类型 | 默认值 |
|---|---|---|
source | string undefined | undefined |
a11yMode | 'informative' 'decorative' | informative |
alternativeText | string | '' |
fit | 'contain' 'cover' 'fill' | contain |
appearance | 'default' 'rounded' 'polaroid' 'circle' | default |
暴露状态与事件
Section titled “暴露状态与事件”| 名称 | 类型 | 说明 |
|---|---|---|
source | ExposeState<string> | 当前生效的图片源 URI |
fit | ExposeState<'contain' 'cover' 'fill'> | 当前缩放填充模式 |
loadingStatus | ExposeState<'idle' 'loading' 'loaded' 'error'> | 当前加载生命周期状态 |
loadingStatusChange | ExposeEvent<{ status, previousStatus, source }> | 加载状态变化时触发(React/Vue 中可绑定 onLoadingStatusChange) |