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
12 KiB
12 KiB
title, description, component, group
| title | description | component | group |
|---|---|---|---|
| AlertDialog 警告对话框 | 需要用户明确确认的警告对话框,默认禁止误关闭。 | alert-dialog | 组件 |
基于固定 HeroUI 3.2.6(ce90ea3)迁移。命名组件、v-model、作用域插槽与 DOM attrs 为 Vue 适配;预览、复制与高亮来自同一份 SFC。
用法
import { AlertDialog } from "@heroui-vue/components";
组件结构
<script setup lang="ts">
import {
AlertDialog,
AlertDialogBackdrop,
AlertDialogBody,
AlertDialogClose,
AlertDialogCloseTrigger,
AlertDialogContainer,
AlertDialogDialog,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogHeading,
AlertDialogIcon,
Button,
} from "@heroui-vue/components";
</script>
<template>
<AlertDialog>
<Button variant="danger">删除项目</Button>
<AlertDialogBackdrop>
<AlertDialogContainer>
<AlertDialogDialog>
<AlertDialogCloseTrigger />
<AlertDialogHeader>
<AlertDialogIcon status="danger" />
<AlertDialogHeading>要永久删除项目吗?</AlertDialogHeading>
</AlertDialogHeader>
<AlertDialogBody>此操作无法撤销。</AlertDialogBody>
<AlertDialogFooter>
<AlertDialogClose as-child>
<Button variant="tertiary">取消</Button>
</AlertDialogClose>
<AlertDialogClose as-child>
<Button variant="danger">删除</Button>
</AlertDialogClose>
</AlertDialogFooter>
</AlertDialogDialog>
</AlertDialogContainer>
</AlertDialogBackdrop>
</AlertDialog>
</template>
Dialog 渲染 role="alertdialog"。默认 isDismissable=false、isKeyboardDismissDisabled=true(与 Modal 相反),二者可独立配置。
示例
状态类型
弹出位置
尺寸
受控模式
自定义图标
自定义触发器
遮罩变体
自定义遮罩
关闭行为
关闭方式
自定义动画
自定义 Portal
自定义样式
Tailwind CSS
全局 CSS
若要自定义组件类,可使用 @layer components 指令:
@layer components {
.hv-alert-dialog__backdrop {
@apply bg-gradient-to-br from-black/60 to-black/80;
}
.hv-alert-dialog__dialog {
@apply rounded-2xl border border-red-500/20 shadow-2xl;
}
.hv-alert-dialog__header {
@apply gap-4;
}
.hv-alert-dialog__icon {
@apply size-16;
}
.hv-alert-dialog__close-trigger {
@apply rounded-full bg-white/10 hover:bg-white/20;
}
}
样式参考
HeroUI 遵循 BEM 方法论。类名前缀 hv-。
CSS 类
基础类
.hv-alert-dialog__trigger- 打开警告对话框的触发元素.hv-alert-dialog__backdrop- 遮罩层.hv-alert-dialog__container- 支持 placement 的定位包裹层.hv-alert-dialog__dialog- 对话框内容容器.hv-alert-dialog__header- 图标与标题头部.hv-alert-dialog__heading- 标题文本.hv-alert-dialog__body- 主内容区域.hv-alert-dialog__footer- 操作按钮区域.hv-alert-dialog__icon- 状态色图标容器.hv-alert-dialog__close-trigger- 关闭按钮
遮罩变体
.hv-alert-dialog__backdrop--opaque/--blur/--transparent
状态变体(图标)[!toc]
.hv-alert-dialog__icon--default/--accent/--success/--warning/--danger
交互状态
- Focus:
:focus-visible或[data-focus-visible="true"] - Hover:
:hover或[data-hovered="true"] - Active:
:active或[data-pressed="true"] - Entering:
[data-entering] - Exiting:
[data-exiting] - Placement:
[data-placement="*"](auto、top、center、bottom)
API 参考
AlertDialog / AlertDialogRoot
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
open / isOpen |
boolean |
- | 受控打开 |
defaultOpen |
boolean |
false |
初始打开 |
state |
OverlayState |
- | useOverlayState 实例 |
update:open / update:isOpen / openChange |
(value: boolean) => void |
- | 状态事件 |
| 默认插槽 | { isOpen, close } |
- | 内容;首个 Button 自动作为触发器 |
AlertDialogTrigger
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
as |
string |
'div' |
渲染元素 |
asChild |
boolean |
false |
合并到唯一子元素 |
isDisabled |
boolean |
false |
禁用触发 |
class |
string | Array | Object |
- | CSS 类 |
| 默认插槽 | - | - | 触发器内容 |
AlertDialogBackdrop
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
variant |
'opaque' | 'blur' | 'transparent' |
'opaque' |
遮罩样式 |
isDismissable |
boolean |
false |
点击遮罩是否关闭 |
isKeyboardDismissDisabled |
boolean |
true |
是否禁用 ESC |
open / isOpen / defaultOpen |
无父 AlertDialog 时自建状态 | ||
state |
OverlayState |
- | 受控状态 |
to |
string | HTMLElement |
body | 传送门容器(替代 UNSTABLE_portalContainer) |
update:open / openChange |
(value: boolean) => void |
- | 状态事件 |
| 默认插槽 | { isOpen, close } |
- | Container 等 |
AlertDialogContainer
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
placement |
'auto' | 'center' | 'top' | 'bottom' |
'auto' |
位置 |
size |
'xs' | 'sm' | 'md' | 'lg' | 'cover' |
'md' |
尺寸 |
as |
string |
'div' |
渲染元素 |
class |
string | Array | Object |
- | CSS 类 |
| 默认插槽 | { close } |
- | Dialog 等 |
AlertDialogDialog
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
role |
string |
'alertdialog' |
ARIA role |
aria-label / aria-labelledby / aria-describedby |
string |
自动标题关联 | 无障碍名称与描述 |
as |
string |
'div' |
渲染元素 |
id |
string |
自动 | 内容 id |
class |
string | Array | Object |
- | CSS 类 |
| 默认插槽 | { close, isOpen } |
- | 面板内容 |
AlertDialogHeader / Heading / Body / Footer
| 部件 | Prop | 描述 |
|---|---|---|
| Header | class、默认插槽 |
图标 + 标题容器 |
| Heading | as(默认 h2)、id、class |
注册为 dialog 标题 |
| Body | class、默认插槽 |
正文 |
| Footer | class、默认插槽 |
操作区 |
AlertDialogIcon
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
status |
'default' | 'accent' | 'success' | 'warning' | 'danger' |
'danger' |
状态配色与默认图标 |
as |
string |
'div' |
渲染元素 |
class |
string | Array | Object |
- | CSS 类 |
| 默认插槽 | - | 状态 SVG | 自定义图标 |
AlertDialogCloseTrigger / AlertDialogClose
| 部件 | Prop | 描述 |
|---|---|---|
| CloseTrigger | variant、isDisabled、class |
X 按钮,点击关闭 |
| Close | as、asChild、isDisabled |
包裹任意控件以关闭;替代上游 slot="close" |
useOverlayState
import { useOverlayState } from "@heroui-vue/components";
const state = useOverlayState({ defaultOpen: false });
state.isOpen.value;
state.open();
state.close();
state.toggle();
state.setOpen(true);
上游差异
| 上游 React | Vue |
|---|---|
对象子部件 AlertDialog.Icon |
具名导出 |
Button slot="close" |
AlertDialogClose as-child |
| Dialog render props | 作用域插槽 { close, isOpen } |
UNSTABLE_portalContainer |
to |
onPress |
@click |
无障碍
role="alertdialog",标题经aria-labelledby关联真实 Heading- 显式
aria-labelledby/aria-label优先于自动计算 - 默认禁止 ESC 与外部点击误关闭
- 破坏性操作示例仅修改本地演示状态