Notification center
A bell button with an unread count that opens a list of notifications, with mark read, clear and an empty state.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- 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
Props
NotificationCenterProps
| Prop | Type | Default | Description |
|---|---|---|---|
notifications required | NotificationItem[] | – | 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. |
label | string | 'Notifications' | Name of the bell button and the panel. Default "Notifications". |
emptyText | string | "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.
| Attribute | Stylesheet |
|---|---|
[data-disabled] | popover.css |
[data-highlighted] | popover.css |
[data-variant="danger"] | popover.css |
[data-unread] | notification-center.css |
CSS classes
| Class | Stylesheet |
|---|---|
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
.badge | 05-marks.css |
.badge-accent | 05-marks.css |
.badge-solid | 05-marks.css |
.check | 05-marks.css |
.check-fail | 05-marks.css |
.check-pass | 05-marks.css |
.dot | 05-marks.css |
.heat-0 | 05-marks.css |
.heat-1 | 05-marks.css |
.heat-2 | 05-marks.css |
.heat-3 | 05-marks.css |
.heat-4 | 05-marks.css |
.kbd | 05-marks.css |
.key-hints | 05-marks.css |
.swatch | 05-marks.css |
.btn | icon-button.css |
.btn-icon | icon-button.css |
.btn-sm | icon-button.css |
.menu-content | popover.css |
.menu-indicator | popover.css |
.menu-item | popover.css |
.menu-item-check | popover.css |
.menu-label | popover.css |
.popover | popover.css |
.notification-center | notification-center.css |
.notification-center-actions | notification-center.css |
.notification-center-badge | notification-center.css |
.notification-center-desc | notification-center.css |
.notification-center-empty | notification-center.css |
.notification-center-head | notification-center.css |
.notification-center-item | notification-center.css |
.notification-center-list | notification-center.css |
.notification-center-panel | notification-center.css |
.notification-center-text | notification-center.css |
.notification-center-time | notification-center.css |
.notification-center-title | notification-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.