Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào ứng dụng đã cài registry, hoặc mở trong StackBlitz. Bấm một nút, hoặc Tab tới nó rồi nhấn Enter.
Xác nhận xóa
Nút thao tác nói rõ nó làm gì và dùng kiểu Danger. Hủy đứng trước, nhận focus khi dialog mở, và là điều Esc làm.
AlertDialogDelete.vue
<script setup lang="ts">
import { Trash2 } from '@lucide/vue'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
// Thao tác không hoàn tác được. Nút thao tác nói rõ nó làm gì; Hủy đứng trước và nhận focus.
</script>
<template>
<AlertDialog>
<AlertDialogTrigger as-child>
<Button variant="ghost-destructive"><Trash2 />Xóa mapping</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Xóa mapping này?</AlertDialogTitle>
<AlertDialogDescription>"SKU sản phẩm → Mã hàng" ngừng đồng bộ ngay. Các bản ghi đã đồng bộ giữ nguyên. Không thể hoàn tác.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Hủy</AlertDialogCancel>
<AlertDialogAction variant="destructive">Xóa mapping</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</template>Có icon
AlertDialogMedia đặt một ô icon cạnh tiêu đề. Chữ mang nghĩa; icon chỉ nhắc lại.
AlertDialogWithMedia.vue
<script setup lang="ts">
import { Unplug } from '@lucide/vue'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogMedia,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
// Ô icon cạnh tiêu đề. Icon nhắc lại thao tác; chữ mới mang ý nghĩa.
</script>
<template>
<AlertDialog>
<AlertDialogTrigger as-child>
<Button variant="outline">Ngắt kết nối cửa hàng</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogMedia>
<Unplug class="text-(--bh-color-icon-danger)" aria-hidden="true" />
</AlertDialogMedia>
<AlertDialogTitle>Ngắt kết nối cửa hàng online?</AlertDialogTitle>
<AlertDialogDescription>Đơn hàng ngừng đồng bộ sang ERP. Bạn có thể kết nối lại sau; cài đặt của cửa hàng được giữ.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Hủy</AlertDialogCancel>
<AlertDialogAction variant="destructive">Ngắt kết nối</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</template>Cỡ nhỏ
size="sm": một câu hỏi ngắn, căn giữa, hai câu trả lời đặt cạnh nhau.
AlertDialogSmall.vue
<script setup lang="ts">
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
// size="sm": câu hỏi ngắn, căn giữa, hai câu trả lời nằm cạnh nhau.
</script>
<template>
<AlertDialog>
<AlertDialogTrigger as-child>
<Button variant="outline">Rời trình soạn</Button>
</AlertDialogTrigger>
<AlertDialogContent size="sm">
<AlertDialogHeader>
<AlertDialogTitle>Bỏ các thay đổi?</AlertDialogTitle>
<AlertDialogDescription>Các chỉnh sửa bảng giá này chưa được lưu.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Tiếp tục sửa</AlertDialogCancel>
<AlertDialogAction variant="destructive">Bỏ thay đổi</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</template>