@fibrae/semi-ui-svelte 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -4
- package/README.zh-CN.md +8 -4
- package/dist/components/anchor/interface.d.ts +14 -0
- package/dist/components/audio-player/interface.d.ts +5 -0
- package/dist/components/auto-complete/interface.d.ts +29 -0
- package/dist/components/avatar/interface.d.ts +24 -0
- package/dist/components/backtop/interface.d.ts +2 -0
- package/dist/components/badge/interface.d.ts +7 -0
- package/dist/components/banner/interface.d.ts +7 -0
- package/dist/components/breadcrumb/interface.d.ts +10 -0
- package/dist/components/button/interface.d.ts +18 -0
- package/dist/components/calendar/interface.d.ts +16 -0
- package/dist/components/card/interface.d.ts +18 -0
- package/dist/components/carousel/interface.d.ts +16 -0
- package/dist/components/cascader/cascader.svelte +1 -0
- package/dist/components/cascader/interface.d.ts +57 -0
- package/dist/components/checkbox/interface.d.ts +19 -0
- package/dist/components/code-highlight/interface.d.ts +3 -0
- package/dist/components/collapse/interface.d.ts +16 -0
- package/dist/components/collapsible/interface.d.ts +10 -0
- package/dist/components/color-picker/interface.d.ts +10 -0
- package/dist/components/config-provider/interface.d.ts +7 -0
- package/dist/components/cropper/interface.d.ts +11 -0
- package/dist/components/date-picker/interface.d.ts +47 -0
- package/dist/components/descriptions/interface.d.ts +6 -0
- package/dist/components/divider/interface.d.ts +4 -0
- package/dist/components/dropdown/interface.d.ts +8 -0
- package/dist/components/empty/interface.d.ts +7 -0
- package/dist/components/feedback/interface.d.ts +16 -0
- package/dist/components/float-button/interface.d.ts +14 -0
- package/dist/components/form/interface.d.ts +47 -0
- package/dist/components/form/label.svelte +2 -2
- package/dist/components/grid/interface.d.ts +13 -0
- package/dist/components/highlight/interface.d.ts +7 -0
- package/dist/components/hot-keys/interface.d.ts +3 -0
- package/dist/components/image/interface.d.ts +59 -0
- package/dist/components/input/interface.d.ts +67 -0
- package/dist/components/input-number/interface.d.ts +24 -0
- package/dist/components/json-viewer/interface.d.ts +7 -0
- package/dist/components/layout/interface.d.ts +3 -0
- package/dist/components/list/interface.d.ts +18 -0
- package/dist/components/locale/interface.d.ts +4 -0
- package/dist/components/lottie/interface.d.ts +2 -0
- package/dist/components/markdown-render/interface.d.ts +5 -0
- package/dist/components/modal/interface.d.ts +29 -0
- package/dist/components/navigation/interface.d.ts +47 -0
- package/dist/components/overflow-list/interface.d.ts +11 -0
- package/dist/components/pagination/interface.d.ts +12 -0
- package/dist/components/pincode/interface.d.ts +8 -0
- package/dist/components/popconfirm/interface.d.ts +12 -0
- package/dist/components/popover/interface.d.ts +30 -0
- package/dist/components/progress/interface.d.ts +13 -0
- package/dist/components/radio/interface.d.ts +22 -0
- package/dist/components/rating/interface.d.ts +12 -0
- package/dist/components/resizable/interface.d.ts +30 -0
- package/dist/components/scroll-list/interface.d.ts +6 -0
- package/dist/components/select/interface.d.ts +63 -0
- package/dist/components/side-sheet/interface.d.ts +19 -0
- package/dist/components/skeleton/interface.d.ts +7 -0
- package/dist/components/slider/interface.d.ts +23 -0
- package/dist/components/space/interface.d.ts +4 -0
- package/dist/components/spin/interface.d.ts +7 -0
- package/dist/components/steps/interface.d.ts +9 -0
- package/dist/components/switch/interface.d.ts +7 -0
- package/dist/components/table/interface.d.ts +48 -0
- package/dist/components/tabs/interface.d.ts +29 -0
- package/dist/components/tag/interface.d.ts +22 -0
- package/dist/components/tag-input/interface.d.ts +29 -0
- package/dist/components/time-picker/interface.d.ts +31 -0
- package/dist/components/timeline/interface.d.ts +5 -0
- package/dist/components/tooltip/interface.d.ts +20 -0
- package/dist/components/tooltip/tooltip.svelte +3 -0
- package/dist/components/transfer/interface.d.ts +18 -0
- package/dist/components/tree/interface.d.ts +45 -0
- package/dist/components/tree-select/interface.d.ts +55 -0
- package/dist/components/typography/interface.d.ts +33 -0
- package/dist/components/upload/interface.d.ts +64 -0
- package/dist/components/user-guide/interface.d.ts +15 -0
- package/dist/components/video-player/interface.d.ts +22 -0
- package/dist/styles.css +1 -1
- package/docs/advanced/dark-mode.md +288 -0
- package/docs/basic/button.md +605 -0
- package/docs/basic/divider.md +103 -0
- package/docs/basic/float-button.md +246 -0
- package/docs/basic/grid.md +427 -0
- package/docs/basic/layout.md +459 -0
- package/docs/basic/resizable.md +584 -0
- package/docs/basic/space.md +163 -0
- package/docs/basic/tokens.md +425 -0
- package/docs/basic/typography.md +615 -0
- package/docs/changes-from-semi.md +105 -0
- package/docs/ecosystem/tailwind.md +210 -0
- package/docs/experience/accessibility.md +82 -0
- package/docs/experience/content-guidelines.md +819 -0
- package/docs/experience/internationalization.md +7 -0
- package/docs/feedback/banner.md +198 -0
- package/docs/feedback/feedback.md +294 -0
- package/docs/feedback/notification.md +401 -0
- package/docs/feedback/popconfirm.md +243 -0
- package/docs/feedback/progress.md +389 -0
- package/docs/feedback/skeleton.md +388 -0
- package/docs/feedback/spin.md +172 -0
- package/docs/feedback/toast.md +393 -0
- package/docs/input/auto-complete.md +399 -0
- package/docs/input/cascader.md +1558 -0
- package/docs/input/checkbox.md +408 -0
- package/docs/input/color-picker.md +175 -0
- package/docs/input/date-picker.md +942 -0
- package/docs/input/form.md +2550 -0
- package/docs/input/input-number.md +451 -0
- package/docs/input/input.md +640 -0
- package/docs/input/pincode.md +191 -0
- package/docs/input/radio.md +337 -0
- package/docs/input/rating.md +214 -0
- package/docs/input/select.md +1230 -0
- package/docs/input/slider.md +347 -0
- package/docs/input/switch.md +206 -0
- package/docs/input/tag-input.md +465 -0
- package/docs/input/time-picker.md +358 -0
- package/docs/input/transfer.md +1061 -0
- package/docs/input/tree-select.md +1300 -0
- package/docs/input/upload.md +1811 -0
- package/docs/llms.txt +147 -0
- package/docs/navigation/anchor.md +377 -0
- package/docs/navigation/backtop.md +100 -0
- package/docs/navigation/breadcrumb.md +284 -0
- package/docs/navigation/navigation.md +851 -0
- package/docs/navigation/pagination.md +217 -0
- package/docs/navigation/steps.md +315 -0
- package/docs/navigation/tabs.md +754 -0
- package/docs/navigation/tree.md +1956 -0
- package/docs/other/config-provider.md +599 -0
- package/docs/other/locale.md +353 -0
- package/docs/plus/audio-player.md +155 -0
- package/docs/plus/code-highlight.md +150 -0
- package/docs/plus/drag-move.md +214 -0
- package/docs/plus/hot-keys.md +174 -0
- package/docs/plus/json-viewer.md +392 -0
- package/docs/plus/lottie.md +176 -0
- package/docs/plus/markdown-render.md +240 -0
- package/docs/plus/video-player.md +325 -0
- package/docs/show/avatar.md +475 -0
- package/docs/show/badge.md +276 -0
- package/docs/show/calendar.md +352 -0
- package/docs/show/card.md +485 -0
- package/docs/show/carousel.md +592 -0
- package/docs/show/collapse.md +289 -0
- package/docs/show/collapsible.md +216 -0
- package/docs/show/cropper.md +285 -0
- package/docs/show/descriptions.md +325 -0
- package/docs/show/dropdown.md +466 -0
- package/docs/show/empty.md +225 -0
- package/docs/show/highlight.md +144 -0
- package/docs/show/image.md +433 -0
- package/docs/show/list.md +927 -0
- package/docs/show/modal.md +517 -0
- package/docs/show/overflow-list.md +272 -0
- package/docs/show/popover.md +534 -0
- package/docs/show/scroll-list.md +156 -0
- package/docs/show/side-sheet.md +274 -0
- package/docs/show/table.md +5437 -0
- package/docs/show/tag.md +428 -0
- package/docs/show/timeline.md +277 -0
- package/docs/show/tooltip.md +442 -0
- package/docs/show/user-guide.md +419 -0
- package/docs/start/getting-started.md +234 -0
- package/docs/start/introduction.md +57 -0
- package/docs/start/overview.md +21 -0
- package/package.json +5 -4
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
# Image
|
|
2
|
+
|
|
3
|
+
> Used to display and preview images.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/show/image/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Image, ImagePreview } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic usage
|
|
18
|
+
|
|
19
|
+
You can get an image with preview function by specifying the image path through `src`, and specify the width and height of the image through `width`, `height`
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { Image } from '@fibrae/semi-ui-svelte';
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<Image alt="Abstract colorful artwork" height={200} src="/assets/root-web-sites/abstract.jpg" width={360} />
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Loading failed placeholder
|
|
30
|
+
|
|
31
|
+
`fallback` takes a string or a snippet: a string is the URL of the image shown when loading fails, and a snippet renders custom content; without it, the default failure icon is shown
|
|
32
|
+
|
|
33
|
+
```svelte
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import { IconUploadError } from '@fibrae/semi-icons-svelte';
|
|
36
|
+
import { Image } from '@fibrae/semi-ui-svelte';
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<div style="display: flex; align-items: center; flex-direction: column">
|
|
40
|
+
<span>加载失败默认样式</span>
|
|
41
|
+
<Image alt="加载失败的图片" height={200} src="https://load-error.jpeg" width={200} />
|
|
42
|
+
<br />
|
|
43
|
+
<span>自定义加载失败占位图</span>
|
|
44
|
+
<Image alt="加载失败的图片" height={200} src="https://load-error.jpeg" width={200}>
|
|
45
|
+
{#snippet fallback()}
|
|
46
|
+
<IconUploadError style="font-size: 50px" />
|
|
47
|
+
{/snippet}
|
|
48
|
+
</Image>
|
|
49
|
+
</div>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Progressive loading
|
|
53
|
+
|
|
54
|
+
Large images can be progressively loaded through the `placeholder` snippet: what it renders is shown until the image has loaded
|
|
55
|
+
|
|
56
|
+
```svelte
|
|
57
|
+
<script lang="ts">
|
|
58
|
+
import { Button, Image } from '@fibrae/semi-ui-svelte';
|
|
59
|
+
|
|
60
|
+
let timestamp = $state('');
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<Image alt="Abstract colorful artwork" height={200} src="/assets/root-web-sites/abstract-big.png?{timestamp}" width={300}>
|
|
64
|
+
{#snippet placeholder()}
|
|
65
|
+
<Image alt="" height={200} preview={false} src="/assets/root-web-sites/abstract-small.jpeg" width={300} />
|
|
66
|
+
{/snippet}
|
|
67
|
+
</Image>
|
|
68
|
+
<br />
|
|
69
|
+
<Button style="margin-block-start: 10px" theme="solid" onclick={() => (timestamp = String(Date.now()))}>Reload</Button>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Customize the preview image
|
|
73
|
+
|
|
74
|
+
You can customize the preview image by setting the `src` of the Image component to be different from the `src` in the `preview` parameter
|
|
75
|
+
|
|
76
|
+
```svelte
|
|
77
|
+
<script lang="ts">
|
|
78
|
+
import { Image } from '@fibrae/semi-ui-svelte';
|
|
79
|
+
|
|
80
|
+
const preview = {
|
|
81
|
+
src: '/assets/root-web-sites/abstract-big.png',
|
|
82
|
+
};
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<Image alt="Abstract colorful artwork" height={200} {preview} src="/assets/root-web-sites/abstract-small.jpeg" width={300} />
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Multi-image preview
|
|
89
|
+
|
|
90
|
+
Use ImagePreview to wrap Image to achieve multi-image preview
|
|
91
|
+
|
|
92
|
+
The `src` array of ImagePreview defines the images of the group and their order; an Image does not register itself with the ImagePreview. An Image opens the preview at the position of its own `src` (or `preview.src`) in the list, and an Image whose `src` is not in the list previews on its own. Use `titles` and `alts` to set the title and alternative text of each image, one entry per `src`.
|
|
93
|
+
|
|
94
|
+
```svelte
|
|
95
|
+
<script lang="ts">
|
|
96
|
+
import { Image, ImagePreview } from '@fibrae/semi-ui-svelte';
|
|
97
|
+
|
|
98
|
+
const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg', '/assets/root-web-sites/greenleaf.jpg', '/assets/root-web-sites/colorful.jpg'];
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<ImagePreview src={srcList}>
|
|
102
|
+
{#each srcList as src, index (src)}
|
|
103
|
+
<Image alt="lamp{index + 1}" {src} style="margin-inline-end: 5px" width={200} />
|
|
104
|
+
{/each}
|
|
105
|
+
</ImagePreview>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Use the preview component alone
|
|
109
|
+
|
|
110
|
+
The preview component ImagePreview can be used alone, through `bind:visible` (or `visible` with `onVisibleChange`) to control whether to preview, `src` to pass in the image that can be previewed, and `previewTitle` (a string) to set the title at the top of the preview
|
|
111
|
+
|
|
112
|
+
```svelte
|
|
113
|
+
<script lang="ts">
|
|
114
|
+
import { Button, ImagePreview } from '@fibrae/semi-ui-svelte';
|
|
115
|
+
|
|
116
|
+
const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg', '/assets/root-web-sites/greenleaf.jpg', '/assets/root-web-sites/colorful.jpg'];
|
|
117
|
+
|
|
118
|
+
let visible1 = $state(false);
|
|
119
|
+
let visible2 = $state(false);
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<Button onclick={() => (visible1 = true)}>Preview single Image</Button>
|
|
123
|
+
<ImagePreview bind:visible={visible1} src="/assets/root-web-sites/sky.jpg" />
|
|
124
|
+
<br />
|
|
125
|
+
<Button style="margin-block-start: 20px" onclick={() => (visible2 = true)}>Preview multiple Images</Button>
|
|
126
|
+
<ImagePreview bind:visible={visible2} previewTitle="Scenery" src={srcList} />
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Render in the specified container
|
|
130
|
+
|
|
131
|
+
You can specify the parent DOM of the preview component through `getPopupContainer` (you need to specify `position: relative`), and the image preview will be rendered into this DOM. This will change the DOM tree position, but not the view's rendering position.
|
|
132
|
+
|
|
133
|
+
When the container is not `document.body` (including a `getPopupContainer` set only on ConfigProvider), the preview is non-modal: it does not output `aria-modal`, does not trap Tab and does not lock page scrolling. Returning `document.body` from `getPopupContainer` is the same as not passing it.
|
|
134
|
+
|
|
135
|
+
```svelte
|
|
136
|
+
<script lang="ts">
|
|
137
|
+
import { Image, ImagePreview } from '@fibrae/semi-ui-svelte';
|
|
138
|
+
|
|
139
|
+
const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg', '/assets/root-web-sites/greenleaf.jpg'];
|
|
140
|
+
|
|
141
|
+
const getPopupContainer = () => {
|
|
142
|
+
const node = document.getElementById('container')!;
|
|
143
|
+
return node;
|
|
144
|
+
};
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<div id="container" style="height: 400px; position: relative">
|
|
148
|
+
<ImagePreview {getPopupContainer} src={srcList} style="height: 100%; display: flex; align-items: center; justify-content: center">
|
|
149
|
+
{#each srcList as src, index (src)}
|
|
150
|
+
<Image alt="lamp{index + 1}" {src} style="margin-inline-end: 5px" width={200} />
|
|
151
|
+
{/each}
|
|
152
|
+
</ImagePreview>
|
|
153
|
+
</div>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Customize the bottom operation area of the preview
|
|
157
|
+
|
|
158
|
+
The bottom action area of the preview can be customized with the `previewMenu` snippet, which receives MenuProps. Images wrapped by ImagePreview use the snippet of ImagePreview; a standalone Image uses its own snippet of the same name
|
|
159
|
+
|
|
160
|
+
```svelte
|
|
161
|
+
<script lang="ts">
|
|
162
|
+
import { IconChevronLeft, IconChevronRight, IconDownload, IconMinus, IconPlus, IconRealSizeStroked, IconRotate, IconWindowAdaptionStroked } from '@fibrae/semi-icons-svelte';
|
|
163
|
+
import { Button, Image, ImagePreview } from '@fibrae/semi-ui-svelte';
|
|
164
|
+
|
|
165
|
+
const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg', '/assets/root-web-sites/greenleaf.jpg'];
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<ImagePreview src={srcList}>
|
|
169
|
+
{#snippet previewMenu(menu)}
|
|
170
|
+
<div style="background: grey; height: 40px; width: 280px; display: flex; align-items: center; justify-content: space-around; border-radius: 3px">
|
|
171
|
+
<Button aria-label="上一张" disabled={menu.disabledPrev} type="tertiary" onclick={menu.onPrev}>
|
|
172
|
+
{#snippet icon()}
|
|
173
|
+
<IconChevronLeft size="large" />
|
|
174
|
+
{/snippet}
|
|
175
|
+
</Button>
|
|
176
|
+
<Button aria-label="下一张" disabled={menu.disabledNext} type="tertiary" onclick={menu.onNext}>
|
|
177
|
+
{#snippet icon()}
|
|
178
|
+
<IconChevronRight size="large" />
|
|
179
|
+
{/snippet}
|
|
180
|
+
</Button>
|
|
181
|
+
<Button aria-label="缩小" disabled={menu.disabledZoomOut} type="tertiary" onclick={menu.onZoomOut}>
|
|
182
|
+
{#snippet icon()}
|
|
183
|
+
<IconMinus size="large" />
|
|
184
|
+
{/snippet}
|
|
185
|
+
</Button>
|
|
186
|
+
<Button aria-label="放大" disabled={menu.disabledZoomIn} type="tertiary" onclick={menu.onZoomIn}>
|
|
187
|
+
{#snippet icon()}
|
|
188
|
+
<IconPlus size="large" />
|
|
189
|
+
{/snippet}
|
|
190
|
+
</Button>
|
|
191
|
+
<Button aria-label={menu.ratio === 'adaptation' ? '原始尺寸' : '适应页面'} type="tertiary" onclick={menu.onRatioClick}>
|
|
192
|
+
{#snippet icon()}
|
|
193
|
+
{#if menu.ratio === 'adaptation'}
|
|
194
|
+
<IconRealSizeStroked size="large" />
|
|
195
|
+
{:else}
|
|
196
|
+
<IconWindowAdaptionStroked size="large" />
|
|
197
|
+
{/if}
|
|
198
|
+
{/snippet}
|
|
199
|
+
</Button>
|
|
200
|
+
<Button aria-label="旋转" type="tertiary" onclick={menu.onRotateLeft}>
|
|
201
|
+
{#snippet icon()}
|
|
202
|
+
<IconRotate size="large" />
|
|
203
|
+
{/snippet}
|
|
204
|
+
</Button>
|
|
205
|
+
<Button aria-label="下载" disabled={menu.disableDownload} type="tertiary" onclick={menu.onDownload}>
|
|
206
|
+
{#snippet icon()}
|
|
207
|
+
<IconDownload size="large" />
|
|
208
|
+
{/snippet}
|
|
209
|
+
</Button>
|
|
210
|
+
</div>
|
|
211
|
+
{/snippet}
|
|
212
|
+
{#each srcList as src, index (src)}
|
|
213
|
+
<Image alt="lamp{index + 1}" {src} style="margin-inline-end: 5px" width={200} />
|
|
214
|
+
{/each}
|
|
215
|
+
</ImagePreview>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
To customize the bottom action area based on the default one, render the `menuItems` snippet from the MenuProps. The default items come in the order previous, page counter, next, zoom out, zoom slider, zoom in, original size / fit to page, rotate and download. `{@render menu.menuItems()}` renders all of them; with `start` and `end` it renders only the items `Array.prototype.slice` would pick, such as `{@render menu.menuItems(0, 3)}`, so the items can be rendered one by one or in groups with dividers or custom content between them. The component separates the default items with dividers only when no `previewMenu` is given.
|
|
219
|
+
|
|
220
|
+
```svelte
|
|
221
|
+
<script lang="ts">
|
|
222
|
+
import { IconInfoCircle } from '@fibrae/semi-icons-svelte';
|
|
223
|
+
import { Divider, Image, ImagePreview, Tooltip } from '@fibrae/semi-ui-svelte';
|
|
224
|
+
|
|
225
|
+
const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg', '/assets/root-web-sites/greenleaf.jpg'];
|
|
226
|
+
</script>
|
|
227
|
+
|
|
228
|
+
<ImagePreview src={srcList}>
|
|
229
|
+
{#snippet previewMenu(menu)}
|
|
230
|
+
<div style="display: flex; background-color: rgba(0, 0, 0, 0.75); align-items: center; padding: 5px 16px; border-radius: 4px">
|
|
231
|
+
{@render menu.menuItems(0, 3)}
|
|
232
|
+
<Divider layout="vertical" />
|
|
233
|
+
{@render menu.menuItems(3, 7)}
|
|
234
|
+
<Divider layout="vertical" />
|
|
235
|
+
{@render menu.menuItems(7)}
|
|
236
|
+
<Divider layout="vertical" />
|
|
237
|
+
<Tooltip>
|
|
238
|
+
{#snippet content()}
|
|
239
|
+
我是一个自定义操作
|
|
240
|
+
{/snippet}
|
|
241
|
+
<IconInfoCircle size="large" />
|
|
242
|
+
</Tooltip>
|
|
243
|
+
</div>
|
|
244
|
+
{/snippet}
|
|
245
|
+
{#each srcList as src, index (src)}
|
|
246
|
+
<Image alt="lamp{index + 1}" {src} width={200} />
|
|
247
|
+
{/each}
|
|
248
|
+
</ImagePreview>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Customize the preview top display area
|
|
252
|
+
|
|
253
|
+
The `title` snippet, which receives `{ title, index }`, replaces the content of the title section at the top of the preview. When there is a title, the preview dialog is named by that section through `aria-labelledby`, so its name is the text the snippet renders; without a title the name is "Preview" from the locale. Use the `closeIcon` snippet to replace the close icon, and the `leftIcon` and `rightIcon` snippets, which receive `{ index }`, to replace the arrow icons
|
|
254
|
+
|
|
255
|
+
```svelte
|
|
256
|
+
<script lang="ts">
|
|
257
|
+
import { Image, ImagePreview } from '@fibrae/semi-ui-svelte';
|
|
258
|
+
|
|
259
|
+
const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg'];
|
|
260
|
+
const titles = srcList.map((_, index) => `lamp${index + 1}`);
|
|
261
|
+
</script>
|
|
262
|
+
|
|
263
|
+
<ImagePreview src={srcList} {titles}>
|
|
264
|
+
{#snippet title({ title })}
|
|
265
|
+
<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center">
|
|
266
|
+
<span style="background: black; padding: 0 10px">自定义标题:{title}</span>
|
|
267
|
+
</div>
|
|
268
|
+
{/snippet}
|
|
269
|
+
<div>
|
|
270
|
+
{#each srcList as src, index (src)}
|
|
271
|
+
<Image alt={titles[index]} {src} style="margin-inline-end: 5px" width={200} />
|
|
272
|
+
{/each}
|
|
273
|
+
</div>
|
|
274
|
+
</ImagePreview>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## API reference
|
|
278
|
+
|
|
279
|
+
### Image
|
|
280
|
+
|
|
281
|
+
**Props**
|
|
282
|
+
|
|
283
|
+
| Property | Description | Type | Default |
|
|
284
|
+
| - | - | - | - |
|
|
285
|
+
| alt | Image description, also the accessible name of a previewable thumbnail. | `string` | - |
|
|
286
|
+
| classNames | Class names of the inner parts, keyed by `img` (the inner img element); merged with the built-in classes. | `Partial<Record<ImagePart, ClassValue>>` | - |
|
|
287
|
+
| closeIcon | Custom close icon. It applies to this Image's own preview only and has no effect inside an ImagePreview. | `Snippet` | - |
|
|
288
|
+
| crossOrigin | The crossorigin attribute passed to the native img element. | `'anonymous' \| 'use-credentials'` | - |
|
|
289
|
+
| fallback | Fallback image URL shown when loading fails, or a snippet for custom content. | `string \| Snippet` | - |
|
|
290
|
+
| height | Display height of the image; a number is in px. | `string \| number` | - |
|
|
291
|
+
| leftIcon | Custom previous icon. It applies to this Image's own preview only and has no effect inside an ImagePreview. | `Snippet<[ImagePreviewIconSnippetProps]>` | - |
|
|
292
|
+
| onError | Called when the image fails to load. | `(event: Event) => void` | - |
|
|
293
|
+
| onLoad | Called when the image has loaded. | `(event: Event) => void` | - |
|
|
294
|
+
| placeholder | Snippet for the placeholder content shown until the image has loaded. | `Snippet` | - |
|
|
295
|
+
| preview | Preview options; false disables preview. The object carries data and callbacks only; use the Image snippets for custom content. | `boolean \| ImagePreviewProps` | `true` |
|
|
296
|
+
| previewMenu | Custom bottom menu of the preview. It applies to this Image's own preview only and has no effect inside an ImagePreview. | `Snippet<[MenuProps]>` | - |
|
|
297
|
+
| rightIcon | Custom next icon. It applies to this Image's own preview only and has no effect inside an ImagePreview. | `Snippet<[ImagePreviewIconSnippetProps]>` | - |
|
|
298
|
+
| setDownloadName | Sets the download file name of the image. | `(src: string) => string` | - |
|
|
299
|
+
| src | Image source URL. | `string` | - |
|
|
300
|
+
| styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<ImagePart, string>>` | - |
|
|
301
|
+
| title | Replaces the content of the title section at the top of the preview; when there is a title, the dialog is named by the text the snippet renders. It applies to this Image's own preview only and has no effect inside an ImagePreview. | `Snippet<[ImagePreviewTitleSnippetProps]>` | - |
|
|
302
|
+
| width | Display width of the image; a number is in px. | `string \| number` | - |
|
|
303
|
+
|
|
304
|
+
A number for `width` or `height` is in px. `class` and `style` land on the root element; other undeclared native attributes and event handlers land on the inner img. The `preview` object accepts the props and callbacks of ImagePreview (`onVisibleChange`, `onChange`, `onClose`, `onZoomIn`, `onZoomOut`, `onPrev`, `onNext`, `onRatioChange`, `onRotateLeft`, `onDownload`, `onDownloadError`), except `lazyLoad`, `lazyLoadMargin`, `class` and `style` (use `classNames.preview` and `styles.preview` to style the preview layer). Custom nodes do not go in `preview`; use the snippets of Image. When `preview.src` is an array, switching images returns to "fit to page". An Image inside an ImagePreview ignores the `title`, `previewMenu`, `leftIcon`, `rightIcon` and `closeIcon` snippets; the snippets of the ImagePreview apply.
|
|
305
|
+
|
|
306
|
+
### ImagePreview
|
|
307
|
+
|
|
308
|
+
**Props**
|
|
309
|
+
|
|
310
|
+
| Property | Description | Type | Default |
|
|
311
|
+
| - | - | - | - |
|
|
312
|
+
| adaptiveTip | Tip of the fit-to-page button. | `string` | - |
|
|
313
|
+
| alts | Alternative texts of the preview images, one per entry of src. | `(string \| undefined)[]` | - |
|
|
314
|
+
| children | Snippet for the Image components to preview. | `Snippet` | - |
|
|
315
|
+
| classNames | Class names of the inner parts, keyed by `preview` (the preview layer, the `role="dialog"` element); merged with the built-in classes. | `Partial<Record<ImagePreviewPart, ClassValue>>` | - |
|
|
316
|
+
| closable | Whether to show the close button. | `boolean` | `true` |
|
|
317
|
+
| closeIcon | Snippet for the custom close icon. | `Snippet` | - |
|
|
318
|
+
| closeOnEsc | Whether Esc closes the preview. | `boolean` | `true` |
|
|
319
|
+
| crossOrigin | The crossorigin attribute passed to the preview img element. | `'anonymous' \| 'use-credentials'` | - |
|
|
320
|
+
| currentIndex | Index of the current image; supports bind:currentIndex. Unbound, the component manages it and starts at 0. | `number` | - |
|
|
321
|
+
| disableDownload | Whether to disable download. | `boolean` | `false` |
|
|
322
|
+
| downloadTip | Tip of the download button. | `string` | - |
|
|
323
|
+
| getPopupContainer | Parent DOM the preview renders into. A container other than document.body makes the preview non-modal; a custom container needs position: relative. | `() => HTMLElement` | - |
|
|
324
|
+
| infinite | Whether switching loops around. | `boolean` | `false` |
|
|
325
|
+
| initialZoom | Initial zoom factor of an image, applied once when it first opens or is switched to, clamped by minZoom and maxZoom. | `number` | - |
|
|
326
|
+
| lazyLoad | Whether to lazy-load the images of the group. | `boolean` | `true` |
|
|
327
|
+
| lazyLoadMargin | The rootMargin of the lazy-load observer, relative to the viewport; scrolling ancestors still clip. | `string` | `"0px 100px 100px 0px"` |
|
|
328
|
+
| leftIcon | Snippet for the custom previous icon, receiving `{ index }`. | `Snippet<[ImagePreviewIconSnippetProps]>` | - |
|
|
329
|
+
| maskClosable | Whether clicking the mask closes the preview. | `boolean` | `true` |
|
|
330
|
+
| maxZoom | Maximum zoom factor. | `number` | `5` |
|
|
331
|
+
| minZoom | Minimum zoom factor. | `number` | `0.1` |
|
|
332
|
+
| nextTip | Tip of the next button. | `string` | - |
|
|
333
|
+
| onChange | Called when the image switches. | `(index: number) => void` | - |
|
|
334
|
+
| onClose | Called when closed with the close button or Esc; closing by the mask triggers onVisibleChange only. | `() => void` | - |
|
|
335
|
+
| onDownload | Called when an image is downloaded. | `(src: string, index: number) => void` | - |
|
|
336
|
+
| onDownloadError | Called when a download fails. | `(src: string) => void` | - |
|
|
337
|
+
| onNext | Called when switching to the next image. | `(index: number) => void` | - |
|
|
338
|
+
| onPrev | Called when switching to the previous image. | `(index: number) => void` | - |
|
|
339
|
+
| onRatioChange | Called when switching between original size and fit-to-page. | `(type: RatioType) => void` | - |
|
|
340
|
+
| onRotateLeft | Called when the image rotates counterclockwise. | `(angle: number) => void` | - |
|
|
341
|
+
| onVisibleChange | Called when visibility changes. | `(visible: boolean) => void` | - |
|
|
342
|
+
| onZoomIn | Called when the image zooms in. | `(zoom: number) => void` | - |
|
|
343
|
+
| onZoomOut | Called when the image zooms out. | `(zoom: number) => void` | - |
|
|
344
|
+
| originTip | Tip of the original-size button. | `string` | - |
|
|
345
|
+
| preLoad | Whether to preload neighboring images. | `boolean` | `true` |
|
|
346
|
+
| preLoadGap | How many images ahead and behind to preload. | `number` | `2` |
|
|
347
|
+
| previewMenu | Snippet for the custom bottom menu, receiving MenuProps. menuItems is a snippet that renders the default items: all of them without arguments, or the slice that start and end pick, so they can be rendered one by one or in groups. | `Snippet<[MenuProps]>` | - |
|
|
348
|
+
| previewTitle | Title at the top of the preview and the accessible name of the dialog; the title of the current image in titles takes precedence. | `string` | - |
|
|
349
|
+
| prevTip | Tip of the previous button. | `string` | - |
|
|
350
|
+
| rightIcon | Snippet for the custom next icon, receiving `{ index }`. | `Snippet<[ImagePreviewIconSnippetProps]>` | - |
|
|
351
|
+
| rotateTip | Tip of the rotate button. | `string` | - |
|
|
352
|
+
| setDownloadName | Sets the download file name of an image. | `(src: string) => string` | - |
|
|
353
|
+
| showTooltip | Whether to show tooltips on the bottom controls. | `boolean` | `false` |
|
|
354
|
+
| src | Image URLs to preview; they define the images of the group and their order. A wrapped Image opens the preview at the position of its own src (or preview\.src) in the list; an Image not in the list previews on its own. | `string \| string[]` | `[]` |
|
|
355
|
+
| styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<ImagePreviewPart, string>>` | - |
|
|
356
|
+
| title | Snippet that replaces the content of the title section at the top of the preview, receiving `{ title, index }`. When there is a title, the dialog is named by that section through aria-labelledby, so its name is the text the snippet renders; without a title the name comes from the locale. | `Snippet<[ImagePreviewTitleSnippetProps]>` | - |
|
|
357
|
+
| titles | Preview titles, one per entry of src. | `(string \| undefined)[]` | - |
|
|
358
|
+
| viewerVisibleDelay | Idle time in milliseconds before the preview controls hide. | `number` | `10000` |
|
|
359
|
+
| visible | Whether the preview is open; supports bind:visible. Unbound, the component manages it and starts closed. | `boolean` | - |
|
|
360
|
+
| zIndex | z-index of the preview layer. | `number` | `1070` |
|
|
361
|
+
| zoomInTip | Tip of the zoom-in button. | `string` | - |
|
|
362
|
+
| zoomOutTip | Tip of the zoom-out button. | `string` | - |
|
|
363
|
+
| zoomStep | Zoom change per step. | `number` | `0.1` |
|
|
364
|
+
|
|
365
|
+
`class`, `style` and native attributes (such as `aria-label` and `aria-labelledby`) land on the group root div; with `aria-label` or `aria-labelledby` and no `role`, the root gets `role="group"`. The preview dialog is rendered into `getPopupContainer` (`document.body` by default) and is named by `previewTitle`, or by the locale when there is no title.
|
|
366
|
+
|
|
367
|
+
### MenuProps
|
|
368
|
+
|
|
369
|
+
`min`, `max`, `step` and `zoom` are percentages (a `min` of `10` means 10%, a `step` of `10` means 10% per step), unlike `minZoom`, `maxZoom`, `zoomStep` and `initialZoom` of ImagePreview, which are factors (such as `0.1` and `5`).
|
|
370
|
+
|
|
371
|
+
| Properties | Instructions | Type |
|
|
372
|
+
| - | - | - |
|
|
373
|
+
| curPage | Current image page subscript | number |
|
|
374
|
+
| disabledPrev | Whether to disable the left toggle button | boolean |
|
|
375
|
+
| disabledNext | Whether to disable the right toggle button | boolean |
|
|
376
|
+
| disabledZoomIn | Whether the zoom is at its maximum (the zoom-in button is disabled) | boolean |
|
|
377
|
+
| disabledZoomOut | Whether the zoom is at its minimum (the zoom-out button is disabled) | boolean |
|
|
378
|
+
| disableDownload | Whether to disable the download button | boolean |
|
|
379
|
+
| max | The maximum zoom of the image (percentage) | number |
|
|
380
|
+
| min | The minimum zoom of the image (percentage) | number |
|
|
381
|
+
| onDownload | Call function when the image is downloaded | () => void |
|
|
382
|
+
| onZoomIn | Call function when the image is zoomed in | () => void |
|
|
383
|
+
| onZoomOut | Call function when the image is zoomed out | () => void |
|
|
384
|
+
| onRatioClick | Call function to switch between the original size and fit to page | () => void |
|
|
385
|
+
| onPrev | Call function to switch the picture forward | () => void |
|
|
386
|
+
| onNext | Call function to switch the picture backward | () => void |
|
|
387
|
+
| onRotateLeft | Call function to rotate the image counterclockwise | () => void |
|
|
388
|
+
| onRotateRight | Call function to rotate the image clockwise | () => void |
|
|
389
|
+
| ratio | Original size or Fit to page button state | `"adaptation" \| "realSize"` |
|
|
390
|
+
| step | Step size of zooming (percentage) | number |
|
|
391
|
+
| totalNum | The total number of images that can be previewed | number |
|
|
392
|
+
| zoom | Current zoom of the image (percentage) | number |
|
|
393
|
+
| menuItems | Snippet that renders the default bottom operation area items in their default order; `start` and `end` pick a slice of them, all of them when omitted | `Snippet<[start?: number, end?: number]>` |
|
|
394
|
+
|
|
395
|
+
## Accessibility
|
|
396
|
+
|
|
397
|
+
### ARIA
|
|
398
|
+
|
|
399
|
+
- When rendered into `document.body` (the default), the preview is a modal dialog with `role="dialog"` and `aria-modal="true"`; rendered into a custom container (`getPopupContainer` returns another element, including a container set on ConfigProvider) it is a non-modal dialog and does not output `aria-modal`. It is named by its title (`previewTitle`, or `preview.previewTitle` of an image in a group) when there is one, otherwise by "Preview" from the locale
|
|
400
|
+
- Close, the left and right arrows, and the footer's previous, next, zoom out, zoom in, original size / adapt to the page, rotate and download controls are native `button` elements. Their accessible names come from the matching `prevTip`, `nextTip` and other tip props, or from the locale when those are not set. The zoom slider is named "Zoom" from the locale, with the current percentage as its `aria-valuetext`
|
|
401
|
+
- At the first or last image, or at a zoom limit, the matching footer button gets `aria-disabled="true"` and stays focusable, so focus is not lost. The download button is also disabled when there is no current image (an empty `src` list)
|
|
402
|
+
- The footer page counter has `aria-live="polite"`, so screen readers announce the new position when the image changes
|
|
403
|
+
- With the preview enabled and the image loaded, the root of an Image thumbnail is a focusable button (`role="button"`, `tabindex="0"`, `aria-haspopup="dialog"`) named by the `alt` of the image; with `preview` set to false, or before the image has loaded, it is not focusable. Closing the preview returns focus to the thumbnail. A thumbnail inside an ImagePreview group that opens with the mouse also opens with the keyboard: while loading or after a load error it still has the button role and is focusable, and Enter or Space opens the group preview
|
|
404
|
+
- The `alt` of the preview image is the `alt` of the thumbnail it shows (an `ImagePreview` `src` array has no alt, so it is an empty string)
|
|
405
|
+
|
|
406
|
+
### Keyboard interaction
|
|
407
|
+
|
|
408
|
+
- With focus on a thumbnail, Enter or Space opens the preview
|
|
409
|
+
- Opening the preview moves focus into it. In a modal preview, Tab and Shift + Tab cycle through its controls and closing it returns focus to the element focused before; a non-modal preview rendered into a custom container does not trap Tab, and on close focus returns to the element focused before only if it is still inside the preview or on body, and stays where it is when it has moved elsewhere on the page
|
|
410
|
+
- Enter or Space presses the focused button
|
|
411
|
+
- ← and → switch to the previous and next image, swapped in RTL (ConfigProvider `direction="rtl"`). At the first or last image they behave like the buttons: they wrap around when `infinite` is true and do nothing otherwise
|
|
412
|
+
- ← and → do not switch images while focus is in an input, textarea, select or editable element (such as an input in a custom footer), or while Alt, Ctrl, Meta or Shift is held; on the focused zoom slider they change the zoom
|
|
413
|
+
- Esc closes the preview (unless `closeOnEsc` is false)
|
|
414
|
+
- After the controls hide because of `viewerVisibleDelay`, a key press or focus on a control shows them again; they stay shown while focus is on one of them
|
|
415
|
+
|
|
416
|
+
## Design Token
|
|
417
|
+
|
|
418
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/show/image/>
|
|
419
|
+
|
|
420
|
+
## Changes from Semi Design
|
|
421
|
+
|
|
422
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
423
|
+
|
|
424
|
+
- 破坏性:Image 删除 `imgCls`、`imgStyle`,改用 `classNames.img`、`styles.img`,落在内部 img 上;ImagePreview 与 Image 的 `preview` 对象删除 `previewCls`、`previewStyle`,改用 `classNames.preview`、`styles.preview`,落在预览层 `role="dialog"` 元素上。
|
|
425
|
+
- 破坏性:删除 `@fibrae/semi-ui-react/image` 的 `PreviewInner` 导出、静态标记 `isSemiImage` 与 `ImageProps.imageID`(分组位置由缩略图文档顺序决定)。破坏性(类型):单图 `preview` 改为 `ImagePreviewProps`(不含 `lazyLoad`、`children`、`className`、`style` 等,预览层样式用 `classNames.preview`、`styles.preview`);`PreviewImageProps` 删除 `clickZoom`、`setRatio`、`style`;`onLoad`、`onError` 参数改为 `React.SyntheticEvent<HTMLImageElement>`;`renderLeftIcon`、`renderRightIcon` 返回类型收紧为 `ReactElement`。分组改为注册式:封装组件内部的 Image 也加入分组;Image 的 ref 指向 `img`,未声明属性落在缩略图分组元素上;预览图 `max-width: none` 写在 `.semi-image-preview-image-img`。
|
|
426
|
+
- 行为变化:受控 `currentIndex={0}`、`visible={false}` 首次渲染时不再被 `defaultCurrentIndex`、`defaultVisible` 覆盖。
|
|
427
|
+
- React、Vue、Solid:服务端渲染的 Image 在 hydration 前已加载完成或失败时,hydration 后补发 `onLoad` 或 `onError` 并更新加载状态(原来一直停在加载中)。Avatar、Cropper 与 Upload 的文件卡片同样补发;Svelte 的 hydration 自带补发。
|
|
428
|
+
- Svelte:分组列表是数据,由 `ImagePreview` 的 `src`(`string | string[]`)给出,Image 不向父级注册;Image 用自己的 `src`(或 `preview.src` 的第一项)在列表里找索引,找不到或 `preview` 为 false 时不入组,前者单独预览;不再按 DOM 顺序排序,不支持「src 加子元素」的组合写法;逐张的 `alt`、`title` 改为 `ImagePreview` 的 `titles`、`alts` 数组属性(按索引对应)。
|
|
429
|
+
- Svelte:没有 `defaultVisible`、`defaultCurrentIndex`,`visible`、`currentIndex` 可绑定(`bind:visible`、`bind:currentIndex`,函数绑定与单向传值也成立),Image 的 `preview` 对象不含 `defaultCurrentIndex`;插槽改为同名 snippet:`title({ title, index })`、`previewMenu(MenuProps)`、`leftIcon({ index })`、`rightIcon({ index })`、`closeIcon`,Image 另有 `placeholder`、`fallback`(`fallback` 可为字符串或 snippet);`MenuProps.menuItems` 是渲染 9 个默认底部按钮的 snippet(`Snippet<[start?: number, end?: number]>`),不含分隔线,`menuItems(start, end)` 按 slice 规则只渲染其中一段,可逐项或按组渲染。
|
|
430
|
+
- Svelte:Image 的 `onLoad`、`onError` 是带 Event 的 Semi 回调;`class`、`style` 落在根 div,其余未声明属性落在 img;未入组的 Image 加载成功后才可打开预览,入组的缩略图无需加载;分组 `lazyLoad` 时缩略图先只有 `data-src`,进入视口后才给 `src`。
|
|
431
|
+
- Svelte 破坏性(类型):`title` snippet 的参数类型 `ImagePreviewTitleSnippetProps.title` 改为可选属性 `title?: string`,手写成必填的 snippet 参数类型需改用导出的 `ImagePreviewTitleSnippetProps`。
|
|
432
|
+
- 行为变化:`getPopupContainer` 返回 null 时,四个框架都在显示时报错(原来只有 Vue 报错);焦点归还统一由预览自己的模态资源负责,React `<Activity>` 隐藏预览时不再重置预览状态。
|
|
433
|
+
- Image 的 `preview.setDownloadName` 生效。Vue 的优先级为顶层 `setDownloadName` > `preview` > 全局默认值;React、Solid、Svelte 的全局默认值与顶层 `setDownloadName` 同级,先于 `preview`。
|