Feedback & Status
Notification Center
A bell with an unread count that opens a panel of notifications, for the top bar of an app.
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.
Preview
Section titled “Preview”<div
style="
width: 100%;
border: 1px solid var(--nana-surface-border);
border-radius: 0.5rem;
"
>
<nana-top-bar sticky="false" style="border-radius: 0.5rem 0.5rem 0 0">
<span slot="start" style="font-weight: 600; white-space: nowrap">
Nana Insurance
</span>
<nana-notification-center slot="end" id="notifications-demo">
<button
slot="footer"
type="button"
style="
font: inherit;
font-weight: 500;
color: var(--nana-surface-accent);
background: none;
border: 0;
cursor: pointer;
"
>
View all notifications
</button>
</nana-notification-center>
</nana-top-bar>
<div
id="notifications-page"
style="
height: 28rem;
padding: 1.5rem;
background: var(--nana-surface-subtle);
border-radius: 0 0 0.5rem 0.5rem;
font-size: 0.875rem;
color: var(--nana-surface-text-subtle);
"
>
Page content
</div>
</div>
<script type="module">
const minutes = (count) => Date.now() - count * 60000;
const center = document.getElementById("notifications-demo");
center.items = [
{
id: "claim",
title: "Claim CLM-2041 approved",
description: "KES 48,500 will be paid to the garage.",
time: minutes(5),
},
{
id: "payment",
title: "Premium received",
description: "KES 3,200 by M-Pesa for policy MTR-118.",
time: minutes(42),
},
{
id: "renewal",
title: "Policy MTR-118 renews in 7 days",
time: minutes(300),
read: true,
},
{
id: "message",
title: "New message from your agent",
description: "Wanjiru sent the inspection report.",
time: minutes(1620),
read: true,
},
];
center.addEventListener("nana-select", (event) => {
document.getElementById("notifications-page").textContent =
"Opened: " + event.detail.item.title;
});
center
.querySelector("[slot=footer]")
.addEventListener("click", () => center.hide());
</script> <script lang="ts">
import { NanaNotificationCenter, NanaTopBar, type NotificationItem } from '$lib';
const minutes = (count: number): number => Date.now() - count * 60_000;
let items = $state<NotificationItem[]>([
{
id: 'claim',
title: 'Claim CLM-2041 approved',
description: 'KES 48,500 will be paid to the garage.',
time: minutes(5),
},
{
id: 'payment',
title: 'Premium received',
description: 'KES 3,200 by M-Pesa for policy MTR-118.',
time: minutes(42),
},
{
id: 'renewal',
title: 'Policy MTR-118 renews in 7 days',
time: minutes(60 * 5),
read: true,
},
{
id: 'message',
title: 'New message from your agent',
description: 'Wanjiru sent the inspection report.',
time: minutes(60 * 27),
read: true,
},
]);
let chosen = $state('');
</script>
<div class="w-full rounded-lg border border-line">
<NanaTopBar sticky={false} class="rounded-t-lg">
{#snippet start()}
<span class="font-semibold whitespace-nowrap">Nana Insurance</span>
{/snippet}
{#snippet end()}
<NanaNotificationCenter bind:items onSelect={(item) => (chosen = item.title)}>
{#snippet footer({ close })}
<button type="button" class="text-sm font-medium text-primary" onclick={close}>
View all notifications
</button>
{/snippet}
</NanaNotificationCenter>
{/snippet}
</NanaTopBar>
<div class="h-[28rem] rounded-b-lg bg-surface-subtle p-6 text-sm text-foreground-muted">
{chosen ? `Opened: ${chosen}` : 'Page content'}
</div>
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add notification-center --framework web-componentsnpx @nana-tec/ui add notification-center --framework svelteLands 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.
Keyboard
Section titled “Keyboard”| Key | Does |
|---|---|
| Enter or Space on the bell | Opens or closes the panel, moving focus into it |
| Tab | Moves through the panel’s buttons and notifications |
| Up and Down arrows | Move between notifications |
| Home and End | Go to the first or last notification |
| Escape | Closes the panel and returns to the bell |
A press outside the panel also closes it.
Accessibility
Section titled “Accessibility”- 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
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
empty | empty | string | '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. |
label | label | string | 'Notifications' | Names the bell and heads the panel. |
locale | locale | string | undefined | — | Locale for the times, such as en-KE. The page's locale by default. |
open | open | boolean | false | Whether the panel is open. |
Methods
| Method | Description |
|---|---|
hide(): void | Close the panel. |
show(): void | Open the panel. |
toggle(): void | Open the panel if it is closed, close it if it is open. |
Events
| Event | Description |
|---|---|
nana-select | A notification was chosen (detail.item), already marked read |
nana-read-all | Everything was marked read |
nana-change | The notifications changed (detail.items) |
nana-open | The panel opened |
nana-close | The panel closed |
Slots
| Slot | Description |
|---|---|
footer | Content under the list, such as a link to every notification |
CSS parts
| Part | Description |
|---|---|
::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
| Property | Description |
|---|---|
--nana-notification-center-z | Stacking order of the open panel |
NanaNotificationCenter
| Prop | Type | Default |
|---|---|---|
itemsbind: | NotificationItem[] | [] |
openbind: | boolean | false |
label | string | 'Notifications' |
empty | string | 'You’re all caught up.' |
locale | string | |
placement | Placement | 'bottom-end' |
onSelect | (item: NotificationItem) => void | |
onReadAll | () => void | |
onOpenChange | (open: boolean) => void | |
footer | Snippet<[{ close: () => void }]> |