Alert
A static notification component for contextual feedback messages with semantic variants, dismissible close, collapsible content, and optional animated entrance.
Basic
Contextual feedback messages for inline notifications, validation, system status, tips, and collapsible information blocks. Supports 5 semantic variants, dismissible close, collapsible mode, and animated entrance.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add alertpnpm dlx @work-rjkashyap/unified-ui add alertnpx @work-rjkashyap/unified-ui add alertbunx @work-rjkashyap/unified-ui add alertIf you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.
Or install the full package
Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.
npm install @work-rjkashyap/unified-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
import {
Alert,
Callout,
} from "@work-rjkashyap/unified-ui";Basic Usage
<Alert variant="info" title="Did you know?">
Unified UI components are fully tree-shakeable via layer-specific imports.
</Alert>
<Alert variant="danger" dismissible onDismiss={() => setVisible(false)}>
Something went wrong. Please try again.
</Alert>
<Alert variant="info" title="FAQ" collapsible defaultOpen={false}>
Expandable content goes here.
</Alert>Variants
Alert supports five semantic variants that determine color, icon, and ARIA role.
Info (default)
Used for informational messages, tips, and notes. Renders with role="status" (polite live region).
Success
Used for positive outcomes like confirmations and completions. Renders with role="status".
Warning
Used for caution messages and deprecation notices. Renders with role="alert" (assertive live region).
Danger
Used for error messages and destructive action warnings. Renders with role="alert".
Default
A neutral variant with no semantic color. Use for generic notes that don't fit info/success/warning/danger. Renders with role="status".
| Variant | Background | Border | Icon Color | ARIA Role | Use Case |
|---|---|---|---|---|---|
info | --info-muted | --info/20 | --info | "status" | Tips, guidance, neutral info |
success | --success-muted | --success/20 | --success | "status" | Confirmations, completed actions |
warning | --warning-muted | --warning/20 | --warning | "alert" | Cautions, deprecation notices |
danger | --danger-muted | --danger/20 | --danger | "alert" | Errors, destructive action alerts |
default | --muted | --border | --muted-fg | "status" | Generic notes, neutral callouts |
Without Title
Alerts can be rendered without a title for simpler, single-line messages.
Dismissible
Add the dismissible prop to show a close button. Provide an onDismiss callback to control visibility externally, or let the alert manage its own visibility.
Collapsible
Set collapsible to make the body expandable/collapsible. The chevron animates on toggle. Use defaultOpen to control initial state.
Animated
Set animated to enable a fade-in entrance animation. The animation respects prefers-reduced-motion.
Custom Icons
Override the default variant icon with the icon prop, or pass null to hide it entirely.
In Context
A common pattern is to place alerts above or below forms to provide contextual guidance.
<form className="flex flex-col gap-4">
<Alert variant="info" title="Changing your email">
A verification link will be sent to your new address. Your current email
remains active until the new one is confirmed.
</Alert>
<div className="flex flex-col gap-1.5">
<label className="text-sm font-medium">New Email</label>
<Input type="email" placeholder="you@example.com" />
</div>
<Button variant="primary">Update Email</Button>
</form>Migrating from Callout
The Callout component has been merged into Alert. The Callout export is still available as a backward-compatible alias that defaults to animated={true} and rounded-lg.
// Before (Callout)
import { Callout } from "@work-rjkashyap/unified-ui";
<Callout variant="info" title="Did you know?" collapsible>
Content here.
</Callout>;
// After (Alert) — equivalent
import { Alert } from "@work-rjkashyap/unified-ui";
<Alert
variant="info"
title="Did you know?"
collapsible
animated
className="rounded-lg"
>
Content here.
</Alert>;| Callout Prop | Alert Equivalent |
|---|---|
variant | variant (now includes "default") |
title | title |
icon | icon |
collapsible | collapsible |
defaultOpen | defaultOpen |
| (always animated) | animated={true} |
(always rounded-lg) | className="rounded-lg" |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "info" | "success" | "warning" | "danger" | "default" | "info" | Semantic variant determining color, icon, and ARIA role. |
title | ReactNode | — | Title text displayed prominently at the top. |
icon | ReactNode | null | Auto (per variant) | Custom icon. Pass null to hide. |
dismissible | boolean | false | Whether to show a close button. Cannot combine with collapsible. |
onDismiss | () => void | — | Callback when dismissed. If omitted, alert self-manages visibility. |
dismissLabel | string | "Dismiss alert" | Accessible label for the dismiss button. |
collapsible | boolean | false | Whether the body can be toggled open/closed. Cannot combine with dismissible. |
defaultOpen | boolean | true | Initial open state when collapsible is true. |
animated | boolean | false | Animate entrance with fadeIn Framer Motion preset. |
role | "alert" | "status" | Auto (per variant) | ARIA role. Danger/warning default to "alert", others "status". |
className | string | — | Additional CSS classes merged on the root element. |
children | ReactNode | — | Description / body content. |
Motion
- Animated entrance —
fadeInpreset withopacity: 0 → 1and subtle translate. Opt-in viaanimatedprop. - Collapsible —
expandHeightpreset for smooth height transitions when toggling open/close. - Chevron rotation — Smooth 180° rotation on the collapsible toggle indicator.
- All animations respect
prefers-reduced-motion— disabled automatically when the user prefers reduced motion.
Accessibility
- Danger and warning alerts use
role="alert"(assertive live region) — screen readers announce them immediately. - Info, success, and default alerts use
role="status"(polite live region) — announced at the next opportunity. - Each variant renders a unique icon so meaning is never conveyed by color alone (WCAG 1.4.1).
- The dismiss button has a configurable
aria-label(defaults to"Dismiss alert"). - Collapsible header uses
aria-expandedfor screen readers and responds toEnter/Space. - Icons are decorative and marked with
aria-hidden="true". - The chevron icon is
aria-hidden="true".
Design Tokens
| Token | Usage |
|---|---|
--info-muted | Info variant background |
--success-muted | Success variant background |
--warning-muted | Warning variant background |
--danger-muted | Danger variant background |
--muted | Default variant background |
--border | Default variant border |
--radius-md | Border radius (rounded-md) |
--radius-lg | Callout alias radius |
--duration-fast | Transition speed |