Skip to content

Alert

Component callout để hiển thị các thông báo quan trọng với nhiều biến thể khác nhau.

Cài đặt

bash
npx @galaxy-stack/nebula-cli@latest add alert
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add alert
bash
yarn dlx @galaxy-stack/nebula-cli@latest add alert
bash
bunx @galaxy-stack/nebula-cli@latest add alert
bash
# Nếu bạn đã cài đặt galaxy-design toàn cục
galaxy-design add alert

Dependencies

Component này tự động cài đặt các dependencies sau:

  • React: class-variance-authority
  • Vue: class-variance-authority
  • Angular: class-variance-authority
  • React Native: nativewind, tailwindcss
  • Flutter: Không cần thêm dependencies

Không cần cài đặt thủ công!

Sử dụng

Ví dụ cơ bản

tsx
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"

export default function AlertDemo() {
  return (
    <Alert>
      <AlertTitle>Chú ý!</AlertTitle>
      <AlertDescription>Bạn có thể thêm các component vào ứng dụng của mình bằng CLI.</AlertDescription>
    </Alert>
  )
}
vue
<script setup lang="ts">
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
</script>

<template>
  <Alert>
    <AlertTitle>Chú ý!</AlertTitle>
    <AlertDescription>Bạn có thể thêm các component vào ứng dụng của mình bằng CLI.</AlertDescription>
  </Alert>
</template>
typescript
import { Component } from '@angular/core';
import { AlertComponent, AlertTitleComponent, AlertDescriptionComponent } from '@/components/ui/alert';

@Component({
  selector: 'app-alert-demo',
  standalone: true,
  imports: [AlertComponent, AlertTitleComponent, AlertDescriptionComponent],
  template: `
    <ui-alert>
      <ui-alert-title>Chú ý!</ui-alert-title>
      <ui-alert-description>Bạn có thể thêm các component vào ứng dụng của mình bằng CLI.</ui-alert-description>
    </ui-alert>
  `
})
export class AlertDemoComponent {}

Biến thể Destructive

tsx
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"

export default function AlertDestructive() {
  return (
    <Alert variant="destructive">
      <AlertTitle>Lỗi</AlertTitle>
      <AlertDescription>Phiên của bạn đã hết hạn. Vui lòng đăng nhập lại.</AlertDescription>
    </Alert>
  )
}
vue
<script setup lang="ts">
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
</script>

<template>
  <Alert variant="destructive">
    <AlertTitle>Lỗi</AlertTitle>
    <AlertDescription>Phiên của bạn đã hết hạn. Vui lòng đăng nhập lại.</AlertDescription>
  </Alert>
</template>

API Reference

Props

PropTypeDefaultDescriptionFramework Support
variant'default' | 'destructive''default'Kiểu hiển thị của alertTất cả
className / classstring''Tên class CSSTất cả
asChildbooleanfalseRender như child elementChỉ React, Vue

Accessibility

  • Screen Reader: Sử dụng semantic markup với ARIA attributes
  • Role: Sử dụng role="alert" cho thông báo quan trọng
  • Keyboard: Có thể điều hướng bằng bàn phím

Source Code

Phát hành theo Giấy phép MIT.