Sonner堆叠通知
查看源码components/sonner.go单条通知#
真实 Toast 配方,带稳定操作与关闭 ID。
toast := tree.ID(page, "toast")
toasts := [...]components.SonnerToast{{
Snapshot: components.ToastSnapshot{
Title: "Project saved", Description: "All local changes are written.", Type: components.ToastSuccess,
},
Scope: toast, DismissID: tree.ID(page, "dismiss"),
ActionID: tree.ID(page, "action"), ActionLabel: "View",
}}
components.PaintSonner(canvas, theme, viewport, toasts[:], components.SonnerOptions{Layer: 40})折叠堆栈#
最新通知在前,使用小间距叠放。
toast := tree.Sub(page, tree.Name("toast"))
toasts := [...]components.SonnerToast{
{Snapshot: components.ToastSnapshot{Title: "Project saved", Type: components.ToastSuccess},
Scope: toast.At(0)},
{Snapshot: components.ToastSnapshot{Title: "Update available", Type: components.ToastInfo},
Scope: toast.At(1)},
{Snapshot: components.ToastSnapshot{Title: "Connection lost", Type: components.ToastError},
Scope: toast.At(2)},
}
components.PaintSonner(canvas, theme, viewport, toasts[:], components.SonnerOptions{Layer: 40})展开堆栈#
显式展开多条不同语义通知。
toast := tree.Sub(page, tree.Name("toast"))
action := tree.Sub(page, tree.Name("action"))
toasts := [...]components.SonnerToast{
{Snapshot: components.ToastSnapshot{Title: "Project saved", Type: components.ToastSuccess},
Scope: toast.At(0), ActionID: action.At(0), ActionLabel: "View"},
{Snapshot: components.ToastSnapshot{Title: "Update available", Type: components.ToastInfo},
Scope: toast.At(1), ActionID: action.At(1), ActionLabel: "Later"},
{Snapshot: components.ToastSnapshot{Title: "Connection lost", Type: components.ToastError},
Scope: toast.At(2)},
}
components.PaintSonner(canvas, theme, viewport, toasts[:], components.SonnerOptions{
Layer: 40, Expanded: true,
})安装
将组件源码复制到自己的项目,直接修改。
go run ./cmd/viva add --out ./components/local sonner源码组件用法#
此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。
- 标题旁的源码链接列出了全部选项与视觉决策。
- 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
- 浏览器预览验证共享布局和场景行为,不代表原生性能。
验证边界#
示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。
键盘操作
Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。