A semantic callout with five theme-aware tones, clear icon placement, an action row, and opt-in urgent announcements.
import { ShieldCheck } from "lucide-react"
import {
Alert,
AlertTitle,
AlertDescription,
AlertAction,
} from "@/components/ballmac/alert"
import { buttonVariants } from "@/components/ballmac/button"
export default function AlertDemo() {
return (
<Alert variant="success" className="max-w-md">
<ShieldCheck aria-hidden="true" />
<AlertTitle>Workspace is protected</AlertTitle>
<AlertDescription>
Two-factor authentication is active for every team member. Your security
review is complete.
</AlertDescription>
<AlertAction>
<a
href="#security"
className={buttonVariants({ variant: "outline", size: "sm" })}
>
Review settings
</a>
</AlertAction>
</Alert>
)
}Installation
$ pnpm dlx shadcn@latest add @ballmac/alertInstall the dependencies.
$ pnpm add class-variance-authorityCopy the source into your project.
components/ballmac/alert.tsx// Ballmac UI: Alert. https://ui.ballmac.com/components/alert // Based on shadcn/ui Alert (MIT, Copyright (c) 2023 shadcn), adding semantic tones and an action slot. import * as React from "react" import { cva, type VariantProps } from "class-variance-authority" import { cn } from "@/lib/utils" const alertVariants = cva( "grid w-full grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-1 rounded-xl border p-4 text-sm [&>svg]:mt-0.5 [&>svg]:size-4", { variants: { variant: { default: "border-border bg-card text-card-foreground", info: "border-primary/25 bg-primary/5 text-foreground", success: "border-chart-2/30 bg-chart-2/10 text-foreground", warning: "border-chart-3/30 bg-chart-3/10 text-foreground", destructive: "border-destructive/30 bg-destructive/10 text-foreground", }, }, defaultVariants: { variant: "default" }, }, ) type AlertProps = React.ComponentProps<"div"> & VariantProps<typeof alertVariants> & { /** Announce urgent messages; ordinary alerts remain in the reading order. */ urgent?: boolean } function Alert({ className, variant = "default", urgent = false, ...props }: AlertProps) { return ( <div data-slot="alert" role={urgent ? "alert" : undefined} className={cn(alertVariants({ variant }), className)} {...props} /> ) } function AlertTitle({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-title" className={cn("col-start-2 font-semibold leading-5", className)} {...props} /> ) } function AlertDescription({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-description" className={cn( "col-start-2 text-muted-foreground leading-relaxed [&_p]:leading-relaxed", className, )} {...props} /> ) } function AlertAction({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-action" className={cn( "col-start-2 mt-2 flex flex-wrap items-center gap-2", className, )} {...props} /> ) } export { Alert, AlertTitle, AlertDescription, AlertAction, alertVariants, type AlertProps, }Update the import paths to match your project setup.
Usage
import { Alert, AlertTitle, AlertDescription, AlertAction } from "@/components/ballmac/alert"The full example is in the Code tab above.
Examples
States and variants
import { CircleAlert, Info } from "lucide-react"
import { Alert, AlertTitle, AlertDescription } from "@/components/ballmac/alert"
export default function AlertStates() {
return (
<div className="flex w-full max-w-md flex-col gap-3">
<Alert variant="info">
<Info aria-hidden="true" />
<AlertTitle>Scheduled maintenance</AlertTitle>
<AlertDescription>
Reports will pause for ten minutes tonight.
</AlertDescription>
</Alert>
<Alert variant="warning">
<CircleAlert aria-hidden="true" />
<AlertTitle>Review needed</AlertTitle>
<AlertDescription>
One integration needs a new access token.
</AlertDescription>
</Alert>
</div>
)
}API reference
| Prop | Type | Default |
|---|---|---|
urgentAnnounce urgent messages; ordinary alerts remain in the reading order. | boolean | false |
variant | "default" | "info" | "success" | "warning" | "destructive" | "default" |
Also accepts the standard attributes of its root element.
Accessibility
| Key | Action |
|---|---|
| Tab | moves to links and actions |
Use with AI
A semantic callout with five theme-aware tones, clear icon placement, an action row, and opt-in urgent announcements. With the shadcn MCP server set up (guide), ask your agent:
Add the Ballmac UI Alert (@ballmac/alert) to this project with the shadcn MCP, then use it where it fits.
Use it for
- Display a status or important message
- Pair a warning with a clear next action
Not for
- Use a toast for transient confirmation
Registry JSON: https://ui.ballmac.com/r/alert.json
Credits
Based on shadcn/ui Alert, adapted by Ballmac. Free to use in personal and commercial projects.
- Registry
- shadcn/utils
Pairs well with
Badge
A small pill label in four variants with an optional status dot and success, warning and error tones. Style links with badgeVariants().
Button
A button with six variants, three sizes, a pill shape and a built-in loading state. buttonVariants() styles links the same way.
Alert Dialog
Focus-managed confirmation for consequential actions, with a clear cancel path, optional media, and a token-based destructive action.
Banner
A page-wide announcement with semantic tones, optional action, and controlled or local dismissal.