Feedback

Notification

Feed item for a notification center: who did what, when, with quotes and actions.

react-aria-componentslucide-react

Preview

Priya Raman replied to “Quick question about Fathom’s SDR ramp”

12 min ago · Series B — VP Sales

“Happy to chat — does Thursday at 10 work?”

Leah Moss shared the list UK Revenue Leaders with you

1h ago

Salesforce sync finished

2,318 accounts mapped · 14 skipped

Yesterday

Installation

Components are copied into your project — no runtime package.

  1. Install the following dependencies:

    terminal
    npm install react-aria-components lucide-react
  2. Create a notification.tsx file and paste the following code into it.

    src/components/ui/notification.tsx
    "use client";
    
    import type { ReactNode } from "react";
    import { cx } from "@/utils/cx";
    import { CloseButton } from "./close-button";
    
    export interface NotificationProps {
      /** An <Avatar>, <IntegrationMark> or icon tile. */
      leading?: ReactNode;
      title: ReactNode;
      /** Secondary line, e.g. the message excerpt. */
      description?: ReactNode;
      time?: string;
      unread?: boolean;
      /** Buttons such as Accept / Decline. */
      actions?: ReactNode;
      /** Attachment or quoted content rendered in a muted box. */
      attachment?: ReactNode;
      onDismiss?: () => void;
      className?: string;
    }
    
    /** Feed item for the notification center: who did what, when, with optional actions. */
    export function Notification({ leading, title, description, time, unread, actions, attachment, onDismiss, className }: NotificationProps) {
      return (
        <article className={cx("group relative flex gap-3 rounded-md p-3 transition-colors hover:bg-subtle", className)}>
          {leading && <div className="shrink-0">{leading}</div>}
          <div className="min-w-0 flex-1">
            <div className="flex items-start gap-2">
              <p className="min-w-0 flex-1 text-base text-fg">{title}</p>
              {unread && <span aria-label="Unread" className="mt-1.5 size-2 shrink-0 rounded-full bg-accent" />}
              {onDismiss && <CloseButton size="sm" aria-label="Dismiss notification" onPress={onDismiss} className="opacity-0 transition-opacity group-hover:opacity-100 data-focus-visible:opacity-100" />}
            </div>
            {description && <p className="mt-0.5 text-sm text-fg-secondary">{description}</p>}
            {time && <p className="mt-1 text-sm text-fg-muted">{time}</p>}
            {attachment && <div className="mt-2.5 rounded-sm border border-line bg-subtle px-3 py-2 text-sm text-fg-secondary">{attachment}</div>}
            {actions && <div className="mt-3 flex flex-wrap gap-2">{actions}</div>}
          </div>
        </article>
      );
    }
  3. Create a close-button.tsx file and paste the following code into it.

    src/components/ui/close-button.tsx
    "use client";
    
    import { X } from "lucide-react";
    import { Button as AriaButton, type ButtonProps as AriaButtonProps } from "react-aria-components";
    import { cx } from "@/utils/cx";
    
    export interface CloseButtonProps extends Omit<AriaButtonProps, "className" | "children"> {
      size?: "sm" | "md" | "lg";
      /** `ghost` is transparent until hovered; `filled` sits on a muted circle. */
      variant?: "ghost" | "filled";
      "aria-label"?: string;
      className?: string;
    }
    
    const sizes = { sm: "size-5 [&_svg]:size-3", md: "size-7 [&_svg]:size-3.5", lg: "size-8 [&_svg]:size-4" };
    
    /** Dismiss control for dialogs, toasts, tags and banners. */
    export function CloseButton({ size = "md", variant = "ghost", className, ...props }: CloseButtonProps) {
      return (
        <AriaButton
          aria-label="Close"
          {...props}
          className={cx(
            "inline-flex shrink-0 cursor-default items-center justify-center text-fg-muted outline-none transition-colors data-focus-visible:shadow-focus data-disabled:text-fg-disabled",
            variant === "ghost" ? "rounded-sm data-hovered:bg-muted data-hovered:text-fg" : "rounded-full bg-muted data-hovered:bg-active data-hovered:text-fg",
            sizes[size],
            className,
          )}
        >
          <X strokeWidth={2} />
        </AriaButton>
      );
    }
  4. Add the theme tokens and the cx helper from Installation if you haven’t yet, then update the import paths to match your project setup.