The Notification Center Web Component is a custom element that can be used in any web application. It is built by wrapping the React components and consists from its core the three pieces:  NovuProviderPopoverNotificationCenter, and  NotificationBell combined together into one.

ESM module

Make sure that you have installed the @novu/notification-center package:

npm install @novu/notification-center

Then, import the web component and register it as a custom element:

import { NotificationCenterWebComponent } from "@novu/notification-center";

customElements.define(
  "notification-center-component",
  NotificationCenterWebComponent
);

After that, you can use the web component in your HTML:

<!-- HTML -->
<notification-center-component
  style="display: inline-flex"
  application-identifier="APPLICATION_IDENTIFIER"
  subscriber-id="SUBSCRIBER_ID"
></notification-center-component>
<script>
  // here you can attach any callbacks, interact with the Notification Center Web Component API
  let nc = document.getElementsByTagName("notification-center-component")[0];
  nc.onLoad = () => console.log("Notification Center session loaded!");
</script>

Please note: that the properties are named with a kebab-case in the HTML, but depending on the technology you use it might be a camelCase, for ex. Vue/Angular props are bound with variables using that convention.

Example

CodeSandBox Link 🔗

Bundled version (preview)

Sometimes you might not be able to use the ESM module, for example in the WordPress environment. In that case, you can use the bundled version of the Notification Center Web Component that is available on the CDN.

<!DOCTYPE html>
<html lang="en">
  <head>
    ...
    <script src="​https://web-component.novu.co/index.js"></script>
  </head>
  <body>
    <notification-center-component
      style="display: inline-flex"
      application-identifier="APPLICATION_IDENTIFIER"
      subscriber-id="SUBSCRIBER_ID"
    ></notification-center-component>
    <script>
      // here you can attach any callbacks, interact with the web component API
      let nc = document.getElementsByTagName(
        "notification-center-component"
      )[0];
      nc.onLoad = () => console.log("hello world!");
    </script>
  </body>
</html>

Example

CodeSandBox Link 🔗

Properties

The Notification Center Web Component has a few properties that you can use to customize the behavior of the component. The only required property is applicationIdentifier.

If you are using TypeScript, then you might want to check the NotificationCenterComponentProps interface.

PropTypeDescription
backendUrlstringCustom API location in case of self-hosted version of Novu.
socketUrlstringCustom WebSocket Service location in case of self-hosted version of Novu.
subscriberIdstringThe subscriberId is a custom identifier used when identifying your users within the Novu platform.
applicationIdentifierstringIs a public identifier used to identify your application, can be found in the Novu Admin panel.
subscriberHashstringThe hashed subscriber id. Read more about hmac encryption.
storesobject[]The array of the store items that are bound with the feed, it’s used together with tabs property if you would like to have separate feeds in the notification center. Read more here
tabsobject[]The array of items that do describe the tabs/feeds, they are bound with the stores property. Read more here.
showUserPreferencesbooleanThe flag indicating whether the user preference settings should be visible or not.
allowedNotificationActionsbooleanThe flag indicating whether to show/hide the dots menu for actions performed on a notification.
popoverConfigobjectThe object defining how the popover should be positioned. It’s properties are position and offset.
popoverobjectThe object defining how the popover should be positioned. It’s properties are position and offset. popover is deprecated, use popoverConfig instead.
themeINovuThemeThe object defining the the light/dark styles of the Notification Center component. We discourage you to use this prop to do the styling, instead it’s recommended to use the styles property.
stylesNotificationCenterStylesThe object allows you to define the custom CSS code.
colorSchemestringThe prop defines which color version of the styles the component should set. The options are light and dark.
i18nobjectThe object allowing to customize the UI language.
onLoadfunctionThe callback function that is called when the session is successfully initiated. It receives the first argument object with the organization property. There is a sibling property sessionLoaded that might be used in environments that do not allow to use properties with the prefix on, like in Angular.
onNotificationClickfunctionThe callback function that is called when the user has clicked on the notification. The first argument it receives is the notification object. There is a sibling property notificationClicked.
onUnseenCountChangedfunctionThe callback function that is called when the unseen notifications count changes. The first argument it receives is the number of unseen notifications count. There is a sibling property unseenCountChanged.
onActionClickfunctionThe callback function that is called when user clicks on one of the notification buttons (primary/secondary). The arguments it receives are: template identifier, button type, and notification object. There is a sibling property actionClicked.
onTabClickfunctionThe callback function that is called when user clicks on the feed tab. The first arguments it receives is the tab object. There is a sibling property tabClicked.

Limitations

It’s important to note that there are some limitations when using the Web Component compared to the React version:

  • You get an all-in-one component
  • It doesn’t support the children, header, footer, emptyState, listItem props
  • It’s a wrapped react component, which means a bigger bundle size (we are working on it to make it smaller)