NotificationsProvider

Context for showing notifications from descendants.

useNotifications exposes notifications, showNotification, and hideNotification.

Live example

Example controls

Usage

import { Button, NotificationsProvider, useNotifications } from '@prosazhin/pbcomponents';

function Example() {
  const { showNotification } = useNotifications();
  return (
    <Button onClick={() => showNotification({ headline: 'Saved', children: 'Changes saved.' })}>
      Show
    </Button>
  );
}

<NotificationsProvider top={80}>
  <Example />
</NotificationsProvider>;

Component API

PropType / variantsPurposeDefault
childrenReactNodeDescendants that can use useNotifications.—
topnumberTop offset of notifications in pixels.0
delaynumberNotification lifetime in milliseconds.5000
animationDurationnumberAnimation duration in milliseconds.200
estimatedNotificationHeightnumberEstimated height for notification layout.80
disableTimerbooleanDisables auto-dismiss.false
disableProgressBarbooleanHides the timer progress bar.false
disableTimerPauseOnHoverbooleanTimer does not pause on hover.false
disableTimerPauseOnContainerHoverbooleanTimer does not pause when hovering the container.false
disableCloseByClickInsideAnywherebooleanPrevents dismissing by clicking inside.false
classNamestringClass of the root element.—

Native HTML attributes are accepted where the component renders the corresponding element. className props only affect styling.