轻提示
对齐目标:@astryxdesign/core v0.7.1 · Toast
Toast Props #
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
type | ToastType | 'info' | 提示的类型,可选 info、success、warning、error;error 类型会自动应用 role="alert"。 |
body | string | - | 提示的正文文本,默认渲染在提示内容区。 |
isAutoHide | boolean | error 以外为 true | 是否自动关闭。error 类型默认一直留着,直到被关掉。 |
autoHideDuration | number | 5000 | 自动关闭前的停留时长,单位毫秒。悬停、聚焦或窗口失焦会暂停计时,恢复后至少还剩一秒。 |
autoClose | boolean | - | isAutoHide 的旧名字,写哪个都行,同名时以 isAutoHide 为准。 |
duration | number | - | autoHideDuration 的旧名字,写哪个都行,同名时以 autoHideDuration 为准。 |
uniqueID | string | - | 用来把同一条提示合并成一个的标识。 |
collisionBehavior | 'ignore' | 'overwrite' | 'overwrite' | 屏幕上已有同 uniqueID 的提示时怎么办。 |
endContent | Component | - | 末尾动作,例如撤销按钮。临时内容用 end 插槽。 |
onDismiss | (reason: 'auto' | 'manual') => void | - | 卡片自己关掉提示时触发:计时器、关闭按钮或自定义内容。useToast() 的参数里使用。 |
onHide | (reason: 'auto' | 'manual') => void | - | 提示被移除时触发,包括用 useToast() 返回的函数关掉的情况。useToast() 的参数里使用。 |
Toast 事件 #
| 名称 | 说明 |
|---|---|
dismiss | 卡片自己关闭提示时触发,参数是原因('auto' 或 'manual')。 |
close | dismiss 的旧名字,同时触发,不带原因。 |
Toast Slots #
| 名称 | 说明 |
|---|---|
default | 自定义提示的内容区域,未提供时默认显示 body 文本。 |
end | 末尾内容,替代 endContent。 |
content | 替换整块卡片内容,参数是 { body, endContent, type, isAutoHide, autoHideDuration, dismiss }。这时不再渲染自带的关闭按钮,控件全部由自定义布局负责。 |
ToastViewport Props #
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
placement | ToastPlacement | 'bottom-end' | 提示在屏幕上的弹出位置,可选 top-start、top-center、top-end、bottom-start、bottom-center、bottom-end。 |
useToast #
TypeScript
const toast = useToast()
const dismiss = toast({
body: 'Hello',
type: 'info',
autoHideDuration: 3000,
onDismiss: reason => console.log('关闭原因', reason),
onHide: reason => console.log('已移除', reason),
})
// 手动关闭
dismiss()
// 关闭全部
toast.clear()