145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
149 lines
5.0 KiB
Markdown
149 lines
5.0 KiB
Markdown
---
|
||
title: Alert 警告
|
||
description: 向用户展示重要消息与通知,并提供状态指示
|
||
component: alert
|
||
group: 组件
|
||
---
|
||
|
||
## 用法
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import {
|
||
Alert,
|
||
AlertContent,
|
||
AlertDescription,
|
||
AlertIndicator,
|
||
AlertTitle,
|
||
} from "@heroui-vue/components";
|
||
</script>
|
||
```
|
||
|
||
<ComponentPreview name="alert-basic" />
|
||
|
||
## 组件结构
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import {
|
||
Alert,
|
||
AlertContent,
|
||
AlertDescription,
|
||
AlertIndicator,
|
||
AlertTitle,
|
||
} from "@heroui-vue/components";
|
||
</script>
|
||
|
||
<template>
|
||
<Alert>
|
||
<AlertIndicator />
|
||
<AlertContent>
|
||
<AlertTitle />
|
||
<AlertDescription />
|
||
</AlertContent>
|
||
</Alert>
|
||
</template>
|
||
```
|
||
|
||
省略 `AlertIndicator` 默认插槽时显示随 `status` 变化的状态图标;传入自定义内容会替换默认图标。
|
||
|
||
## 自定义样式
|
||
|
||
### Tailwind CSS
|
||
|
||
<ComponentPreview name="alert-custom-styles" />
|
||
|
||
### 全局 CSS
|
||
|
||
要自定义 Alert 的组件类,可使用 `@layer components` 指令。
|
||
|
||
```css
|
||
@layer components {
|
||
.hv-alert {
|
||
@apply rounded-2xl shadow-lg;
|
||
}
|
||
|
||
.hv-alert__title {
|
||
@apply font-bold text-lg;
|
||
}
|
||
|
||
.hv-alert--danger {
|
||
@apply border-l-4 border-red-600;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 样式参考
|
||
|
||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||
|
||
### CSS 类
|
||
|
||
Alert 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/alert.css)):
|
||
|
||
#### 基础类 [!toc]
|
||
|
||
- `.hv-alert` - Alert 根容器
|
||
- `.hv-alert__indicator` - 图标/指示器容器
|
||
- `.hv-alert__content` - 包裹标题与说明的内容容器
|
||
- `.hv-alert__title` - Alert 标题文本
|
||
- `.hv-alert__description` - Alert 说明文本
|
||
|
||
#### 状态变体类 [!toc]
|
||
|
||
- `.hv-alert--default` - 默认灰色状态
|
||
- `.hv-alert--accent` - 强调蓝色状态
|
||
- `.hv-alert--success` - 成功绿色状态
|
||
- `.hv-alert--warning` - 警告黄/橙色状态
|
||
- `.hv-alert--danger` - 危险红色状态
|
||
|
||
### 交互状态
|
||
|
||
Alert 主要用于信息展示,基础组件本身通常没有交互状态;但它可以包含按钮或关闭按钮等交互元素。不会自动获得焦点、弹窗或自动关闭行为。
|
||
|
||
## API 参考
|
||
|
||
### Alert
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | ------------------------------------------------------------- | ----------- | ----------------------------- |
|
||
| `status` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | Alert 的视觉状态 |
|
||
| 默认插槽 | `Component` | - | Alert 内容 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
### AlertIndicator
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | --------------------------- | ------ | ------------------------------------------------------------ |
|
||
| 默认插槽 | `Component` | - | 自定义指示图标;省略或内容为空时显示随 status 更新的默认图标 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
### AlertContent
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | --------------------------- | ------ | ----------------------------------- |
|
||
| 默认插槽 | `Component` | - | 内容(通常为 Title 与 Description) |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
### AlertTitle
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||
| 默认插槽 | `Component` | - | Alert 标题文本 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
### AlertDescription
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||
| 默认插槽 | `Component` | - | Alert 说明文本 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与对应 slot 的基础类合并;不要使用 React 的 `className`。命名导出为 `Alert` / `AlertIndicator` / `AlertContent` / `AlertTitle` / `AlertDescription`,不使用 `Alert.Indicator` 对象式子部件。
|
||
|
||
Alert 会把内部 `surfaceContext` 重置为 `default`,避免嵌套在其他 Surface 中时意外继承外层表面变体。
|
||
|
||
## 相关组件
|
||
|
||
[CloseButton 关闭按钮](./close-button) · [Button 按钮](./button) · [Spinner 加载指示器](./spinner)
|