Skip to content
Nana UI

Feedback & Status

Notification Center

A bell with an unread count that opens a panel of notifications, for the top bar of an app.

View .md Download

The notification center keeps what has happened since someone last looked: a bell in the top bar with the unread count, and a panel listing each notification with how long ago it arrived. People can show only the unread, mark everything read, or open one, which marks it read. For a message that needs no record, use a toast; for one that belongs on the page, an alert.

Nana Insurance
Page content
Nana Insurance
Page content

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add notification-center --framework web-components
npx @nana-tec/ui add notification-center --framework svelte

Lands in src/lib/components/ui/notification-center/ as NanaNotificationCenter.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

The notifications are data, newest first. Each has an id and a title, and can carry a description, a time (a Date, a timestamp or an ISO string), read, and an href that makes it a link. Choosing a notification marks it read, hands it back and closes the panel; “Mark all as read” marks the rest. Keep the list on your server and save those changes there.

<script lang="ts">
import {
NanaNotificationCenter,
type NotificationItem,
} from '$lib/components/ui/notification-center';
let items = $state<NotificationItem[]>([
{ id: 'clm-2041', title: 'Claim CLM-2041 approved', time: '2026-11-20T09:15:00Z' },
{ id: 'pay-118', title: 'Premium received', time: '2026-11-20T08:40:00Z', read: true },
]);
</script>
<NanaNotificationCenter
bind:items
onSelect={(item) => console.log('open', item.id)}
onReadAll={() => console.log('all read')}
/>

items is bindable, so the read flags it sets land in your state. Pass a footer snippet for a link to every notification; it receives close.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/notification-center";

Copied in with npx @nana-tec/ui add notification-center? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

<nana-notification-center>
<a slot="footer" href="/notifications">View all notifications</a>
</nana-notification-center>
<script type="module">
const center = document.querySelector('nana-notification-center');
center.items = [
{ id: 'clm-2041', title: 'Claim CLM-2041 approved', time: '2026-11-20T09:15:00Z' },
{ id: 'pay-118', title: 'Premium received', time: '2026-11-20T08:40:00Z', read: true },
];
center.addEventListener('nana-select', (event) => console.log('open', event.detail.item.id));
center.addEventListener('nana-change', (event) => console.log(event.detail.items));
</script>

The element replaces items when it marks notifications read, and fires nana-change with the new list. Anything in the footer slot sits under the list.

Each time reads as how long ago it was, such as “5 min. ago” or “yesterday”, in the page’s language, or in locale when set. The times are worked out each time the panel opens.

KeyDoes
Enter or Space on the bellOpens or closes the panel, moving focus into it
TabMoves through the panel’s buttons and notifications
Up and Down arrowsMove between notifications
Home and EndGo to the first or last notification
EscapeCloses the panel and returns to the bell

A press outside the panel also closes it.

  • The bell is named by label, “Notifications” by default, with the unread count added: “Notifications, 2 unread”. The badge itself is hidden from screen readers.
  • The panel is a dialog named by its heading. The All and Unread buttons say which is pressed.
  • An unread notification starts with “Unread:” for screen readers; the dot and the bold title show it on screen.
  • Each time is a <time> element carrying the exact date and time.
  • The message shown when there is nothing to show is a status, so it is announced.

Properties

PropertyAttributeTypeDefaultDescription
emptyemptystring'You’re all caught up.'Message shown when there is nothing to show.
items—NotificationItem[][]The notifications, newest first. Choosing one or marking all read replaces the array.
labellabelstring'Notifications'Names the bell and heads the panel.
localelocalestring | undefined—Locale for the times, such as en-KE. The page's locale by default.
openopenbooleanfalseWhether the panel is open.

Methods

MethodDescription
hide(): voidClose the panel.
show(): voidOpen the panel.
toggle(): voidOpen the panel if it is closed, close it if it is open.

Events

EventDescription
nana-selectA notification was chosen (detail.item), already marked read
nana-read-allEverything was marked read
nana-changeThe notifications changed (detail.items)
nana-openThe panel opened
nana-closeThe panel closed

Slots

SlotDescription
footerContent under the list, such as a link to every notification

CSS parts

PartDescription
::part(base)The wrapper around the bell and the panel
::part(trigger)The bell button, with the open state
::part(bell)The bell icon
::part(badge)The unread count on the bell
::part(panel)The panel, with the open state
::part(header)The row holding the heading and the mark-all button
::part(heading)The panel's heading
::part(mark-all)The button that marks everything read
::part(filters)The All and Unread buttons
::part(filter)One of them, with the active state
::part(list)The list of notifications
::part(item)A notification, with the unread or read state
::part(action)The link or button inside it, with the unread or read state
::part(dot)The unread marker
::part(title)A notification's title
::part(description)The line under the title
::part(time)How long ago it arrived
::part(empty)The message shown when there is nothing to show
::part(footer)The footer around the slotted content

CSS custom properties

PropertyDescription
--nana-notification-center-zStacking order of the open panel

NanaNotificationCenter

PropTypeDefault
itemsbind:NotificationItem[][]
openbind:booleanfalse
labelstring'Notifications'
emptystring'You’re all caught up.'
localestring
placementPlacement'bottom-end'
onSelect(item: NotificationItem) => void
onReadAll() => void
onOpenChange(open: boolean) => void
footerSnippet<[{ close: () => void }]>