Skip to content

Alert

A callout component that displays important messages with different variants.

Installation

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
# If you have installed galaxy-design globally
galaxy-design add alert

Dependencies

This component automatically installs the following dependencies:

  • React: class-variance-authority
  • Vue: class-variance-authority
  • Angular: class-variance-authority
  • React Native: nativewind, tailwindcss
  • Flutter: No additional dependencies

No manual installation needed!

Usage

Basic Example

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

export default function AlertDemo() {
  return (
    <Alert>
      <AlertTitle>Heads up!</AlertTitle>
      <AlertDescription>You can add components to your app using the cli.</AlertDescription>
    </Alert>
  )
}
vue
<script setup lang="ts">
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
</script>

<template>
  <Alert>
    <AlertTitle>Heads up!</AlertTitle>
    <AlertDescription>You can add components to your app using the 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>Heads up!</ui-alert-title>
      <ui-alert-description>You can add components to your app using the cli.</ui-alert-description>
    </ui-alert>
  `
})
export class AlertDemoComponent {}

Destructive Variant

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

export default function AlertDestructive() {
  return (
    <Alert variant="destructive">
      <AlertTitle>Error</AlertTitle>
      <AlertDescription>Your session has expired. Please log in again.</AlertDescription>
    </Alert>
  )
}
vue
<script setup lang="ts">
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
</script>

<template>
  <Alert variant="destructive">
    <AlertTitle>Error</AlertTitle>
    <AlertDescription>Your session has expired. Please log in again.</AlertDescription>
  </Alert>
</template>
typescript
<ui-alert variant="destructive">
  <ui-alert-title>Error</ui-alert-title>
  <ui-alert-description>Your session has expired. Please log in again.</ui-alert-description>
</ui-alert>

API Reference

Props

PropTypeDefaultDescriptionFrameworks
variant'default' | 'destructive''default'Visual style variant for the alertAll
className / classstring''CSS class names for the alert containerAll

AlertTitle Props

PropTypeDefaultDescriptionFrameworks
className / classstring''CSS class names for the alert titleAll

AlertDescription Props

PropTypeDefaultDescriptionFrameworks
className / classstring''CSS class names for the alert descriptionAll

Accessibility

  • Semantic HTML: Uses appropriate ARIA roles for alert regions
  • Screen Reader: Announces alert content with proper priority
  • Destructive alerts: Clearly indicate error states
  • WCAG Compliance: WCAG 2.1 Level AA compliant

Author

Bùi Trọng Hiếu (kevinbui)

License

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Released under the MIT License.