Playground

Notification center

A bell button with an unread count that opens a list of notifications, with mark read, clear and an empty state.

  • Built on native elements
  • The bell is a button named 'Notifications, 3 unread'; the visible count badge is aria-hidden so the number is announced once.
  • The panel is a labelled dialog: Escape or an outside click closes it and focus returns to the bell.
  • Unread items are bold, start with a visually hidden 'Unread:' and have a 'Mark read' button named after the item; unread is never shown by colour alone.
  • Styles in one file: 02-buttons.css

Import

import '@monoline/css';
import {NotificationCenter} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add notification-center

Usage

import {useState} from 'react';
import {NotificationCenter, type NotificationItem} from '@monoline/react';

const start: NotificationItem[] = [
  {id: '1', title: 'Deploy finished', description: 'Production, 41 seconds.', time: '2 min ago'},
  {id: '2', title: 'Ada commented on your pull request', time: '1 hour ago'},
  {id: '3', title: 'Invoice paid', time: 'Yesterday', read: true},
];

function Demo1() {
  const [list, setList] = useState(start);
  return (
    <div style={{display: 'flex', justifyContent: 'flex-end', minHeight: '280px'}}>
      <NotificationCenter
        notifications={list}
        onMarkRead={(id) => setList((l) => l.map((n) => (n.id === id ? {...n, read: true} : n)))}
        onMarkAllRead={() => setList((l) => l.map((n) => ({...n, read: true})))}
        onClear={() => setList([])}
      />
    </div>
  );
}

<Demo1 />

Examples

Inbox

Mark items read, then clear the list to see the empty state.

Props

NotificationCenterProps

PropTypeDefaultDescription
notifications requiredNotificationItem[]–The notifications, newest first. You own this list: update it in the callbacks below.
onMarkRead((id: string) => void)–Called with the id when the user marks one notification as read. Hides that item's "Mark read" button once `read` is true.
onMarkAllRead(() => void)–Called when the user chooses "Mark all read". The button is disabled when nothing is unread.
onClear(() => void)–Called when the user chooses "Clear all". The button is disabled when the list is empty.
labelstring'Notifications'Name of the bell button and the panel. Default "Notifications".
emptyTextstring"You're all caught up."Shown when there are no notifications. Default "You're all caught up."

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-disabled]popover.css
[data-highlighted]popover.css
[data-variant="danger"]popover.css
[data-unread]notification-center.css

CSS classes

ClassStylesheet
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css
.badge05-marks.css
.badge-accent05-marks.css
.badge-solid05-marks.css
.check05-marks.css
.check-fail05-marks.css
.check-pass05-marks.css
.dot05-marks.css
.heat-005-marks.css
.heat-105-marks.css
.heat-205-marks.css
.heat-305-marks.css
.heat-405-marks.css
.kbd05-marks.css
.key-hints05-marks.css
.swatch05-marks.css
.btnicon-button.css
.btn-iconicon-button.css
.btn-smicon-button.css
.menu-contentpopover.css
.menu-indicatorpopover.css
.menu-itempopover.css
.menu-item-checkpopover.css
.menu-labelpopover.css
.popoverpopover.css
.notification-centernotification-center.css
.notification-center-actionsnotification-center.css
.notification-center-badgenotification-center.css
.notification-center-descnotification-center.css
.notification-center-emptynotification-center.css
.notification-center-headnotification-center.css
.notification-center-itemnotification-center.css
.notification-center-listnotification-center.css
.notification-center-panelnotification-center.css
.notification-center-textnotification-center.css
.notification-center-timenotification-center.css
.notification-center-titlenotification-center.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.btn {
  border-color: var(--accent);
}
.btn[data-disabled] {
  background: var(--wash);
}

Accessibility

  • The bell is a button named 'Notifications, 3 unread'; the visible count badge is aria-hidden so the number is announced once.
  • The panel is a labelled dialog: Escape or an outside click closes it and focus returns to the bell.
  • Unread items are bold, start with a visually hidden 'Unread:' and have a 'Mark read' button named after the item; unread is never shown by colour alone.
  • 'Mark all read' and 'Clear all' are disabled when they have nothing to do; an empty list shows plain text.