AlertDialog
用于关键操作确认的模态对话框,默认将焦点落在安全取消按钮上并阻止点击外部关闭。
用于重要或不可逆操作确认的模态对话框,提供明确的操作意图、安全取消焦点并阻止点击外部意外关闭。本页示例采用 Shadcn Rhea 风格。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-alert-dialog-root style-profile="rhea">
<wc-shadcn-alert-dialog-trigger
style-profile="rhea"
variant="outline"
>
Show Dialog
</wc-shadcn-alert-dialog-trigger>
<wc-shadcn-alert-dialog-mask
style-profile="rhea"
></wc-shadcn-alert-dialog-mask>
<wc-shadcn-alert-dialog-content style-profile="rhea">
<wc-shadcn-alert-dialog-header style-profile="rhea">
<wc-shadcn-alert-dialog-title style-profile="rhea">
Are you absolutely sure?
</wc-shadcn-alert-dialog-title>
<wc-shadcn-alert-dialog-description style-profile="rhea">
This action cannot be undone. This will permanently delete
your account and remove your data from our servers.
</wc-shadcn-alert-dialog-description>
</wc-shadcn-alert-dialog-header>
<wc-shadcn-alert-dialog-footer style-profile="rhea">
<wc-shadcn-alert-dialog-cancel style-profile="rhea">
Cancel
</wc-shadcn-alert-dialog-cancel>
<wc-shadcn-alert-dialog-action style-profile="rhea">
Continue
</wc-shadcn-alert-dialog-action>
</wc-shadcn-alert-dialog-footer>
</wc-shadcn-alert-dialog-content>
</wc-shadcn-alert-dialog-root>将于 0.3.0-rc.1 及后续版本中通过 @proto.ui/prototypes-shadcn 与 CLI 提供(当前可从源码工作区直接使用)。
import { ShadcnAlertDialogRoot, ShadcnAlertDialogTrigger, ShadcnAlertDialogMask, ShadcnAlertDialogContent, ShadcnAlertDialogHeader, ShadcnAlertDialogTitle, ShadcnAlertDialogDescription, ShadcnAlertDialogFooter, ShadcnAlertDialogCancel, ShadcnAlertDialogAction,} from '../proto-ui/components/react';
export function Example() { return ( <ShadcnAlertDialogRoot styleProfile="rhea"> <ShadcnAlertDialogTrigger variant="outline">Show Dialog</ShadcnAlertDialogTrigger> <ShadcnAlertDialogMask /> <ShadcnAlertDialogContent> <ShadcnAlertDialogHeader> <ShadcnAlertDialogTitle>Are you absolutely sure?</ShadcnAlertDialogTitle> <ShadcnAlertDialogDescription> This action cannot be undone. This will permanently delete your account. </ShadcnAlertDialogDescription> </ShadcnAlertDialogHeader> <ShadcnAlertDialogFooter> <ShadcnAlertDialogCancel>Cancel</ShadcnAlertDialogCancel> <ShadcnAlertDialogAction>Continue</ShadcnAlertDialogAction> </ShadcnAlertDialogFooter> </ShadcnAlertDialogContent> </ShadcnAlertDialogRoot> );}AlertDialogRoot├── AlertDialogTrigger├── AlertDialogMask└── AlertDialogContent ├── AlertDialogHeader │ ├── AlertDialogTitle │ └── AlertDialogDescription └── AlertDialogFooter ├── AlertDialogCancel └── AlertDialogAction- Root:管理打开状态并固定启用
alertdialog模态语义。 - Trigger / Cancel / Action:各自持有独立命令状态,支持
variant、size、wrap与disabled。点击Action会先发出action事件,再请求关闭对话框。 - Mask / Content:提供模态遮罩、焦点锁定与 150ms 出入场过渡;打开时优先聚焦
Cancel,并阻止点击外部意外关闭。 - 风格预设(
styleProfile):支持vega、nova、maia、lyra、mira、luma、sera、rhea与new-york-v4(new-york兼容别名),省略时继承最近的 Style Scope。
键盘与无障碍
Section titled “键盘与无障碍”Escape或点击Cancel请求关闭并将焦点归还触发器。Tab/Shift + Tab在对话框内循环焦点。- 打开时默认优先聚焦安全的
Cancel操作;禁用的按钮不会激活。
紧凑尺寸(Small)
Section titled “紧凑尺寸(Small)”在 Content 上设置 size="sm" 以使用更紧凑的确认面板,并配合 Header 的 align="center" 居中排版。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-alert-dialog-root style-profile="rhea">
<wc-shadcn-alert-dialog-trigger
style-profile="rhea"
variant="outline"
>
Show Dialog
</wc-shadcn-alert-dialog-trigger>
<wc-shadcn-alert-dialog-mask
style-profile="rhea"
></wc-shadcn-alert-dialog-mask>
<wc-shadcn-alert-dialog-content style-profile="rhea" size="sm">
<wc-shadcn-alert-dialog-header
style-profile="rhea"
align="center"
>
<wc-shadcn-alert-dialog-title style-profile="rhea">
Allow accessory to connect?
</wc-shadcn-alert-dialog-title>
<wc-shadcn-alert-dialog-description style-profile="rhea">
Do you want to allow the USB accessory to connect to this
device?
</wc-shadcn-alert-dialog-description>
</wc-shadcn-alert-dialog-header>
<wc-shadcn-alert-dialog-footer style-profile="rhea">
<wc-shadcn-alert-dialog-cancel style-profile="rhea">
Don't allow
</wc-shadcn-alert-dialog-cancel>
<wc-shadcn-alert-dialog-action style-profile="rhea">
Allow
</wc-shadcn-alert-dialog-action>
</wc-shadcn-alert-dialog-footer>
</wc-shadcn-alert-dialog-content>
</wc-shadcn-alert-dialog-root>图标媒体(Media)
Section titled “图标媒体(Media)”在 Header 中放置图标容器以突出当前操作主题。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-alert-dialog-root style-profile="rhea">
<wc-shadcn-alert-dialog-trigger
style-profile="rhea"
variant="outline"
>
Share Project
</wc-shadcn-alert-dialog-trigger>
<wc-shadcn-alert-dialog-mask
style-profile="rhea"
></wc-shadcn-alert-dialog-mask>
<wc-shadcn-alert-dialog-content style-profile="rhea">
<wc-shadcn-alert-dialog-header
style-profile="rhea"
align="center"
>
<div
class="mb-2 inline-flex size-10 items-center justify-center rounded-lg bg-muted text-foreground"
aria-hidden="true"
>
+
</div>
<wc-shadcn-alert-dialog-title style-profile="rhea">
Share this project?
</wc-shadcn-alert-dialog-title>
<wc-shadcn-alert-dialog-description style-profile="rhea">
Anyone with the link will be able to view and edit this
project.
</wc-shadcn-alert-dialog-description>
</wc-shadcn-alert-dialog-header>
<wc-shadcn-alert-dialog-footer style-profile="rhea">
<wc-shadcn-alert-dialog-cancel style-profile="rhea">
Cancel
</wc-shadcn-alert-dialog-cancel>
<wc-shadcn-alert-dialog-action style-profile="rhea">
Share
</wc-shadcn-alert-dialog-action>
</wc-shadcn-alert-dialog-footer>
</wc-shadcn-alert-dialog-content>
</wc-shadcn-alert-dialog-root>破坏性操作(Destructive)
Section titled “破坏性操作(Destructive)”为 Trigger 与 Action 设置 variant="destructive",并搭配紧凑确认面板提示高风险删除操作。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-alert-dialog-root style-profile="rhea">
<wc-shadcn-alert-dialog-trigger
style-profile="rhea"
variant="destructive"
>
Delete Chat
</wc-shadcn-alert-dialog-trigger>
<wc-shadcn-alert-dialog-mask
style-profile="rhea"
></wc-shadcn-alert-dialog-mask>
<wc-shadcn-alert-dialog-content style-profile="rhea" size="sm">
<wc-shadcn-alert-dialog-header
style-profile="rhea"
align="center"
>
<div
class="mb-2 inline-flex size-10 items-center justify-center rounded-lg bg-destructive/10 text-destructive"
aria-hidden="true"
>
!
</div>
<wc-shadcn-alert-dialog-title style-profile="rhea">
Delete chat?
</wc-shadcn-alert-dialog-title>
<wc-shadcn-alert-dialog-description style-profile="rhea">
This will permanently delete this chat conversation and
remove any memories saved during this chat.
</wc-shadcn-alert-dialog-description>
</wc-shadcn-alert-dialog-header>
<wc-shadcn-alert-dialog-footer style-profile="rhea">
<wc-shadcn-alert-dialog-cancel
style-profile="rhea"
variant="outline"
>
Cancel
</wc-shadcn-alert-dialog-cancel>
<wc-shadcn-alert-dialog-action
style-profile="rhea"
variant="destructive"
>
Delete
</wc-shadcn-alert-dialog-action>
</wc-shadcn-alert-dialog-footer>
</wc-shadcn-alert-dialog-content>
</wc-shadcn-alert-dialog-root>受控状态(Controlled)
Section titled “受控状态(Controlled)”传入 open 并监听 openChange 与 action 事件,由外部状态驱动显示与确认后的业务更新。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-alert-dialog-root
id="controlled-alert"
style-profile="rhea"
>
<wc-shadcn-alert-dialog-trigger
style-profile="rhea"
variant="outline"
>
Archive Workspace
</wc-shadcn-alert-dialog-trigger>
<wc-shadcn-alert-dialog-mask
style-profile="rhea"
></wc-shadcn-alert-dialog-mask>
<wc-shadcn-alert-dialog-content style-profile="rhea">
<wc-shadcn-alert-dialog-header style-profile="rhea">
<wc-shadcn-alert-dialog-title style-profile="rhea">
Archive this workspace?
</wc-shadcn-alert-dialog-title>
<wc-shadcn-alert-dialog-description style-profile="rhea">
Members will keep read-only access until an administrator
restores the workspace.
</wc-shadcn-alert-dialog-description>
</wc-shadcn-alert-dialog-header>
<wc-shadcn-alert-dialog-footer style-profile="rhea">
<wc-shadcn-alert-dialog-cancel style-profile="rhea">
Cancel
</wc-shadcn-alert-dialog-cancel>
<wc-shadcn-alert-dialog-action
id="archive-action"
style-profile="rhea"
>
Archive
</wc-shadcn-alert-dialog-action>
</wc-shadcn-alert-dialog-footer>
</wc-shadcn-alert-dialog-content>
</wc-shadcn-alert-dialog-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#controlled-alert');
setElementProps(root, { open: false });
root.addEventListener('openChange', (e) =>
setElementProps(root, { open: e.detail.open })
);
</script>从右到左(RTL)
Section titled “从右到左(RTL)”在容器与对话框内容中设置 dir="rtl",Header 会通过逻辑对齐(text-start)自动适配阅读方向。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div dir="rtl" lang="ar" class="flex gap-4">
<wc-shadcn-alert-dialog-root style-profile="rhea">
<wc-shadcn-alert-dialog-trigger
style-profile="rhea"
variant="outline"
>
إظهار الحوار
</wc-shadcn-alert-dialog-trigger>
<wc-shadcn-alert-dialog-mask
style-profile="rhea"
></wc-shadcn-alert-dialog-mask>
<wc-shadcn-alert-dialog-content style-profile="rhea">
<div dir="rtl" lang="ar" class="grid gap-6">
<wc-shadcn-alert-dialog-header style-profile="rhea">
<wc-shadcn-alert-dialog-title style-profile="rhea">
هل أنت متأكد تمامًا؟
</wc-shadcn-alert-dialog-title>
<wc-shadcn-alert-dialog-description style-profile="rhea">
لا يمكن التراجع عن هذا الإجراء. سيؤدي هذا إلى حذف حسابك
نهائيًا من خوادمنا.
</wc-shadcn-alert-dialog-description>
</wc-shadcn-alert-dialog-header>
<wc-shadcn-alert-dialog-footer style-profile="rhea">
<wc-shadcn-alert-dialog-cancel style-profile="rhea">
إلغاء
</wc-shadcn-alert-dialog-cancel>
<wc-shadcn-alert-dialog-action style-profile="rhea">
متابعة
</wc-shadcn-alert-dialog-action>
</wc-shadcn-alert-dialog-footer>
</div>
</wc-shadcn-alert-dialog-content>
</wc-shadcn-alert-dialog-root>
</div>与 Dialog 不同,AlertDialog 的 Root 始终保持 alertdialog 模式。
| 属性 / 事件 / 方法 | 类型 | 默认值 |
|---|---|---|
open | boolean | undefined(非受控) |
defaultOpen | boolean | false |
disabled | boolean | false |
a11yLabel | string | '' |
styleProfile | ShadcnStyleChoice | inherit → scope → new-york-v4 |
openChange(事件) | { open: boolean; reason: string null; focusReason: string null } | — |
openAlertDialog / close / toggle(方法) | (reason?: string) => void | — |
Content 与 Mask
Section titled “Content 与 Mask”| 属性 | 类型 | 默认值 |
|---|---|---|
Content.size | 'default' 'sm' | 'default' |
Content.enterDuration / leaveDuration | number | 150 |
Mask.passthrough | boolean | false |
Mask.enterDuration / leaveDuration | number | 150 |
Header.align | 'start' 'center' | 'start' |
Trigger、Cancel 与 Action
Section titled “Trigger、Cancel 与 Action”| 属性 / 事件 | 类型 | 默认值 |
|---|---|---|
variant | 'default' 'destructive' 'outline' 'secondary' 'ghost' 'link' | Trigger/Cancel: 'outline' / Action: 'default' |
size | 'default' 'sm' 'lg' 'icon' | 'default' |
wrap | boolean | false |
disabled | boolean | false |
Action.action(事件) | { reason: string } | — |