警告提示
基于 zw-alert 基础组件构建的样式化警告提示组件族。
@zeus-web/alert反馈zweb add alert自动生成
交互演示
源码
请选择与你的应用框架匹配的入口。
html
<script type="module">
import '@zeus-web/alert/wc/auto'
</script>
<zw-alert variant="success">
<zw-alert-title>Deployment complete</zw-alert-title>
<zw-alert-description>
The new version is now available.
</zw-alert-description>
</zw-alert>tsx
import { Alert, AlertDescription, AlertTitle } from '@zeus-web/alert/react'
export function AlertExample() {
return (
<Alert variant="success">
<AlertTitle>Deployment complete</AlertTitle>
<AlertDescription>The new version is now available.</AlertDescription>
</Alert>
)
}vue
<script setup lang="ts">
import { Alert, AlertDescription, AlertTitle } from '@zeus-web/alert/vue'
</script>
<template>
<Alert variant="success">
<AlertTitle>Deployment complete</AlertTitle>
<AlertDescription>The new version is now available.</AlertDescription>
</Alert>
</template>添加
bash
zweb add alert导入
样式化 Registry 组件:
tsx
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'基础组件 React 包装器:
tsx
import { Alert, AlertTitle, AlertDescription } from '@zeus-web/alert/react'Web Component 入口:
ts
import '@zeus-web/alert/wc/auto'属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
variant | AlertVariant可选值: default, info, success, warning, danger | default | 视觉样式变体。 |
live | string | polite | ARIA 实时区域模式。 |
事件
暂无公开事件。
插槽
| 插槽 | 说明 |
|---|---|
default | 警告提示内容。 |
样式
使用 Tailwind: 是
主题变量:
bg-backgroundtext-foregroundborder
内部选择器:
[data-slot=alert-root][data-slot=alert-title][data-slot=alert-description]
Registry
Registry 源码:可用。
添加命令: zweb add alert
类型: component
依赖:
@zeus-web/alertclass-variance-authority
Registry 依赖:
cnglobals
文件:
templates/react/alert.tsx→components/ui/alert.tsxtemplates/vue/alert.ts→components/ui/alert.ts
AI 使用规则
建议:
- 使用 Alert 展示系统消息。
- 标题使用 AlertTitle。
- 详细说明使用 AlertDescription。
避免:
- 不要将 Alert 用作页面内容之外的持久横幅。
示例
React 样式化用法
tsx
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
export function Example() {
return (
<Alert variant="info">
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>Info message here.</AlertDescription>
</Alert>
)
}