Web · Components
NotificationCenter
Notification center: a bell button, an unread count badge and a dropdown notification list.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Notification center: a bell button, an unread count badge and a dropdown notification list. For the app's top bar.
- List: grouped by day (Today, Yesterday…), times written relatively ("3 min ago"); unread ones are highlighted with a dot. Rows have an icon or avatar, action buttons ("Accept") and removal with ×.
- Tabs: All / Unread or your own categories.
- Read: on press, on panel close or manually (
readOn); "Mark all as read" is always available. - Live: when a new notification arrives the bell shakes slightly and screen readers say "New notification: …". It doesn't shake with the reduced motion preference.
- Paged: with
onLoadMore+hasMore, the next page at the end of the list. - Mobile: the panel becomes a bottom sheet; the back button and pulling down close it. With
inlineit is embedded in the page.
If you don't want to keep the state yourself, see useNotifications.
Examples
useNotifications
functionReady-made state for NotificationCenter: add, mark as read, remove. If you need to save to a server, wire up the component's events yourself; this hook only keeps client state.
Examples
NotificationAction
interfaceAn action button on a NotificationItem ("Accept", "Decline").
| Name | Type | Default | Description |
|---|---|---|---|
label | ReactNode | Button text. | |
onClick | () => unknown | Called on press. If it returns a Promise, the button shows loading until it settles. | |
primary? | boolean | false | The primary action is filled, the others outlined. |
NotificationItem
interfaceA notification in the NotificationCenter.
| Name | Type | Default | Description |
|---|---|---|---|
id | string | Unique id. | |
title | ReactNode | Title ("Ayşe commented"). | |
description? | ReactNode | Details; at most two lines are shown. | |
date | Date | string | number | Time of the notification; written relatively like "3 min ago" and grouped by day. | |
read? | boolean | false | Has it been read? Unread ones are highlighted with a dot. |
icon? | IconProp | Leading icon (when there is no avatar). | |
tone? | Tone | "primary" | Color of the icon. |
avatar? | string | ReactNode | Avatar on the left: an image URL or an element (e.g. <Avatar … />). | |
href? | string | URL to go to on press; in-site URLs open with UIProvider link. | |
actions? | readonly NotificationAction[] | Action buttons under the row. See NotificationAction. | |
category? | string | Category for splitting into tabs (e.g. "mention", "system"). See NotificationCenterProps.tabs. |
NotificationTab
interfaceA tab at the top of the NotificationCenter.
| Name | Type | Description |
|---|---|---|
value | string | Key of the tab: "all", "unread" or a NotificationItem.category. |
label | ReactNode | Tab text. |
When does NotificationCenter count notifications as read?
NotificationCenterClassNames
interfaceClasses that can be passed to the inner parts of NotificationCenter.
| Name | Type | Description |
|---|---|---|
trigger? | string | Bell button. |
badge? | string | Unread count badge. |
panel? | string | The dropdown panel (or the inline box). |
item? | string | Notification row. |
group? | string | Day title. |
NotificationCenterProps
interfaceProps of the NotificationCenter component.
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly NotificationItem[] | Notifications. See NotificationItem. They don't need to come sorted; they are ordered newest first. | |
onRead? | (ids: string[]) => void | Called with the ids when notifications are read. | |
onReadAll? | () => void | "Mark all as read". If omitted, onRead is called with all unread ones. | |
onRemove? | (id: string) => void | When removed with × on the row; if omitted, × isn't shown. | |
onClear? | () => void | "Clear all"; if omitted, the button isn't shown. | |
onSelect? | (item: NotificationItem) => void | Called when a notification is pressed (before navigating). | |
readOn? | NotificationReadMode | "click" | When it counts as read. See NotificationReadMode. |
tabs? | boolean | readonly NotificationTab[] | true | Tabs at the top. true: "All" and "Unread"; an array: your own tabs (value is a category or "all"/"unread"); false: none. |
groupByDay? | boolean | true | Group by day ("Today", "Yesterday", "Monday, November 3")? |
title? | ReactNode | "Bildirimler"` (`messages.notifications`) | Panel title. |
actions? | ReactNode | Extra content next to the title (e.g. a settings link). | |
footer? | ReactNode | Footer of the panel (e.g. a "See all" link). | |
empty? | ReactNode | Content shown when there are no notifications. | |
onLoadMore? | () => unknown | Loads the next page; called when the end of the list is reached. | |
hasMore? | boolean | false | Are there more notifications to load? |
loading? | boolean | Is the first load in progress? | |
inline? | boolean | false | A list embedded in the page instead of a panel (e.g. a /notifications page). The bell button isn't rendered. |
trigger? | ReactElement | Open button used instead of the bell. | |
icon? | IconProp | bell | Bell icon. |
badgeTone? | Tone | "danger" | Badge color. |
announce? | boolean | true | Shake the bell and announce to screen readers when a new notification arrives? |
side? | Placement | "bottom-right" | Position of the panel. See Placement. |
open? | boolean | Whether the panel is open when controlled. | |
defaultOpen? | boolean | false | Is it initially open when uncontrolled? |
onOpenChange? | (open: boolean) => void | When the panel opens or closes. | |
maxHeight? | string | "min(32rem, 70dvh)" | Maximum list height. |
className? | string | Classes added to the container. | |
classNames? | NotificationCenterClassNames | Classes added to the inner parts. | |
effect? | EffectProp | Effect or effects of the notification rows (e.g. "ripple", "border"). If omitted, UIProvider appearance.defaults.notificationCenter.effect. See BuiltinEffect. |
UseNotificationsResult
interfaceValue returned by the useNotifications hook.
| Name | Type | Description |
|---|---|---|
items | NotificationItem[] | Notifications, newest to oldest. |
unreadCount | number | Number of unread notifications. |
add | (item: Omit<NotificationItem, "id" | "date"> & Partial<Pick<NotificationItem, "id" | "date">>) => string | Adds a new notification (at the top); id is generated if omitted, date defaults to now. |
markRead | (ids: readonly string[]) => void | Marks the given notifications as read. |
markAllRead | () => void | Marks all as read. |
remove | (id: string) => void | Deletes a notification. |
clear | () => void | Removes all. |
setItems | (items: NotificationItem[]) => void | Replaces the list (e.g. the first page from the server). |
props | { items: NotificationItem[]; onRead: (ids: string[]) => void; onReadAll: () => void; onRemove: (id: string) => void; onClear: () => void; } | Props to spread onto NotificationCenter: <NotificationCenter {...notifications.props} />. |