Alert
An inline callout with title, description and tone variants.
For a message that belongs to a place on the page and stays there. An alert has role="alert", so a screen reader reads it the moment it is added to the page: keep it for what the person must know, and use @khaeli/sonner for a message that comes and goes.
Default
Scheduled maintenance
Exports pause on Saturday from 02:00 to 03:00 UTC. Nothing else is affected.
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
export default function AlertDefault() {
return (
<Alert className="max-w-md">
<AlertTitle>Scheduled maintenance</AlertTitle>
<AlertDescription>Exports pause on Saturday from 02:00 to 03:00 UTC. Nothing else is affected.</AlertDescription>
</Alert>
)
}
With icon
Release 4.2 is rolling out
Half of your workspaces have it. The rest follow by Friday.
Your trial ends in 5 days
import { InfoIcon } from "@keyline-icons/react"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
export default function AlertWithIcon() {
return (
<div className="flex w-full max-w-md flex-col gap-3">
<Alert>
<InfoIcon />
<AlertTitle>Release 4.2 is rolling out</AlertTitle>
<AlertDescription>Half of your workspaces have it. The rest follow by Friday.</AlertDescription>
</Alert>
<Alert>
<InfoIcon />
<AlertTitle>Your trial ends in 5 days</AlertTitle>
</Alert>
</div>
)
}
Destructive
The import stopped at row 214
The due date is not a date. Fix the row in your file and import it again.
import { CircleAlertIcon } from "@keyline-icons/react"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
export default function AlertDestructive() {
return (
<Alert variant="destructive" className="max-w-md">
<CircleAlertIcon />
<AlertTitle>The import stopped at row 214</AlertTitle>
<AlertDescription>The due date is not a date. Fix the row in your file and import it again.</AlertDescription>
</Alert>
)
}
With an action
Invoice INV-1040 is overdue
It was due on 15 November.
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
export default function AlertWithAnAction() {
return (
<Alert className="max-w-md">
<AlertTitle>Invoice INV-1040 is overdue</AlertTitle>
<AlertDescription>It was due on 15 November.</AlertDescription>
<AlertAction>
<Button size="sm" variant="outline" aria-label="Remind about invoice INV-1040">
Remind
</Button>
</AlertAction>
</Alert>
)
}
Installation
npx shadcn@latest add @khaeli/alertbunx --bun shadcn@latest add @khaeli/alertInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- class-variance-authority ^0.7.1
Accessible name
- An alert needs no label: it is read by its content, the title first.
- An icon is decorative. The
destructivevariant differs from the default by colour alone, so let the title and the icon say that something went wrong. - A button in
AlertActionis read apart from the title: when its text does not say what it acts on, name it in full witharia-label(Remind about invoice INV-1040).
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/alert.json