Notification center
A bell with an unread count that opens your notifications. Write the list in HTML: Momo keeps the count, the read state and the times up to date.
Bell and panel
Notifications
- Today
- AK
-
Payment received $129.00 from Max Ruiz
-
Order #10418 shipped Tracking is on its way to the customer.
-
LT
Lena Torres mentioned you in Returns
- Earlier
-
Card declined Order #10402 needs a new payment method.
-
Sam Okafor joined your team
You're all caught up.
<div class="cluster justify-between items-center p-3 border rounded bg-surface">
<b>Shop admin</b>
<div class="cluster gap-3 items-center">
<button class="btn btn-icon" type="button" data-momo-popover="inbox" data-momo-align="end" aria-label="Notifications"><i class="mi mi-bell"></i><span class="badge-corner"></span></button>
<span class="avatar avatar-sm bg-yellow">JD</span>
</div>
</div>
<div class="popover notifications" id="inbox" data-momo-close-outside aria-label="Notifications">
<div class="notifications-head">
<h2 class="notifications-title">Notifications <span class="badge-count" data-momo-unread-count></span></h2>
<button class="btn btn-sm btn-ghost" type="button" data-momo-mark-all>Mark all as read</button>
<div class="tabs tabs-boxed tabs-sm tabs-block notifications-filter" role="group" aria-label="Show">
<button class="tab" type="button" data-momo-notify-filter="all">All</button>
<button class="tab" type="button" data-momo-notify-filter="unread">Unread</button>
</div>
</div>
<ul class="notifications-list">
<li class="notifications-group">Today</li>
<li class="notification is-unread">
<span class="avatar avatar-sm bg-pink">AK</span>
<div class="notification-body">
<p class="notification-text"><a class="notification-link" href="#n-order"><b>Ana Kim</b> commented on order #10421: "Can this ship by Friday?"</a></p>
<time class="notification-time" data-ago-min="4"></time>
</div>
</li>
<li class="notification is-unread">
<span class="notification-icon bg-green"><i class="mi mi-credit-card"></i></span>
<div class="notification-body">
<p class="notification-text"><b>Payment received</b> $129.00 from Max Ruiz</p>
<time class="notification-time" data-ago-min="38"></time>
</div>
</li>
<li class="notification is-unread">
<span class="notification-icon bg-cyan"><i class="mi mi-truck"></i></span>
<div class="notification-body">
<p class="notification-text"><b>Order #10418 shipped</b> <span class="notification-sub">Tracking is on its way to the customer.</span></p>
<time class="notification-time" data-ago-min="125"></time>
</div>
</li>
<li class="notification">
<span class="avatar avatar-sm bg-violet">LT</span>
<div class="notification-body">
<p class="notification-text"><b>Lena Torres</b> mentioned you in Returns</p>
<time class="notification-time" data-ago-min="300"></time>
</div>
</li>
<li class="notifications-group">Earlier</li>
<li class="notification">
<span class="notification-icon bg-red"><i class="mi mi-alert-triangle"></i></span>
<div class="notification-body">
<p class="notification-text"><b>Card declined</b> <span class="notification-sub">Order #10402 needs a new payment method.</span></p>
<time class="notification-time" data-ago-min="1500"></time>
</div>
</li>
<li class="notification">
<span class="notification-icon bg-yellow"><i class="mi mi-user-plus"></i></span>
<div class="notification-body">
<p class="notification-text"><b>Sam Okafor</b> joined your team</p>
<time class="notification-time" data-ago-min="3000"></time>
</div>
</li>
</ul>
<p class="notifications-empty" hidden><i class="mi mi-circle-check"></i> You're all caught up.</p>
<div class="notifications-foot"><a class="btn btn-sm btn-ghost" href="#notify-page">View all notifications</a></div>
</div>- The count on the bell (a
.badge-cornerinside the button) and every[data-momo-unread-count]follow the unread items, and hide at zero. Screen readers hear "Notifications, 3 unread". - A click on a notification marks it read (a link in it still opens). Hover or focus one for read / unread and dismiss buttons, added for you; on touch screens they always show.
data-momo-mark-allmarks everything read.data-momo-notify-filter="unread"and"all"buttons switch the view; something you read while looking at Unread stays until you switch. Group headings hide when they have nothing to show, and.notifications-emptyappears when the list is empty.- A
<time class="notification-time" datetime="…">reads "5 min. ago", "yesterday" and so on, and stays fresh. Hover it for the exact date. - It is a list, like a menu:
data-momo-close-outsidelets a click outside close it, and Esc closes it too.
Add from code
Momo.notify() adds one at the top: newest first, under the first group (or the one you name). Add toast: true to also show it as a toast.
<button class="btn" type="button" id="notify-add"><i class="mi mi-plus"></i> New notification</button>
<button class="btn" type="button" id="notify-toast"><i class="mi mi-bell"></i> ...with a toast</button>
<button class="btn btn-ghost" type="button" data-momo-popover="inbox" data-momo-align="start">Open the panel</button>
<script>
document.getElementById('notify-add').addEventListener('click', function () {
Momo.notify('#inbox', { title: 'Max Ruiz', text: 'placed order #10422', avatar: 'MR', color: 'cyan', href: '#n-10422' });
});
document.getElementById('notify-toast').addEventListener('click', function () {
Momo.notify('#inbox', { title: 'Low stock', text: 'Momo Mug: 4 left', icon: 'package', color: 'orange', toast: true });
});
</script>Momo.notify('#inbox', {
title: 'Max Ruiz',
text: 'placed order #10422',
avatar: 'MR', color: 'cyan', // or icon: 'package' (with color)
href: '/orders/10422',
time: Date.now(), // any date; default now
group: 'Today', // optional
toast: true, // also show a toast
});As a page
Without .popover it is a plain block, for a full "All notifications" page. Add .notifications-page for a card look.
All notifications
-
AK
Ana Kim commented on order #10421: "Can this ship by Friday?"
-
Payment received $129.00 from Max Ruiz
-
Order #10418 shipped
Nothing here yet.
<div class="notifications notifications-page" id="notify-page" aria-label="All notifications">
<div class="notifications-head">
<h2 class="notifications-title">All notifications</h2>
<button class="btn btn-sm" type="button" data-momo-mark-all>Mark all as read</button>
</div>
<ul class="notifications-list">
<li class="notification is-unread">
<span class="avatar avatar-sm bg-pink">AK</span>
<div class="notification-body"><p class="notification-text"><b>Ana Kim</b> commented on order #10421: "Can this ship by Friday?"</p><time class="notification-time" data-ago-min="12"></time></div>
</li>
<li class="notification">
<span class="notification-icon bg-green"><i class="mi mi-credit-card"></i></span>
<div class="notification-body"><p class="notification-text"><b>Payment received</b> $129.00 from Max Ruiz</p><time class="notification-time" data-ago-min="90"></time></div>
</li>
<li class="notification">
<span class="notification-icon bg-cyan"><i class="mi mi-truck"></i></span>
<div class="notification-body"><p class="notification-text"><b>Order #10418 shipped</b></p><time class="notification-time" data-ago-min="2900"></time></div>
</li>
</ul>
<p class="notifications-empty" hidden><i class="mi mi-bell-off"></i> Nothing here yet.</p>
</div>
<script>
document.querySelectorAll('#notify-page time[data-ago-min]').forEach(function (t) { t.setAttribute('datetime', new Date(Date.now() - t.dataset.agoMin * 60000).toISOString()); });
</script>Two looks
By default it is a list: a light dashed line between items, and unread ones get a violet dot, a faint tint and bold text, while read ones calm down. .notifications-cards makes each item its own rounded card instead.
- AK
Ana Kim commented on order #10421
Payment received $129.00 from Max Ruiz
Order #10418 shipped
<div class="notifications notifications-page notifications-cards" aria-label="Cards look">
<ul class="notifications-list pt-2">
<li class="notification is-unread"><span class="avatar avatar-sm bg-pink">AK</span><div class="notification-body"><p class="notification-text"><b>Ana Kim</b> commented on order #10421</p></div></li>
<li class="notification is-unread"><span class="notification-icon bg-green"><i class="mi mi-credit-card"></i></span><div class="notification-body"><p class="notification-text"><b>Payment received</b> $129.00 from Max Ruiz</p></div></li>
<li class="notification"><span class="notification-icon bg-cyan"><i class="mi mi-truck"></i></span><div class="notification-body"><p class="notification-text"><b>Order #10418 shipped</b></p></div></li>
</ul>
</div>Colors
The unread dot and tint are violet; .notifications-<color> on the panel changes them. Icons take their own color.
Low stock Momo Mug: 4 left
New message from Ana Kim
Payout failed Check your bank details
<div class="notifications notifications-page notifications-orange" aria-label="Store alerts">
<ul class="notifications-list pt-2">
<li class="notification is-unread"><span class="notification-icon bg-orange"><i class="mi mi-package"></i></span><div class="notification-body"><p class="notification-text"><b>Low stock</b> Momo Mug: 4 left</p></div></li>
<li class="notification is-unread"><span class="notification-icon bg-violet"><i class="mi mi-message-circle"></i></span><div class="notification-body"><p class="notification-text"><b>New message</b> from Ana Kim</p></div></li>
<li class="notification"><span class="notification-icon bg-red"><i class="mi mi-alert-triangle"></i></span><div class="notification-body"><p class="notification-text"><b>Payout failed</b> Check your bank details</p></div></li>
</ul>
</div>Events
inbox.addEventListener('momo:read', (e) => save(e.detail.item, e.detail.read)); // item is null for "mark all"
inbox.addEventListener('momo:dismiss', (e) => { // cancelable
if (!confirm('Dismiss?')) e.preventDefault();
});
inbox.addEventListener('momo:notify', (e) => e.detail.item); // after Momo.notify()Parts
| Class / attribute | What it does |
|---|---|
.popover.notifications + data-momo-popover | The panel and its bell |
.badge-corner | A count on the corner of a button or avatar (empty: a dot) |
.notifications-head, -title, -filter, -foot | The top bar, its title, the All / Unread switch, the bottom bar |
.notifications-list > li.notification | One notification; .is-unread for new ones |
li.notifications-group | A heading like "Today" |
.notification-icon, .avatar | The round picture on the left |
.notification-text, -sub, -time, -link | The text, a second line, the time, and a link that makes the whole row clickable |
[data-momo-unread-count] | Shows the unread count (inside the panel, or ="inbox" anywhere) |
.notifications-empty | Shown when nothing is left to show |