Skip to content

Alert

Download .md

An alert shows a message that stays on the page until its cause is gone, such as a rejected release or a subscription about to end.

  • Use it for a state of the page or the account that people need to see while they work.
  • Use a Toast to confirm an action that just happened; a toast goes away by itself.
  • Show validation errors under their field with a Field, not in an alert. A form may add one destructive alert at the top when the backend refuses the whole form.
  • Write a short title and one sentence that says what to do.
React
Vue
1234
  1. 1Container in a soft status color
  2. 2Icon
  3. 3Title
  4. 4Description

An icon on the left, a title and a description, on radius-lg with px-4 py-3. The status variants sit on the soft status surface with the icon and title in the status color and the description in foreground; default sits on card with a border.

Variant Use it for
default Neutral news, such as a report that is ready.
info Something to know, such as a scheduled release.
success A state that turned out well, such as a delivered release.
warning Something that needs attention soon, such as a subscription about to end.
destructive Something that failed or was refused, such as a rejected release.
React Vue Flutter Type Default Use
variant variant ShadAlert / ShadAlert.destructive, status colors from context.sosialoka text default The status.
AlertTitle AlertTitle title text none The short title.
AlertDescription AlertDescription description text none One sentence on what to do.
icon as the first child icon as the first child icon element none A Lucide icon for the status.
import { CircleAlertIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, type LucideIcon } from "lucide-react"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
const alerts: { variant: "default" | "info" | "success" | "warning" | "destructive"; icon: LucideIcon; title: string; description: string }[] = [
{ variant: "default", icon: InfoIcon, title: "Laporan bulan ini sudah siap", description: "Kamu bisa mengunduhnya dari menu Royalti." },
{ variant: "info", icon: InfoIcon, title: "Rilis dijadwalkan", description: "\"Senja di Kota\" tayang 1 Des 2026 pukul 00.00 WIB." },
{ variant: "success", icon: CircleCheckIcon, title: "Rilis terkirim", description: "Semua toko musik sudah menerima \"Kaset Pertama\"." },
{ variant: "warning", icon: TriangleAlertIcon, title: "Langgananmu hampir habis", description: "Masa langgananmu habis 3 hari lagi." },
{ variant: "destructive", icon: CircleAlertIcon, title: "Rilis ditolak", description: "Sampulnya belum sesuai aturan toko musik." },
]
export default function AlertDemo() {
return (
<div className="grid w-full max-w-md gap-3">
{alerts.map(({ variant, icon: Icon, title, description }) => (
<Alert key={variant} variant={variant}>
<Icon />
<AlertTitle>{title}</AlertTitle>
<AlertDescription>{description}</AlertDescription>
</Alert>
))}
</div>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/alert.json
  • It has role="alert", so screen readers announce it when it appears. Render alerts that are there from the start with the page, so they are not announced again on every change.
  • The status is in the title too, not only in the color.
  • The icon is decorative.