数据与反馈@neumorphism-ui/alert

Alert

用于排列图标、标题和说明的组合式 Alert。提供 default、success、destructive 三种变体,所有变体都同时使用边框和文字对比度,而不只依赖颜色。

@neumorphism-ui/alert
Registry JSON

预览

安装

安装: alertnpx shadcn@latest add @neumorphism-ui/alert

CLI 会依次处理 npm 依赖、base token、utils 和组件源码。

首次使用此 Registry?请先完成 namespace 配置 。

用法

Import

Alert import 代码
import {
  Alert,
  AlertDescription,
  AlertTitle,
} from "@/components/ui/alert"

Example

Alert 用法代码
<Alert variant="success">
  <svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="m5 12 4 4L19 6" /></svg>
  <AlertTitle>更改已保存</AlertTitle>
  <AlertDescription>
    所有团队成员都可以看到这些更改。
  </AlertDescription>
</Alert>

API 参考

组件属性类型默认值说明
Alertvariant"default" | "success" | "destructive""default"选择消息的语义和视觉状态。
AlertchildrenReact.ReactNode—排列图标、AlertTitle 和 AlertDescription。
AlertclassNamestring—扩展默认表面样式。

无障碍

  • 01

    Alert 使用 role=alert,适合动态出现的重要消息。

  • 02

    页面加载时已经存在的普通提示通常不需要 role=alert 的即时朗读,可覆盖 role 或改用其他容器。

  • 03

    装饰性图标应设置 aria-hidden=true,同时用标题和说明文本传达其含义。