Notification
A full-width banner for a message about the whole page. Five kinds, a bold lead-in, an action and a close button, announced as a live region.
Version 0.4.1 ·
Installation
bunx --bun shadcn@latest add @dga/notificationUsage
import { Notification } from "@/components/ui/notification";
export function MaintenanceNotice() {
return (
<Notification
variant="warning"
title="Notice:"
dismissible
dismissLabel="Dismiss"
action={<a href="/status">Details</a>}
>
The portal will be down for maintenance on Friday.
</Notification>
);
}Use a Notification at the top of a page or section for something that concerns all of it: planned maintenance, a new service, an account problem. It stays until the person dismisses it or the cause is gone. For a message tied to one form or card use an Inline Alert; for something that just happened use a Toast. Mount a Notification when it applies, not before: a live region is announced when its content appears. Start it with a short bold title ("Important:").
Anatomy
- Banner (
role="status", orrole="alert"forcritical): full width, padding 8 by 24px, radius-xs, a 2px bottom border in the kind's colour. - Icon (optional), title (bold lead-in) and the message.
- Action (a link or a small Button) and close button, on the end side.
Examples
Kinds
variant is neutral, info, success, warning or critical. Each is a 50 tint with text and an icon in the kind's colour. Dismiss one to see it go.
Without an icon and dismissed
hideIcon removes the status icon: the colour and the bold title still carry the kind. After the person dismisses a notification onDismiss runs and nothing is rendered in its place, so keep the state in the page if you need to bring it back.
RTL
The icon is on the right, the action and close button on the left, and the text starts on the right. Nothing is flipped by hand.
Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the action, then to the close button. |
| Enter | Presses the focused link or button. |
| Space | Presses the focused button. |
- A live region:
criticalhasrole="alert"and interrupts; the others arerole="status"and wait for a pause. Focus does not move. - The kind is shown by the icon and the lead-in as well as colour. Text is 4.5:1 and icons 3:1 or better on the tint, light and dark.
- The close button has an accessible name (
dismissLabel) and a 2px focus outline. Links in the message keep their underline.
API Reference
Notification
A full-width banner for a message that concerns the whole page (DGA: Notification), at the top of the page or a section. It is a live region: `critical` is announced at once (`role="alert"`), the others politely (`role="status"`). Mount it when the message applies, not before, so it is announced.
| Prop | Type | Default |
|---|---|---|
"neutral" | "critical" | "success" | "warning" | "info"Kind: `neutral`, `info`, `success`, `warning` or `critical`. | "neutral" | |
| ||
string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<AwaitedReactNode>Bold lead-in text before the message, such as "Important:". | No default | |
| ||
booleanHides the status icon. | No default | |
| ||
string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<AwaitedReactNode>A link or a small Button after the message. | No default | |
| ||
() => voidCalled after the notification is dismissed. | No default | |
| ||
booleanShows the close button. The notification hides itself, then calls `onDismiss`. | No default | |
| ||
stringAccessible name of the close button. Translate it on Arabic pages. | "Dismiss" | |
| ||
Also accepts the props of the element it renders.
Deviations from DGA
- Figma colours the icon
icon-oncolor(white) on a 50 tint: 1.0 to 1.1:1, so it cannot be seen. The icon uses the kind's icon colour. - The CSS draws success in the brand green where Figma uses the success tokens; Figma wins. Every kind is announced as a live region.
| Change | Reason |
|---|---|
Notification: the icon colour | A white icon on a 50 tint is 1.0 to 1.1:1: it cannot be seen. The kinds should read as one set. |
Notification, Inline Alert: live regions | A message that appears on its own must be announced without moving focus (WCAG 4.1.3). Urgent kinds interrupt; the rest wait. |
Contrast
80 pairs checked · all pass WCAG 2.1 AAShow 20 statesHide
| Variant / state | Light | Dark |
|---|---|---|
| neutral / text | 9.73:1 AAA | 12.93:1 AAA |
| neutral / icon | 17.31:1 3:1 | 17.04:1 3:1 |
| neutral / close icon | 17.31:1 3:1 | 17.04:1 3:1 |
| neutral / focus ring | 17.31:1 3:1 | 18.77:1 3:1 |
| info / text | 5.57:1 AA | 8.53:1 AAA |
| info / icon | 5.57:1 3:1 | 8.53:1 3:1 |
| info / close icon | 16.83:1 3:1 | 13.69:1 3:1 |
| info / focus ring | 16.83:1 3:1 | 15.09:1 3:1 |
| success / text | 5.39:1 AA | 9.08:1 AAA |
| success / icon | 5.39:1 3:1 | 9.08:1 3:1 |
| success / close icon | 17.15:1 3:1 | 13.34:1 3:1 |
| success / focus ring | 17.15:1 3:1 | 14.70:1 3:1 |
| warning / text | 5.20:1 AA | 9.75:1 AAA |
| warning / icon | 5.20:1 3:1 | 9.75:1 3:1 |
| warning / close icon | 17.34:1 3:1 | 13.70:1 3:1 |
| warning / focus ring | 17.34:1 3:1 | 15.09:1 3:1 |
| critical / text | 6.04:1 AA | 7.94:1 AAA |
| critical / icon | 6.04:1 3:1 | 7.94:1 3:1 |
| critical / close icon | 16.64:1 3:1 | 14.00:1 3:1 |
| critical / focus ring | 16.64:1 3:1 | 15.42:1 3:1 |
Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report