外观
Toast 旧版轻提示
为沿用旧版 shadcn-vue SToast API 的界面提供短暂的操作反馈。
import { SToast } from '@icecreamqaq/shadcn/toast'使用示例
常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
SToastToaster | 组件 | 挂载通知提供者、视口和当前消息。 |
useToast().toast(options) | 函数 | 发送消息,支持 title、description、duration 和 variant 等选项。 |
options.variant | "default" | "destructive" | 设置消息样式。 |
useToast().dismiss(id?) | 函数 | 传入字符串 ID 关闭指定消息,省略 ID 则关闭当前消息。 |
示例从 @icecreamqaq/shadcn/toast 导入旧版 SToastToaster。根入口提供的同名组件属于 Sonner。
完整 API
Toast20 个成员
属性
| 名称 | 类型 |
|---|---|
class | ClassValue |
variant | "default" | "destructive" | null |
defaultOpen | boolean |
forceMount | boolean |
type | "foreground" | "background" |
open | boolean |
duration | number |
toast | ToastObject<any> |
asChild | boolean |
as | AsTag | Component |
事件
| 名称 | 类型 |
|---|---|
openChange | ((value: boolean) => void) |
pause | (() => any) |
escapeKeyDown | ((event: KeyboardEvent) => any) |
update:open | ((value: boolean) => any) |
resume | (() => any) |
swipeStart | ((event: { currentTarget: EventTarget & HTMLElement; } & Omit<CustomEvent<{ originalEvent: PointerEvent; delta: { x: number; y: number; }; }>, "currentTarget">) => any) |
swipeMove | ((event: { currentTarget: EventTarget & HTMLElement; } & Omit<CustomEvent<{ originalEvent: PointerEvent; delta: { x: number; y: number; }; }>, "currentTarget">) => any) |
swipeCancel | ((event: { currentTarget: EventTarget & HTMLElement; } & Omit<CustomEvent<{ originalEvent: PointerEvent; delta: { x: number; y: number; }; }>, "currentTarget">) => any) |
swipeEnd | ((event: { currentTarget: EventTarget & HTMLElement; } & Omit<CustomEvent<{ originalEvent: PointerEvent; delta: { x: number; y: number; }; }>, "currentTarget">) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ToastAction6 个成员
属性
| 名称 | 类型 |
|---|---|
altText | string |
closeOnClick | boolean |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ToastClose3 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
ToastDescription4 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ToastProvider10 个成员
属性
| 名称 | 类型 |
|---|---|
label | string |
duration | number |
disableSwipe | boolean |
swipeDirection | SwipeDirection |
swipeThreshold | number |
disableHoverPause | boolean |
disableWindowBlurPause | boolean |
limit | number |
toastManager | GlobalToastManager<any> |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ToastTitle4 个成员
属性
| 名称 | 类型 |
|---|---|
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
ToastToaster3 个成员
插槽
| 名称 | 类型 |
|---|---|
title | ((props: { id: string; dismiss: () => void; toast: ToasterToast; }) => any) |
description | ((props: { id: string; dismiss: () => void; toast: ToasterToast; }) => any) |
action | ((props: { id: string; dismiss: () => void; toast: ToasterToast; }) => any) |
ToastViewport5 个成员
属性
| 名称 | 类型 |
|---|---|
hotkey | string[] |
label | string | ((hotkey: string) => string) |
asChild | boolean |
as | AsTag | Component |
class | ClassValue |
分组导出
模板标签为 <s-toast>。
组件 SToast、SToastAction、SToastClose、SToastDescription、SToastProvider、SToastTitle、SToastToaster、SToastViewport
函数与常量 toast、toastVariants、useToast
类型 ToastProps、ToastRenderScope、ToasterToast