Components
Alert
A flexible alert component for displaying important messages with variants and customizable content.
Installation
bunx --bun harukit@latest add alert
npx harukit@latest add alert
pnpm dlx harukit@latest add alert
yarn dlx harukit@latest add alert
Example
Alert Title
This is an important message that requires the user's attention.
import {
Alert,
AlertTitle,
AlertDescription,
} from "@/components/ui/alert";
export function BasicAlert() {
return (
<Alert>
<AlertTitle>Alert Title</AlertTitle>
<AlertDescription>
This is an important message that requires the user's attention.
</AlertDescription>
</Alert>
);
}
Variants
Default Alert
This is a default alert message.
Destructive Alert
This is a destructive alert message indicating an error or warning.
import {
Alert,
AlertTitle,
AlertDescription,
} from "@/components/ui/alert";
export function AlertVariants() {
return (
<div className="space-y-4">
<Alert>
<AlertTitle>Default Alert</AlertTitle>
<AlertDescription>
This is a default alert message.
</AlertDescription>
</Alert>
<Alert variant="destructive">
<AlertTitle>Destructive Alert</AlertTitle>
<AlertDescription>
This is a destructive alert message indicating an error or warning.
</AlertDescription>
</Alert>
</div>
);
}
With Icon
Information
You can add icons to your alerts for better visual communication.
import {
Alert,
AlertTitle,
AlertDescription,
} from "@/components/ui/alert";
import { Info } from "lucide-react";
export function AlertWithIcon() {
return (
<Alert>
<Info className="h-4 w-4" />
<AlertTitle>Information</AlertTitle>
<AlertDescription>
You can add icons to your alerts for better visual communication.
</AlertDescription>
</Alert>
);
}
API Reference
Alert
The main alert container component with support for variants.
import { Alert } from "@/components/ui/alert";
Props
Prop | Type | Default | Description |
---|---|---|---|
variant | "default" | "destructive" | "default" | The visual style variant of the alert. |
className | string | - | Additional CSS classes to apply to the alert. |
role | string | "alert" | ARIA role for accessibility (automatically set). |
AlertTitle
The title component for the alert header.
import { AlertTitle } from "@/components/ui/alert";
Props
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the title. |
AlertDescription
The description component for the alert content.
import { AlertDescription } from "@/components/ui/alert";
Props
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes to apply to the description. |
Accessibility
The Alert component includes built-in accessibility features:
- Uses
role="alert"
to announce important messages to screen readers - Proper semantic HTML structure with heading elements
- Support for keyboard navigation
- High contrast variants for better visibility
Styling
The component uses Tailwind CSS classes and can be customized through:
- The
variant
prop for predefined styles - The
className
prop for additional custom styling - CSS custom properties for theme customization
Default Styling
- Rounded corners with border
- Padding and typography optimized for readability
- Icon positioning and spacing handled automatically
- Responsive design considerations