Skip to Content
Habi

Notification

Tells people what happened after an action, or about something in their records.

Payment received

Your reference number is NBI-2026-1215-0417. We've sent it to your email.

Installation

npm install @heroicons/react class-variance-authority clsx tailwind-merge

Add the cn helper if you haven't already:

lib/utils.ts
import { clsx, type ClassValue } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";

const twMerge = extendTailwindMerge({
  extend: {
    theme: {
      text: [
        "display",
        "heading-xl",
        "heading-lg",
        "heading-md",
        "heading-sm",
        "heading-xs",
        "body-lg",
        "body-md",
        "body-sm",
        "label",
        "helper",
        "button",
      ],
      "font-weight": ["regular"],
    },
  },
});

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

Add the status icon, which Notification uses:

components/ui/status-icon.tsx
import type { ComponentProps } from "react";
import {
  CheckCircleIcon,
  ExclamationCircleIcon,
  ExclamationTriangleIcon,
  InformationCircleIcon,
} from "@heroicons/react/20/solid";

import { cn } from "@/lib/utils";

const statusIcons = {
  info: {
    Icon: InformationCircleIcon,
    color: "text-support-info",
    backing: "inset-[17.5%] rounded-full bg-white",
  },
  success: {
    Icon: CheckCircleIcon,
    color: "text-support-success",
    backing: "inset-[17.5%] rounded-full bg-white",
  },
  warning: {
    Icon: ExclamationTriangleIcon,
    color: "text-support-warning",
    backing: "inset-x-[45%] top-[23.75%] bottom-[28.75%] bg-icon-primary",
  },
  error: {
    Icon: ExclamationCircleIcon,
    color: "text-support-error",
    backing: "inset-[17.5%] rounded-full bg-white",
  },
};

type StatusKind = keyof typeof statusIcons;

type StatusIconProps = ComponentProps<"span"> & { kind: StatusKind };

function StatusIcon({ kind, className, ...props }: StatusIconProps) {
  const { Icon, color, backing } = statusIcons[kind];

  return (
    <span
      data-slot="status-icon"
      aria-hidden
      className={cn("relative inline-block size-5 shrink-0", className)}
      {...props}
    >
      <span className={cn("absolute", backing)} />
      <Icon className={cn("relative size-5", color)} />
    </span>
  );
}

export { StatusIcon, type StatusIconProps, type StatusKind };

Add the component:

components/ui/notification.tsx
import type { ComponentProps, ReactNode } from "react";
import { XMarkIcon } from "@heroicons/react/20/solid";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { StatusIcon } from "@/components/ui/status-icon";

const notificationVariants = cva(
  "flex w-full items-start gap-3 rounded-sm border p-4 text-text-primary",
  {
    variants: {
      kind: {
        info: "border-support-info bg-support-info-subtle",
        success: "border-support-success bg-support-success-subtle",
        warning: "border-support-warning bg-support-warning-subtle",
        error: "border-support-error bg-support-error-subtle",
      },
    },
    defaultVariants: {
      kind: "info",
    },
  },
);

type NotificationProps = Omit<ComponentProps<"div">, "title"> &
  VariantProps<typeof notificationVariants> & {
    title: ReactNode;
    onDismiss?: () => void;
    dismissLabel?: string;
  };

function Notification({
  className,
  kind,
  title,
  children,
  onDismiss,
  dismissLabel = "Dismiss",
  ...props
}: NotificationProps) {
  const statusKind = kind ?? "info";

  return (
    <div
      data-slot="notification"
      role={statusKind === "error" ? "alert" : "status"}
      className={cn(notificationVariants({ kind }), className)}
      {...props}
    >
      <StatusIcon kind={statusKind} />
      <div className="flex min-w-0 flex-1 flex-col gap-1">
        <p className="text-heading-xs">{title}</p>
        {children && <div className="text-body-sm">{children}</div>}
      </div>
      {onDismiss && (
        <button
          type="button"
          aria-label={dismissLabel}
          onClick={onDismiss}
          className="-m-0.5 inline-flex size-6 shrink-0 items-center justify-center rounded-sm text-icon-primary focus-visible:focus-ring"
        >
          <XMarkIcon className="size-5" />
        </button>
      )}
    </div>
  );
}

export { Notification, notificationVariants, type NotificationProps };

Usage

import { Notification } from "@/components/ui/notification";

<Notification kind="success" title="Appointment booked">
  See you on 15 March 2026 at 9:00 AM.
</Notification>;

Examples

Kinds

Use info for news, success when something worked, warning for something people should act on soon, and error when something went wrong. Say what happened and what to do next.

Offices close early on 24 December

Appointments that day end at 12:00 PM.

Appointment booked

See you on 15 March 2026 at 9:00 AM.

Your ID expires in 30 days

Renew it before booking your clearance.

Dismissible

Pass onDismiss to show a close button. Only make notifications dismissible when people no longer need them, and never for errors they still have to fix.

We've updated the requirements

You now need one valid ID instead of two.

Props

PropTypeDefaultDescription
kind"info" | "success" | "warning" | "error""info"The type of message, which sets the color, icon and role.
titleReactNode–A short summary. Together with the icon, it carries the meaning.
childrenReactNode–The details: what happened and what to do next.
onDismiss() => void–Shows a close button and is called when people press it.
dismissLabelstring"Dismiss"The close button's accessible name. Translate it, like "Isara".

Accessibility

  • Roles: errors use role="alert", which screen readers announce straight away. Other kinds use role="status", announced when the screen reader is idle.
  • Announcements: screen readers only announce a live region when it's added or changed after the page loads. Show

Accessibility

  • Roles: errors use role="alert", which screen readers announce straight away. Other kinds use role="status", announced when the screen reader is idle.
  • Announcements: screen readers only announce a live region when it's added or changed after the page loads. Show the notification when the event happens, like after a payment, not as part of the initial page.
  • Not just color: the icon and title carry the meaning, so the message is clear without color.
  • Focus stays put: notifications don't move focus, so people aren't pulled away from what they were doing.
  • Dismiss button: has an accessible name ("Dismiss" by default) and a 24 x 24px target.

On this page