Alert
Shows a message that needs attention.
Installation
pnpm dlx shadcn@latest add @paneui/alertUsage
Composition
Examples
Motion
The alert scales from 96% as it enters and reverses on dismiss, so the content below slides up. With reduced motion it only fades.
Accessibility
warning and destructive alerts get role="alert" so screen readers announce them at once; the others get role="status". Override with role.
Alert
Inline message surface that animates in and out. Also accepts every prop of motion.div.
- size= "default"
- "sm" | "default"
smuses 10px padding, a 14px radius and the 24px icon chip;default14px, 18px and 32px.- variant= "default"
- "default" | "info" | "success" | "warning" | "destructive"
- Background tint, icon chip tone and default icon.
- open
- boolean
- Controlled visibility. Hiding animates the alert out.
- defaultOpen= true
- boolean
- Visible on first render.
- onOpenChange
- (open: boolean) => void
- Called when the alert is shown or dismissed.
- role
- "alert" | "status"
- Defaults to
alertforwarning/destructiveandstatusotherwise. - contentClassName
- string
- Classes for the inner surface row;
classNamegoes on the outer element that animates height.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "sm" | "default" | "default" | sm uses 10px padding, a 14px radius and the 24px icon chip; default 14px, 18px and 32px. |
| variant | "default" | "info" | "success" | "warning" | "destructive" | "default" | Background tint, icon chip tone and default icon. |
| open | boolean | — | Controlled visibility. Hiding animates the alert out. |
| defaultOpen | boolean | true | Visible on first render. |
| onOpenChange | (open: boolean) => void | — | Called when the alert is shown or dismissed. |
| role | "alert" | "status" | — | Defaults to alert for warning / destructive and status otherwise. |
| contentClassName | string | — | Classes for the inner surface row; className goes on the outer element that animates height. |
- data-variant
- The
variantvalue. - data-size
- The
sizevalue.
| Data attribute | Description |
|---|---|
| data-variant | The variant value. |
| data-size | The size value. |
AlertIcon
An IconChip in the variant's tone. Renders the variant's default icon unless children are given. Also accepts every prop of span.
- children
- ReactNode
- Icon to show instead of the default.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Icon to show instead of the default. |
AlertClose
Round × button that dismisses the alert. Call event.preventDefault() in onClick to keep it open. Also accepts every prop of button.
- children= <XIcon />
- ReactNode
- Replace the × icon.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | <XIcon /> | Replace the × icon. |
useAlert
Reads the nearest Alert. Throws outside one.
- open
- boolean
- Whether the alert is visible.
- variant
- AlertVariant
- The alert's variant.
- size
- AlertSize
- The alert's size.
- setOpen
- (open: boolean) => void
- Show or hide the alert.
- dismiss
- () => void
- Hide the alert with its exit animation.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | — | Whether the alert is visible. |
| variant | AlertVariant | — | The alert's variant. |
| size | AlertSize | — | The alert's size. |
| setOpen | (open: boolean) => void | — | Show or hide the alert. |
| dismiss | () => void | — | Hide the alert with its exit animation. |