Notifications popover

Notifications in a popover from the bell: the latest grouped by day with unread dots, an access request answered in place, and the way to the full inbox.

Open full screen

A panel opens over any screen and keeps its own look in every direction: it has no direction of its own.

npx wideset add block-notifications-popover

Import the default export from @/blocks/wideset/notifications-popover. The files below are relative to your project's source directory.

Installed with this block
  • app-shell
  • avatar
  • block-styles
  • breadcrumbs
  • button
  • divider
  • dropdown-menu
  • icon-button
  • link-button
  • list-item
  • popup
  • sidebar
  • status-badge
  • table
  • tabs
  • text-input
  • utils
blocks/wideset/notifications-popover/index.tsx
'use client';

import '@/styles/wideset-blocks.css';

import { RiSideBarLine } from '@remixicon/react';
import { AppShell } from '@/components/ui/wideset/app-shell/AppShell';
import { Breadcrumbs } from '@/components/ui/wideset/breadcrumbs/Breadcrumbs';
import { IconButton } from '@/components/ui/wideset/button/IconButton';
import { useId, useState } from 'react';

import { type Notification, notifications as notificationsAtStart, TODAY } from './data';
import { HomePage } from './home-page';
import { NotificationsPopover } from './notifications-popover';
import { WorkspaceSidebar } from './sidebar';

/**
 * Notifications popover (panel over Home, Inset direction): the bell at the right of the page bar,
 * its popover open on load. Opening a notification reads it and closes the popover, as going to
 * it would; answering the access request resolves it in place; when nothing is left unread the
 * bell loses its dot.
 */
export default function NotificationsPopoverBlock() {
  const sidebarId = useId();
  const [collapsed, setCollapsed] = useState(false);
  const [open, setOpen] = useState(true);
  const [notifications, setNotifications] = useState(notificationsAtStart);

  const update = (id: string, change: Partial<Notification>) =>
    setNotifications((current) => current.map((n) => (n.id === id ? { ...n, ...change } : n)));

  return (
    <AppShell className="ws-block-utility" direction="inset">
      <WorkspaceSidebar id={sidebarId} collapsed={collapsed} onCollapsedChange={setCollapsed} />
      <AppShell.Main>
        <div className="h-ws-18 border-ws-static-base flex shrink-0 items-center border-b">
          {/* The bar belongs to the surround: it runs edge to edge. The sidebar's toggle is pulled
              left so its glyph, not its box, sits 20px from the edge; the crumbs follow it, the
              bell is pulled right the same way. */}
          <div className="gap-ws-5 px-ws-11 flex w-full items-center">
            <IconButton
              icon={RiSideBarLine}
              variant="secondary"
              preset="ghost"
              size="sm"
              iconClassName="text-ws-static-subtle size-ws-9"
              aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
              aria-expanded={!collapsed}
              aria-controls={sidebarId}
              onClick={() => setCollapsed((collapsed) => !collapsed)}
              className="-ml-ws-5"
            />
            <Breadcrumbs separator="arrow">
              <Breadcrumbs.Item>Home</Breadcrumbs.Item>
            </Breadcrumbs>
            <div className="-mr-ws-5 ml-auto">
              <NotificationsPopover
                notifications={notifications}
                today={TODAY}
                open={open}
                onOpenChange={setOpen}
                onOpen={(id) => {
                  update(id, { read: true });
                  setOpen(false);
                }}
                onAnswer={(id, approved) =>
                  update(id, {
                    read: true,
                    request: { status: approved ? 'approved' : 'declined' },
                  })
                }
                onMarkAllRead={() =>
                  setNotifications((current) => current.map((n) => ({ ...n, read: true })))
                }
              />
            </div>
          </div>
        </div>

        <HomePage />
      </AppShell.Main>
    </AppShell>
  );
}