Skip to content
Primitives

Notification Center

A bell trigger with an unread dot opens a scrollable list of recent items — activity, mentions, or a "what's new" changelog. Composes Popover + ScrollArea + Badge + RelativeTime.

Motionpopover scale-in (shared Popover)

Install

Install Kineto and follow the theme setup once in your app.

bash
npm install kineto
tsx
import { NotificationCenter } from "kineto/notification-center";

Preview

tsx
"use client";

import * as React from "react";
import { Bell } from "lucide-react";

import { cn } from "@/lib/cn";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Badge } from "@/components/ui/badge";
import { RelativeTime } from "@/components/ui/relative-time";
import type { TimeInput } from "@/lib/format-time";

export interface NotificationItem {
  id?: string;
  title: React.ReactNode;
  description?: React.ReactNode;
  /** When it happened — rendered as a relative time. */
  date?: TimeInput;
  /** Optional category chip, e.g. "New", "Fix", "Mention". */
  tag?: string;
}

export interface NotificationCenterProps {
  items: NotificationItem[];
  /** Header text. */
  title?: string;
  /** Show an unread dot on the bell trigger. */
  unread?: boolean;
  /** Replace the default bell trigger. */
  trigger?: React.ReactNode;
  align?: React.ComponentProps<typeof PopoverContent>["align"];
  side?: React.ComponentProps<typeof PopoverContent>["side"];
  className?: string;
}

/**
 * A notification center — a bell trigger (with an optional unread dot) opens a scrollable list of
 * recent items, each with a category chip and a relative timestamp. Works for activity, mentions,
 * or a "what's new" changelog. Composes Popover + ScrollArea + Badge + RelativeTime.
 */
export function NotificationCenter({
  items,
  title = "Notifications",
  unread = false,
  trigger,
  align = "end",
  side = "bottom",
  className,
}: NotificationCenterProps) {
  return (
    <Popover>
      <PopoverTrigger asChild>
        {trigger ?? (
          <button
            type="button"
            aria-label={title}
            className="relative inline-flex size-9 items-center justify-center rounded-md border border-border bg-background text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
          >
            <Bell className="size-4" />
            {unread ? (
              <span className="absolute right-1.5 top-1.5 size-2 rounded-full bg-brand ring-2 ring-background" />
            ) : null}
          </button>
        )}
      </PopoverTrigger>
      <PopoverContent align={align} side={side} className={cn("w-80 p-0", className)}>
        <div className="flex items-center justify-between border-b border-border px-4 py-3">
          <span className="font-display text-sm font-semibold">{title}</span>
          {unread ? (
            <Badge variant="brand" dot>
              New
            </Badge>
          ) : null}
        </div>

        <ScrollArea className="max-h-80">
          <ul className="divide-y divide-border">
            {items.map((item, i) => (
              <li key={item.id ?? i} className="px-4 py-3">
                <div className="flex items-center gap-2">
                  {item.tag ? (
                    <Badge variant="secondary" className="text-[10px]">
                      {item.tag}
                    </Badge>
                  ) : null}
                  <span className="text-sm font-medium">{item.title}</span>
                </div>
                {item.description ? (
                  <p className="mt-1 text-sm text-muted-foreground">{item.description}</p>
                ) : null}
                {item.date != null ? (
                  <RelativeTime date={item.date} className="mt-1.5 block text-xs text-muted-foreground" />
                ) : null}
              </li>
            ))}
          </ul>
        </ScrollArea>
      </PopoverContent>
    </Popover>
  );
}

src/components/ui/notification-center.tsx

Props

PropTypeDefaultDescription
itemsNotificationItem[]—Entries: { title, description?, date?, tag? }.
titlestring"Notifications"Header text.
unreadbooleanfalseShow an unread dot on the bell trigger.
triggerReactNode—Replace the default bell trigger.