Skip to content

AlertDialog 提示对话框

新粗野主义风格的确认对话框,需要用户交互。基于 reka-ui 的 AlertDialog 原语构建。

预览

Preview

安装

pnpm dlx brutx-vue@latest add alert-dialog

用法

vue
<script setup>
import { AlertDialogRoot as AlertDialog, AlertDialogTrigger } from 'reka-ui'
import { AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel } from 'brutx-ui-vue'
import { Button } from 'brutx-ui-vue'
</script>

<template>
    <AlertDialog>
        <AlertDialogTrigger as-child>
            <Button variant="danger">Delete Account</Button>
        </AlertDialogTrigger>
        <AlertDialogContent>
            <AlertDialogHeader>
                <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
                <AlertDialogDescription>
                    This action cannot be undone. This will permanently delete your account and remove your data.
                </AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
                <AlertDialogCancel>Cancel</AlertDialogCancel>
                <AlertDialogAction>Continue</AlertDialogAction>
            </AlertDialogFooter>
        </AlertDialogContent>
    </AlertDialog>
</template>

子组件

组件说明
AlertDialog根组件(需从 reka-ui 导入:import { AlertDialogRoot as AlertDialog } from 'reka-ui'
AlertDialogTrigger打开对话框的按钮(需从 reka-ui 导入:import { AlertDialogTrigger } from 'reka-ui'
AlertDialogPortal传送门组件(需从 reka-ui 导入:import { AlertDialogPortal } from 'reka-ui'
AlertDialogContent对话框内容面板
AlertDialogHeader标题和描述的头部容器
AlertDialogFooter操作按钮的底部容器
AlertDialogTitle对话框标题
AlertDialogDescription对话框描述文本
AlertDialogAction确认操作按钮
AlertDialogCancel关闭对话框的取消按钮

Props

AlertDialogContent

属性类型默认值说明
classstring自定义样式类

AlertDialogHeader

属性类型默认值说明
classstring自定义样式类

AlertDialogFooter

属性类型默认值说明
classstring自定义样式类

AlertDialogTitle

属性类型默认值说明
classstring自定义样式类

AlertDialogDescription

属性类型默认值说明
classstring自定义样式类

AlertDialogAction

属性类型默认值说明
variant'default' | 'primary' | 'secondary' | 'accent' | 'danger' | 'success' | 'outline' | 'ghost' | 'link''default'按钮变体
classstring自定义样式类
asstring | Component渲染为指定元素或组件
asChildboolean是否以子元素方式渲染

AlertDialogCancel

属性类型默认值说明
classstring自定义样式类

AlertDialogCancel 使用硬编码的 variant: 'outline'

插槽

插槽作用域说明
default所有子组件均支持默认插槽,用于插入自定义内容

可访问性

  • 键盘操作:按 Escape 关闭对话框;AlertDialogCancel 点击后关闭对话框;AlertDialogAction 确认并关闭对话框
  • ARIA 属性:对话框使用语义化的 role="alertdialog" 属性
  • 焦点管理:对话框打开时,焦点被限制在对话框内

蛮力铸就。