@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,393 @@
|
|
|
1
|
+
# Toast
|
|
2
|
+
|
|
3
|
+
> Toast component is used to give timely feedback to user's operations. It could be the result feedback of the operation, such as success, failure, error, warning, etc.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/feedback/toast/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Toast } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The static methods can only be called in the browser (calling them on the server throws); call them in event handlers. Use `Toast.useToast()` when you need to read context during component initialization.
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
Calling Toast's related methods to show timely feedback to user's operations. It is recommended to set the `stack` property to apply the stacking style to multiple Toasts on the same screen, and expand them by hovering, which can effectively prevent multiple parallel Toasts at one time.
|
|
22
|
+
|
|
23
|
+
```svelte
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { throttle } from 'es-toolkit';
|
|
26
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
27
|
+
|
|
28
|
+
const opts = {
|
|
29
|
+
content: 'Hi, Semi dance dance',
|
|
30
|
+
duration: 3,
|
|
31
|
+
stack: true,
|
|
32
|
+
};
|
|
33
|
+
const throttleOpts = {
|
|
34
|
+
content: 'Hi, Semi dance dance',
|
|
35
|
+
duration: 10,
|
|
36
|
+
onClose: () => throttled.cancel(),
|
|
37
|
+
stack: true,
|
|
38
|
+
};
|
|
39
|
+
const throttled = throttle(() => Toast.info(throttleOpts), 10000, { edges: ['leading'] });
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<div>
|
|
43
|
+
<Button onclick={() => Toast.info(opts)}>Display Toast</Button>
|
|
44
|
+
<br />
|
|
45
|
+
<br />
|
|
46
|
+
<Button onclick={throttled}>Throttled Toast</Button>
|
|
47
|
+
</div>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Other Types
|
|
51
|
+
|
|
52
|
+
Use different methods to show different Toast including success, warning, error and info.
|
|
53
|
+
|
|
54
|
+
```svelte
|
|
55
|
+
<script lang="ts">
|
|
56
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
57
|
+
|
|
58
|
+
const opts = {
|
|
59
|
+
content: 'Hi, Semi dance dance',
|
|
60
|
+
duration: 3,
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<Button style="color: var(--semi-color-success)" onclick={() => Toast.success('Hi,Semi dance dance')}>Success</Button>
|
|
65
|
+
<br />
|
|
66
|
+
<br />
|
|
67
|
+
<Button type="warning" onclick={() => Toast.warning(opts)}>Warning</Button>
|
|
68
|
+
<br />
|
|
69
|
+
<br />
|
|
70
|
+
<Button type="danger" onclick={() => Toast.error(opts)}>Error</Button>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Colored Background
|
|
74
|
+
|
|
75
|
+
You could use `theme` for a colored background style. Default is `normal`.
|
|
76
|
+
|
|
77
|
+
```svelte
|
|
78
|
+
<script lang="ts">
|
|
79
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
80
|
+
|
|
81
|
+
const opts = {
|
|
82
|
+
content: 'Hi, Semi dance dance',
|
|
83
|
+
duration: 3,
|
|
84
|
+
theme: 'light',
|
|
85
|
+
} as const;
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<Button onclick={() => Toast.info(opts)}>Info</Button>
|
|
89
|
+
<br />
|
|
90
|
+
<br />
|
|
91
|
+
<Button style="color: var(--semi-color-success)" onclick={() => Toast.success(opts)}>Success</Button>
|
|
92
|
+
<br />
|
|
93
|
+
<br />
|
|
94
|
+
<Button type="warning" onclick={() => Toast.warning(opts)}>Warning</Button>
|
|
95
|
+
<br />
|
|
96
|
+
<br />
|
|
97
|
+
<Button type="danger" onclick={() => Toast.error(opts)}>Error</Button>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Stacking styles
|
|
101
|
+
|
|
102
|
+
With `stack`, the Toasts on screen stack once there are more than the threshold, and expand on hover. `true` sets the threshold to 3, and a number sets a custom one; a stack shows its front 3 layers only.
|
|
103
|
+
|
|
104
|
+
```svelte
|
|
105
|
+
<script lang="ts">
|
|
106
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
107
|
+
|
|
108
|
+
const opts = {
|
|
109
|
+
content: 'Hi, Semi dance dance',
|
|
110
|
+
duration: 10,
|
|
111
|
+
stack: true,
|
|
112
|
+
};
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<Button onclick={() => Toast.info(opts)}>多次点击</Button>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Custom Children with Link
|
|
119
|
+
|
|
120
|
+
Informational feedback
|
|
121
|
+
|
|
122
|
+
`content` and `icon` accept a string or a snippet: define it with `{#snippet}` in the component and pass it in; components such as Typography can be used directly inside the snippet.
|
|
123
|
+
|
|
124
|
+
```svelte
|
|
125
|
+
<script lang="ts">
|
|
126
|
+
import { Button, Toast, Typography } from '@fibrae/semi-ui-svelte';
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
{#snippet single()}
|
|
130
|
+
<span>
|
|
131
|
+
<Typography.Text>Hi, Semi dance dance</Typography.Text>
|
|
132
|
+
<Typography.Text link style="margin-inline-start: 12px">更多</Typography.Text>
|
|
133
|
+
</span>
|
|
134
|
+
{/snippet}
|
|
135
|
+
{#snippet multiLine()}
|
|
136
|
+
<div>Hi, Semi dance dance</div>
|
|
137
|
+
<div style="margin-block-start: 8px">
|
|
138
|
+
<Typography.Text link>查看详情</Typography.Text>
|
|
139
|
+
<Typography.Text link style="margin-inline-start: 20px">一会再看</Typography.Text>
|
|
140
|
+
</div>
|
|
141
|
+
{/snippet}
|
|
142
|
+
|
|
143
|
+
<Button onclick={() => Toast.info({ content: single, duration: 3 })}>Display Toast</Button>
|
|
144
|
+
<br />
|
|
145
|
+
<br />
|
|
146
|
+
<Button onclick={() => Toast.info({ content: multiLine, duration: 3 })}>Display Multi-line Toast</Button>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Delay
|
|
150
|
+
|
|
151
|
+
Use `duration` to set up time delay. By default it closes after 3 seconds.
|
|
152
|
+
|
|
153
|
+
```svelte
|
|
154
|
+
<script lang="ts">
|
|
155
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
156
|
+
|
|
157
|
+
const opts = {
|
|
158
|
+
content: 'Hi, Semi dance dance',
|
|
159
|
+
duration: 10,
|
|
160
|
+
};
|
|
161
|
+
</script>
|
|
162
|
+
|
|
163
|
+
<Button onclick={() => Toast.info(opts)}>Close After 10s</Button>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Manual Close
|
|
167
|
+
|
|
168
|
+
Set `duration` to 0 if you do not want the Toast to close by itself. In this case, it could only be closed manually.
|
|
169
|
+
|
|
170
|
+
```svelte
|
|
171
|
+
<script lang="ts">
|
|
172
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
173
|
+
|
|
174
|
+
let toastId: string | null = null;
|
|
175
|
+
|
|
176
|
+
const destroy = () => {
|
|
177
|
+
toastId = null;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const opts = {
|
|
181
|
+
content: 'Not auto close',
|
|
182
|
+
duration: 0,
|
|
183
|
+
onClose: destroy,
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const show = () => {
|
|
187
|
+
if (toastId) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
toastId = Toast.info(opts);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const hide = () => {
|
|
194
|
+
if (toastId) {
|
|
195
|
+
Toast.close(toastId);
|
|
196
|
+
}
|
|
197
|
+
destroy();
|
|
198
|
+
};
|
|
199
|
+
</script>
|
|
200
|
+
|
|
201
|
+
<Button type="primary" onclick={show}>Show Toast</Button>
|
|
202
|
+
<br />
|
|
203
|
+
<br />
|
|
204
|
+
<Button type="primary" onclick={hide}>Hide Toast</Button>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Update Toast Content
|
|
208
|
+
|
|
209
|
+
Use unique Toast `id` to update toast content.
|
|
210
|
+
|
|
211
|
+
```svelte
|
|
212
|
+
<script lang="ts">
|
|
213
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
214
|
+
|
|
215
|
+
const show = () => {
|
|
216
|
+
const id = 'toastid';
|
|
217
|
+
Toast.info({ content: 'Update Content By Id', id });
|
|
218
|
+
setTimeout(() => {
|
|
219
|
+
Toast.success({ content: 'Id By Content Update', id });
|
|
220
|
+
}, 1000);
|
|
221
|
+
};
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<Button type="primary" onclick={show}>Update Content By Id</Button>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Destroy all
|
|
228
|
+
|
|
229
|
+
Globally Destroy:
|
|
230
|
+
|
|
231
|
+
- `Toast.destroyAll()`
|
|
232
|
+
|
|
233
|
+
### Consume Context
|
|
234
|
+
|
|
235
|
+
Call `Toast.useToast()` during component initialization. The toasts it opens inherit the context, ConfigProvider and locale of the calling component, and no Holder is needed. They are mounted under `document.body` and removed when the calling component is destroyed.
|
|
236
|
+
|
|
237
|
+
`Toast.useToast()` returns the `toast` object: `info`, `success`, `warning`, `error` and `open` take the Options without `type`, `id`, `top`, `bottom`, `left`, `right`, `zIndex` and `getPopupContainer` and return the `toastId`; `close(toastId)` closes one manually. A snippet passed as `content` or `icon` can call `getContext` to read the calling component's context. The values of ConfigProvider and LocaleProvider cannot be read by the static `Toast`; use `useToast()` when you need them.
|
|
238
|
+
|
|
239
|
+
```svelte
|
|
240
|
+
<script lang="ts">
|
|
241
|
+
import { getContext, setContext } from 'svelte';
|
|
242
|
+
import { Button, Toast } from '@fibrae/semi-ui-svelte';
|
|
243
|
+
|
|
244
|
+
const reachableKey = Symbol('reachable');
|
|
245
|
+
setContext(reachableKey, 'Light');
|
|
246
|
+
|
|
247
|
+
const toast = Toast.useToast();
|
|
248
|
+
const config = { duration: 0, content: reachable };
|
|
249
|
+
</script>
|
|
250
|
+
|
|
251
|
+
<!-- The snippet renders inside the toast list mounted with this component's contexts, so it reads the context set above -->
|
|
252
|
+
{#snippet reachable()}ReachableContext: {getContext(reachableKey)}{/snippet}
|
|
253
|
+
|
|
254
|
+
<div>
|
|
255
|
+
<Button onclick={() => toast.success(config)}>Hook Toast</Button>
|
|
256
|
+
</div>
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Create Toast with different configurations
|
|
260
|
+
|
|
261
|
+
> Commonly used to override global configuration
|
|
262
|
+
|
|
263
|
+
- `ToastFactory.create(config) => Toast`\
|
|
264
|
+
If you need Toast with different configs in your application, you can use ToastFactory.create(config)to create a new Toast:
|
|
265
|
+
|
|
266
|
+
```svelte
|
|
267
|
+
<script lang="ts">
|
|
268
|
+
import { onDestroy } from 'svelte';
|
|
269
|
+
import { Button, Toast, ToastFactory } from '@fibrae/semi-ui-svelte';
|
|
270
|
+
|
|
271
|
+
const ToastInCustomContainer = ToastFactory.create({
|
|
272
|
+
getPopupContainer: () => document.getElementById('custom-toast-container')!,
|
|
273
|
+
});
|
|
274
|
+
onDestroy(() => ToastInCustomContainer.destroyAll());
|
|
275
|
+
</script>
|
|
276
|
+
|
|
277
|
+
<div>
|
|
278
|
+
<Button onclick={() => Toast.info('Toast')}>Default Toast</Button>
|
|
279
|
+
<br />
|
|
280
|
+
<br />
|
|
281
|
+
<Button onclick={() => ToastInCustomContainer.info('Toast in some container')}>Toast in custom container</Button>
|
|
282
|
+
<div id="custom-toast-container">custom container</div>
|
|
283
|
+
</div>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## API Reference
|
|
287
|
+
|
|
288
|
+
The static methods provided are as follows: Display: You can pass in `options` object or string directly. Methods return the value of `toastId`: `const toastId = Toast.info({ /*...options*/ })`
|
|
289
|
+
|
|
290
|
+
**The global configuration is set before any method call, and takes effect only once**
|
|
291
|
+
|
|
292
|
+
- `Toast.config(config)`
|
|
293
|
+
- `Toast.resetConfig()` restores the global configuration to its defaults; only toasts shown afterwards are affected. An instance created by `ToastFactory.create(config)` is restored to the `config` it was created with
|
|
294
|
+
|
|
295
|
+
**Show Toast Directly**
|
|
296
|
+
|
|
297
|
+
- `Toast.info(options || string)`
|
|
298
|
+
- `Toast.error(options || string)`
|
|
299
|
+
- `Toast.warning(options || string)`
|
|
300
|
+
- `Toast.success(options || string)`
|
|
301
|
+
|
|
302
|
+
**`info` `error` `warning` `success` return the `toastId`, can be used for manually closing**
|
|
303
|
+
|
|
304
|
+
- `Toast.close(toastId)` Close Manually
|
|
305
|
+
|
|
306
|
+
## Options
|
|
307
|
+
|
|
308
|
+
**Toast Options supports the following APIs as well as the APIs in Config**
|
|
309
|
+
|
|
310
|
+
| Property | Description | Type | Default |
|
|
311
|
+
| - | - | - | - |
|
|
312
|
+
| content | Toast content, a string or a snippet; the snippet runs where the toast renders | string \| Snippet | '' |
|
|
313
|
+
| icon | Custom icon, a string or a snippet, replacing the icon of `type` | string \| Snippet | |
|
|
314
|
+
| showClose | Whether to show the close button | boolean | true |
|
|
315
|
+
| textMaxWidth | Maximum width of the content | number \| string | 450 |
|
|
316
|
+
| onClose | Callback function when the toast closes | () => void | |
|
|
317
|
+
| stack | Stack the toasts on screen once there are more than this many; `true` means 3, `false` never stacks | boolean \| number | false |
|
|
318
|
+
| id | Custom ToastId; a toast with the same id is updated | string | |
|
|
319
|
+
| motion | Whether to animate entering and leaving | boolean | true |
|
|
320
|
+
| class | Class name | string \| object \| array | |
|
|
321
|
+
| style | Inline style, a string only | string | |
|
|
322
|
+
|
|
323
|
+
`class`, `style` and undeclared options (such as `data-*` and `aria-*`) land on `.semi-toast`, in stack mode too.
|
|
324
|
+
|
|
325
|
+
## Config
|
|
326
|
+
|
|
327
|
+
**The following API supports global configuration to change the default configuration of the current Toast**
|
|
328
|
+
|
|
329
|
+
| Properties | Instructions | type | Default |
|
|
330
|
+
| - | - | - | - |
|
|
331
|
+
| bottom | Pop-up position bottom | number \| string | - |
|
|
332
|
+
| left | Pop-up position left | number \| string | - |
|
|
333
|
+
| right | Pop-up position right | number \| string | - |
|
|
334
|
+
| top | Pop-up position top | number \| string | - |
|
|
335
|
+
| zIndex | Z-index value | number | 1010 |
|
|
336
|
+
| theme | Style of background fill, one of `light`, `normal` | string | `normal` |
|
|
337
|
+
| duration | Automatic close delay, no auto-close when set to 0 | number | 3 |
|
|
338
|
+
| getPopupContainer | Specifies the parent DOM, and the bullet layer will be rendered to the DOM, you need to set container and inner .semi-toast-wrapper 'position: relative\` This will change the DOM tree position, but not the view's rendering position. | () => HTMLElement | () => document.body |
|
|
339
|
+
|
|
340
|
+
## Accessibility
|
|
341
|
+
|
|
342
|
+
### ARIA
|
|
343
|
+
|
|
344
|
+
- The role of Toast depends on its type: `alert` for `warning` and `error`, `status` for `info`, `success` and a Toast without `type`
|
|
345
|
+
- `status` Toasts are read by a persistent `aria-live="polite"` region owned by the list; the Toast itself is `aria-live="off"`, and only the text of `content` is announced. `warning` and `error` still announce themselves as `alert`
|
|
346
|
+
|
|
347
|
+
### Keyboard and Focus
|
|
348
|
+
|
|
349
|
+
- The close button is a native `button`: focus it with `Tab`, and activate it with `Enter` or `Space`
|
|
350
|
+
- A Toast does not take focus when it appears
|
|
351
|
+
- When the pointer or keyboard focus enters a Toast, its auto-close timer pauses and a stack expands; both resume when it leaves
|
|
352
|
+
|
|
353
|
+
## Content Guidelines
|
|
354
|
+
|
|
355
|
+
- Keep it simple
|
|
356
|
+
- Do not use periods at the end of sentences
|
|
357
|
+
- Explain using the noun + verb format
|
|
358
|
+
|
|
359
|
+
| ✅ Recommended usage | ❌ Deprecated usage |
|
|
360
|
+
| - | - |
|
|
361
|
+
| Language added | New language has been added successfully |
|
|
362
|
+
| Ticket transfer failed | Can't transfer ticket |
|
|
363
|
+
|
|
364
|
+
- Provide prompt message for action
|
|
365
|
+
- only provide one action
|
|
366
|
+
- Don't use actions like "read" like OK, Got it, Dismiss, Cancel
|
|
367
|
+
|
|
368
|
+
| ✅ Recommended usage | ❌ Deprecated usage |
|
|
369
|
+
| - | - |
|
|
370
|
+
| | |
|
|
371
|
+
|
|
372
|
+
## Design Tokens
|
|
373
|
+
|
|
374
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/feedback/toast/>
|
|
375
|
+
|
|
376
|
+
## Changes from Semi Design
|
|
377
|
+
|
|
378
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
379
|
+
|
|
380
|
+
- 与 Notification 相同的变化:新增 `Toast.resetConfig()`,悬停或聚焦时暂停全部 Toast 自动关闭,每次调用都应用 `zIndex`。`stack` 类型改为 `boolean | number`,`true` 为 3,收起时只显示最前 3 层。
|
|
381
|
+
- 破坏性:`Toast.defaultOpts`(及 `ToastFactory.create()` 返回实例上的同名属性)改为只读,整体赋值会抛错,修改默认值用 `config()`、`resetConfig()`。
|
|
382
|
+
- 破坏性(类型):`useToast` 返回元组 `[toast, contextHolder]`,方法参数不含 `type`、`id`,`content`、`icon` 只接受 ReactNode;静态方法与 `useToast` 选项类型不含 `close`,`useToast` 另不含 `zIndex`、`getPopupContainer`;`getPopupContainer` 改为 `() => HTMLElement`;删除 `ToastListHandle`、`ToastHandle`,新增 `ToastHookApi`。
|
|
383
|
+
- 行为变化:`useToast` 支持 `stack`,先来的在前,`contextHolder` 输出固定定位的 `.semi-toast-wrapper`;滑动统一由 `.semi-toast-content` 承担,`semi-toast-keyframe-toast-show` 不再含位移,覆盖动画样式的使用方注意选择器变化。
|
|
384
|
+
- 样式:`.semi-toast-content` 去掉下外边距,相邻 Toast 的间距由 24px 改为 12px,与第一条距顶部的距离相同。
|
|
385
|
+
- 样式:堆叠中的 `.semi-toast-zero-height-wrapper` 改为单行 grid,展开收起由 `grid-template-rows` 过渡,覆盖其 `height` 的样式不再生效;不支持 `interpolate-size` 的浏览器在离场动画期间给 Toast 写内联 `height`。
|
|
386
|
+
- Svelte:提供静态 `Toast`(含 `ToastFactory`)和 `Toast.useToast()`;`useToast()` 在组件初始化时调用,只返回 `api`,没有 Holder:hook 的 Toast 挂在 `document.body`,读调用组件所在处的 context、ConfigProvider 与语言包,调用组件销毁时一并移除。`content`、`icon` 接受字符串或 snippet,静态 Toast 的 snippet 读不到调用方的 context;服务端调用静态方法或 hook 的 `api` 抛 "can only be called in the browser" 错误,`useToast()` 本身可在服务端调用。
|
|
387
|
+
- Svelte:进场、离场由 store 持有离场状态,CSS 动画结束后才移除元素,不使用 Svelte 的 `in:`、`out:`;同一元素有多个离场动画时等最后一个结束(Notification 同)。
|
|
388
|
+
- 同一批内更新一条消息再新增另一条时,被更新的消息仍重新计时。
|
|
389
|
+
- 行为变化:`useToast` 返回的 id 前缀由 `semi_toast_` 改为 `toast-`(Vue 原本如此);React、Solid 的 `useToast` 不再把 `duration: 3` 写死在选项里盖掉全局 `Toast.duration`,hook 与静态方法一样按「全局默认 < 调用参数」合并,显式 `undefined` 不覆盖。Vue、Svelte 的 `useNotification` 同样在 `open` 时合并全局默认,结果不变。
|
|
390
|
+
- `Toast`、`Notification` 默认导出现在是 foundation 类的实例加 `useToast`、`useNotification`(Vue 另有 `install`);方法都是箭头属性,可以解构,`defaultOpts` 是原型上的 getter,对象展开 `{ ...Toast }` 取不到它。
|
|
391
|
+
- Svelte:内部导出 `createToastHookApi(store, beforeAdd?)` 改为 `createToastHookApi(store, { beforeAdd?, readGlobalDefaults? })`。
|
|
392
|
+
- React、Vue:静态方法与 `useToast` 的选项类型并入 Toast 元素的原生属性(`dir`、`title`、`onClick` 等)与 `data-*`,与运行时透传一致(F6)。React 深路径 `toast/toast` 的单条 Toast 组件 props 类型改名 `ToastItemProps`(`ToastReactProps` 只指选项类型)。
|
|
393
|
+
- 未传 `getPopupContainer` 时,Toast、Notification 的静态方法与 Svelte hook 在全屏期间把容器移进 `document.fullscreenElement`,退出全屏后的下一次调用移回 `body`(原来全屏时看不到);移动会重启已显示条目的 CSS 动画。
|