Skip to main content

Notifications Block

Notifications is a notification panel built on MUI.

Installationโ€‹

npm install @nodeblocks/frontend-notifications-block

What You Needโ€‹

ItemWhy it matters
isNotificationsOpenControls whether the popover panel is open
setIsNotificationsOpenLets the panel close (for example, on click outside)
notificationsListArray of notification items to render in the panel
onClickHandles bell button clicks (typically toggles open state)
unreadCount (optional)Drives the badge count on the bell button
heading (optional)Panel heading above the list
emptyStateMessage (optional)Copy shown when the list is empty
Controlled open state

Notifications does not own panel open state. Keep isNotificationsOpen in your app and pass setIsNotificationsOpen so the popover can close correctly.

Each item in notificationsList supports:

FieldTypeRequiredDescription
titlestringYesNotification heading
createdAtstringYesISO date string used for relative time display
textReactNodeNoOptional body copy
hrefstringNoWhen set, the item renders as a link
iconPartial<AvatarProps> & { isLoading?: boolean }NoAvatar image, initials, or loading placeholder

Code Examplesโ€‹

Live Editor
function Example() {
  const [isNotificationsOpen, setIsNotificationsOpen] = React.useState(false);
  const [unreadCount, setUnreadCount] = React.useState(10);

  const notificationsList = [
    {
      title: 'Email updated',
      text: 'Your email has been updated successfully.',
      createdAt: new Date().toISOString(),
      href: '/settings',
    },
    {
      icon: {children: 'G'},
      title: 'Order shipped',
      text: 'Your order #2847 has been dispatched.',
      href: '/orders',
      createdAt: new Date(Date.now() - 86400000).toISOString(),
    },
  ];

  return (
    <Notifications
      isNotificationsOpen={isNotificationsOpen}
      setIsNotificationsOpen={setIsNotificationsOpen}
      notificationsList={notificationsList}
      unreadCount={unreadCount}
      onClick={() => {
        setUnreadCount(0);
        setIsNotificationsOpen(!isNotificationsOpen);
      }}
    />
  );
}
Result
Loading...

Important Propsโ€‹

Core Propsโ€‹

PropTypeRequiredDefaultDescription
isNotificationsOpenbooleanYes-Whether the notifications popover is open
setIsNotificationsOpen(open: boolean) => voidYes-Updates open state; required for closing on outside click
onClickReact.MouseEventHandler<HTMLButtonElement>Yes-Bell button click handler; typically toggles open state
notificationsListNotificationItem[]Yes-Items rendered in the panel (see shape above)
unreadCountnumberNoundefinedBadge count on the bell button; values above 50 display as 50+

Content Propsโ€‹

PropTypeRequiredDefaultDescription
headingstringNo'Notifications'Panel heading above the list
emptyStateMessagestringNo'No notifications'Message shown when the list is empty
isLoadingbooleanNoundefinedWhen true, shows a loader instead of list items

Layout and Composition Propsโ€‹

PropTypeRequiredDefaultDescription
anchorElHTMLElement | nullNointernal stateAnchor element for popover positioning
setAnchorEl(el: HTMLElement | null) => voidNointernal setterUpdates the popover anchor element
childrenBlocksOverride | ReactNodeNoundefinedCompound sub-components or a block override function
classNamestringNoundefinedClass name for the root container (also applies nbb-notifications)
sxSxPropsNoundefinedMUI system styles for the root Stack

Notifications inherits StackProps (except children), so standard layout props are supported on the root. Default block order is button โ†’ list; listItem and loader are default blocks used internally by Notifications.List.

Sub-components read values from context and accept partial MUI props:

formatRelativeDateText defaults to ISO date parsing with date-fns and the Japanese locale, returning ไปŠๆ—ฅ for notifications created today. Pass a custom formatter on Notifications.List or Notifications.ListItem if your dates use another format or locale.

Default UI Blocksโ€‹

BlockBuilt onNotes
Notifications (root)Stack rendered as asideInline wrapper for the trigger button and popover list
Notifications.ButtonIconButton + BadgeBell icon with optional unread count badge
Notifications.ListPopover + TypographyScrollable panel with heading, dividers, empty state, and loading state
Notifications.ListItemStack + Avatar + TypographyRenders as an anchor when href is set
Notifications.LoaderStack + CircularProgressCentered spinner shown while isLoading is true

TypeScriptโ€‹

import {Notifications} from '@nodeblocks/frontend-notifications-block';
import type {ComponentProps} from 'react';

type NotificationsProps = ComponentProps<typeof Notifications>;

type NotificationItem = NotificationsProps['notificationsList'][number];

function ActivityNotifications({items, unreadCount}: {items: NotificationItem[]; unreadCount: number}) {
const [isOpen, setIsOpen] = React.useState(false);

return (
<Notifications
isNotificationsOpen={isOpen}
setIsNotificationsOpen={setIsOpen}
notificationsList={items}
heading="Activity"
unreadCount={unreadCount}
onClick={() => setIsOpen(prev => !prev)}
/>
);
}