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
"use client";
import { useState } from "react";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import { IntegrationMark } from "@/components/ui/integration-mark";
import { Notification } from "@/components/ui/notification";
export default function Example() {
const [items, setItems] = useState(["reply", "share", "sync"]);
const remove = (id: string) => setItems((x) => x.filter((y) => y !== id));
return (
<div className="w-full max-w-md divide-y divide-line-subtle rounded-lg border border-line bg-surface p-1 shadow-card">
{items.includes("reply") && (
<Notification
unread
leading={<Avatar name="Priya Raman" size="lg" status="online" />}
title={<><b className="font-medium">Priya Raman</b> replied to “Quick question about Fathom’s SDR ramp”</>}
time="12 min ago · Series B — VP Sales"
attachment="“Happy to chat — does Thursday at 10 work?”"
onDismiss={() => remove("reply")}
/>
)}
{items.includes("share") && (
<Notification
unread
leading={<Avatar name="Leah Moss" size="lg" />}
title={<><b className="font-medium">Leah Moss</b> shared the list <b className="font-medium">UK Revenue Leaders</b> with you</>}
time="1h ago"
actions={
<>
<Button size="xs" onPress={() => remove("share")}>Decline</Button>
<Button size="xs" variant="primary" onPress={() => remove("share")}>Accept</Button>
</>
}
onDismiss={() => remove("share")}
/>
)}
{items.includes("sync") && (
<Notification leading={<IntegrationMark id="salesforce" size="lg" />} title="Salesforce sync finished" description="2,318 accounts mapped · 14 skipped" time="Yesterday" onDismiss={() => remove("sync")} />
)}
{items.length === 0 && <p className="py-8 text-center text-base text-fg-muted">You’re all caught up.</p>}
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
notification.tsxfile 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> ); }Create a
close-button.tsxfile 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> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.