Alert
ui.widgets.Alert页面内持久反馈。
BEHAVIOR CONTRACT
info / success / warning / error 语义色、标题和无标题消息保持一致布局。
RECORDED INTERACTION
录像展示四种语义级别。
// ── Alert ──
pub fn buildAlert(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
const a = cx.allocator;
const c = try col(cx, 12);
// 全 4 变体,且都带 closable(× 关闭按钮)
try c.appendChild(a, try W.Alert(.{ .variant = .info, .title = "Info", .message = "Informational message.", .closable = true }).mount(scope, cx));
try c.appendChild(a, try W.Alert(.{ .variant = .success, .title = "Success", .message = "It worked.", .closable = true }).mount(scope, cx));
try c.appendChild(a, try W.Alert(.{ .variant = .warning, .title = "Warning", .message = "Be careful.", .closable = true }).mount(scope, cx));
try c.appendChild(a, try W.Alert(.{ .variant = .@"error", .title = "Error", .message = "Something broke.", .closable = true }).mount(scope, cx));
// 无标题(仅 message)
try c.appendChild(a, try W.Alert(.{ .variant = .info, .message = "Title-less alert with just a message." }).mount(scope, cx));
return c;
}这是 Storybook 中该 story 的原样代码(zenit 5f9add5+wip 2026-09-30)。其中 W 即 ui.widgets,col / row / label 是 Storybook 内的布局小工具。
AlertProps
ui.widgets.Alertfn Alert(props: AlertProps) AlertBuilder字段
类型
默认值
说明
variantAlertVariant.info.success.warning.@"error".info—
title?[]const u8null—
message[]const u8""—
closableboolfalse—
on_close?core.HandlerRefnull—
close_icon_asset?svg_assets.Assetnull—
*Node
ui.widgets.Alertmount 直接返回 *Node,把它 append 到父节点即可。