Skip to content

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 ·

Notification

Installation

bunx --bun shadcn@latest add @dga/notification

Usage

page.tsx
tsx
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", or role="alert" for critical): 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.

Kinds

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.

Without an icon and dismissed

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.

LTR (English)
RTL (Arabic)

Accessibility

KeyAction
TabMoves focus to the action, then to the close button.
EnterPresses the focused link or button.
SpacePresses the focused button.
  • A live region: critical has role="alert" and interrupts; the others are role="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.

Notification props
PropTypeDefault
"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
boolean

Hides 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
() => void

Called after the notification is dismissed.

No default
boolean

Shows the close button. The notification hides itself, then calls `onDismiss`.

No default
string

Accessible 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.
ChangeReason
Notification: the icon colourA 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 regionsA message that appears on its own must be announced without moving focus (WCAG 4.1.3). Urgent kinds interrupt; the rest wait.

View all 2 deviations for this component

Contrast

80 pairs checked · all pass WCAG 2.1 AAShow 20 states
Variant / stateLightDark
neutral / text9.73:1 AAA12.93:1 AAA
neutral / icon17.31:1 3:117.04:1 3:1
neutral / close icon17.31:1 3:117.04:1 3:1
neutral / focus ring17.31:1 3:118.77:1 3:1
info / text5.57:1 AA8.53:1 AAA
info / icon5.57:1 3:18.53:1 3:1
info / close icon16.83:1 3:113.69:1 3:1
info / focus ring16.83:1 3:115.09:1 3:1
success / text5.39:1 AA9.08:1 AAA
success / icon5.39:1 3:19.08:1 3:1
success / close icon17.15:1 3:113.34:1 3:1
success / focus ring17.15:1 3:114.70:1 3:1
warning / text5.20:1 AA9.75:1 AAA
warning / icon5.20:1 3:19.75:1 3:1
warning / close icon17.34:1 3:113.70:1 3:1
warning / focus ring17.34:1 3:115.09:1 3:1
critical / text6.04:1 AA7.94:1 AAA
critical / icon6.04:1 3:17.94:1 3:1
critical / close icon16.64:1 3:114.00:1 3:1
critical / focus ring16.64:1 3:115.42:1 3:1

Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report