Alert
Displays a callout for important information, with support for default and destructive variants.
The Alert component displays a prominent message to the user. It supports a default informational style and a destructive variant for warnings or errors. Built with NativeWind for consistent styling across platforms.
Preview
You can add components to your app using the CLI.
Your session has expired. Please log in again.
Installation
npx novaui-cli add alertImport
import { Alert, AlertTitle, AlertDescription } from 'novaui-components'Basic Usage
The Alert component is a compound component with three parts:
Alert- The container with variant stylingAlertTitle- The bold heading textAlertDescription- The body text
You can add components to your app using the CLI.
import { Alert, AlertTitle, AlertDescription } from 'novaui-components'
export function BasicAlert() {
return (
<Alert>
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components to your app using the CLI.
</AlertDescription>
</Alert>
)
}Variants
Default
The standard alert for general information:
This is an informational alert with the default styling.
<Alert variant="default">
<AlertTitle>Default Alert</AlertTitle>
<AlertDescription>
This is an informational alert with the default styling.
</AlertDescription>
</Alert>Destructive
Use for errors, warnings, or destructive information:
Your session has expired. Please log in again.
<Alert variant="destructive">
<AlertTitle>Error</AlertTitle>
<AlertDescription>
Your session has expired. Please log in again.
</AlertDescription>
</Alert>With Icon
Pass an icon prop or include an icon as a child for visual emphasis:
This alert includes an icon for better visual communication.
import { Alert, AlertTitle, AlertDescription } from 'novaui-components'
import { Info } from 'lucide-react-native'
export function AlertWithIcon() {
return (
<Alert icon={<Info size={16} />}>
<AlertTitle>Note</AlertTitle>
<AlertDescription>
This alert includes an icon for better visual communication.
</AlertDescription>
</Alert>
)
}Custom Styling
Apply custom classes to any part of the Alert:
An alert with custom border and background colors.
<Alert className="border-2 border-primary bg-primary/10">
<AlertTitle className="text-primary">Custom Styled</AlertTitle>
<AlertDescription className="text-primary/80">
An alert with custom border and background colors.
</AlertDescription>
</Alert>Props API
Alert Props
Extends React.ComponentPropsWithoutRef<typeof View> and includes:
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'destructive' | 'default' | The visual style variant |
icon | React.ReactNode | - | Optional icon displayed at the top-left |
className | string | - | Additional CSS classes |
AlertTitle Props
Extends React.ComponentPropsWithoutRef<typeof Text>:
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The title text |
className | string | - | Additional CSS classes |
AlertDescription Props
Extends React.ComponentPropsWithoutRef<typeof Text>:
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The description text |
className | string | - | Additional CSS classes |
Accessibility
The Alert component includes built-in accessibility:
- Sets
role="alert"on the container for screen readers - Supports custom
accessibilityLabelfor additional context
Best Practices
-
Use appropriate variants:
defaultfor info,destructivefor errors/warnings -
Keep it brief: Alert content should be concise and actionable
-
Add icons: Use icons to quickly communicate the alert type visually
-
Don't overuse: Too many alerts can cause alert fatigue
Related Components
- Use
AlertDialogfor alerts that require user confirmation - Combine with
Buttonfor dismissible alerts