Alert
Displays a callout for user attention.
Overview
图标 + 标题 + 描述的基础提示块,Overview 连续展示两条。
GPUI · Live previewTry it out
Installation
Alert 是单个 Rust 文件(src/alert.rs),直接用 gpui 的元素与 PathBuilder 图标绘制。复制到你的 crate,或下载完整示例直接运行。
[dependencies]gpui-kit = "0.6.6"# alert.rs is a single styled component —# it uses gpui's div / canvas / PathBuilder# directly, no extra primitives needed.# Download the runnable example crate, then:cargo run --locked -- --alert# Other demos:cargo run --locked -- --alert destructivecargo run --locked -- --alert actioncargo run --locked -- --alert customUsage
builder 链式配置图标、标题、描述与操作按钮;把实体保留在宿主视图上,渲染时放进任意容器。
use justdo_command::alert::{Alert, AlertIcon};// Keep the entity on your host view.let alert = cx.new(|_| { Alert::new() .icon(AlertIcon::Check) .title("Payment successful") .description("Your payment of $29.99 has been processed.")});// In render: div().child(self.alert.clone())网页预览与桌面端运行同一份 Rust / GPUI 组件。
Composition
组合结构对齐 shadcn/ui 的 Alert:容器 + 图标 + 标题 + 描述 + 可选操作。操作按钮独立可聚焦。
Alert status callout├── Icon info · check · error · warning├── AlertTitle .title(..)├── AlertDescription .description(..)└── AlertAction .action(..) -> AlertActionEventAccessibility
Keyboard
- Tab 沿页面 tab 序聚焦操作按钮
- Enter Space 触发 AlertActionEvent
Semantics
Alert 是静态状态提示(对应 role="alert" 的展示语义),action 变体的按钮可聚焦、带 focus-visible 高亮。reduced-motion 下入场动画自动关闭。
API Reference
组件实体暴露的方法与事件。
| API | Signature | Notes |
|---|---|---|
Alert::new() | -> Alert | Creates the entity content. Default variant, no icon. |
.variant(..) | AlertVariant | Default | Destructive — flips surface, border and ink colors. |
.icon(..) | AlertIcon | Info | Check | Error | Warning, drawn with PathBuilder. |
.title(..) | impl Into<SharedString> | Bold heading line inside the callout. |
.description(..) | impl Into<SharedString> | Secondary copy under the title. |
.action(..) | impl Into<SharedString> | Right-side button; pressing it emits AlertActionEvent. |
.surface/.edge/.tint(..) | impl Into<Hsla> | Per-alert color overrides for custom-color variants. |
.dark(bool) | bool | Dark color scheme for surfaces, text and borders. |
AlertActionEvent | { label } | Emitted on action press; subscribe with cx.subscribe. |
// AlertActionEvent { label } is emitted when the action is pressed.cx.subscribe(&self.alert, |view, _alert, event, cx| { println!("pressed: {}", event.label); cx.notify();});Source & inspiration
结构与视觉参考 shadcn/ui Alert 。本页交互由 Rust / GPUI 绘制,基础样式来自 gpui-kit 。