Alert Dialog警告对话框
查看源码components/alert_dialog.go删除确认#
确认和取消动作均由调用方处理。
options := components.AlertDialogOptions{
Layer: 8, Scope: scope, ActionID: confirmID, CancelID: cancelID,
ActionVariant: components.ButtonDestructive,
}
components.BeginAlertDialog(canvas, theme, viewport, options).
Paint("Delete this project?", "This cannot be undone.", "Delete", "Cancel")
if canvas.Clicked(confirmID) || canvas.Clicked(cancelID) {
open = false
}带媒体的小尺寸#
预留可由调用方绘制的媒体区域。
dialog := components.BeginAlertDialog(canvas, theme, viewport, components.AlertDialogOptions{
Layer: 8, Scope: scope, ActionID: confirmID, CancelID: cancelID,
Size: components.AlertDialogSmall,
}).WithMedia()
layout := dialog.Begin("Replace avatar?", "The new image replaces it.", "Replace", "Cancel")
canvas.Rounded(layout.Media, min(layout.Media.Width, layout.Media.Height)/2, theme.Muted)
canvas.LabelCenter("SK", layout.Media, ui.TextStyle{Size: theme.Metrics.FontSizeM})
dialog.End()安装
将组件源码复制到自己的项目,直接修改。
go run ./cmd/viva add --out ./components/local alert-dialog源码组件用法#
此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。
- 标题旁的源码链接列出了全部选项与视觉决策。
- 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
- 浏览器预览验证共享布局和场景行为,不代表原生性能。
验证边界#
示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。
键盘操作
Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。