react-web-notification

React component with HTML5 Web Notification API

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
react-web-notification
270220.8.04 years ago9 years agoMinified + gzip package size for react-web-notification in KB

Readme

React-web-notification Build Status npm version codebeat badge FOSSA Status codecov
React component with HTML5 Web Notification API. This component show nothing in dom element, but trigger HTML5 Web Notification API with render method in the life cycle of React.js.

Demo

View Demo

Installation

npm install --save react-web-notification

API

Notification

React component which wrap web-notification.

Props

Notification.propTypes = {
  ignore: bool,
  disableActiveWindow: bool,
  askAgain: bool,
  notSupported: func,
  onPermissionGranted: func,
  onPermissionDenied: func,
  onShow: func,
  onClick: func,
  onClose: func,
  onError: func,
  timeout: number,
  title: string.isRequired,
  options: object,
  swRegistration: object,
};

  • ignore : if true, nothing will be happen

  • disableActiveWindow : if true, nothing will be happen when window is active

  • askAgain : if true, window.Notification.requestPermission will be called on componentDidMount, even if it was denied before,


  • onPermissionGranted() : Called when permission granted.

  • onPermissionDenied() : Called when permission denied. Notification will do nothing until permission granted again.

  • onShow(e, tag) : Called when Desktop notification is shown.

  • onClick(e, tag) : Called when Desktop notification is clicked.

  • onClose(e, tag) : Called when Desktop notification is closed.

  • onError(e, tag) : Called when Desktop notification happen error.

  • timeout : milli sec to close notification automatically. Ignored if 0 or less. (Default 5000)

  • title : Notification title.

  • options : Notification options. set body, tag, icon here.
See also (https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification)
  • swRegistration : ServiceWorkerRegistration. Use this prop to delegate the notification creation to a service worker.
See also (https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification) ⚠️ onShow, onClick, onClose and onError handlers won't work when notification is created by the service worker.

Usage example

See example
yarn
yarn run start:example

Tests

yarn test

Update dependencies

Use npm-check-updates

Known Issues

Notification.sound Notification.sound is not supported in any browser. You can emulate it with onShow callback. see example.

License

FOSSA Status