DocsBlog
  • 0.25.3

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Styling
Theming

Concepts

OverviewCompositionTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Notifications

The Notification component is used to display notifications in your application.

  • npm
  • source
  • recipe
  • Ark
import { NotificationCenter, toaster } from '@cerberus/react'

Usage

The NotificationCenter component is used to manage notifications in your application. It works together with the toaster object to display notifications.

Copy
Basic demo
'use client';
import { toaster } from '@cerberus/react'
function Feature() {
const handleClick = useCallback(() => {
toaster.create({
type: 'info',
title: 'Update Available',
description: 'A new version of the app is available',
action: {
label: 'Refresh',
onClick: () => {
window.location.reload()
}
}
})
}, [])
return <Button onClick={handleClick}>Trigger notification</Button>
}
layout.tsx
import { NotificationCenter } from '@cerberus/react'
export function Layout(props: PropsWithChildren<{}>) {
return (
<>
{props.children}
<NotificationCenter />
</>
)
}

Types

Just update the options.types to change the theme of the notification. The options are info, success, warning, error, and loading.

Copy
Types demo
'use client';
import { toaster } from '@cerberus/react'
function Feature() {
const handleClick = useCallback(() => {
toaster.create({
type: 'loading',
title: 'Loading',
description: 'It's taking longer than normal.',
})
}, [toaster.create])
return <Button onClick={handleClick}>Trigger notification</Button>
}

Subtle Notifications

Subtle notifications are a less intrusive way to inform users about events or updates. They typically have a softer appearance and may not require immediate user action.

Use the -subtle suffix with the notification type to create a subtle notification.

Copy
Subtle Notifications Demo
'use client';
import { toaster } from '@cerberus/react'
function Feature() {
const handleClick = useCallback(() => {
toaster.create({
type: 'info-subtle',
title: 'Update Available',
description: 'A new version of the app is available',
action: {
label: 'Refresh',
onClick: () => {
window.location.reload()
}
}
})
}, [])
return <Button onClick={handleClick}>Trigger subtle notification</Button>
}

Custom Configuration

You can customize the notification behavior by calling the createToaster function. This allows you to create a new toaster instance with your desired configuration.

We recommend scoping this to a component to ensure Next.js rehydration works correctly.

Copy
Custom Configuration
'use client';
import { createToaster, NotificationCenter, Button } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
function CustomConfigDemo() {
const customToaster = createToaster({
gap: 24,
overlap: false,
placement: 'bottom-end',
})
return (
<>
<HStack>
<Button
onClick={() => {
customToaster.create({
title: 'Custom Toaster',
description:
'This notification is using a custom toaster configuration.',
type: 'success',
})
}}
>
Show Notification
</Button>
</HStack>
<NotificationCenter toaster={customToaster} />
</>
)
}

Badges

Badges can be used to show the number of notifications on any trigger by using the data-notify and data-notify-count attributes.

Note

Combine this with the `formatNotifyCount` helper that will restrict the count to 3 digits.

Small IconButton
Large IconButton
Copy
some-page.tsx
import { IconButton, formatNotifyCount } from '@cerberus/react'
import { Notifications } from '@cerberus/icons'
export function NotifyBadgePreview() {
return (
<IconButton
ariaLabel="View notifications"
data-notify
data-notify-count={formatNotifyCount(100)}
>
<Notifications />
</IconButton>
)
}

Primitives

You can utilize the primitive components to customize the toast notification.

ComponentDescription
NotificationProviderThe context provider for the toast notifications.
NotificationRootThe context provider for the toast parts.
NotificationHeadingThe title heading of the toast.
NotificationDescriptionThe description of the toast.
NotificationCloseTriggerThe close button of the toast.
NotificationActionTriggerThe action button of the toast.

API

Props

The NotificationCenter component is an abstraction of the primitives and doesn't accept any props.

toaster

The toaster object is used to create notifications and accepts the following options:

NameTypeDescription
typestringThe type of notification. Options are info, success, warning, error, and loading.
titlestringThe title of the notification.
descriptionstringThe description of the notification.
actionToasterActionThe action object of the notification.
durationnumberA custom duration of the notification.
onClosefunctionThe callback function when the notification is closed.

ToasterAction

The ToasterAction object is used to create an action button for the notification and accepts the following options:

NameTypeDescription
labelstringThe label of the action button.
onClickfunctionThe callback function when the action button is clicked.

Parts

The NotificationParts API is an Object containing the full family of components.

Note

It is best to only use the NotificationParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe NotificationRoot component which is the Provider for the toast.
HeadingThe NotificationHeading component which displays the heading title for the toast.
DescriptionThe NotificationDescription component which displays the description for the toast.
CloseTriggerThe NotificationCloseTrigger component which displays the close button for the toast.
ActionTriggerThe NotificationActionTrigger component which displays the action button for the toast.

On this page

  • Edit this page on Github
Cerberus Design System | Docs