Trên trang này

Alert

Ví dụ chạy được của Alert, kèm đúng file Vue tạo ra từng ví dụ.

Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào app đã cài registry, hoặc mở trong StackBlitz.

Bốn vai trạng thái

Info, success, warning và destructive (hoặc danger). Icon mang màu của vai; chữ giữ color.text. Banner có sẵn trên trang từ đầu dùng role="status".

Đơn hàng đồng bộ mỗi 15 phút
Đơn hàng mới từ cửa hàng online tới ERP trong vòng mười lăm phút.
Đã đồng bộ cả 1.240 đơn hàng
Lần chạy gần nhất xong lúc 09:30, không có lỗi.
Số tồn kho đã cũ 2 giờ
Kết nối kho đang chậm. Số tồn kho có thể chưa đúng cho tới khi kết nối bắt kịp.
AlertRoles.vue
<script setup lang="ts">
import { CircleCheck, Info, OctagonX, TriangleAlert } from '@lucide/vue'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
</script>

<template>
  <div class="flex w-full max-w-120 flex-col gap-(--bh-space-150)">
    <Alert variant="info" role="status">
      <Info />
      <AlertTitle>Đơn hàng đồng bộ mỗi 15 phút</AlertTitle>
      <AlertDescription>Đơn hàng mới từ cửa hàng online tới ERP trong vòng mười lăm phút.</AlertDescription>
    </Alert>
    <Alert variant="success" role="status">
      <CircleCheck />
      <AlertTitle>Đã đồng bộ cả 1.240 đơn hàng</AlertTitle>
      <AlertDescription>Lần chạy gần nhất xong lúc 09:30, không có lỗi.</AlertDescription>
    </Alert>
    <Alert variant="warning" role="status">
      <TriangleAlert />
      <AlertTitle>Số tồn kho đã cũ 2 giờ</AlertTitle>
      <AlertDescription>Kết nối kho đang chậm. Số tồn kho có thể chưa đúng cho tới khi kết nối bắt kịp.</AlertDescription>
    </Alert>
    <Alert variant="destructive">
      <OctagonX />
      <AlertTitle>Đơn hàng không đồng bộ được</AlertTitle>
      <AlertDescription>ERP từ chối API key. Nhờ quản trị viên kết nối lại ERP.</AlertDescription>
    </Alert>
  </div>
</template>

Kèm một thao tác

AlertAction đặt một nút nhỏ ở cuối. Nhãn nút nói rõ nút làm gì.

Kết nối CRM hết hạn sau 3 ngày
Kết nối lại để khách hàng và cơ hội bán hàng tiếp tục đồng bộ.
AlertWithAction.vue
<script setup lang="ts">
import { TriangleAlert } from '@lucide/vue'
import { Alert, AlertAction, AlertDescription, AlertTitle } from '@/components/ui/alert'
import { Button } from '@/components/ui/button'
</script>

<template>
  <Alert variant="warning" role="status" class="max-w-120">
    <TriangleAlert />
    <AlertTitle>Kết nối CRM hết hạn sau 3 ngày</AlertTitle>
    <AlertDescription>Kết nối lại để khách hàng và cơ hội bán hàng tiếp tục đồng bộ.</AlertDescription>
    <AlertAction>
      <Button variant="outline" size="sm">Kết nối lại</Button>
    </AlertAction>
  </Alert>
</template>

Lỗi sau khi lưu

Hiện để trả lời việc người dùng vừa làm, nên giữ role="alert" mặc định và được đọc ngay.

AlertErrorList.vue
<script setup lang="ts">
import { OctagonX } from '@lucide/vue'
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
</script>

<template>
  <!-- Hiện sau khi lưu thất bại: role="alert" (mặc định) đọc ngay nội dung. -->
  <Alert variant="destructive" class="max-w-120">
    <OctagonX />
    <AlertTitle>Chưa lưu được mapping</AlertTitle>
    <AlertDescription>
      <p>Sửa 2 trường này rồi lưu lại:</p>
      <ul class="m-0 ps-(--bh-space-300)">
        <li>SKU: sản phẩm nào cũng cần có.</li>
        <li>Nhóm thuế: chọn một nhóm có trong ERP.</li>
      </ul>
    </AlertDescription>
  </Alert>
</template>