Installations
npm install simple-react-notifications2
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
12.22.12
NPM Version
6.14.16
Score
63.3
Supply Chain
91.4
Quality
75.1
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (71.82%)
CSS (18.38%)
JavaScript (9.8%)
Developer
Download Statistics
Total Downloads
3,404
Last Day
1
Last Week
13
Last Month
53
Last Year
815
GitHub Statistics
4 Stars
79 Commits
1 Watching
8 Branches
3 Contributors
Bundle Size
2.97 kB
Minified
1.36 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.0
Package Id
simple-react-notifications2@2.0.0
Unpacked Size
18.32 kB
Size
5.93 kB
File Count
11
NPM Version
6.14.16
Node Version
12.22.12
Total Downloads
Cumulative downloads
Total Downloads
3,404
Last day
0%
1
Compared to previous day
Last week
8.3%
13
Compared to previous week
Last month
60.6%
53
Compared to previous month
Last year
-24%
815
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
20
Simple-React-Notifications2
Tiny library (only 1.3kb gzip - typescript support) that allows you to add notifications to your app. We don't want to blow up our bundle size because of notifications, right?
Forked from https://github.com/alexpermiakov/simple-react-notifications because maintainer didn't had time for fixes/enhancements.
You can check size from https://arve0.github.io/npm-download-size/ or https://bundlephobia.com/
Demo
https://rizwan-ishtiaq.github.io/simple-react-notifications2/
Despite the small size, it supports:
Installation
$ npm install simple-react-notifications2
$ yarn add simple-react-notifications2
Usage
Rendering success and error default notifications
Notifier has a few built-in components for displaying an error or a successfull operation:
1import React from "react"; 2import notifier from "simple-react-notifications2"; 3import "simple-react-notifications2/dist/index.css"; 4 5const App = () => ( 6 <div> 7 <button 8 onClick={() => { 9 notifier.success("Your items have been updated"); 10 // notifier.error("Something went wrong, try again."); 11 }} 12 > 13 Lets render a default component 14 </button> 15 </div> 16);
Rendering user defined component
The real power comes with rendering our own component. In this case it's not even a notification, just a view with real data:
1const RouteInfo = ({ header, onClosePanel }) => ( 2 <div 3 className="route-info" 4 onClick={onClosePanel} 5 style={{ 6 height: "200px", 7 background: "#54cea7", 8 color: "white", 9 padding: "8px 16px", 10 position: "relative", 11 boxShadow: "rgba(0, 0, 0, 1) 0px 0px 14px 2px" 12 }} 13 > 14 <h3 className="subtitle">{header}</h3> 15 <p>Bicycle 2.4 km, 8 min.</p> 16 <p>Use caution - may involve errors or sections not suited for bicycling</p> 17 <button 18 className="button" 19 style={{ position: "absolute", bottom: "16px", right: "16px" }} 20 > 21 Use this route 22 </button> 23 </div> 24);
It completely up to us the way we add styles. We can use styled-components or whatever we like. The notify() method will just render it:
1const App = () => ( 2 <div> 3 <button 4 onClick={() => 5 notifier({ 6 render: ({ id, onClose }) => ( 7 <RouteInfo 8 key={id} 9 onClosePanel={onClose} 10 header={"The shortest way to ride home."} 11 /> 12 ) 13 }) 14 } 15 > 16 Notify with just a text message! 17 </button> 18 </div> 19);
As you can see here, render() receives onClose callback, which we have to pass inside our component in order to close the notification when user click on the button.
Positioning
By default, all items will be positioned in the top right corner. The following values are allowed: top-right, top-center, top-left, bottom-right, bottom-center, bottom-left.
1const App = () => ( 2 <div> 3 <button 4 onClick={() => { 5 // notifier({ 6 // position: "top-left" 7 // }); 8 9 notifier({ 10 single: true, // display only the latest item 11 position: "top-center", 12 render: ({ id, onClose }) => ( 13 <RouteInfo 14 key={id} 15 onClosePanel={onClose} 16 header={"The shortest way to ride home."} 17 /> 18 ) 19 }); 20 }} 21 > 22 Show two of them in different places 23 </button> 24 </div> 25);
Configuring all in one place
Instead of specifing all params again and again for each item, we can put it in one place:
1notifier.configure({ 2 autoClose: 2000, 3 position: "top-center", 4 delay: 500, 5 single: false, 6 width: "480px" 7}); 8 9const App = () => ( 10 <div> 11 <button 12 onClick={() => { 13 notifier.success("Your items have been updated"); 14 }} 15 > 16 Display an item with 500 ms delay. Now it is done in configure() 17 </button> 18 </div> 19);
Params in notifier function will override their default values in configure().
Animation
First, define the css-animation somewhere in your .css file:
1@keyframes fadeIn { 2 from { 3 opacity: 0; 4 } 5 to { 6 opacity: 1; 7 } 8} 9 10@keyframes fadeOut { 11 from { 12 opacity: 1; 13 } 14 to { 15 opacity: 0; 16 } 17}
Second, specify it during the notifier() call or in configure():
1notifier.configure({ 2 position: "top-center", 3 animation: { 4 in: "fadeIn", // try to comment it out 5 out: "fadeOut", 6 duration: 600 // overriding the default(300ms) value 7 } 8}); 9 10const App = () => ( 11 <div> 12 <button 13 onClick={() => { 14 notifier.success("Your items have been updated"); 15 }} 16 > 17 Show two of them in different places 18 </button> 19 </div> 20);
You can specify only in or out params as well.
Remove notification items programmatically
1import React from "react"; 2import notifier from "simple-react-notifications2"; 3 4notifier.configure({ 5 render: ({ id, onClose }) => ( 6 <RouteInfo 7 key={id} 8 onClosePanel={onClose} 9 header={"The shortest way to ride home."} 10 /> 11 ) 12}); 13 14class App extends React.Component { 15 id = null; 16 17 render() { 18 return ( 19 <div> 20 <button onClick={() => (this.id = notifier())}>Notify</button> 21 <button onClick={() => notifier.dismiss(this.id)}>Dismiss</button> 22 <button onClick={() => notifier.dismiss()}>Dismiss all</button> 23 </div> 24 ); 25 } 26}
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/rizwan-ishtiaq/simple-react-notifications2/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/rizwan-ishtiaq/simple-react-notifications2/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/rizwan-ishtiaq/simple-react-notifications2/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/rizwan-ishtiaq/simple-react-notifications2/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/rizwan-ishtiaq/simple-react-notifications2/npm-publish.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/rizwan-ishtiaq/simple-react-notifications2/npm-publish.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/npm-publish.yml:16
- Warn: npmCommand not pinned by hash: .github/workflows/npm-publish.yml:28
- Info: 0 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
34 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-hpx4-r86g-5jrg
- Warn: Project is vulnerable to: GHSA-prr3-c3m5-p7q2
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-hc6q-2mpp-qw7j
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.5
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More