保存成功#

成功通知带稳定操作与关闭按钮。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
snapshot := components.ToastSnapshot{
    Title: "Project saved", Description: "Changes are safely written locally.", Type: components.ToastSuccess,
}
if open {
    components.PaintToast(canvas, theme, viewport, snapshot, components.ToastOptions{
        Layer: 52, Scope: tree.ID(page, "toast"),
        DismissID: tree.ID(page, "dismiss"), ActionID: tree.ID(page, "action"),
        ActionLabel: "View",
    })
    if canvas.Clicked(tree.ID(page, "dismiss")) { open = false }
}

语义类型#

通过点击操作在信息、警告和错误样式间切换。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
types := [...]components.ToastType{
    components.ToastInfo, components.ToastWarning, components.ToastError,
}
titles := [...]string{"Update available", "Low disk space", "Build failed"}
snapshot := components.ToastSnapshot{
    Title: titles[selected], Description: "Activate the action button to see the next semantic type.",
    Type: types[selected],
}
components.PaintToast(canvas, theme, viewport, snapshot, components.ToastOptions{
    Layer: 52, Scope: tree.ID(page, "toast"), DismissID: tree.ID(page, "dismiss"),
    ActionID: tree.ID(page, "action"), ActionLabel: "Switch",
})
if canvas.Clicked(tree.ID(page, "action")) { selected = (selected + 1) % len(types) }

手势快照#

仅展示调用方提供的横向位移;组件不解释手势。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
snapshot := components.ToastSnapshot{
    Title: "Download almost complete", Description: "The horizontal offset comes from the caller's snapshot.",
    Type: components.ToastInfo, SwipeX: -8,
}
components.PaintToast(canvas, theme, viewport, snapshot, components.ToastOptions{
    Layer: 52, Scope: tree.ID(page, "toast"), DismissID: tree.ID(page, "dismiss"),
    ActionID: tree.ID(page, "action"), ActionLabel: "Continue",
})

安装

将组件源码复制到自己的项目,直接修改。

仓库命令
go run ./cmd/viva add --out ./components/local toast

源码组件用法#

此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。

  • 标题旁的源码链接列出了全部选项与视觉决策。
  • 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
  • 浏览器预览验证共享布局和场景行为,不代表原生性能。

验证边界#

示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。

键盘操作

Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。