外观
Toaster 消息通知
通过函数发送短时提示,可带说明、撤销按钮或关闭按钮。
import { SToaster } from '@icecreamqaq/shadcn/sonner'使用示例
常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
SToaster.position | Position | 设置通知出现的位置,例如 top-center 或 bottom-right。 |
SToaster.closeButton | boolean | 给通知提供关闭按钮。 |
toast.success(message, options) | 函数 | 发送成功通知,返回消息 ID。 |
options.action | { label, onClick } | 在消息中加入操作,例如撤销刚刚的更改。 |
toast.dismiss(id) | 函数 | 按消息 ID 关闭通知。 |
在应用布局挂载一个 SToaster,业务组件即可调用同一分组的 toast。
完整 API
Toaster27 个成员
属性
| 名称 | 类型 |
|---|---|
id | string |
invert | boolean |
theme | Theme |
position | Position |
closeButtonPosition | CloseButtonPosition |
hotkey | string[] |
richColors | boolean |
expand | boolean |
duration | number |
gap | number |
visibleToasts | number |
closeButton | boolean |
toastOptions | ToastOptions |
class | string |
style | CSSProperties |
offset | Offset |
mobileOffset | Offset |
dir | "ltr" | "rtl" | "auto" |
swipeDirections | SwipeDirection[] |
icons | ToastIcons |
containerAriaLabel | string |
插槽
| 名称 | 类型 |
|---|---|
success-icon | ((props: {}) => any) |
info-icon | ((props: {}) => any) |
warning-icon | ((props: {}) => any) |
error-icon | ((props: {}) => any) |
loading-icon | ((props: {}) => any) |
close-icon | ((props: {}) => any) |
分组导出
模板标签为 <s-toaster>。
组件 SToaster
函数与常量 toast
类型 ToastContent