Alert
An alert that conveys important information to the user. Supports four variants (info, success, warning, danger).
View in Storybook (opens in a new tab)
Installation
import { Alert } from "@ginga-ui/core";Basic usage
A simple alert with a title and description.
The service will be unavailable tomorrow from 2:00 AM to 4:00 AM for scheduled maintenance.
import { Alert, AlertDescription, AlertTitle } from "@ginga-ui/core";
import { Info } from "lucide-react";
export function BasicExample() {
return (
<Alert icon={<Info />}>
<AlertTitle>Notice</AlertTitle>
<AlertDescription>
The service will be unavailable tomorrow from 2:00 AM to 4:00 AM for
scheduled maintenance.
</AlertDescription>
</Alert>
);
}Variants
Four variants are available: info, success, warning, and danger.
A new version is available.
Your changes have been saved.
You are running low on storage space.
Failed to load data.
import { Alert, AlertDescription, AlertTitle } from "@ginga-ui/core";
import styles from "./alert.module.css";
import { CircleAlert, CircleCheck, Info, TriangleAlert } from "lucide-react";
export function VariantsExample() {
return (
<div className={styles.alertStack}>
<Alert variant="info" icon={<Info />}>
<AlertTitle>Info</AlertTitle>
<AlertDescription>A new version is available.</AlertDescription>
</Alert>
<Alert variant="success" icon={<CircleCheck />}>
<AlertTitle>Success</AlertTitle>
<AlertDescription>Your changes have been saved.</AlertDescription>
</Alert>
<Alert variant="warning" icon={<TriangleAlert />}>
<AlertTitle>Warning</AlertTitle>
<AlertDescription>
You are running low on storage space.
</AlertDescription>
</Alert>
<Alert variant="danger" icon={<CircleAlert />}>
<AlertTitle>Error</AlertTitle>
<AlertDescription>Failed to load data.</AlertDescription>
</Alert>
</div>
);
}Description only
You can omit the title and show only the description. When inserting it dynamically as a notification, pass alert to the role attribute or consider using Toast.
Your profile has been updated.
import { Alert, AlertDescription } from "@ginga-ui/core";
import { CircleCheck } from "lucide-react";
export function DescriptionOnlyExample() {
return (
<Alert variant="success" icon={<CircleCheck />}>
<AlertDescription>Your profile has been updated.</AlertDescription>
</Alert>
);
}Props
Alert
| Name | Type | Default | Description |
|---|---|---|---|
variant | "info" | "success" | "warning" | "danger" | "info" | Color variant that represents the kind of message. |
icon | ReactNode | - | Icon shown before the content. |
render | (props) => ReactElement | - | Replaces the root element. Return an element that receives the given props, such as next/link. |
Also accepts the attributes of the HTML div (opens in a new tab) element.
AlertTitle
| Name | Type | Default | Description |
|---|---|---|---|
render | (props) => ReactElement | - | Replaces the root element. Return an element that receives the given props, such as next/link. |
Also accepts the attributes of the HTML div (opens in a new tab) element.
AlertDescription
| Name | Type | Default | Description |
|---|---|---|---|
render | (props) => ReactElement | - | Replaces the root element. Return an element that receives the given props, such as next/link. |
Also accepts the attributes of the HTML p (opens in a new tab) element.