├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .npmignore
├── README.md
├── dist
├── fonts
│ ├── notification.eot
│ ├── notification.svg
│ ├── notification.ttf
│ └── notification.woff
├── react-notifications.css
└── react-notifications.js
├── example
├── src
│ ├── app.js
│ ├── assets
│ │ ├── fonts
│ │ │ └── .gitkeep
│ │ ├── images
│ │ │ └── logo.svg
│ │ └── styles
│ │ │ ├── _animations.scss
│ │ │ ├── _mixins.scss
│ │ │ ├── _variables.scss
│ │ │ ├── app.scss
│ │ │ ├── components
│ │ │ ├── _footer.scss
│ │ │ ├── _header.scss
│ │ │ ├── _page.scss
│ │ │ └── _pre-render.scss
│ │ │ └── pages
│ │ │ └── _home.scss
│ ├── components
│ │ ├── App.js
│ │ ├── Document.js
│ │ ├── Footer.js
│ │ └── Header.js
│ ├── index.html
│ └── pages
│ │ ├── Home
│ │ └── index.js
│ │ ├── NotFound
│ │ └── index.js
│ │ └── TransitionAnimation
│ │ ├── index.js
│ │ └── notifications.scss
├── webpack.config.babel.js
└── webpack.server.js
├── gulpfile.babel.js
├── lib
├── Notification.js
├── NotificationContainer.js
├── NotificationManager.js
├── Notifications.js
├── fonts
│ ├── notification.eot
│ ├── notification.svg
│ ├── notification.ttf
│ └── notification.woff
├── index.js
└── notifications.css
├── package-lock.json
├── package.json
├── postcss.config.js
├── screenshot.png
├── src
├── Notification.js
├── NotificationContainer.js
├── NotificationManager.js
├── Notifications.js
├── _variables.scss
├── fonts
│ ├── notification.eot
│ ├── notification.svg
│ ├── notification.ttf
│ └── notification.woff
├── index.js
└── notifications.scss
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/preset-env",
5 | {
6 | "targets": {
7 | "browsers": [
8 | "last 2 versions"
9 | ]
10 | }
11 | }
12 | ],
13 | "@babel/preset-react"
14 | ],
15 | "plugins": [
16 | "@babel/plugin-proposal-object-rest-spread",
17 | "@babel/plugin-proposal-class-properties"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/*
2 | dist/*
3 | example/dist/*
4 | lib/*
5 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "extends": "airbnb",
4 | "env": {
5 | "browser": true,
6 | "node": true
7 | },
8 | "rules": {
9 | "comma-dangle": "off",
10 | "global-require": "off",
11 | "import/no-extraneous-dependencies": "off",
12 | "import/no-unresolved": "off",
13 | "import/extensions": "off",
14 | "react/jsx-filename-extension": "off",
15 | "react/prefer-stateless-function": ["error", {"ignorePureComponents": true}],
16 | "react/jsx-tag-spacing": "off",
17 | "react/forbid-prop-types": "off",
18 | "react/no-array-index-key": "off",
19 | "react/static-property-placement": ["off"],
20 | "react/state-in-constructor": ["off"],
21 | "react/destructuring-assignment": ["off"],
22 | "jsx-a11y/click-events-have-key-events": ["off"],
23 | "jsx-a11y/no-static-element-interactions": "off",
24 | "no-alert": "off",
25 | "no-bitwise": "off"
26 | },
27 | "globals": {
28 | "jQuery": false,
29 | "$": false
30 | },
31 | "settings": {
32 | "react": {
33 | "version": "16.0"
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | example/dist
3 |
4 | # Environment files to ignore
5 | .DS_Store
6 | .vscode
7 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .idea
2 | example
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Notifications
2 |
3 | [
](http://minhtranite.github.io/react-notifications)
4 |
5 | ## Installation
6 |
7 | ```
8 | npm install --save react-notifications
9 | ```
10 |
11 | ## Usage
12 |
13 | ### Note
14 |
15 | **Use only one 'NotificationContainer' component in the app.**
16 |
17 | ### CSS
18 |
19 | #### Webpack:
20 | ```js
21 | import 'react-notifications/lib/notifications.css';
22 | ```
23 |
24 | #### Other
25 | ```html
26 |
27 | ```
28 |
29 | ### JS
30 |
31 | ```js
32 | import React from 'react';
33 | import {NotificationContainer, NotificationManager} from 'react-notifications';
34 |
35 | class Example extends React.Component {
36 | createNotification = (type) => {
37 | return () => {
38 | switch (type) {
39 | case 'info':
40 | NotificationManager.info('Info message');
41 | break;
42 | case 'success':
43 | NotificationManager.success('Success message', 'Title here');
44 | break;
45 | case 'warning':
46 | NotificationManager.warning('Warning message', 'Close after 3000ms', 3000);
47 | break;
48 | case 'error':
49 | NotificationManager.error('Error message', 'Click me!', 5000, () => {
50 | alert('callback');
51 | });
52 | break;
53 | }
54 | };
55 | };
56 |
57 | render() {
58 | return (
59 |
60 |
63 |
64 |
67 |
68 |
71 |
72 |
75 |
76 |
77 |
78 | );
79 | }
80 | }
81 |
82 | export default Example;
83 | ```
84 |
85 | ### UMD
86 |
87 | ```html
88 |
89 |
90 | ```
91 |
92 | ```js
93 | const NotificationContainer = window.ReactNotifications.NotificationContainer;
94 | const NotificationManager = window.ReactNotifications.NotificationManager;
95 | ```
96 |
97 | ## NotificationContainer Props
98 |
99 | | Name | Type | Default | Required |
100 | |------|------|---------|----------|
101 | | enterTimeout | number | 400 | false |
102 | | leaveTimeout | number | 400 | false |
103 |
104 | ## NotificationManager API
105 |
106 | - NotificationManager.info(message, title, timeOut, callback, priority);
107 | - NotificationManager.success(message, title, timeOut, callback, priority);
108 | - NotificationManager.warning(message, title, timeOut, callback, priority);
109 | - NotificationManager.error(message, title, timeOut, callback, priority);
110 |
111 | | Name | Type | Description |
112 | |------|------|-------------|
113 | | message | string | The message string |
114 | | title | string | The title string |
115 | | timeOut | integer | The popup timeout in milliseconds |
116 | | callback | function | A function that gets fired when the popup is clicked |
117 | | priority | boolean | If true, the message gets inserted at the top |
118 |
119 | ## Example
120 | View [demo](http://minhtranite.github.io/react-notifications) or example folder.
121 |
122 | ## Contributing
123 |
124 | When contributing to this reposity, please first open an issue and discuss intended changes with maintainers. If there is already an issue open for the feature you are looking to develop, please just coordinate with maintainers before assigning issue to yourself.
125 |
126 | ### Branches
127 |
128 | `master` is the main branch from which we publish packages. `next` is the branch from which we will publish the next release. All `issue` branches should be branched from `master`, unless specifically told by the maintainers to use a different branch. All pull requests should be submitted to merge with `next` in order to make the next release.
129 |
130 | ### Workflow
131 |
132 | - Fork repo
133 | - Create an issue branch
134 | - Commit your changes
135 | - Open a PR against `next`.
136 | - Link the Issue to your PR.
137 |
138 | ### Pull Request Guidelines
139 |
140 | - PRs should be submitted to merge with `next`.
141 | - PRs should be small in scope, work on 1 issue in a single PR.
142 | - Link the Issue you are working to your PR.
143 |
144 | You can add as many commits to your PR as you would like. All commits will be squashed into a single commit when merging PR.
--------------------------------------------------------------------------------
/dist/fonts/notification.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/dist/fonts/notification.eot
--------------------------------------------------------------------------------
/dist/fonts/notification.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/dist/fonts/notification.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/dist/fonts/notification.ttf
--------------------------------------------------------------------------------
/dist/fonts/notification.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/dist/fonts/notification.woff
--------------------------------------------------------------------------------
/dist/react-notifications.css:
--------------------------------------------------------------------------------
1 | @charset "UTF-8";@font-face{font-family:Notification;src:url(fonts/notification.eot?s3g3t9);src:url(fonts/notification.eot?#iefixs3g3t9) format("embedded-opentype"),url(fonts/notification.woff?s3g3t9) format("woff"),url(fonts/notification.ttf?s3g3t9) format("truetype"),url(fonts/notification.svg?s3g3t9#notification) format("svg");font-weight:400;font-style:normal}.notification-container{position:fixed;top:0;right:0;z-index:999999;width:320px;padding:0 15px;max-height:calc(100% - 30px);overflow-x:hidden;overflow-y:auto}.notification,.notification-container{-webkit-box-sizing:border-box;box-sizing:border-box}.notification{padding:15px 15px 15px 58px;border-radius:2px;color:#fff;background-color:#ccc;-webkit-box-shadow:0 0 12px #999;box-shadow:0 0 12px #999;cursor:pointer;font-size:1em;line-height:1.2em;position:relative;opacity:.9;margin-top:15px}.notification .title{font-size:1em;line-height:1.2em;font-weight:700;margin:0 0 5px}.notification:focus,.notification:hover{opacity:1}.notification-enter{visibility:hidden;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}.notification-enter.notification-enter-active{-webkit-transition:all .4s;transition:all .4s}.notification-enter.notification-enter-active,.notification-exit{visibility:visible;-webkit-transform:translateZ(0);transform:translateZ(0)}.notification-exit.notification-exit-active{visibility:hidden;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0);-webkit-transition:all .4s;transition:all .4s}.notification:before{position:absolute;top:50%;left:15px;margin-top:-14px;display:block;font-family:Notification;width:28px;height:28px;font-size:28px;text-align:center;line-height:28px}.notification-info{background-color:#2f96b4}.notification-info:before{content:""}.notification-success{background-color:#51a351}.notification-success:before{content:""}.notification-warning{background-color:#f89406}.notification-warning:before{content:""}.notification-error{background-color:#bd362f}.notification-error:before{content:""}
--------------------------------------------------------------------------------
/dist/react-notifications.js:
--------------------------------------------------------------------------------
1 | (function webpackUniversalModuleDefinition(root, factory) {
2 | if(typeof exports === 'object' && typeof module === 'object')
3 | module.exports = factory(require("react"), require("prop-types"), require("react-transition-group"));
4 | else if(typeof define === 'function' && define.amd)
5 | define(["react", "prop-types", "react-transition-group"], factory);
6 | else if(typeof exports === 'object')
7 | exports["ReactNotifications"] = factory(require("react"), require("prop-types"), require("react-transition-group"));
8 | else
9 | root["ReactNotifications"] = factory(root["React"], root["PropTypes"], root["ReactTransitionGroup"]);
10 | })(window, function(__WEBPACK_EXTERNAL_MODULE__0__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__3__) {
11 | return /******/ (function(modules) { // webpackBootstrap
12 | /******/ // The module cache
13 | /******/ var installedModules = {};
14 | /******/
15 | /******/ // The require function
16 | /******/ function __webpack_require__(moduleId) {
17 | /******/
18 | /******/ // Check if module is in cache
19 | /******/ if(installedModules[moduleId]) {
20 | /******/ return installedModules[moduleId].exports;
21 | /******/ }
22 | /******/ // Create a new module (and put it into the cache)
23 | /******/ var module = installedModules[moduleId] = {
24 | /******/ i: moduleId,
25 | /******/ l: false,
26 | /******/ exports: {}
27 | /******/ };
28 | /******/
29 | /******/ // Execute the module function
30 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31 | /******/
32 | /******/ // Flag the module as loaded
33 | /******/ module.l = true;
34 | /******/
35 | /******/ // Return the exports of the module
36 | /******/ return module.exports;
37 | /******/ }
38 | /******/
39 | /******/
40 | /******/ // expose the modules object (__webpack_modules__)
41 | /******/ __webpack_require__.m = modules;
42 | /******/
43 | /******/ // expose the module cache
44 | /******/ __webpack_require__.c = installedModules;
45 | /******/
46 | /******/ // define getter function for harmony exports
47 | /******/ __webpack_require__.d = function(exports, name, getter) {
48 | /******/ if(!__webpack_require__.o(exports, name)) {
49 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
50 | /******/ }
51 | /******/ };
52 | /******/
53 | /******/ // define __esModule on exports
54 | /******/ __webpack_require__.r = function(exports) {
55 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57 | /******/ }
58 | /******/ Object.defineProperty(exports, '__esModule', { value: true });
59 | /******/ };
60 | /******/
61 | /******/ // create a fake namespace object
62 | /******/ // mode & 1: value is a module id, require it
63 | /******/ // mode & 2: merge all properties of value into the ns
64 | /******/ // mode & 4: return value when already ns object
65 | /******/ // mode & 8|1: behave like require
66 | /******/ __webpack_require__.t = function(value, mode) {
67 | /******/ if(mode & 1) value = __webpack_require__(value);
68 | /******/ if(mode & 8) return value;
69 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
70 | /******/ var ns = Object.create(null);
71 | /******/ __webpack_require__.r(ns);
72 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
73 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
74 | /******/ return ns;
75 | /******/ };
76 | /******/
77 | /******/ // getDefaultExport function for compatibility with non-harmony modules
78 | /******/ __webpack_require__.n = function(module) {
79 | /******/ var getter = module && module.__esModule ?
80 | /******/ function getDefault() { return module['default']; } :
81 | /******/ function getModuleExports() { return module; };
82 | /******/ __webpack_require__.d(getter, 'a', getter);
83 | /******/ return getter;
84 | /******/ };
85 | /******/
86 | /******/ // Object.prototype.hasOwnProperty.call
87 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
88 | /******/
89 | /******/ // __webpack_public_path__
90 | /******/ __webpack_require__.p = "";
91 | /******/
92 | /******/
93 | /******/ // Load entry module and return exports
94 | /******/ return __webpack_require__(__webpack_require__.s = 5);
95 | /******/ })
96 | /************************************************************************/
97 | /******/ ([
98 | /* 0 */
99 | /***/ (function(module, exports) {
100 |
101 | module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
102 |
103 | /***/ }),
104 | /* 1 */
105 | /***/ (function(module, exports) {
106 |
107 | module.exports = __WEBPACK_EXTERNAL_MODULE__1__;
108 |
109 | /***/ }),
110 | /* 2 */
111 | /***/ (function(module, exports, __webpack_require__) {
112 |
113 | var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
114 | Copyright (c) 2018 Jed Watson.
115 | Licensed under the MIT License (MIT), see
116 | http://jedwatson.github.io/classnames
117 | */
118 | /* global define */
119 |
120 | (function () {
121 | 'use strict';
122 |
123 | var hasOwn = {}.hasOwnProperty;
124 |
125 | function classNames() {
126 | var classes = [];
127 |
128 | for (var i = 0; i < arguments.length; i++) {
129 | var arg = arguments[i];
130 | if (!arg) continue;
131 |
132 | var argType = typeof arg;
133 |
134 | if (argType === 'string' || argType === 'number') {
135 | classes.push(arg);
136 | } else if (Array.isArray(arg)) {
137 | if (arg.length) {
138 | var inner = classNames.apply(null, arg);
139 | if (inner) {
140 | classes.push(inner);
141 | }
142 | }
143 | } else if (argType === 'object') {
144 | if (arg.toString === Object.prototype.toString) {
145 | for (var key in arg) {
146 | if (hasOwn.call(arg, key) && arg[key]) {
147 | classes.push(key);
148 | }
149 | }
150 | } else {
151 | classes.push(arg.toString());
152 | }
153 | }
154 | }
155 |
156 | return classes.join(' ');
157 | }
158 |
159 | if ( true && module.exports) {
160 | classNames.default = classNames;
161 | module.exports = classNames;
162 | } else if (true) {
163 | // register as 'classnames', consistent with npm package name
164 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
165 | return classNames;
166 | }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
167 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
168 | } else {}
169 | }());
170 |
171 |
172 | /***/ }),
173 | /* 3 */
174 | /***/ (function(module, exports) {
175 |
176 | module.exports = __WEBPACK_EXTERNAL_MODULE__3__;
177 |
178 | /***/ }),
179 | /* 4 */
180 | /***/ (function(module, exports, __webpack_require__) {
181 |
182 | "use strict";
183 | // Copyright Joyent, Inc. and other Node contributors.
184 | //
185 | // Permission is hereby granted, free of charge, to any person obtaining a
186 | // copy of this software and associated documentation files (the
187 | // "Software"), to deal in the Software without restriction, including
188 | // without limitation the rights to use, copy, modify, merge, publish,
189 | // distribute, sublicense, and/or sell copies of the Software, and to permit
190 | // persons to whom the Software is furnished to do so, subject to the
191 | // following conditions:
192 | //
193 | // The above copyright notice and this permission notice shall be included
194 | // in all copies or substantial portions of the Software.
195 | //
196 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
197 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
198 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
199 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
200 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
201 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
202 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
203 |
204 |
205 |
206 | var R = typeof Reflect === 'object' ? Reflect : null
207 | var ReflectApply = R && typeof R.apply === 'function'
208 | ? R.apply
209 | : function ReflectApply(target, receiver, args) {
210 | return Function.prototype.apply.call(target, receiver, args);
211 | }
212 |
213 | var ReflectOwnKeys
214 | if (R && typeof R.ownKeys === 'function') {
215 | ReflectOwnKeys = R.ownKeys
216 | } else if (Object.getOwnPropertySymbols) {
217 | ReflectOwnKeys = function ReflectOwnKeys(target) {
218 | return Object.getOwnPropertyNames(target)
219 | .concat(Object.getOwnPropertySymbols(target));
220 | };
221 | } else {
222 | ReflectOwnKeys = function ReflectOwnKeys(target) {
223 | return Object.getOwnPropertyNames(target);
224 | };
225 | }
226 |
227 | function ProcessEmitWarning(warning) {
228 | if (console && console.warn) console.warn(warning);
229 | }
230 |
231 | var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
232 | return value !== value;
233 | }
234 |
235 | function EventEmitter() {
236 | EventEmitter.init.call(this);
237 | }
238 | module.exports = EventEmitter;
239 | module.exports.once = once;
240 |
241 | // Backwards-compat with node 0.10.x
242 | EventEmitter.EventEmitter = EventEmitter;
243 |
244 | EventEmitter.prototype._events = undefined;
245 | EventEmitter.prototype._eventsCount = 0;
246 | EventEmitter.prototype._maxListeners = undefined;
247 |
248 | // By default EventEmitters will print a warning if more than 10 listeners are
249 | // added to it. This is a useful default which helps finding memory leaks.
250 | var defaultMaxListeners = 10;
251 |
252 | function checkListener(listener) {
253 | if (typeof listener !== 'function') {
254 | throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
255 | }
256 | }
257 |
258 | Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
259 | enumerable: true,
260 | get: function() {
261 | return defaultMaxListeners;
262 | },
263 | set: function(arg) {
264 | if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
265 | throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
266 | }
267 | defaultMaxListeners = arg;
268 | }
269 | });
270 |
271 | EventEmitter.init = function() {
272 |
273 | if (this._events === undefined ||
274 | this._events === Object.getPrototypeOf(this)._events) {
275 | this._events = Object.create(null);
276 | this._eventsCount = 0;
277 | }
278 |
279 | this._maxListeners = this._maxListeners || undefined;
280 | };
281 |
282 | // Obviously not all Emitters should be limited to 10. This function allows
283 | // that to be increased. Set to zero for unlimited.
284 | EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
285 | if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
286 | throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
287 | }
288 | this._maxListeners = n;
289 | return this;
290 | };
291 |
292 | function _getMaxListeners(that) {
293 | if (that._maxListeners === undefined)
294 | return EventEmitter.defaultMaxListeners;
295 | return that._maxListeners;
296 | }
297 |
298 | EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
299 | return _getMaxListeners(this);
300 | };
301 |
302 | EventEmitter.prototype.emit = function emit(type) {
303 | var args = [];
304 | for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
305 | var doError = (type === 'error');
306 |
307 | var events = this._events;
308 | if (events !== undefined)
309 | doError = (doError && events.error === undefined);
310 | else if (!doError)
311 | return false;
312 |
313 | // If there is no 'error' event listener then throw.
314 | if (doError) {
315 | var er;
316 | if (args.length > 0)
317 | er = args[0];
318 | if (er instanceof Error) {
319 | // Note: The comments on the `throw` lines are intentional, they show
320 | // up in Node's output if this results in an unhandled exception.
321 | throw er; // Unhandled 'error' event
322 | }
323 | // At least give some kind of context to the user
324 | var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
325 | err.context = er;
326 | throw err; // Unhandled 'error' event
327 | }
328 |
329 | var handler = events[type];
330 |
331 | if (handler === undefined)
332 | return false;
333 |
334 | if (typeof handler === 'function') {
335 | ReflectApply(handler, this, args);
336 | } else {
337 | var len = handler.length;
338 | var listeners = arrayClone(handler, len);
339 | for (var i = 0; i < len; ++i)
340 | ReflectApply(listeners[i], this, args);
341 | }
342 |
343 | return true;
344 | };
345 |
346 | function _addListener(target, type, listener, prepend) {
347 | var m;
348 | var events;
349 | var existing;
350 |
351 | checkListener(listener);
352 |
353 | events = target._events;
354 | if (events === undefined) {
355 | events = target._events = Object.create(null);
356 | target._eventsCount = 0;
357 | } else {
358 | // To avoid recursion in the case that type === "newListener"! Before
359 | // adding it to the listeners, first emit "newListener".
360 | if (events.newListener !== undefined) {
361 | target.emit('newListener', type,
362 | listener.listener ? listener.listener : listener);
363 |
364 | // Re-assign `events` because a newListener handler could have caused the
365 | // this._events to be assigned to a new object
366 | events = target._events;
367 | }
368 | existing = events[type];
369 | }
370 |
371 | if (existing === undefined) {
372 | // Optimize the case of one listener. Don't need the extra array object.
373 | existing = events[type] = listener;
374 | ++target._eventsCount;
375 | } else {
376 | if (typeof existing === 'function') {
377 | // Adding the second element, need to change to array.
378 | existing = events[type] =
379 | prepend ? [listener, existing] : [existing, listener];
380 | // If we've already got an array, just append.
381 | } else if (prepend) {
382 | existing.unshift(listener);
383 | } else {
384 | existing.push(listener);
385 | }
386 |
387 | // Check for listener leak
388 | m = _getMaxListeners(target);
389 | if (m > 0 && existing.length > m && !existing.warned) {
390 | existing.warned = true;
391 | // No error code for this since it is a Warning
392 | // eslint-disable-next-line no-restricted-syntax
393 | var w = new Error('Possible EventEmitter memory leak detected. ' +
394 | existing.length + ' ' + String(type) + ' listeners ' +
395 | 'added. Use emitter.setMaxListeners() to ' +
396 | 'increase limit');
397 | w.name = 'MaxListenersExceededWarning';
398 | w.emitter = target;
399 | w.type = type;
400 | w.count = existing.length;
401 | ProcessEmitWarning(w);
402 | }
403 | }
404 |
405 | return target;
406 | }
407 |
408 | EventEmitter.prototype.addListener = function addListener(type, listener) {
409 | return _addListener(this, type, listener, false);
410 | };
411 |
412 | EventEmitter.prototype.on = EventEmitter.prototype.addListener;
413 |
414 | EventEmitter.prototype.prependListener =
415 | function prependListener(type, listener) {
416 | return _addListener(this, type, listener, true);
417 | };
418 |
419 | function onceWrapper() {
420 | if (!this.fired) {
421 | this.target.removeListener(this.type, this.wrapFn);
422 | this.fired = true;
423 | if (arguments.length === 0)
424 | return this.listener.call(this.target);
425 | return this.listener.apply(this.target, arguments);
426 | }
427 | }
428 |
429 | function _onceWrap(target, type, listener) {
430 | var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
431 | var wrapped = onceWrapper.bind(state);
432 | wrapped.listener = listener;
433 | state.wrapFn = wrapped;
434 | return wrapped;
435 | }
436 |
437 | EventEmitter.prototype.once = function once(type, listener) {
438 | checkListener(listener);
439 | this.on(type, _onceWrap(this, type, listener));
440 | return this;
441 | };
442 |
443 | EventEmitter.prototype.prependOnceListener =
444 | function prependOnceListener(type, listener) {
445 | checkListener(listener);
446 | this.prependListener(type, _onceWrap(this, type, listener));
447 | return this;
448 | };
449 |
450 | // Emits a 'removeListener' event if and only if the listener was removed.
451 | EventEmitter.prototype.removeListener =
452 | function removeListener(type, listener) {
453 | var list, events, position, i, originalListener;
454 |
455 | checkListener(listener);
456 |
457 | events = this._events;
458 | if (events === undefined)
459 | return this;
460 |
461 | list = events[type];
462 | if (list === undefined)
463 | return this;
464 |
465 | if (list === listener || list.listener === listener) {
466 | if (--this._eventsCount === 0)
467 | this._events = Object.create(null);
468 | else {
469 | delete events[type];
470 | if (events.removeListener)
471 | this.emit('removeListener', type, list.listener || listener);
472 | }
473 | } else if (typeof list !== 'function') {
474 | position = -1;
475 |
476 | for (i = list.length - 1; i >= 0; i--) {
477 | if (list[i] === listener || list[i].listener === listener) {
478 | originalListener = list[i].listener;
479 | position = i;
480 | break;
481 | }
482 | }
483 |
484 | if (position < 0)
485 | return this;
486 |
487 | if (position === 0)
488 | list.shift();
489 | else {
490 | spliceOne(list, position);
491 | }
492 |
493 | if (list.length === 1)
494 | events[type] = list[0];
495 |
496 | if (events.removeListener !== undefined)
497 | this.emit('removeListener', type, originalListener || listener);
498 | }
499 |
500 | return this;
501 | };
502 |
503 | EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
504 |
505 | EventEmitter.prototype.removeAllListeners =
506 | function removeAllListeners(type) {
507 | var listeners, events, i;
508 |
509 | events = this._events;
510 | if (events === undefined)
511 | return this;
512 |
513 | // not listening for removeListener, no need to emit
514 | if (events.removeListener === undefined) {
515 | if (arguments.length === 0) {
516 | this._events = Object.create(null);
517 | this._eventsCount = 0;
518 | } else if (events[type] !== undefined) {
519 | if (--this._eventsCount === 0)
520 | this._events = Object.create(null);
521 | else
522 | delete events[type];
523 | }
524 | return this;
525 | }
526 |
527 | // emit removeListener for all listeners on all events
528 | if (arguments.length === 0) {
529 | var keys = Object.keys(events);
530 | var key;
531 | for (i = 0; i < keys.length; ++i) {
532 | key = keys[i];
533 | if (key === 'removeListener') continue;
534 | this.removeAllListeners(key);
535 | }
536 | this.removeAllListeners('removeListener');
537 | this._events = Object.create(null);
538 | this._eventsCount = 0;
539 | return this;
540 | }
541 |
542 | listeners = events[type];
543 |
544 | if (typeof listeners === 'function') {
545 | this.removeListener(type, listeners);
546 | } else if (listeners !== undefined) {
547 | // LIFO order
548 | for (i = listeners.length - 1; i >= 0; i--) {
549 | this.removeListener(type, listeners[i]);
550 | }
551 | }
552 |
553 | return this;
554 | };
555 |
556 | function _listeners(target, type, unwrap) {
557 | var events = target._events;
558 |
559 | if (events === undefined)
560 | return [];
561 |
562 | var evlistener = events[type];
563 | if (evlistener === undefined)
564 | return [];
565 |
566 | if (typeof evlistener === 'function')
567 | return unwrap ? [evlistener.listener || evlistener] : [evlistener];
568 |
569 | return unwrap ?
570 | unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
571 | }
572 |
573 | EventEmitter.prototype.listeners = function listeners(type) {
574 | return _listeners(this, type, true);
575 | };
576 |
577 | EventEmitter.prototype.rawListeners = function rawListeners(type) {
578 | return _listeners(this, type, false);
579 | };
580 |
581 | EventEmitter.listenerCount = function(emitter, type) {
582 | if (typeof emitter.listenerCount === 'function') {
583 | return emitter.listenerCount(type);
584 | } else {
585 | return listenerCount.call(emitter, type);
586 | }
587 | };
588 |
589 | EventEmitter.prototype.listenerCount = listenerCount;
590 | function listenerCount(type) {
591 | var events = this._events;
592 |
593 | if (events !== undefined) {
594 | var evlistener = events[type];
595 |
596 | if (typeof evlistener === 'function') {
597 | return 1;
598 | } else if (evlistener !== undefined) {
599 | return evlistener.length;
600 | }
601 | }
602 |
603 | return 0;
604 | }
605 |
606 | EventEmitter.prototype.eventNames = function eventNames() {
607 | return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
608 | };
609 |
610 | function arrayClone(arr, n) {
611 | var copy = new Array(n);
612 | for (var i = 0; i < n; ++i)
613 | copy[i] = arr[i];
614 | return copy;
615 | }
616 |
617 | function spliceOne(list, index) {
618 | for (; index + 1 < list.length; index++)
619 | list[index] = list[index + 1];
620 | list.pop();
621 | }
622 |
623 | function unwrapListeners(arr) {
624 | var ret = new Array(arr.length);
625 | for (var i = 0; i < ret.length; ++i) {
626 | ret[i] = arr[i].listener || arr[i];
627 | }
628 | return ret;
629 | }
630 |
631 | function once(emitter, name) {
632 | return new Promise(function (resolve, reject) {
633 | function errorListener(err) {
634 | emitter.removeListener(name, resolver);
635 | reject(err);
636 | }
637 |
638 | function resolver() {
639 | if (typeof emitter.removeListener === 'function') {
640 | emitter.removeListener('error', errorListener);
641 | }
642 | resolve([].slice.call(arguments));
643 | };
644 |
645 | eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
646 | if (name !== 'error') {
647 | addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
648 | }
649 | });
650 | }
651 |
652 | function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
653 | if (typeof emitter.on === 'function') {
654 | eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
655 | }
656 | }
657 |
658 | function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
659 | if (typeof emitter.on === 'function') {
660 | if (flags.once) {
661 | emitter.once(name, listener);
662 | } else {
663 | emitter.on(name, listener);
664 | }
665 | } else if (typeof emitter.addEventListener === 'function') {
666 | // EventTarget does not have `error` event semantics like Node
667 | // EventEmitters, we do not listen for `error` events here.
668 | emitter.addEventListener(name, function wrapListener(arg) {
669 | // IE does not have builtin `{ once: true }` support so we
670 | // have to do it manually.
671 | if (flags.once) {
672 | emitter.removeEventListener(name, wrapListener);
673 | }
674 | listener(arg);
675 | });
676 | } else {
677 | throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
678 | }
679 | }
680 |
681 |
682 | /***/ }),
683 | /* 5 */
684 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
685 |
686 | "use strict";
687 | // ESM COMPAT FLAG
688 | __webpack_require__.r(__webpack_exports__);
689 |
690 | // EXPORTS
691 | __webpack_require__.d(__webpack_exports__, "Notifications", function() { return /* reexport */ src_Notifications; });
692 | __webpack_require__.d(__webpack_exports__, "NotificationContainer", function() { return /* reexport */ src_NotificationContainer; });
693 | __webpack_require__.d(__webpack_exports__, "NotificationManager", function() { return /* reexport */ src_NotificationManager; });
694 |
695 | // EXTERNAL MODULE: external {"root":"React","commonjs":"react","commonjs2":"react","amd":"react"}
696 | var external_root_React_commonjs_react_commonjs2_react_amd_react_ = __webpack_require__(0);
697 | var external_root_React_commonjs_react_commonjs2_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs_react_commonjs2_react_amd_react_);
698 |
699 | // EXTERNAL MODULE: external {"root":"PropTypes","commonjs":"prop-types","commonjs2":"prop-types","amd":"prop-types"}
700 | var external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_ = __webpack_require__(1);
701 | var external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default = /*#__PURE__*/__webpack_require__.n(external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_);
702 |
703 | // EXTERNAL MODULE: external {"root":["ReactTransitionGroup"],"commonjs":"react-transition-group","commonjs2":"react-transition-group","amd":"react-transition-group"}
704 | var external_root_ReactTransitionGroup_commonjs_react_transition_group_commonjs2_react_transition_group_amd_react_transition_group_ = __webpack_require__(3);
705 |
706 | // EXTERNAL MODULE: ./node_modules/classnames/index.js
707 | var classnames = __webpack_require__(2);
708 | var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames);
709 |
710 | // CONCATENATED MODULE: ./src/Notification.js
711 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
712 |
713 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
714 |
715 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
716 |
717 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
718 |
719 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
720 |
721 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
722 |
723 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
724 |
725 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
726 |
727 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
728 |
729 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
730 |
731 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
732 |
733 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
734 |
735 |
736 |
737 |
738 |
739 | var Notification_Notification = /*#__PURE__*/function (_React$Component) {
740 | _inherits(Notification, _React$Component);
741 |
742 | var _super = _createSuper(Notification);
743 |
744 | function Notification() {
745 | var _this;
746 |
747 | _classCallCheck(this, Notification);
748 |
749 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
750 | args[_key] = arguments[_key];
751 | }
752 |
753 | _this = _super.call.apply(_super, [this].concat(args));
754 |
755 | _defineProperty(_assertThisInitialized(_this), "componentDidMount", function () {
756 | var timeOut = _this.props.timeOut;
757 |
758 | if (timeOut !== 0) {
759 | _this.timer = setTimeout(_this.requestHide, timeOut);
760 | }
761 | });
762 |
763 | _defineProperty(_assertThisInitialized(_this), "componentWillUnmount", function () {
764 | if (_this.timer) {
765 | clearTimeout(_this.timer);
766 | }
767 | });
768 |
769 | _defineProperty(_assertThisInitialized(_this), "handleClick", function () {
770 | var onClick = _this.props.onClick;
771 |
772 | if (onClick) {
773 | onClick();
774 | }
775 |
776 | _this.requestHide();
777 | });
778 |
779 | _defineProperty(_assertThisInitialized(_this), "requestHide", function () {
780 | var onRequestHide = _this.props.onRequestHide;
781 |
782 | if (onRequestHide) {
783 | onRequestHide();
784 | }
785 | });
786 |
787 | return _this;
788 | }
789 |
790 | _createClass(Notification, [{
791 | key: "render",
792 | value: function render() {
793 | var _this$props = this.props,
794 | type = _this$props.type,
795 | message = _this$props.message;
796 | var title = this.props.title;
797 | var className = classnames_default()(['notification', "notification-".concat(type)]);
798 | title = title ? /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement("h4", {
799 | className: "title"
800 | }, title) : null;
801 | return /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement("div", {
802 | className: className,
803 | onClick: this.handleClick
804 | }, /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement("div", {
805 | className: "notification-message",
806 | role: "alert"
807 | }, title, /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement("div", {
808 | className: "message"
809 | }, message)));
810 | }
811 | }]);
812 |
813 | return Notification;
814 | }(external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.Component);
815 |
816 | _defineProperty(Notification_Notification, "propTypes", {
817 | type: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.oneOf(['info', 'success', 'warning', 'error']),
818 | title: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.node,
819 | message: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.node,
820 | timeOut: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.number,
821 | onClick: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.func,
822 | onRequestHide: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.func
823 | });
824 |
825 | _defineProperty(Notification_Notification, "defaultProps", {
826 | type: 'info',
827 | title: null,
828 | message: null,
829 | timeOut: 5000,
830 | onClick: function onClick() {},
831 | onRequestHide: function onRequestHide() {}
832 | });
833 |
834 | /* harmony default export */ var src_Notification = (Notification_Notification);
835 | // CONCATENATED MODULE: ./src/Notifications.js
836 | function Notifications_typeof(obj) { "@babel/helpers - typeof"; return Notifications_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, Notifications_typeof(obj); }
837 |
838 | function Notifications_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
839 |
840 | function Notifications_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
841 |
842 | function Notifications_createClass(Constructor, protoProps, staticProps) { if (protoProps) Notifications_defineProperties(Constructor.prototype, protoProps); if (staticProps) Notifications_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
843 |
844 | function Notifications_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) Notifications_setPrototypeOf(subClass, superClass); }
845 |
846 | function Notifications_setPrototypeOf(o, p) { Notifications_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return Notifications_setPrototypeOf(o, p); }
847 |
848 | function Notifications_createSuper(Derived) { var hasNativeReflectConstruct = Notifications_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = Notifications_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = Notifications_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return Notifications_possibleConstructorReturn(this, result); }; }
849 |
850 | function Notifications_possibleConstructorReturn(self, call) { if (call && (Notifications_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return Notifications_assertThisInitialized(self); }
851 |
852 | function Notifications_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
853 |
854 | function Notifications_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
855 |
856 | function Notifications_getPrototypeOf(o) { Notifications_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return Notifications_getPrototypeOf(o); }
857 |
858 | function Notifications_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 | var Notifications_Notifications = /*#__PURE__*/function (_React$Component) {
867 | Notifications_inherits(Notifications, _React$Component);
868 |
869 | var _super = Notifications_createSuper(Notifications);
870 |
871 | function Notifications() {
872 | var _this;
873 |
874 | Notifications_classCallCheck(this, Notifications);
875 |
876 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
877 | args[_key] = arguments[_key];
878 | }
879 |
880 | _this = _super.call.apply(_super, [this].concat(args));
881 |
882 | Notifications_defineProperty(Notifications_assertThisInitialized(_this), "handleRequestHide", function (notification) {
883 | return function () {
884 | var onRequestHide = _this.props.onRequestHide;
885 |
886 | if (onRequestHide) {
887 | onRequestHide(notification);
888 | }
889 | };
890 | });
891 |
892 | return _this;
893 | }
894 |
895 | Notifications_createClass(Notifications, [{
896 | key: "render",
897 | value: function render() {
898 | var _this2 = this;
899 |
900 | var _this$props = this.props,
901 | notifications = _this$props.notifications,
902 | enterTimeout = _this$props.enterTimeout,
903 | leaveTimeout = _this$props.leaveTimeout;
904 | var className = classnames_default()('notification-container', {
905 | 'notification-container-empty': notifications.length === 0
906 | });
907 | var items = notifications.map(function (notification) {
908 | var key = notification.id || new Date().getTime();
909 | return /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement(external_root_ReactTransitionGroup_commonjs_react_transition_group_commonjs2_react_transition_group_amd_react_transition_group_["CSSTransition"], {
910 | key: key,
911 | classNames: "notification",
912 | timeout: {
913 | enter: enterTimeout,
914 | exit: leaveTimeout
915 | }
916 | }, /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement(src_Notification, {
917 | type: notification.type,
918 | title: notification.title,
919 | message: notification.message,
920 | timeOut: notification.timeOut,
921 | onClick: notification.onClick,
922 | onRequestHide: _this2.handleRequestHide(notification)
923 | }));
924 | });
925 | return /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement("div", {
926 | className: className
927 | }, /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement(external_root_ReactTransitionGroup_commonjs_react_transition_group_commonjs2_react_transition_group_amd_react_transition_group_["TransitionGroup"], null, items));
928 | }
929 | }]);
930 |
931 | return Notifications;
932 | }(external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.Component);
933 |
934 | Notifications_defineProperty(Notifications_Notifications, "propTypes", {
935 | notifications: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.array,
936 | onRequestHide: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.func,
937 | enterTimeout: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.number,
938 | leaveTimeout: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.number
939 | });
940 |
941 | Notifications_defineProperty(Notifications_Notifications, "defaultProps", {
942 | notifications: [],
943 | onRequestHide: function onRequestHide() {},
944 | enterTimeout: 400,
945 | leaveTimeout: 400
946 | });
947 |
948 | /* harmony default export */ var src_Notifications = (Notifications_Notifications);
949 | // EXTERNAL MODULE: ./node_modules/events/events.js
950 | var events = __webpack_require__(4);
951 |
952 | // CONCATENATED MODULE: ./src/NotificationManager.js
953 | function NotificationManager_typeof(obj) { "@babel/helpers - typeof"; return NotificationManager_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, NotificationManager_typeof(obj); }
954 |
955 | function NotificationManager_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
956 |
957 | function NotificationManager_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
958 |
959 | function NotificationManager_createClass(Constructor, protoProps, staticProps) { if (protoProps) NotificationManager_defineProperties(Constructor.prototype, protoProps); if (staticProps) NotificationManager_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
960 |
961 | function NotificationManager_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) NotificationManager_setPrototypeOf(subClass, superClass); }
962 |
963 | function NotificationManager_setPrototypeOf(o, p) { NotificationManager_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return NotificationManager_setPrototypeOf(o, p); }
964 |
965 | function NotificationManager_createSuper(Derived) { var hasNativeReflectConstruct = NotificationManager_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = NotificationManager_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = NotificationManager_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return NotificationManager_possibleConstructorReturn(this, result); }; }
966 |
967 | function NotificationManager_possibleConstructorReturn(self, call) { if (call && (NotificationManager_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return NotificationManager_assertThisInitialized(self); }
968 |
969 | function NotificationManager_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
970 |
971 | function NotificationManager_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
972 |
973 | function NotificationManager_getPrototypeOf(o) { NotificationManager_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return NotificationManager_getPrototypeOf(o); }
974 |
975 |
976 |
977 | var createUUID = function createUUID() {
978 | var pattern = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
979 | return pattern.replace(/[xy]/g, function (c) {
980 | var r = Math.random() * 16 | 0;
981 | var v = c === 'x' ? r : r & 0x3 | 0x8;
982 | return v.toString(16);
983 | });
984 | };
985 |
986 | var Constants = {
987 | CHANGE: 'change',
988 | INFO: 'info',
989 | SUCCESS: 'success',
990 | WARNING: 'warning',
991 | ERROR: 'error'
992 | };
993 |
994 | var NotificationManager = /*#__PURE__*/function (_EventEmitter) {
995 | NotificationManager_inherits(NotificationManager, _EventEmitter);
996 |
997 | var _super = NotificationManager_createSuper(NotificationManager);
998 |
999 | function NotificationManager() {
1000 | var _this;
1001 |
1002 | NotificationManager_classCallCheck(this, NotificationManager);
1003 |
1004 | _this = _super.call(this);
1005 | _this.listNotify = [];
1006 | return _this;
1007 | }
1008 |
1009 | NotificationManager_createClass(NotificationManager, [{
1010 | key: "create",
1011 | value: function create(notify) {
1012 | var defaultNotify = {
1013 | id: createUUID(),
1014 | type: 'info',
1015 | title: null,
1016 | message: null,
1017 | timeOut: 5000
1018 | };
1019 |
1020 | if (notify.priority) {
1021 | this.listNotify.unshift(Object.assign(defaultNotify, notify));
1022 | } else {
1023 | this.listNotify.push(Object.assign(defaultNotify, notify));
1024 | }
1025 |
1026 | this.emitChange();
1027 | }
1028 | }, {
1029 | key: "info",
1030 | value: function info(message, title, timeOut, onClick, priority) {
1031 | this.create({
1032 | type: Constants.INFO,
1033 | message: message,
1034 | title: title,
1035 | timeOut: timeOut,
1036 | onClick: onClick,
1037 | priority: priority
1038 | });
1039 | }
1040 | }, {
1041 | key: "success",
1042 | value: function success(message, title, timeOut, onClick, priority) {
1043 | this.create({
1044 | type: Constants.SUCCESS,
1045 | message: message,
1046 | title: title,
1047 | timeOut: timeOut,
1048 | onClick: onClick,
1049 | priority: priority
1050 | });
1051 | }
1052 | }, {
1053 | key: "warning",
1054 | value: function warning(message, title, timeOut, onClick, priority) {
1055 | this.create({
1056 | type: Constants.WARNING,
1057 | message: message,
1058 | title: title,
1059 | timeOut: timeOut,
1060 | onClick: onClick,
1061 | priority: priority
1062 | });
1063 | }
1064 | }, {
1065 | key: "error",
1066 | value: function error(message, title, timeOut, onClick, priority) {
1067 | this.create({
1068 | type: Constants.ERROR,
1069 | message: message,
1070 | title: title,
1071 | timeOut: timeOut,
1072 | onClick: onClick,
1073 | priority: priority
1074 | });
1075 | }
1076 | }, {
1077 | key: "remove",
1078 | value: function remove(notification) {
1079 | this.listNotify = this.listNotify.filter(function (n) {
1080 | return notification.id !== n.id;
1081 | });
1082 | this.emitChange();
1083 | }
1084 | }, {
1085 | key: "removeAll",
1086 | value: function removeAll() {
1087 | this.listNotify.length = 0;
1088 | this.emitChange();
1089 | }
1090 | }, {
1091 | key: "emitChange",
1092 | value: function emitChange() {
1093 | this.emit(Constants.CHANGE, this.listNotify);
1094 | }
1095 | }, {
1096 | key: "addChangeListener",
1097 | value: function addChangeListener(callback) {
1098 | this.addListener(Constants.CHANGE, callback);
1099 | }
1100 | }, {
1101 | key: "removeChangeListener",
1102 | value: function removeChangeListener(callback) {
1103 | this.removeListener(Constants.CHANGE, callback);
1104 | }
1105 | }]);
1106 |
1107 | return NotificationManager;
1108 | }(events["EventEmitter"]);
1109 |
1110 | /* harmony default export */ var src_NotificationManager = (new NotificationManager());
1111 | // CONCATENATED MODULE: ./src/NotificationContainer.js
1112 | function NotificationContainer_typeof(obj) { "@babel/helpers - typeof"; return NotificationContainer_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, NotificationContainer_typeof(obj); }
1113 |
1114 | function NotificationContainer_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1115 |
1116 | function NotificationContainer_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
1117 |
1118 | function NotificationContainer_createClass(Constructor, protoProps, staticProps) { if (protoProps) NotificationContainer_defineProperties(Constructor.prototype, protoProps); if (staticProps) NotificationContainer_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1119 |
1120 | function NotificationContainer_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) NotificationContainer_setPrototypeOf(subClass, superClass); }
1121 |
1122 | function NotificationContainer_setPrototypeOf(o, p) { NotificationContainer_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return NotificationContainer_setPrototypeOf(o, p); }
1123 |
1124 | function NotificationContainer_createSuper(Derived) { var hasNativeReflectConstruct = NotificationContainer_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = NotificationContainer_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = NotificationContainer_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return NotificationContainer_possibleConstructorReturn(this, result); }; }
1125 |
1126 | function NotificationContainer_possibleConstructorReturn(self, call) { if (call && (NotificationContainer_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return NotificationContainer_assertThisInitialized(self); }
1127 |
1128 | function NotificationContainer_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
1129 |
1130 | function NotificationContainer_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1131 |
1132 | function NotificationContainer_getPrototypeOf(o) { NotificationContainer_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return NotificationContainer_getPrototypeOf(o); }
1133 |
1134 | function NotificationContainer_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 | var NotificationContainer_NotificationContainer = /*#__PURE__*/function (_React$Component) {
1142 | NotificationContainer_inherits(NotificationContainer, _React$Component);
1143 |
1144 | var _super = NotificationContainer_createSuper(NotificationContainer);
1145 |
1146 | function NotificationContainer() {
1147 | var _this;
1148 |
1149 | NotificationContainer_classCallCheck(this, NotificationContainer);
1150 |
1151 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1152 | args[_key] = arguments[_key];
1153 | }
1154 |
1155 | _this = _super.call.apply(_super, [this].concat(args));
1156 |
1157 | NotificationContainer_defineProperty(NotificationContainer_assertThisInitialized(_this), "state", {
1158 | notifications: []
1159 | });
1160 |
1161 | NotificationContainer_defineProperty(NotificationContainer_assertThisInitialized(_this), "componentDidMount", function () {
1162 | src_NotificationManager.addChangeListener(_this.handleStoreChange);
1163 | });
1164 |
1165 | NotificationContainer_defineProperty(NotificationContainer_assertThisInitialized(_this), "componentWillUnmount", function () {
1166 | src_NotificationManager.removeChangeListener(_this.handleStoreChange);
1167 | });
1168 |
1169 | NotificationContainer_defineProperty(NotificationContainer_assertThisInitialized(_this), "handleStoreChange", function (notifications) {
1170 | _this.setState({
1171 | notifications: notifications
1172 | });
1173 | });
1174 |
1175 | NotificationContainer_defineProperty(NotificationContainer_assertThisInitialized(_this), "handleRequestHide", function (notification) {
1176 | src_NotificationManager.remove(notification);
1177 | });
1178 |
1179 | return _this;
1180 | }
1181 |
1182 | NotificationContainer_createClass(NotificationContainer, [{
1183 | key: "render",
1184 | value: function render() {
1185 | var notifications = this.state.notifications;
1186 | var _this$props = this.props,
1187 | enterTimeout = _this$props.enterTimeout,
1188 | leaveTimeout = _this$props.leaveTimeout;
1189 | return /*#__PURE__*/external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.createElement(src_Notifications, {
1190 | enterTimeout: enterTimeout,
1191 | leaveTimeout: leaveTimeout,
1192 | notifications: notifications,
1193 | onRequestHide: this.handleRequestHide
1194 | });
1195 | }
1196 | }]);
1197 |
1198 | return NotificationContainer;
1199 | }(external_root_React_commonjs_react_commonjs2_react_amd_react_default.a.Component);
1200 |
1201 | NotificationContainer_defineProperty(NotificationContainer_NotificationContainer, "propTypes", {
1202 | enterTimeout: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.number,
1203 | leaveTimeout: external_root_PropTypes_commonjs_prop_types_commonjs2_prop_types_amd_prop_types_default.a.number
1204 | });
1205 |
1206 | NotificationContainer_defineProperty(NotificationContainer_NotificationContainer, "defaultProps", {
1207 | enterTimeout: 400,
1208 | leaveTimeout: 400
1209 | });
1210 |
1211 | /* harmony default export */ var src_NotificationContainer = (NotificationContainer_NotificationContainer);
1212 | // CONCATENATED MODULE: ./src/index.js
1213 |
1214 |
1215 |
1216 |
1217 | /* harmony default export */ var src = __webpack_exports__["default"] = (src_Notifications);
1218 |
1219 | /***/ })
1220 | /******/ ]);
1221 | });
--------------------------------------------------------------------------------
/example/src/app.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './components/App';
4 |
5 | import 'bootstrap/dist/css/bootstrap.css';
6 | import '../../src/notifications.scss';
7 | import './assets/styles/app.scss';
8 |
9 | const run = () => {
10 | ReactDOM.render(, document.getElementById('app'));
11 | };
12 |
13 | window.addEventListener('DOMContentLoaded', run);
14 |
--------------------------------------------------------------------------------
/example/src/assets/fonts/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/example/src/assets/fonts/.gitkeep
--------------------------------------------------------------------------------
/example/src/assets/images/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
22 |
--------------------------------------------------------------------------------
/example/src/assets/styles/_animations.scss:
--------------------------------------------------------------------------------
1 | @keyframes spinner {
2 | 0% {
3 | transform: rotate(0deg);
4 | }
5 | 100% {
6 | transform: rotate(360deg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/example/src/assets/styles/_mixins.scss:
--------------------------------------------------------------------------------
1 | @mixin clearfix() {
2 | &:before,
3 | &:after {
4 | content: " ";
5 | display: table;
6 | }
7 | &:after {
8 | clear: both;
9 | }
10 | }
11 |
12 | @function str-replace($string, $search, $replace: "") {
13 | $index: str-index($string, $search);
14 | @if $index {
15 | @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
16 | }
17 | @return $string;
18 | }
19 |
20 | @mixin font-face($name, $path, $weight: null, $style: null, $extensions: eot woff2 woff ttf svg) {
21 | $src: null;
22 | $extensionMods: (
23 | eot: "?",
24 | svg: "#" + str-replace($name, " ", "_")
25 | );
26 | $formats: (
27 | otf: "opentype",
28 | ttf: "truetype"
29 | );
30 | @each $extension in $extensions {
31 | $extensionMod: if(map-has-key($extensionMods, $extension), $extension + map-get($extensionMods, $extension), $extension);
32 | $format: if(map-has-key($formats, $extension), map-get($formats, $extension), $extension);
33 | $src: append($src, url(quote($path + "." + $extensionMod)) format(quote($format)), comma);
34 | }
35 | @font-face {
36 | font-family: quote($name);
37 | font-style: $style;
38 | font-weight: $weight;
39 | src: $src;
40 | }
41 | }
42 |
43 | @mixin placeholder {
44 | &::-webkit-input-placeholder {
45 | @content;
46 | }
47 | &::-moz-placeholder {
48 | @content;
49 | }
50 | &:-ms-input-placeholder {
51 | @content;
52 | }
53 | }
54 |
55 | @function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
56 | $n: index($breakpoint-names, $name);
57 | @return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
58 | }
59 |
60 | @function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
61 | $min: map-get($breakpoints, $name);
62 | @return if($min != 0, $min, null);
63 | }
64 |
65 | @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
66 | $next: breakpoint-next($name, $breakpoints);
67 | @return if($next, breakpoint-min($next, $breakpoints) - 1px, null);
68 | }
69 |
70 | @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
71 | $min: breakpoint-min($name, $breakpoints);
72 | @if $min {
73 | @media (min-width: $min) {
74 | @content;
75 | }
76 | } @else {
77 | @content;
78 | }
79 | }
80 |
81 | @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
82 | $max: breakpoint-max($name, $breakpoints);
83 | @if $max {
84 | @media (max-width: $max) {
85 | @content;
86 | }
87 | } @else {
88 | @content;
89 | }
90 | }
91 |
92 | @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
93 | @include media-breakpoint-up($name, $breakpoints) {
94 | @include media-breakpoint-down($name, $breakpoints) {
95 | @content;
96 | }
97 | }
98 | }
99 |
100 | @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
101 | @include media-breakpoint-up($lower, $breakpoints) {
102 | @include media-breakpoint-down($upper, $breakpoints) {
103 | @content;
104 | }
105 | }
106 | }
107 |
108 | @mixin ellipsis() {
109 | display: block;
110 | max-width: 100%;
111 | text-overflow: ellipsis;
112 | white-space: nowrap;
113 | overflow: hidden;
114 | }
115 |
--------------------------------------------------------------------------------
/example/src/assets/styles/_variables.scss:
--------------------------------------------------------------------------------
1 | // Grid
2 | $grid-breakpoints: (xs: 0, sm: 540px, md: 768px, lg: 992px, xl: 1200px);
3 |
4 | // Colors
5 | $primary: #222;
6 |
--------------------------------------------------------------------------------
/example/src/assets/styles/app.scss:
--------------------------------------------------------------------------------
1 | /* ==========================================================================
2 | React flux starter
3 | ========================================================================== */
4 | @import "variables";
5 | @import "mixins";
6 | @import "animations";
7 | @import "components/pre-render";
8 | @import "components/page";
9 | @import "components/header";
10 | @import "components/footer";
11 | @import "pages/home";
12 |
--------------------------------------------------------------------------------
/example/src/assets/styles/components/_footer.scss:
--------------------------------------------------------------------------------
1 | /* Footer
2 | ========================================================================== */
3 | .footer {
4 | background-color: #f8f8f8;
5 | padding: 20px 0;
6 | }
7 |
--------------------------------------------------------------------------------
/example/src/assets/styles/components/_header.scss:
--------------------------------------------------------------------------------
1 | /* Header
2 | ========================================================================== */
3 | .navbar {
4 | border-radius: 0;
5 | margin: 0;
6 | }
7 |
--------------------------------------------------------------------------------
/example/src/assets/styles/components/_page.scss:
--------------------------------------------------------------------------------
1 | /* Page
2 | ========================================================================== */
3 | html,
4 | body,
5 | #app {
6 | height: 100%;
7 | }
8 |
9 | .page {
10 | display: flex;
11 | flex-flow: column;
12 | min-height: 100vh;
13 | &__wrapper {
14 | flex-grow: 1;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/example/src/assets/styles/components/_pre-render.scss:
--------------------------------------------------------------------------------
1 | /* Pre-render
2 | ========================================================================== */
3 | .pre-render {
4 | background: rgba(255, 255, 255, .7);
5 | position: fixed;
6 | top: 0;
7 | left: 0;
8 | width: 100%;
9 | height: 100%;
10 | z-index: 99999;
11 | &__spinner {
12 | width: 48px;
13 | height: 48px;
14 | border: 1px solid lighten($primary, 40%);
15 | border-left-color: darken($primary, 10%);
16 | border-radius: 50%;
17 | animation: spinner 700ms infinite linear;
18 | position: absolute;
19 | top: 50%;
20 | left: 50%;
21 | margin-left: -24px;
22 | margin-top: -24px;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/example/src/assets/styles/pages/_home.scss:
--------------------------------------------------------------------------------
1 | /* Home
2 | ========================================================================== */
3 |
--------------------------------------------------------------------------------
/example/src/components/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
3 | import Header from './Header';
4 | import Footer from './Footer';
5 | import Home from '../pages/Home';
6 | import NotFound from '../pages/NotFound';
7 | import TransitionAnimation from '../pages/TransitionAnimation';
8 | import pkg from '../../../package.json';
9 |
10 | const DEV = process && process.env && process.env.NODE_ENV === 'development';
11 |
12 | const App = () => (
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | );
29 |
30 | export default App;
31 |
--------------------------------------------------------------------------------
/example/src/components/Document.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | class Document extends React.Component {
5 | static propTypes = {
6 | title: PropTypes.string.isRequired,
7 | className: PropTypes.string.isRequired,
8 | children: PropTypes.element.isRequired,
9 | };
10 |
11 | state = {
12 | oldTitle: document.title,
13 | oldClassName: document.body.className,
14 | };
15 |
16 | componentDidMount = () => {
17 | if (this.props.title) {
18 | document.title = this.props.title;
19 | }
20 | if (this.props.className) {
21 | const className = `${this.state.oldClassName} ${this.props.className}`;
22 | document.body.className = className.trim().replace(' ', ' ');
23 | }
24 | };
25 |
26 | componentWillUnmount = () => {
27 | document.title = this.state.oldTitle;
28 | document.body.className = this.state.oldClassName;
29 | };
30 |
31 | render() {
32 | if (this.props.children) {
33 | return React.Children.only(this.props.children);
34 | }
35 | return null;
36 | }
37 | }
38 |
39 | export default Document;
40 |
--------------------------------------------------------------------------------
/example/src/components/Footer.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const Footer = () => (
4 |
11 | );
12 |
13 | export default Footer;
14 |
--------------------------------------------------------------------------------
/example/src/components/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'react-router-dom';
3 |
4 | import logo from '../assets/images/logo.svg';
5 |
6 | const Header = () => (
7 |
8 |
28 |
29 | );
30 |
31 | export default Header;
32 |
--------------------------------------------------------------------------------
/example/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | React notifications
6 |
7 |
8 |
9 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/example/src/pages/Home/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Document from '../../components/Document';
3 | import { NotificationContainer, NotificationManager } from '../../../../dist/react-notifications';
4 |
5 | class HomePage extends React.Component {
6 | createNotification = (type) => () => {
7 | switch (type) {
8 | case 'info':
9 | NotificationManager.info('Info message');
10 | break;
11 | case 'success':
12 | NotificationManager.success('Success message', 'Title here');
13 | break;
14 | case 'warning':
15 | NotificationManager.warning('Warning message', 'Close after 3000ms', 3000);
16 | break;
17 | case 'error':
18 | NotificationManager.error('Error message', 'Click me!', 5000, () => {
19 | alert('callback');
20 | });
21 | break;
22 | default:
23 | break;
24 | }
25 | };
26 |
27 | render() {
28 | return (
29 |
30 |
31 |
32 |
Simple sample
33 |
34 |
37 |
38 |
41 |
42 |
45 |
46 |
49 |
50 |
51 |
52 |
53 | );
54 | }
55 | }
56 |
57 | export default HomePage;
58 |
--------------------------------------------------------------------------------
/example/src/pages/NotFound/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Document from '../../components/Document';
3 |
4 | const NotFoundPage = () => (
5 |
6 | Page Not Found
7 |
8 | );
9 |
10 | export default NotFoundPage;
11 |
--------------------------------------------------------------------------------
/example/src/pages/TransitionAnimation/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Document from '../../components/Document';
3 | import { NotificationContainer, NotificationManager } from '../../../../dist/react-notifications';
4 |
5 | import './notifications.scss';
6 |
7 | class TransitionAnimationPage extends React.Component {
8 | createNotification = (type) => () => {
9 | switch (type) {
10 | case 'info':
11 | NotificationManager.info('Info message');
12 | break;
13 | case 'success':
14 | NotificationManager.success('Success message', 'Title here');
15 | break;
16 | case 'warning':
17 | NotificationManager.warning('Warning message', 'Close after 3000ms', 3000);
18 | break;
19 | case 'error':
20 | NotificationManager.error('Error message', 'Click me!', 5000, () => {
21 | alert('callback');
22 | });
23 | break;
24 | default:
25 | break;
26 | }
27 | };
28 |
29 | render() {
30 | return (
31 |
35 |
36 |
37 |
Transition & animation
38 |
39 |
42 |
43 |
46 |
47 |
50 |
51 |
54 |
55 |
56 |
57 |
58 | );
59 | }
60 | }
61 |
62 | export default TransitionAnimationPage;
63 |
--------------------------------------------------------------------------------
/example/src/pages/TransitionAnimation/notifications.scss:
--------------------------------------------------------------------------------
1 | .page-transition-animation {
2 | .notification-enter {
3 | visibility: hidden;
4 | transform: translate3d(100%, 0, 0) scale(0, 0);
5 | }
6 |
7 | .notification-enter.notification-enter-active {
8 | visibility: visible;
9 | transform: translate3d(0, 0, 0) scale(1, 1);
10 | transition: all 0.8s;
11 | }
12 |
13 | .notification-leave {
14 | visibility: visible;
15 | transform: translate3d(0, 0, 0) scale(1, 1);
16 | }
17 |
18 | .notification-leave.notification-leave-active {
19 | visibility: hidden;
20 | transform: translate3d(100%, 0, 0) scale(0, 0);
21 | transition: all 0.5s;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/example/webpack.config.babel.js:
--------------------------------------------------------------------------------
1 | import webpack from 'webpack';
2 | import path from 'path';
3 | import HtmlWebpackPlugin from 'html-webpack-plugin';
4 | import LiveReloadPlugin from 'webpack-livereload-plugin';
5 |
6 | const ENV = process.env.NODE_ENV || 'development';
7 | const DEV = ENV === 'development';
8 | const PROD = ENV === 'production';
9 | const SOURCE_DIR = 'src';
10 | const DEST_DIR = 'dist';
11 | const PUBLIC_PATH = '/';
12 |
13 | export default {
14 | mode: ENV,
15 | entry: path.join(__dirname, SOURCE_DIR, 'app.js'),
16 | output: {
17 | path: path.join(__dirname, DEST_DIR),
18 | filename: '[name].js'
19 | },
20 | module: {
21 | rules: [
22 | {
23 | test: /\.(js|jsx)$/,
24 | exclude: /node_modules/,
25 | use: {
26 | loader: 'eslint-loader',
27 | options: {
28 | configFile: path.join(__dirname, '../.eslintrc'),
29 | failOnError: PROD,
30 | emitError: PROD
31 | }
32 | },
33 | enforce: 'pre'
34 | },
35 | {
36 | use: 'babel-loader',
37 | test: /\.js$/,
38 | exclude: /node_modules/
39 | },
40 | {
41 | use: ['style-loader', 'css-loader'],
42 | test: /\.css$/
43 | },
44 | {
45 | test: /\.scss$/,
46 | use: [{
47 | loader: 'style-loader'
48 | }, {
49 | loader: 'css-loader',
50 | options: {
51 | sourceMap: true
52 | }
53 | }, {
54 | loader: 'sass-loader',
55 | options: {
56 | sourceMap: true
57 | }
58 | }]
59 | },
60 | {
61 | test: /\.(png|jpg|gif|swf)$/,
62 | use: 'file-loader'
63 | },
64 | {
65 | test: /\.(ttf|eot|svg|woff(2)?)(\S+)?$/,
66 | use: 'file-loader'
67 | }
68 | ]
69 | },
70 | plugins: [
71 | new HtmlWebpackPlugin({
72 | template: './example/src/index.html'
73 | }),
74 | new LiveReloadPlugin()
75 | ]
76 | };
77 |
--------------------------------------------------------------------------------
/example/webpack.server.js:
--------------------------------------------------------------------------------
1 | import express from 'express';
2 | import webpackMiddleware from 'webpack-dev-middleware';
3 | import webpack from 'webpack';
4 | import webpackConfig from './webpack.config.babel.js';
5 |
6 | const app = express();
7 | app.use(webpackMiddleware(webpack(webpackConfig)));
8 |
9 | app.listen(3000, () => {
10 | console.log('Listening');
11 | });
12 |
--------------------------------------------------------------------------------
/gulpfile.babel.js:
--------------------------------------------------------------------------------
1 | import gulp from 'gulp';
2 | import del from 'del';
3 | import babel from 'gulp-babel';
4 | import webpackStream from 'webpack-stream';
5 | import webpack from 'webpack';
6 | import sass from 'gulp-sass';
7 | import postcss from 'gulp-postcss';
8 | import concat from 'gulp-concat';
9 | import pkg from './package.json';
10 | import webpackConfig from './webpack.config';
11 | import exampleWebpackConfig from './example/webpack.config.babel';
12 |
13 | require('regenerator-runtime/runtime');
14 |
15 | gulp.task('build:lib:clean', async () => del.sync(['lib', 'dist']));
16 |
17 | gulp.task('build:lib:babel', async () => {
18 | gulp.src(['src/**/*.js'])
19 | .pipe(babel())
20 | .pipe(gulp.dest('lib'));
21 | });
22 |
23 | gulp.task('build:lib:umd', async () => {
24 | gulp.src(['src/index.js'])
25 | .pipe(webpackStream(webpackConfig, webpack))
26 | .pipe(gulp.dest('dist'));
27 | });
28 |
29 | gulp.task('build:lib:style', async () => {
30 | gulp.src(['src/**/*.scss', '!src/**/_*.scss'])
31 | .pipe(sass({ outputStyle: 'expanded' }).on('error', sass.logError))
32 | .pipe(gulp.dest('lib'))
33 | .pipe(concat(`${pkg.name}.css`))
34 | .pipe(postcss())
35 | .pipe(gulp.dest('dist'));
36 | });
37 |
38 | gulp.task('build:lib:copy', async () => {
39 | gulp.src(['src/**/*', '!src/**/*.{scss,js}'])
40 | .pipe(gulp.dest('lib'))
41 | .pipe(gulp.dest('dist'));
42 | });
43 |
44 | gulp.task('build:lib', gulp.series(
45 | 'build:lib:clean',
46 | 'build:lib:babel',
47 | 'build:lib:umd',
48 | 'build:lib:style',
49 | 'build:lib:copy'
50 | ));
51 |
52 | gulp.task('build:example:clean', async () => del.sync(['example/dist']));
53 |
54 | gulp.task('build:example:webpack', async () => {
55 | gulp.src(['example/app/app.js'], { allowEmpty: true })
56 | .pipe(webpackStream(exampleWebpackConfig, webpack))
57 | .pipe(gulp.dest('example/dist'));
58 | });
59 |
60 | gulp.task('build:example:copy', async () => {
61 | gulp.src(['example/app/*', '!example/app/*.{html,js}'], { nodir: true })
62 | .pipe(gulp.dest('example/dist'));
63 | });
64 |
65 | gulp.task('build:example', gulp.series(
66 | 'build:example:clean',
67 | 'build:example:webpack',
68 | 'build:example:copy'
69 | ));
70 |
71 | gulp.task('build', gulp.series(
72 | 'build:lib',
73 | 'build:example'
74 | ));
75 |
76 | gulp.task('default', gulp.series('build'));
77 |
--------------------------------------------------------------------------------
/lib/Notification.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4 |
5 | Object.defineProperty(exports, "__esModule", {
6 | value: true
7 | });
8 | exports.default = void 0;
9 |
10 | var _react = _interopRequireDefault(require("react"));
11 |
12 | var _propTypes = _interopRequireDefault(require("prop-types"));
13 |
14 | var _classnames = _interopRequireDefault(require("classnames"));
15 |
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17 |
18 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19 |
20 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
21 |
22 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23 |
24 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
25 |
26 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
27 |
28 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
29 |
30 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
31 |
32 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
33 |
34 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
35 |
36 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37 |
38 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
39 |
40 | var Notification = /*#__PURE__*/function (_React$Component) {
41 | _inherits(Notification, _React$Component);
42 |
43 | var _super = _createSuper(Notification);
44 |
45 | function Notification() {
46 | var _this;
47 |
48 | _classCallCheck(this, Notification);
49 |
50 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
51 | args[_key] = arguments[_key];
52 | }
53 |
54 | _this = _super.call.apply(_super, [this].concat(args));
55 |
56 | _defineProperty(_assertThisInitialized(_this), "componentDidMount", function () {
57 | var timeOut = _this.props.timeOut;
58 |
59 | if (timeOut !== 0) {
60 | _this.timer = setTimeout(_this.requestHide, timeOut);
61 | }
62 | });
63 |
64 | _defineProperty(_assertThisInitialized(_this), "componentWillUnmount", function () {
65 | if (_this.timer) {
66 | clearTimeout(_this.timer);
67 | }
68 | });
69 |
70 | _defineProperty(_assertThisInitialized(_this), "handleClick", function () {
71 | var onClick = _this.props.onClick;
72 |
73 | if (onClick) {
74 | onClick();
75 | }
76 |
77 | _this.requestHide();
78 | });
79 |
80 | _defineProperty(_assertThisInitialized(_this), "requestHide", function () {
81 | var onRequestHide = _this.props.onRequestHide;
82 |
83 | if (onRequestHide) {
84 | onRequestHide();
85 | }
86 | });
87 |
88 | return _this;
89 | }
90 |
91 | _createClass(Notification, [{
92 | key: "render",
93 | value: function render() {
94 | var _this$props = this.props,
95 | type = _this$props.type,
96 | message = _this$props.message;
97 | var title = this.props.title;
98 | var className = (0, _classnames.default)(['notification', "notification-".concat(type)]);
99 | title = title ? /*#__PURE__*/_react.default.createElement("h4", {
100 | className: "title"
101 | }, title) : null;
102 | return /*#__PURE__*/_react.default.createElement("div", {
103 | className: className,
104 | onClick: this.handleClick
105 | }, /*#__PURE__*/_react.default.createElement("div", {
106 | className: "notification-message",
107 | role: "alert"
108 | }, title, /*#__PURE__*/_react.default.createElement("div", {
109 | className: "message"
110 | }, message)));
111 | }
112 | }]);
113 |
114 | return Notification;
115 | }(_react.default.Component);
116 |
117 | _defineProperty(Notification, "propTypes", {
118 | type: _propTypes.default.oneOf(['info', 'success', 'warning', 'error']),
119 | title: _propTypes.default.node,
120 | message: _propTypes.default.node,
121 | timeOut: _propTypes.default.number,
122 | onClick: _propTypes.default.func,
123 | onRequestHide: _propTypes.default.func
124 | });
125 |
126 | _defineProperty(Notification, "defaultProps", {
127 | type: 'info',
128 | title: null,
129 | message: null,
130 | timeOut: 5000,
131 | onClick: function onClick() {},
132 | onRequestHide: function onRequestHide() {}
133 | });
134 |
135 | var _default = Notification;
136 | exports.default = _default;
--------------------------------------------------------------------------------
/lib/NotificationContainer.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4 |
5 | Object.defineProperty(exports, "__esModule", {
6 | value: true
7 | });
8 | exports.default = void 0;
9 |
10 | var _react = _interopRequireDefault(require("react"));
11 |
12 | var _propTypes = _interopRequireDefault(require("prop-types"));
13 |
14 | var _NotificationManager = _interopRequireDefault(require("./NotificationManager"));
15 |
16 | var _Notifications = _interopRequireDefault(require("./Notifications"));
17 |
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19 |
20 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21 |
22 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23 |
24 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25 |
26 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
27 |
28 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29 |
30 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
31 |
32 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
33 |
34 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35 |
36 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
37 |
38 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39 |
40 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41 |
42 | var NotificationContainer = /*#__PURE__*/function (_React$Component) {
43 | _inherits(NotificationContainer, _React$Component);
44 |
45 | var _super = _createSuper(NotificationContainer);
46 |
47 | function NotificationContainer() {
48 | var _this;
49 |
50 | _classCallCheck(this, NotificationContainer);
51 |
52 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
53 | args[_key] = arguments[_key];
54 | }
55 |
56 | _this = _super.call.apply(_super, [this].concat(args));
57 |
58 | _defineProperty(_assertThisInitialized(_this), "state", {
59 | notifications: []
60 | });
61 |
62 | _defineProperty(_assertThisInitialized(_this), "componentDidMount", function () {
63 | _NotificationManager.default.addChangeListener(_this.handleStoreChange);
64 | });
65 |
66 | _defineProperty(_assertThisInitialized(_this), "componentWillUnmount", function () {
67 | _NotificationManager.default.removeChangeListener(_this.handleStoreChange);
68 | });
69 |
70 | _defineProperty(_assertThisInitialized(_this), "handleStoreChange", function (notifications) {
71 | _this.setState({
72 | notifications: notifications
73 | });
74 | });
75 |
76 | _defineProperty(_assertThisInitialized(_this), "handleRequestHide", function (notification) {
77 | _NotificationManager.default.remove(notification);
78 | });
79 |
80 | return _this;
81 | }
82 |
83 | _createClass(NotificationContainer, [{
84 | key: "render",
85 | value: function render() {
86 | var notifications = this.state.notifications;
87 | var _this$props = this.props,
88 | enterTimeout = _this$props.enterTimeout,
89 | leaveTimeout = _this$props.leaveTimeout;
90 | return /*#__PURE__*/_react.default.createElement(_Notifications.default, {
91 | enterTimeout: enterTimeout,
92 | leaveTimeout: leaveTimeout,
93 | notifications: notifications,
94 | onRequestHide: this.handleRequestHide
95 | });
96 | }
97 | }]);
98 |
99 | return NotificationContainer;
100 | }(_react.default.Component);
101 |
102 | _defineProperty(NotificationContainer, "propTypes", {
103 | enterTimeout: _propTypes.default.number,
104 | leaveTimeout: _propTypes.default.number
105 | });
106 |
107 | _defineProperty(NotificationContainer, "defaultProps", {
108 | enterTimeout: 400,
109 | leaveTimeout: 400
110 | });
111 |
112 | var _default = NotificationContainer;
113 | exports.default = _default;
--------------------------------------------------------------------------------
/lib/NotificationManager.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4 |
5 | Object.defineProperty(exports, "__esModule", {
6 | value: true
7 | });
8 | exports.default = void 0;
9 |
10 | var _events = require("events");
11 |
12 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13 |
14 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15 |
16 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17 |
18 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
19 |
20 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21 |
22 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
23 |
24 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
25 |
26 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
27 |
28 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
29 |
30 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
31 |
32 | var createUUID = function createUUID() {
33 | var pattern = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
34 | return pattern.replace(/[xy]/g, function (c) {
35 | var r = Math.random() * 16 | 0;
36 | var v = c === 'x' ? r : r & 0x3 | 0x8;
37 | return v.toString(16);
38 | });
39 | };
40 |
41 | var Constants = {
42 | CHANGE: 'change',
43 | INFO: 'info',
44 | SUCCESS: 'success',
45 | WARNING: 'warning',
46 | ERROR: 'error'
47 | };
48 |
49 | var NotificationManager = /*#__PURE__*/function (_EventEmitter) {
50 | _inherits(NotificationManager, _EventEmitter);
51 |
52 | var _super = _createSuper(NotificationManager);
53 |
54 | function NotificationManager() {
55 | var _this;
56 |
57 | _classCallCheck(this, NotificationManager);
58 |
59 | _this = _super.call(this);
60 | _this.listNotify = [];
61 | return _this;
62 | }
63 |
64 | _createClass(NotificationManager, [{
65 | key: "create",
66 | value: function create(notify) {
67 | var defaultNotify = {
68 | id: createUUID(),
69 | type: 'info',
70 | title: null,
71 | message: null,
72 | timeOut: 5000
73 | };
74 |
75 | if (notify.priority) {
76 | this.listNotify.unshift(Object.assign(defaultNotify, notify));
77 | } else {
78 | this.listNotify.push(Object.assign(defaultNotify, notify));
79 | }
80 |
81 | this.emitChange();
82 | }
83 | }, {
84 | key: "info",
85 | value: function info(message, title, timeOut, onClick, priority) {
86 | this.create({
87 | type: Constants.INFO,
88 | message: message,
89 | title: title,
90 | timeOut: timeOut,
91 | onClick: onClick,
92 | priority: priority
93 | });
94 | }
95 | }, {
96 | key: "success",
97 | value: function success(message, title, timeOut, onClick, priority) {
98 | this.create({
99 | type: Constants.SUCCESS,
100 | message: message,
101 | title: title,
102 | timeOut: timeOut,
103 | onClick: onClick,
104 | priority: priority
105 | });
106 | }
107 | }, {
108 | key: "warning",
109 | value: function warning(message, title, timeOut, onClick, priority) {
110 | this.create({
111 | type: Constants.WARNING,
112 | message: message,
113 | title: title,
114 | timeOut: timeOut,
115 | onClick: onClick,
116 | priority: priority
117 | });
118 | }
119 | }, {
120 | key: "error",
121 | value: function error(message, title, timeOut, onClick, priority) {
122 | this.create({
123 | type: Constants.ERROR,
124 | message: message,
125 | title: title,
126 | timeOut: timeOut,
127 | onClick: onClick,
128 | priority: priority
129 | });
130 | }
131 | }, {
132 | key: "remove",
133 | value: function remove(notification) {
134 | this.listNotify = this.listNotify.filter(function (n) {
135 | return notification.id !== n.id;
136 | });
137 | this.emitChange();
138 | }
139 | }, {
140 | key: "removeAll",
141 | value: function removeAll() {
142 | this.listNotify.length = 0;
143 | this.emitChange();
144 | }
145 | }, {
146 | key: "emitChange",
147 | value: function emitChange() {
148 | this.emit(Constants.CHANGE, this.listNotify);
149 | }
150 | }, {
151 | key: "addChangeListener",
152 | value: function addChangeListener(callback) {
153 | this.addListener(Constants.CHANGE, callback);
154 | }
155 | }, {
156 | key: "removeChangeListener",
157 | value: function removeChangeListener(callback) {
158 | this.removeListener(Constants.CHANGE, callback);
159 | }
160 | }]);
161 |
162 | return NotificationManager;
163 | }(_events.EventEmitter);
164 |
165 | var _default = new NotificationManager();
166 |
167 | exports.default = _default;
--------------------------------------------------------------------------------
/lib/Notifications.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4 |
5 | Object.defineProperty(exports, "__esModule", {
6 | value: true
7 | });
8 | exports.default = void 0;
9 |
10 | var _react = _interopRequireDefault(require("react"));
11 |
12 | var _propTypes = _interopRequireDefault(require("prop-types"));
13 |
14 | var _reactTransitionGroup = require("react-transition-group");
15 |
16 | var _classnames = _interopRequireDefault(require("classnames"));
17 |
18 | var _Notification = _interopRequireDefault(require("./Notification"));
19 |
20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21 |
22 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23 |
24 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
25 |
26 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27 |
28 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
29 |
30 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31 |
32 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
33 |
34 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
35 |
36 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
37 |
38 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39 |
40 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
41 |
42 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
43 |
44 | var Notifications = /*#__PURE__*/function (_React$Component) {
45 | _inherits(Notifications, _React$Component);
46 |
47 | var _super = _createSuper(Notifications);
48 |
49 | function Notifications() {
50 | var _this;
51 |
52 | _classCallCheck(this, Notifications);
53 |
54 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
55 | args[_key] = arguments[_key];
56 | }
57 |
58 | _this = _super.call.apply(_super, [this].concat(args));
59 |
60 | _defineProperty(_assertThisInitialized(_this), "handleRequestHide", function (notification) {
61 | return function () {
62 | var onRequestHide = _this.props.onRequestHide;
63 |
64 | if (onRequestHide) {
65 | onRequestHide(notification);
66 | }
67 | };
68 | });
69 |
70 | return _this;
71 | }
72 |
73 | _createClass(Notifications, [{
74 | key: "render",
75 | value: function render() {
76 | var _this2 = this;
77 |
78 | var _this$props = this.props,
79 | notifications = _this$props.notifications,
80 | enterTimeout = _this$props.enterTimeout,
81 | leaveTimeout = _this$props.leaveTimeout;
82 | var className = (0, _classnames.default)('notification-container', {
83 | 'notification-container-empty': notifications.length === 0
84 | });
85 | var items = notifications.map(function (notification) {
86 | var key = notification.id || new Date().getTime();
87 | return /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.CSSTransition, {
88 | key: key,
89 | classNames: "notification",
90 | timeout: {
91 | enter: enterTimeout,
92 | exit: leaveTimeout
93 | }
94 | }, /*#__PURE__*/_react.default.createElement(_Notification.default, {
95 | type: notification.type,
96 | title: notification.title,
97 | message: notification.message,
98 | timeOut: notification.timeOut,
99 | onClick: notification.onClick,
100 | onRequestHide: _this2.handleRequestHide(notification)
101 | }));
102 | });
103 | return /*#__PURE__*/_react.default.createElement("div", {
104 | className: className
105 | }, /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.TransitionGroup, null, items));
106 | }
107 | }]);
108 |
109 | return Notifications;
110 | }(_react.default.Component);
111 |
112 | _defineProperty(Notifications, "propTypes", {
113 | notifications: _propTypes.default.array,
114 | onRequestHide: _propTypes.default.func,
115 | enterTimeout: _propTypes.default.number,
116 | leaveTimeout: _propTypes.default.number
117 | });
118 |
119 | _defineProperty(Notifications, "defaultProps", {
120 | notifications: [],
121 | onRequestHide: function onRequestHide() {},
122 | enterTimeout: 400,
123 | leaveTimeout: 400
124 | });
125 |
126 | var _default = Notifications;
127 | exports.default = _default;
--------------------------------------------------------------------------------
/lib/fonts/notification.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/lib/fonts/notification.eot
--------------------------------------------------------------------------------
/lib/fonts/notification.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/lib/fonts/notification.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/lib/fonts/notification.ttf
--------------------------------------------------------------------------------
/lib/fonts/notification.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/lib/fonts/notification.woff
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | Object.defineProperty(exports, "NotificationContainer", {
7 | enumerable: true,
8 | get: function get() {
9 | return _NotificationContainer.default;
10 | }
11 | });
12 | Object.defineProperty(exports, "NotificationManager", {
13 | enumerable: true,
14 | get: function get() {
15 | return _NotificationManager.default;
16 | }
17 | });
18 | Object.defineProperty(exports, "Notifications", {
19 | enumerable: true,
20 | get: function get() {
21 | return _Notifications.default;
22 | }
23 | });
24 | exports.default = void 0;
25 |
26 | var _Notifications = _interopRequireDefault(require("./Notifications.js"));
27 |
28 | var _NotificationContainer = _interopRequireDefault(require("./NotificationContainer"));
29 |
30 | var _NotificationManager = _interopRequireDefault(require("./NotificationManager"));
31 |
32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33 |
34 | var _default = _Notifications.default;
35 | exports.default = _default;
--------------------------------------------------------------------------------
/lib/notifications.css:
--------------------------------------------------------------------------------
1 | @charset "UTF-8";
2 | @font-face {
3 | font-family: 'Notification';
4 | src: url("./fonts/notification.eot?s3g3t9");
5 | src: url("./fonts/notification.eot?#iefixs3g3t9") format("embedded-opentype"), url("./fonts/notification.woff?s3g3t9") format("woff"), url("./fonts/notification.ttf?s3g3t9") format("truetype"), url("./fonts/notification.svg?s3g3t9#notification") format("svg");
6 | font-weight: normal;
7 | font-style: normal;
8 | }
9 |
10 | .notification-container {
11 | box-sizing: border-box;
12 | position: fixed;
13 | top: 0;
14 | right: 0;
15 | z-index: 999999;
16 | width: 320px;
17 | padding: 0px 15px;
18 | max-height: calc(100% - 30px);
19 | overflow-x: hidden;
20 | overflow-y: auto;
21 | }
22 |
23 | .notification {
24 | box-sizing: border-box;
25 | padding: 15px 15px 15px 58px;
26 | border-radius: 2px;
27 | color: #fff;
28 | background-color: #ccc;
29 | box-shadow: 0 0 12px #999;
30 | cursor: pointer;
31 | font-size: 1em;
32 | line-height: 1.2em;
33 | position: relative;
34 | opacity: 0.9;
35 | margin-top: 15px;
36 | }
37 |
38 | .notification .title {
39 | font-size: 1em;
40 | line-height: 1.2em;
41 | font-weight: bold;
42 | margin: 0 0 5px 0;
43 | }
44 |
45 | .notification:hover, .notification:focus {
46 | opacity: 1;
47 | }
48 |
49 | .notification-enter {
50 | visibility: hidden;
51 | transform: translate3d(100%, 0, 0);
52 | }
53 |
54 | .notification-enter.notification-enter-active {
55 | visibility: visible;
56 | transform: translate3d(0, 0, 0);
57 | transition: all 0.4s;
58 | }
59 |
60 | .notification-exit {
61 | visibility: visible;
62 | transform: translate3d(0, 0, 0);
63 | }
64 |
65 | .notification-exit.notification-exit-active {
66 | visibility: hidden;
67 | transform: translate3d(100%, 0, 0);
68 | transition: all 0.4s;
69 | }
70 |
71 | .notification:before {
72 | position: absolute;
73 | top: 50%;
74 | left: 15px;
75 | margin-top: -14px;
76 | display: block;
77 | font-family: 'Notification';
78 | width: 28px;
79 | height: 28px;
80 | font-size: 28px;
81 | text-align: center;
82 | line-height: 28px;
83 | }
84 |
85 | .notification-info {
86 | background-color: #2f96b4;
87 | }
88 |
89 | .notification-info:before {
90 | content: "";
91 | }
92 |
93 | .notification-success {
94 | background-color: #51a351;
95 | }
96 |
97 | .notification-success:before {
98 | content: "";
99 | }
100 |
101 | .notification-warning {
102 | background-color: #f89406;
103 | }
104 |
105 | .notification-warning:before {
106 | content: "";
107 | }
108 |
109 | .notification-error {
110 | background-color: #bd362f;
111 | }
112 |
113 | .notification-error:before {
114 | content: "";
115 | }
116 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-notifications",
3 | "version": "1.7.4",
4 | "description": "Notification component for ReactJS",
5 | "main": "lib/index.js",
6 | "scripts": {
7 | "start": "NODE_ENV=development babel-node example/webpack.server.js",
8 | "lint": "NODE_ENV=development eslint .",
9 | "build": "NODE_ENV=production gulp build"
10 | },
11 | "keywords": [
12 | "react-component",
13 | "react",
14 | "component",
15 | "notifications",
16 | "notification"
17 | ],
18 | "dependencies": {
19 | "acorn": "6.4.1",
20 | "classnames": "^2.1.1",
21 | "prop-types": "^15.5.10",
22 | "react-transition-group": "^4.4.1"
23 | },
24 | "devDependencies": {
25 | "@babel/cli": "^7.16.0",
26 | "@babel/core": "^7.11.4",
27 | "@babel/node": "^7.10.5",
28 | "@babel/plugin-proposal-class-properties": "^7.10.4",
29 | "@babel/plugin-proposal-object-rest-spread": "^7.11.0",
30 | "@babel/polyfill": "^7.11.5",
31 | "@babel/preset-env": "^7.11.0",
32 | "@babel/preset-react": "^7.10.4",
33 | "@babel/register": "^7.10.5",
34 | "autoprefixer": "^7.0.1",
35 | "babel-eslint": "^10.1.0",
36 | "babel-loader": "^8.1.0",
37 | "bootstrap": "^3.4.1",
38 | "camelcase": "^4.1.0",
39 | "clean-webpack-plugin": "^0.1.9",
40 | "cross-env": "^4.0.0",
41 | "css-loader": "^4.3.0",
42 | "cssnano": "^4.1.10",
43 | "del": "^3.0.0",
44 | "eslint": "^7.7.0",
45 | "eslint-config-airbnb": "^18.2.0",
46 | "eslint-loader": "^4.0.2",
47 | "eslint-plugin-import": "^2.22.0",
48 | "eslint-plugin-jsx-a11y": "^6.3.1",
49 | "eslint-plugin-react": "^7.20.6",
50 | "eslint-plugin-react-hooks": "^4.1.0",
51 | "express": "^4.15.3",
52 | "file-loader": "^1.1.11",
53 | "flux": "^3.1.2",
54 | "globby": "^6.1.0",
55 | "gulp": "^4.0.2",
56 | "gulp-babel": "^8.0.0",
57 | "gulp-concat": "^2.6.1",
58 | "gulp-postcss": "^7.0.0",
59 | "gulp-sass": "^3.1.0",
60 | "html-webpack-plugin": "^3.2.0",
61 | "http-proxy": "^1.18.1",
62 | "lodash.template": "^4.5.0",
63 | "mini-css-extract-plugin": "^0.11.0",
64 | "node-sass": "^4.13.1",
65 | "postcss-loader": "^2.0.5",
66 | "react": "^16.0.0",
67 | "react-dom": "^16.0.0",
68 | "react-hot-loader": "^4.12.21",
69 | "react-router-dom": "^4.1.1",
70 | "regenerator-runtime": "^0.13.7",
71 | "run-sequence": "^1.2.2",
72 | "sass-loader": "^6.0.1",
73 | "style-loader": "^1.2.1",
74 | "webpack": "^4.44.1",
75 | "webpack-dev-server": "^3.11.0",
76 | "webpack-livereload-plugin": "^2.3.0",
77 | "webpack-stream": "^6.1.0"
78 | },
79 | "repository": {
80 | "type": "git",
81 | "url": "https://github.com/tjrexer/react-notifications.git"
82 | },
83 | "author": [
84 | "Minh Tran",
85 | "Tim Rexer"
86 | ],
87 | "license": "MIT",
88 | "bugs": {
89 | "url": "https://github.com/tjrexer/react-notifications/issues"
90 | },
91 | "homepage": "https://github.com/tjrexer/react-notifications"
92 | }
93 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | const autoprefixer = require('autoprefixer');
2 | const cssnano = require('cssnano');
3 |
4 | const ENV = process.env.NODE_ENV || 'development';
5 | const PROD = ENV === 'production';
6 |
7 | const plugins = [
8 | autoprefixer({
9 | browsers: [
10 | 'last 2 versions'
11 | ]
12 | })
13 | ];
14 |
15 | if (PROD) {
16 | plugins.push(cssnano({
17 | safe: true,
18 | discardComments: {
19 | removeAll: true
20 | }
21 | }));
22 | }
23 |
24 | module.exports = {
25 | plugins
26 | };
27 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/screenshot.png
--------------------------------------------------------------------------------
/src/Notification.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import classnames from 'classnames';
4 |
5 | class Notification extends React.Component {
6 | static propTypes = {
7 | type: PropTypes.oneOf(['info', 'success', 'warning', 'error']),
8 | title: PropTypes.node,
9 | message: PropTypes.node,
10 | timeOut: PropTypes.number,
11 | onClick: PropTypes.func,
12 | onRequestHide: PropTypes.func
13 | };
14 |
15 | static defaultProps = {
16 | type: 'info',
17 | title: null,
18 | message: null,
19 | timeOut: 5000,
20 | onClick: () => {
21 | },
22 | onRequestHide: () => {
23 | }
24 | };
25 |
26 | componentDidMount = () => {
27 | const { timeOut } = this.props;
28 | if (timeOut !== 0) {
29 | this.timer = setTimeout(this.requestHide, timeOut);
30 | }
31 | };
32 |
33 | componentWillUnmount = () => {
34 | if (this.timer) {
35 | clearTimeout(this.timer);
36 | }
37 | };
38 |
39 | handleClick = () => {
40 | const { onClick } = this.props;
41 | if (onClick) {
42 | onClick();
43 | }
44 | this.requestHide();
45 | };
46 |
47 | requestHide = () => {
48 | const { onRequestHide } = this.props;
49 | if (onRequestHide) {
50 | onRequestHide();
51 | }
52 | };
53 |
54 | render() {
55 | const { type, message } = this.props;
56 | let { title } = this.props;
57 | const className = classnames(['notification', `notification-${type}`]);
58 | title = title ? ({title}
) : null;
59 | return (
60 |
61 |
62 | {title}
63 |
{message}
64 |
65 |
66 | );
67 | }
68 | }
69 |
70 | export default Notification;
71 |
--------------------------------------------------------------------------------
/src/NotificationContainer.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import NotificationManager from './NotificationManager';
4 | import Notifications from './Notifications';
5 |
6 | class NotificationContainer extends React.Component {
7 | static propTypes = {
8 | enterTimeout: PropTypes.number,
9 | leaveTimeout: PropTypes.number
10 | };
11 |
12 | static defaultProps = {
13 | enterTimeout: 400,
14 | leaveTimeout: 400
15 | };
16 |
17 | state = {
18 | notifications: []
19 | };
20 |
21 | componentDidMount = () => {
22 | NotificationManager.addChangeListener(this.handleStoreChange);
23 | };
24 |
25 | componentWillUnmount = () => {
26 | NotificationManager.removeChangeListener(this.handleStoreChange);
27 | };
28 |
29 | handleStoreChange = (notifications) => {
30 | this.setState({
31 | notifications
32 | });
33 | };
34 |
35 | handleRequestHide = (notification) => {
36 | NotificationManager.remove(notification);
37 | };
38 |
39 | render() {
40 | const { notifications } = this.state;
41 | const { enterTimeout, leaveTimeout } = this.props;
42 | return (
43 |
49 | );
50 | }
51 | }
52 |
53 | export default NotificationContainer;
54 |
--------------------------------------------------------------------------------
/src/NotificationManager.js:
--------------------------------------------------------------------------------
1 | import { EventEmitter } from 'events';
2 |
3 | const createUUID = () => {
4 | const pattern = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
5 | return pattern.replace(/[xy]/g, (c) => {
6 | const r = (Math.random() * 16) | 0;
7 | const v = c === 'x' ? r : ((r & 0x3) | 0x8);
8 | return v.toString(16);
9 | });
10 | };
11 |
12 | const Constants = {
13 | CHANGE: 'change',
14 | INFO: 'info',
15 | SUCCESS: 'success',
16 | WARNING: 'warning',
17 | ERROR: 'error'
18 | };
19 |
20 | class NotificationManager extends EventEmitter {
21 | constructor() {
22 | super();
23 | this.listNotify = [];
24 | }
25 |
26 | create(notify) {
27 | const defaultNotify = {
28 | id: createUUID(),
29 | type: 'info',
30 | title: null,
31 | message: null,
32 | timeOut: 5000
33 | };
34 | if (notify.priority) {
35 | this.listNotify.unshift(Object.assign(defaultNotify, notify));
36 | } else {
37 | this.listNotify.push(Object.assign(defaultNotify, notify));
38 | }
39 | this.emitChange();
40 | }
41 |
42 | info(message, title, timeOut, onClick, priority) {
43 | this.create({
44 | type: Constants.INFO,
45 | message,
46 | title,
47 | timeOut,
48 | onClick,
49 | priority
50 | });
51 | }
52 |
53 | success(message, title, timeOut, onClick, priority) {
54 | this.create({
55 | type: Constants.SUCCESS,
56 | message,
57 | title,
58 | timeOut,
59 | onClick,
60 | priority
61 | });
62 | }
63 |
64 | warning(message, title, timeOut, onClick, priority) {
65 | this.create({
66 | type: Constants.WARNING,
67 | message,
68 | title,
69 | timeOut,
70 | onClick,
71 | priority
72 | });
73 | }
74 |
75 | error(message, title, timeOut, onClick, priority) {
76 | this.create({
77 | type: Constants.ERROR,
78 | message,
79 | title,
80 | timeOut,
81 | onClick,
82 | priority
83 | });
84 | }
85 |
86 | remove(notification) {
87 | this.listNotify = this.listNotify.filter((n) => notification.id !== n.id);
88 | this.emitChange();
89 | }
90 |
91 | removeAll() {
92 | this.listNotify.length = 0;
93 | this.emitChange();
94 | }
95 |
96 | emitChange() {
97 | this.emit(Constants.CHANGE, this.listNotify);
98 | }
99 |
100 | addChangeListener(callback) {
101 | this.addListener(Constants.CHANGE, callback);
102 | }
103 |
104 | removeChangeListener(callback) {
105 | this.removeListener(Constants.CHANGE, callback);
106 | }
107 | }
108 |
109 | export default new NotificationManager();
110 |
--------------------------------------------------------------------------------
/src/Notifications.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import { CSSTransition, TransitionGroup } from 'react-transition-group';
4 | import classnames from 'classnames';
5 | import Notification from './Notification';
6 |
7 | class Notifications extends React.Component {
8 | static propTypes = {
9 | notifications: PropTypes.array,
10 | onRequestHide: PropTypes.func,
11 | enterTimeout: PropTypes.number,
12 | leaveTimeout: PropTypes.number
13 | };
14 |
15 | static defaultProps = {
16 | notifications: [],
17 | onRequestHide: () => {
18 | },
19 | enterTimeout: 400,
20 | leaveTimeout: 400
21 | };
22 |
23 | handleRequestHide = (notification) => () => {
24 | const { onRequestHide } = this.props;
25 | if (onRequestHide) {
26 | onRequestHide(notification);
27 | }
28 | };
29 |
30 | render() {
31 | const { notifications, enterTimeout, leaveTimeout } = this.props;
32 | const className = classnames('notification-container', {
33 | 'notification-container-empty': notifications.length === 0
34 | });
35 |
36 | const items = notifications.map((notification) => {
37 | const key = notification.id || new Date().getTime();
38 | return (
39 |
44 |
52 |
53 | );
54 | });
55 | return (
56 |
57 |
58 | {items}
59 |
60 |
61 | );
62 | }
63 | }
64 |
65 | export default Notifications;
66 |
--------------------------------------------------------------------------------
/src/_variables.scss:
--------------------------------------------------------------------------------
1 | $react-notifications-font-base-path: './fonts' !default;
2 |
3 | $react-notifications-transition-time: 0.4s !default;
4 |
5 | $react-notifications-container-top: 0 !default;
6 | $react-notifications-container-right: 0 !default;
7 | $react-notifications-container-z-index: 999999 !default;
8 | $react-notifications-container-width: 320px !default;
9 | $react-notifications-container-top-padding: 0px !default;
10 | $react-notifications-container-max-height: calc(100% - 30px) !default;
11 | $react-notifications-container-right-padding: 15px !default;
12 |
13 | $react-notifications-border-radius: 2px !default;
14 | $react-notifications-padding-top: 15px !default;
15 | $react-notifications-padding-right: 15px !default;
16 | $react-notifications-padding-bottom: 15px !default;
17 | $react-notifications-padding-left: 58px !default;
18 | $react-notifications-color: #fff !default;
19 | $react-notifications-background-color: #ccc !default;
20 | $react-notifications-box-shadow: 0 0 12px #999 !default;
21 | $react-notifications-cursor: pointer !default;
22 | $react-notifications-font-size: 1em !default;
23 | $react-notifications-line-height: 1.2em !default;
24 | $react-notifications-opacity: 0.9 !default;
25 | $react-notifications-margin-top: 15px !default;
26 |
27 | $react-notifications-icon-top: 50% !default;
28 | $react-notifications-icon-left: 15px !default;
29 | $react-notifications-icon-margin-top: -14px !default;
30 | $react-notifications-icon-width: 28px !default;
31 | $react-notifications-icon-height: 28px !default;
32 | $react-notifications-icon-font-size: 28px !default;
33 | $react-notifications-icon-line-height: 28px !default;
34 |
35 | $react-notifications-hover-opacity: 1 !default;
36 |
37 | $react-notifications-title-font-size: 1em !default;
38 | $react-notifications-title-line-height: 1.2em !default;
39 | $react-notifications-title-font-weight: bold !default;
40 | $react-notifications-title-margin: 0 0 5px 0 !default;
41 |
42 | $react-notifications-info-background-color: #2f96b4 !default;
43 | $react-notifications-info-content: "\f05a" !default;
44 | $react-notifications-success-background-color: #51a351 !default;
45 | $react-notifications-success-content: "\f058" !default;
46 | $react-notifications-warning-background-color: #f89406 !default;
47 | $react-notifications-warning-content: "\f06a" !default;
48 | $react-notifications-error-background-color: #bd362f !default;
49 | $react-notifications-error-content: "\f057" !default;
50 |
--------------------------------------------------------------------------------
/src/fonts/notification.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/src/fonts/notification.eot
--------------------------------------------------------------------------------
/src/fonts/notification.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/fonts/notification.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/src/fonts/notification.ttf
--------------------------------------------------------------------------------
/src/fonts/notification.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjrexer/react-notifications/4157e5e6b7874612b7db389b4c7b5c60c76ab192/src/fonts/notification.woff
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import Notifications from './Notifications.js';
2 | import NotificationContainer from './NotificationContainer';
3 | import NotificationManager from './NotificationManager';
4 |
5 | export { Notifications, NotificationContainer, NotificationManager };
6 | export default Notifications;
7 |
--------------------------------------------------------------------------------
/src/notifications.scss:
--------------------------------------------------------------------------------
1 | @import 'variables';
2 |
3 | @font-face {
4 | font-family: 'Notification';
5 | src: url('#{$react-notifications-font-base-path}/notification.eot?s3g3t9');
6 | src: url('#{$react-notifications-font-base-path}/notification.eot?#iefixs3g3t9') format('embedded-opentype'),
7 | url('#{$react-notifications-font-base-path}/notification.woff?s3g3t9') format('woff'),
8 | url('#{$react-notifications-font-base-path}/notification.ttf?s3g3t9') format('truetype'),
9 | url('#{$react-notifications-font-base-path}/notification.svg?s3g3t9#notification') format('svg');
10 | font-weight: normal;
11 | font-style: normal;
12 | }
13 |
14 | .notification-container {
15 | box-sizing: border-box;
16 | position: fixed;
17 | top: $react-notifications-container-top;
18 | right: $react-notifications-container-right;
19 | z-index: $react-notifications-container-z-index;
20 | width: $react-notifications-container-width;
21 | padding: $react-notifications-container-top-padding $react-notifications-container-right-padding;
22 | max-height: $react-notifications-container-max-height;
23 | overflow-x: hidden;
24 | overflow-y: auto;
25 | }
26 |
27 | .notification {
28 | box-sizing: border-box;
29 | padding: $react-notifications-padding-top $react-notifications-padding-right $react-notifications-padding-bottom $react-notifications-padding-left;
30 | border-radius: $react-notifications-border-radius;
31 | color: $react-notifications-color;
32 | background-color: $react-notifications-background-color;
33 | box-shadow: $react-notifications-box-shadow;
34 | cursor: $react-notifications-cursor;
35 | font-size: $react-notifications-font-size;
36 | line-height: $react-notifications-line-height;
37 | position: relative;
38 | opacity: $react-notifications-opacity;
39 | margin-top: $react-notifications-margin-top;
40 | .title {
41 | font-size: $react-notifications-title-font-size;
42 | line-height: $react-notifications-title-line-height;
43 | font-weight: $react-notifications-title-font-weight;
44 | margin: $react-notifications-title-margin;
45 | }
46 | &:hover, &:focus {
47 | opacity: $react-notifications-hover-opacity;
48 | }
49 | }
50 |
51 | .notification-enter {
52 | visibility: hidden;
53 | transform: translate3d(100%, 0, 0);
54 | }
55 |
56 | .notification-enter.notification-enter-active {
57 | visibility: visible;
58 | transform: translate3d(0, 0, 0);
59 | transition: all $react-notifications-transition-time;
60 | }
61 |
62 | .notification-exit {
63 | visibility: visible;
64 | transform: translate3d(0, 0, 0);
65 | }
66 |
67 | .notification-exit.notification-exit-active {
68 | visibility: hidden;
69 | transform: translate3d(100%, 0, 0);
70 | transition: all $react-notifications-transition-time;
71 | }
72 |
73 | .notification {
74 | &:before {
75 | position: absolute;
76 | top: $react-notifications-icon-top;
77 | left: $react-notifications-icon-left;
78 | margin-top: $react-notifications-icon-margin-top;
79 | display: block;
80 | font-family: 'Notification';
81 | width: $react-notifications-icon-width;
82 | height: $react-notifications-icon-height;
83 | font-size: $react-notifications-icon-font-size;
84 | text-align: center;
85 | line-height: $react-notifications-icon-line-height;
86 | }
87 | }
88 |
89 | .notification-info {
90 | background-color: $react-notifications-info-background-color;
91 | &:before {
92 | content: $react-notifications-info-content;
93 | }
94 | }
95 |
96 | .notification-success {
97 | background-color: $react-notifications-success-background-color;
98 | &:before {
99 | content: $react-notifications-success-content;
100 | }
101 | }
102 |
103 | .notification-warning {
104 | background-color: $react-notifications-warning-background-color;
105 | &:before {
106 | content: $react-notifications-warning-content;
107 | }
108 | }
109 |
110 | .notification-error {
111 | background-color: $react-notifications-error-background-color;
112 | &:before {
113 | content: $react-notifications-error-content;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | import webpack from 'webpack';
2 | import path from 'path';
3 | import camelCase from 'camelcase';
4 | import pkg from './package.json';
5 |
6 | const capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
7 |
8 | const webpackConfig = {
9 | mode: 'production',
10 | optimization: {
11 | minimize: false
12 | },
13 | output: {
14 | filename: `${pkg.name}.js`,
15 | library: capitalizeFirstLetter(camelCase(pkg.name)),
16 | libraryTarget: 'umd'
17 | },
18 | externals: {
19 | react: {
20 | root: 'React',
21 | commonjs: 'react',
22 | commonjs2: 'react',
23 | amd: 'react'
24 | },
25 | 'react-transition-group': {
26 | root: ['ReactTransitionGroup'],
27 | commonjs: 'react-transition-group',
28 | commonjs2: 'react-transition-group',
29 | amd: 'react-transition-group'
30 | },
31 | 'prop-types': {
32 | root: 'PropTypes',
33 | commonjs: 'prop-types',
34 | commonjs2: 'prop-types',
35 | amd: 'prop-types'
36 | }
37 | },
38 | module: {
39 | rules: [
40 | {
41 | test: /\.(js|jsx)$/,
42 | exclude: /node_modules/,
43 | use: {
44 | loader: 'eslint-loader',
45 | options: {
46 | configFile: path.join(__dirname, '.eslintrc'),
47 | failOnError: true,
48 | emitError: true
49 | }
50 | },
51 | enforce: 'pre'
52 | },
53 | {
54 | test: /\.(js|jsx)$/,
55 | exclude: /node_modules/,
56 | loader: 'babel-loader'
57 | }
58 | ]
59 | },
60 | resolve: {
61 | modules: ['node_modules'],
62 | extensions: ['.jsx', '.js']
63 | },
64 | plugins: [
65 | new webpack.DefinePlugin({
66 | 'process.env': {
67 | NODE_ENV: JSON.stringify(process.env.NODE_ENV)
68 | }
69 | })
70 | ]
71 | };
72 |
73 | export default webpackConfig;
74 |
--------------------------------------------------------------------------------