reapop-rails 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4eb4d90e60124271068b9ed188476db5895567f7
4
+ data.tar.gz: 46c7cf4c14a780606444d249d5f8be2c25c95852
5
+ SHA512:
6
+ metadata.gz: d96caf02d8c81d9c6a9c464ade2d0e4b1b45f4f9106135773426477f508ac7728c9a8ead978c1aaf2aee5122d52f3ad4210a3576a4328cc47e883a44f393278f
7
+ data.tar.gz: 8fbd0fa58abc750f9af810fb381af1e178895ab80b77176db401064e408bb2321aa86d82705fe35a17fd7b907ad13c8fc39aa0d1ba25fbab7eee3d59e5e1655c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reapop-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 ACT.md
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Reapop::Rails
2
+
3
+ Rails wrapper for Reapop notification JavaScript library (https://github.com/LouisBarranqueiro/reapop). The version number of this gem follows the version number of the original JavaScript library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'reapop-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install reapop-rails
20
+
21
+ ## Usage
22
+
23
+ Add the following code to ``application.js``:
24
+ ```
25
+ //= require reapop
26
+ ```
27
+
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/LouisBarranqueiro/reapop.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,1112 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory(require("React"), require("ReactRedux"));
4
+ else if(typeof define === 'function' && define.amd)
5
+ define(["React", "ReactRedux"], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["reapop"] = factory(require("React"), require("ReactRedux"));
8
+ else
9
+ root["reapop"] = factory(root["React"], root["ReactRedux"]);
10
+ })(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_5__) {
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
+ /******/ exports: {},
25
+ /******/ id: moduleId,
26
+ /******/ loaded: false
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.loaded = 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
+ /******/ // __webpack_public_path__
47
+ /******/ __webpack_require__.p = "";
48
+
49
+ /******/ // Load entry module and return exports
50
+ /******/ return __webpack_require__(0);
51
+ /******/ })
52
+ /************************************************************************/
53
+ /******/ ([
54
+ /* 0 */
55
+ /***/ function(module, exports, __webpack_require__) {
56
+
57
+ 'use strict';
58
+
59
+ Object.defineProperty(exports, "__esModule", {
60
+ value: true
61
+ });
62
+ exports.removeNotification = exports.updateNotification = exports.addNotification = exports.reducer = exports.types = exports.actions = exports.POSITIONS = exports.STATUS = undefined;
63
+
64
+ var _NotificationsSystem = __webpack_require__(8);
65
+
66
+ var _NotificationsSystem2 = _interopRequireDefault(_NotificationsSystem);
67
+
68
+ var _constants = __webpack_require__(1);
69
+
70
+ var _notifications = __webpack_require__(4);
71
+
72
+ var _notifications2 = _interopRequireDefault(_notifications);
73
+
74
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
75
+
76
+ exports.STATUS = _constants.STATUS;
77
+ exports.POSITIONS = _constants.POSITIONS;
78
+ exports.actions = _notifications.actions;
79
+ exports.types = _notifications.types;
80
+ exports.reducer = _notifications2.default;
81
+ exports.addNotification = _notifications.addNotification;
82
+ exports.updateNotification = _notifications.updateNotification;
83
+ exports.removeNotification = _notifications.removeNotification;
84
+ // NotificationsSystem React component
85
+
86
+ exports.default = _NotificationsSystem2.default;
87
+
88
+ /***/ },
89
+ /* 1 */
90
+ /***/ function(module, exports) {
91
+
92
+ 'use strict';
93
+
94
+ Object.defineProperty(exports, "__esModule", {
95
+ value: true
96
+ });
97
+ var DEFAULT_STATUS = exports.DEFAULT_STATUS = 'default';
98
+ var INFO_STATUS = exports.INFO_STATUS = 'info';
99
+ var SUCCESS_STATUS = exports.SUCCESS_STATUS = 'success';
100
+ var WARNING_STATUS = exports.WARNING_STATUS = 'warning';
101
+ var ERROR_STATUS = exports.ERROR_STATUS = 'error';
102
+
103
+ var STATUS = exports.STATUS = {
104
+ default: DEFAULT_STATUS,
105
+ info: INFO_STATUS,
106
+ success: SUCCESS_STATUS,
107
+ warning: WARNING_STATUS,
108
+ error: ERROR_STATUS
109
+ };
110
+
111
+ var TOP = exports.TOP = 't';
112
+ var TOP_CENTER = exports.TOP_CENTER = 'tc';
113
+ var TOP_LEFT_POSITION = exports.TOP_LEFT_POSITION = 'tl';
114
+ var TOP_RIGHT_POSITION = exports.TOP_RIGHT_POSITION = 'tr';
115
+ var BOTTOM = exports.BOTTOM = 'b';
116
+ var BOTTOM_CENTER = exports.BOTTOM_CENTER = 'bc';
117
+ var BOTTOM_LEFT_POSITION = exports.BOTTOM_LEFT_POSITION = 'bl';
118
+ var BOTTOM_RIGHT_POSITION = exports.BOTTOM_RIGHT_POSITION = 'br';
119
+
120
+ var POSITIONS = exports.POSITIONS = {
121
+ top: TOP,
122
+ topCenter: TOP_CENTER,
123
+ topLeft: TOP_LEFT_POSITION,
124
+ topRight: TOP_RIGHT_POSITION,
125
+ bottom: BOTTOM,
126
+ bottomCenter: BOTTOM_CENTER,
127
+ bottomLeft: BOTTOM_LEFT_POSITION,
128
+ bottomRight: BOTTOM_RIGHT_POSITION
129
+ };
130
+
131
+ /***/ },
132
+ /* 2 */
133
+ /***/ function(module, exports, __webpack_require__) {
134
+
135
+ 'use strict';
136
+
137
+ Object.defineProperty(exports, "__esModule", {
138
+ value: true
139
+ });
140
+ exports.convertStatus = convertStatus;
141
+ exports.Timer = Timer;
142
+ exports.treatNotification = treatNotification;
143
+ exports.preloadImage = preloadImage;
144
+ exports.mapObjectValues = mapObjectValues;
145
+
146
+ var _constants = __webpack_require__(1);
147
+
148
+ /**
149
+ * Convert status in a understandable status for the Notification component
150
+ * @param {String|Number} status
151
+ * @returns {String} status an understandable status
152
+ */
153
+ function convertStatus(status) {
154
+ var reHttpStatusCode = /^\d{3}$/;
155
+ // convert HTTP status code
156
+ if (reHttpStatusCode.test(status)) {
157
+ switch (true) {
158
+ case /^1/.test(status):
159
+ return _constants.STATUS.info;
160
+ case /^2/.test(status):
161
+ return _constants.STATUS.success;
162
+ case /^(4|5)/.test(status):
163
+ return _constants.STATUS.error;
164
+ }
165
+ }
166
+ return status;
167
+ }
168
+
169
+ /**
170
+ * Create a Timer
171
+ * @param {Function} callback
172
+ * @param {Number} delay
173
+ * @constructor
174
+ */
175
+ function Timer(callback, delay) {
176
+ var timerId = void 0;
177
+ var start = void 0;
178
+ var remaining = delay;
179
+
180
+ this.pause = function () {
181
+ clearTimeout(timerId);
182
+ remaining -= new Date() - start;
183
+ };
184
+ this.resume = function () {
185
+ start = new Date();
186
+ clearTimeout(timerId);
187
+ timerId = setTimeout(callback, remaining);
188
+ };
189
+
190
+ this.getTimeRemaining = function () {
191
+ return remaining;
192
+ };
193
+ }
194
+
195
+ /**
196
+ * Treat data of a notification
197
+ * @param {Object} notification
198
+ * @returns {Object} a notification
199
+ */
200
+ function treatNotification(notification) {
201
+ if (notification.dismissAfter) {
202
+ notification.dismissAfter = parseInt(notification.dismissAfter);
203
+ }
204
+ if (notification.image) {
205
+ notification.status = _constants.STATUS.default;
206
+ } else {
207
+ notification.status = convertStatus(notification.status);
208
+ }
209
+ if (!notification.buttons) {
210
+ notification.buttons = [];
211
+ }
212
+ return notification;
213
+ }
214
+
215
+ /**
216
+ * Preload an image
217
+ * @param {String} url url of image to load
218
+ * @param {Function} onload Function called when image is loaded
219
+ * @returns {void}
220
+ */
221
+ function preloadImage(url, onload) {
222
+ var image = new Image();
223
+ image.src = url;
224
+ image.onload = onload;
225
+ return image;
226
+ }
227
+
228
+ /**
229
+ * Return values of an Object in an Array
230
+ * @param {Object} obj
231
+ * @returns {Array}
232
+ */
233
+ function mapObjectValues(obj) {
234
+ var array = [];
235
+
236
+ for (var key in obj) {
237
+ if (obj.hasOwnProperty(key)) {
238
+ array.push(obj[key]);
239
+ }
240
+ }
241
+ return array;
242
+ }
243
+
244
+ /***/ },
245
+ /* 3 */
246
+ /***/ function(module, exports) {
247
+
248
+ module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
249
+
250
+ /***/ },
251
+ /* 4 */
252
+ /***/ function(module, exports, __webpack_require__) {
253
+
254
+ 'use strict';
255
+
256
+ Object.defineProperty(exports, "__esModule", {
257
+ value: true
258
+ });
259
+ exports.types = exports.actions = exports.updateNotification = exports.addNotification = undefined;
260
+ exports.removeNotification = removeNotification;
261
+
262
+ var _helpers = __webpack_require__(2);
263
+
264
+ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
265
+
266
+ // An array to store notifications object
267
+ var INITIAL_STATE = [];
268
+ // Action types
269
+ var ADD_NOTIFICATION = 'ADD_NOTIFICATION';
270
+ var UPDATE_NOTIFICATION = 'UPDATE_NOTIFICATION';
271
+ var REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
272
+
273
+ /**
274
+ * Add a notification (thunk action creator)
275
+ *
276
+ * We use a thunk here to create an ADD_NOTIFICATION action
277
+ * and only return the notification object.
278
+ * @param {Object} notification
279
+ * @returns {Object} notification
280
+ */
281
+ var addNotification = exports.addNotification = function addNotification(notification) {
282
+ return function (dispatch) {
283
+ if (!notification.id) {
284
+ notification.id = new Date().getTime();
285
+ }
286
+ notification = (0, _helpers.treatNotification)(notification);
287
+ // if there is an image, we preload it
288
+ // and add notification when image is loaded
289
+ if (notification.image) {
290
+ (0, _helpers.preloadImage)(notification.image, dispatch.bind(undefined, _addNotification(notification)));
291
+ } else {
292
+ dispatch(_addNotification(notification));
293
+ }
294
+ return notification;
295
+ };
296
+ };
297
+
298
+ /**
299
+ * Add a notification (action creator)
300
+ *
301
+ * @param {Object} notification
302
+ * @returns {{type: string, payload: {Object}}}
303
+ * @private
304
+ */
305
+ function _addNotification(notification) {
306
+ return {
307
+ type: ADD_NOTIFICATION,
308
+ payload: notification
309
+ };
310
+ }
311
+
312
+ /**
313
+ * Update a notification (thunk action creator)
314
+ *
315
+ * We use a thunk here to create an UPDATE_NOTIFICATION action
316
+ * and only return the notification object.
317
+ * @param {Object} notification
318
+ * @returns {Object} notification
319
+ */
320
+ var updateNotification = exports.updateNotification = function updateNotification(notification) {
321
+ return function (dispatch, getState) {
322
+ if (!notification.id) {
323
+ throw new Error('A notification must have an `id` property to be updated');
324
+ }
325
+
326
+ var notifications = getState().notifications;
327
+ var index = notifications.findIndex(function (oldNotification) {
328
+ return oldNotification.id === notification.id;
329
+ });
330
+ var currNotification = notifications[index];
331
+
332
+ notification = (0, _helpers.treatNotification)(notification);
333
+
334
+ // if image is different, then we preload it
335
+ // and update notification when image is loaded
336
+ if (notification.image && (!currNotification.image || currNotification.image && notification.image !== currNotification.image)) {
337
+ (0, _helpers.preloadImage)(notification.image, dispatch.bind(undefined, _updateNotification(notification)));
338
+ } else {
339
+ dispatch(_updateNotification(notification));
340
+ }
341
+ return notification;
342
+ };
343
+ };
344
+
345
+ /**
346
+ * Update a notification (action creator)
347
+ *
348
+ * @param {Object} notification
349
+ * @returns {{type: string, payload: {Object}}}
350
+ * @private
351
+ */
352
+ function _updateNotification(notification) {
353
+ return {
354
+ type: UPDATE_NOTIFICATION,
355
+ payload: notification
356
+ };
357
+ }
358
+
359
+ /**
360
+ * Remove a notification (action creator)
361
+ *
362
+ * @param {Object} notification
363
+ * @returns {{type: string, payload: {Object}}}
364
+ */
365
+ function removeNotification(notification) {
366
+ return {
367
+ type: REMOVE_NOTIFICATION,
368
+ payload: notification
369
+ };
370
+ }
371
+
372
+ // Action creators
373
+ var actions = exports.actions = {
374
+ addNotification: addNotification,
375
+ updateNotification: updateNotification,
376
+ removeNotification: removeNotification
377
+ };
378
+
379
+ // Actions types
380
+ var types = exports.types = {
381
+ ADD_NOTIFICATION: ADD_NOTIFICATION,
382
+ UPDATE_NOTIFICATION: UPDATE_NOTIFICATION,
383
+ REMOVE_NOTIFICATION: REMOVE_NOTIFICATION
384
+ };
385
+
386
+ // Reducers
387
+
388
+ exports.default = function () {
389
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INITIAL_STATE;
390
+ var _ref = arguments[1];
391
+ var type = _ref.type,
392
+ payload = _ref.payload;
393
+
394
+ switch (type) {
395
+ case ADD_NOTIFICATION:
396
+ return [].concat(_toConsumableArray(state), [payload]);
397
+ case UPDATE_NOTIFICATION:
398
+ // get index of the notification
399
+ var index = state.findIndex(function (notification) {
400
+ return notification.id === payload.id;
401
+ });
402
+ // replace the old notification by the new one
403
+ state[index] = Object.assign({}, payload);
404
+ return [].concat(_toConsumableArray(state));
405
+ case REMOVE_NOTIFICATION:
406
+ return state.filter(function (notification) {
407
+ return notification.id !== payload;
408
+ });
409
+ default:
410
+ return state;
411
+ }
412
+ };
413
+
414
+ /***/ },
415
+ /* 5 */
416
+ /***/ function(module, exports) {
417
+
418
+ module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
419
+
420
+ /***/ },
421
+ /* 6 */
422
+ /***/ function(module, exports, __webpack_require__) {
423
+
424
+ 'use strict';
425
+
426
+ Object.defineProperty(exports, "__esModule", {
427
+ value: true
428
+ });
429
+ exports.Notification = undefined;
430
+
431
+ var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
432
+
433
+ var _react = __webpack_require__(3);
434
+
435
+ var _react2 = _interopRequireDefault(_react);
436
+
437
+ var _reactRedux = __webpack_require__(5);
438
+
439
+ var _helpers = __webpack_require__(2);
440
+
441
+ var _notifications = __webpack_require__(4);
442
+
443
+ var _constants = __webpack_require__(1);
444
+
445
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
446
+
447
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
448
+
449
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
450
+
451
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
452
+
453
+ /**
454
+ * Create a timer
455
+ * @param {Number} dismissAfter
456
+ * @param {Array} buttons
457
+ * @param {Function} callback
458
+ * @returns {Function|null} a Timer
459
+ */
460
+ function createTimer(dismissAfter, buttons, callback) {
461
+ if (dismissAfter > 0 && (!buttons || buttons && buttons.length === 0)) {
462
+ return new _helpers.Timer(callback, dismissAfter);
463
+ }
464
+ return null;
465
+ }
466
+
467
+ var Notification = exports.Notification = function (_Component) {
468
+ _inherits(Notification, _Component);
469
+
470
+ /**
471
+ * Constructor
472
+ * Bind methods
473
+ * @param {Object} props
474
+ * @returns {void}
475
+ */
476
+ function Notification(props) {
477
+ _classCallCheck(this, Notification);
478
+
479
+ var _props$notification = props.notification,
480
+ dismissAfter = _props$notification.dismissAfter,
481
+ buttons = _props$notification.buttons;
482
+
483
+ var _this = _possibleConstructorReturn(this, (Notification.__proto__ || Object.getPrototypeOf(Notification)).call(this, props));
484
+
485
+ _this._remove = _this._remove.bind(_this);
486
+ _this._pauseTimer = _this._pauseTimer.bind(_this);
487
+ _this._resumeTimer = _this._resumeTimer.bind(_this);
488
+ _this.state = {
489
+ timer: createTimer(dismissAfter, buttons, _this._remove)
490
+ };
491
+ return _this;
492
+ }
493
+
494
+ /**
495
+ * Run `onAdd` callback function when component is mounted
496
+ * @returns {void}
497
+ */
498
+
499
+ // Properties types
500
+
501
+
502
+ _createClass(Notification, [{
503
+ key: 'componentDidMount',
504
+ value: function componentDidMount() {
505
+ var onAdd = this.props.notification.onAdd;
506
+
507
+ if (typeof onAdd === 'function') {
508
+ onAdd();
509
+ }
510
+ }
511
+
512
+ /**
513
+ * Run `onRemove` callback function when component will unmount
514
+ * @returns {void}
515
+ */
516
+
517
+ }, {
518
+ key: 'componentWillUnmount',
519
+ value: function componentWillUnmount() {
520
+ var onRemove = this.props.notification.onRemove;
521
+
522
+ if (typeof onRemove === 'function') {
523
+ onRemove();
524
+ }
525
+ }
526
+
527
+ /**
528
+ * Update timer
529
+ * @param {Object} nextProps
530
+ * @returns {void}
531
+ */
532
+
533
+ }, {
534
+ key: 'componentWillReceiveProps',
535
+ value: function componentWillReceiveProps(nextProps) {
536
+ var _nextProps$notificati = nextProps.notification,
537
+ dismissAfter = _nextProps$notificati.dismissAfter,
538
+ buttons = _nextProps$notificati.buttons;
539
+
540
+ this.setState({
541
+ timer: createTimer(dismissAfter, buttons, this._remove)
542
+ });
543
+ }
544
+
545
+ /**
546
+ * Remove the notification
547
+ * @private
548
+ * @returns {void}
549
+ */
550
+
551
+ }, {
552
+ key: '_remove',
553
+ value: function _remove() {
554
+ var _props = this.props,
555
+ removeNotification = _props.removeNotification,
556
+ id = _props.notification.id;
557
+
558
+ removeNotification(id);
559
+ }
560
+
561
+ /**
562
+ * Pauses the timer
563
+ * @returns {void}
564
+ * @private
565
+ */
566
+
567
+ }, {
568
+ key: '_pauseTimer',
569
+ value: function _pauseTimer() {
570
+ var timer = this.state.timer;
571
+
572
+ timer.pause();
573
+ }
574
+
575
+ /**
576
+ * Resumes the timer
577
+ * @returns {void}
578
+ * @private
579
+ */
580
+
581
+ }, {
582
+ key: '_resumeTimer',
583
+ value: function _resumeTimer() {
584
+ var timer = this.state.timer;
585
+
586
+ timer.resume();
587
+ }
588
+
589
+ /**
590
+ * Wrap content in an object ready for HTML
591
+ * @param {String} content a text
592
+ * @returns {Object}
593
+ * @private
594
+ */
595
+
596
+ }, {
597
+ key: '_setHTML',
598
+ value: function _setHTML(content) {
599
+ return {
600
+ __html: content
601
+ };
602
+ }
603
+
604
+ /**
605
+ * Render button(s)
606
+ * @returns {*}
607
+ */
608
+
609
+ }, {
610
+ key: '_renderButtons',
611
+ value: function _renderButtons() {
612
+ var _props2 = this.props,
613
+ className = _props2.className,
614
+ buttons = _props2.notification.buttons;
615
+
616
+
617
+ return buttons.map(function (button) {
618
+ return _react2.default.createElement(
619
+ 'button',
620
+ { key: button.name, className: className.button, onClick: button.onClick },
621
+ _react2.default.createElement(
622
+ 'span',
623
+ { className: className.buttonText },
624
+ button.primary ? _react2.default.createElement(
625
+ 'b',
626
+ null,
627
+ button.name
628
+ ) : button.name
629
+ )
630
+ );
631
+ });
632
+ }
633
+
634
+ /**
635
+ * Render
636
+ * @returns {XML}
637
+ */
638
+
639
+ }, {
640
+ key: 'render',
641
+ value: function render() {
642
+ var _props3 = this.props,
643
+ className = _props3.className,
644
+ _props3$notification = _props3.notification,
645
+ title = _props3$notification.title,
646
+ message = _props3$notification.message,
647
+ status = _props3$notification.status,
648
+ dismissible = _props3$notification.dismissible,
649
+ closeButton = _props3$notification.closeButton,
650
+ buttons = _props3$notification.buttons,
651
+ image = _props3$notification.image,
652
+ allowHTML = _props3$notification.allowHTML;
653
+ var timer = this.state.timer;
654
+
655
+ var isDismissible = dismissible && buttons.length === 0;
656
+
657
+ if (timer) {
658
+ this._resumeTimer();
659
+ }
660
+
661
+ return _react2.default.createElement(
662
+ 'div',
663
+ { className: className.wrapper,
664
+ onClick: isDismissible && !closeButton ? this._remove : '',
665
+ onMouseEnter: timer ? this._pauseTimer : '',
666
+ onMouseLeave: timer ? this._resumeTimer : '' },
667
+ _react2.default.createElement(
668
+ 'div',
669
+ { className: className.main + ' ' + className.status(status) + ' ' + ((isDismissible && !closeButton ? className.dismissible : '') + ' ') + ('' + className.buttons(buttons.length)) },
670
+ image ? _react2.default.createElement(
671
+ 'div',
672
+ { className: className.imageContainer },
673
+ _react2.default.createElement('span', { className: className.image, style: { backgroundImage: 'url(' + image + ')' } })
674
+ ) : _react2.default.createElement('span', { className: className.icon }),
675
+ _react2.default.createElement(
676
+ 'div',
677
+ { className: className.meta },
678
+ title ? allowHTML ? _react2.default.createElement('h4', { className: className.title, dangerouslySetInnerHTML: this._setHTML(title) }) : _react2.default.createElement(
679
+ 'h4',
680
+ { className: className.title },
681
+ title
682
+ ) : '',
683
+ message ? allowHTML ? _react2.default.createElement('p', { className: className.message, dangerouslySetInnerHTML: this._setHTML(message) }) : _react2.default.createElement(
684
+ 'p',
685
+ { className: className.message },
686
+ message
687
+ ) : ''
688
+ ),
689
+ isDismissible && closeButton ? _react2.default.createElement(
690
+ 'div',
691
+ { className: className.closeButtonContainer },
692
+ _react2.default.createElement('span', { className: className.closeButton, onClick: this._remove })
693
+ ) : '',
694
+ buttons.length ? _react2.default.createElement(
695
+ 'div',
696
+ { className: className.buttons(), onClick: this._remove },
697
+ this._renderButtons()
698
+ ) : ''
699
+ )
700
+ );
701
+ }
702
+ }]);
703
+
704
+ return Notification;
705
+ }(_react.Component);
706
+
707
+ Notification.propTypes = {
708
+ className: _react2.default.PropTypes.shape({
709
+ main: _react2.default.PropTypes.string.isRequired,
710
+ wrapper: _react2.default.PropTypes.string.isRequired,
711
+ meta: _react2.default.PropTypes.string.isRequired,
712
+ title: _react2.default.PropTypes.string.isRequired,
713
+ message: _react2.default.PropTypes.string.isRequired,
714
+ imageContainer: _react2.default.PropTypes.string.isRequired,
715
+ image: _react2.default.PropTypes.string.isRequired,
716
+ icon: _react2.default.PropTypes.string.isRequired,
717
+ status: _react2.default.PropTypes.func.isRequired,
718
+ dismissible: _react2.default.PropTypes.string.isRequired,
719
+ closeButtonContainer: _react2.default.PropTypes.string.isRequired,
720
+ closeButton: _react2.default.PropTypes.string.isRequired,
721
+ buttons: _react2.default.PropTypes.func.isRequired,
722
+ button: _react2.default.PropTypes.string.isRequired,
723
+ buttonText: _react2.default.PropTypes.string.isRequired
724
+ }).isRequired,
725
+ notification: _react2.default.PropTypes.shape({
726
+ id: _react2.default.PropTypes.string.isRequired,
727
+ title: _react2.default.PropTypes.string,
728
+ message: _react2.default.PropTypes.string,
729
+ image: _react2.default.PropTypes.string,
730
+ status: _react2.default.PropTypes.string.isRequired,
731
+ position: _react2.default.PropTypes.oneOf((0, _helpers.mapObjectValues)(_constants.POSITIONS)),
732
+ dismissAfter: _react2.default.PropTypes.number.isRequired,
733
+ dismissible: _react2.default.PropTypes.bool.isRequired,
734
+ onAdd: _react2.default.PropTypes.func,
735
+ onRemove: _react2.default.PropTypes.func,
736
+ closeButton: _react2.default.PropTypes.bool.isRequired,
737
+ buttons: _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.shape({
738
+ name: _react2.default.PropTypes.string.isRequired,
739
+ onClick: _react2.default.PropTypes.func
740
+ })).isRequired,
741
+ allowHTML: _react2.default.PropTypes.bool.isRequired
742
+ }).isRequired,
743
+ removeNotification: _react2.default.PropTypes.func.isRequired
744
+ };
745
+ exports.default = (0, _reactRedux.connect)(null, { removeNotification: _notifications.removeNotification })(Notification);
746
+
747
+ /***/ },
748
+ /* 7 */
749
+ /***/ function(module, exports, __webpack_require__) {
750
+
751
+ 'use strict';
752
+
753
+ Object.defineProperty(exports, "__esModule", {
754
+ value: true
755
+ });
756
+ exports.NotificationsContainer = undefined;
757
+
758
+ var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
759
+
760
+ var _react = __webpack_require__(3);
761
+
762
+ var _react2 = _interopRequireDefault(_react);
763
+
764
+ var _helpers = __webpack_require__(2);
765
+
766
+ var _Notification = __webpack_require__(6);
767
+
768
+ var _Notification2 = _interopRequireDefault(_Notification);
769
+
770
+ var _constants = __webpack_require__(1);
771
+
772
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
773
+
774
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
775
+
776
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
777
+
778
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
779
+
780
+ var NotificationsContainer = exports.NotificationsContainer = function (_Component) {
781
+ _inherits(NotificationsContainer, _Component);
782
+
783
+ /**
784
+ * Constructor
785
+ * Bind methods
786
+ * @param {Object} props
787
+ * @returns {void}
788
+ */
789
+
790
+ // default types
791
+ function NotificationsContainer(props) {
792
+ _classCallCheck(this, NotificationsContainer);
793
+
794
+ var _this = _possibleConstructorReturn(this, (NotificationsContainer.__proto__ || Object.getPrototypeOf(NotificationsContainer)).call(this, props));
795
+
796
+ _this._renderNotifications = _this._renderNotifications.bind(_this);
797
+ return _this;
798
+ }
799
+
800
+ /**
801
+ * Render notifications
802
+ * @private
803
+ * @returns {XML}
804
+ */
805
+
806
+
807
+ // Properties types
808
+
809
+
810
+ _createClass(NotificationsContainer, [{
811
+ key: '_renderNotifications',
812
+ value: function _renderNotifications() {
813
+ // get all notifications and default values for notifications
814
+ var _props = this.props,
815
+ position = _props.position,
816
+ className = _props.theme.notification.className,
817
+ _props$defaultValues = _props.defaultValues,
818
+ status = _props$defaultValues.status,
819
+ dismissible = _props$defaultValues.dismissible,
820
+ dismissAfter = _props$defaultValues.dismissAfter,
821
+ closeButton = _props$defaultValues.closeButton,
822
+ allowHTML = _props$defaultValues.allowHTML;
823
+ var notifications = this.props.notifications;
824
+
825
+ // when notifications are displayed at the bottom,
826
+ // we display notifications from bottom to top
827
+
828
+ if ([_constants.POSITIONS.bottomLeft, _constants.POSITIONS.bottomRight, _constants.POSITIONS.bottomCenter, _constants.POSITIONS.bottom].indexOf(position) >= 0) {
829
+ notifications = notifications.reverse();
830
+ }
831
+
832
+ return notifications.map(function (notification) {
833
+ // Define default values for notification if it's needed
834
+ if (!notification.status) {
835
+ notification.status = status;
836
+ }
837
+ if (typeof notification.dismissible !== 'boolean') {
838
+ notification.dismissible = dismissible;
839
+ }
840
+ if (typeof notification.dismissAfter !== 'number') {
841
+ notification.dismissAfter = dismissAfter;
842
+ }
843
+ if (typeof notification.closeButton !== 'boolean') {
844
+ notification.closeButton = closeButton;
845
+ }
846
+ if (typeof notification.allowHTML !== 'boolean') {
847
+ notification.allowHTML = allowHTML;
848
+ }
849
+ return _react2.default.createElement(_Notification2.default, { key: notification.id, notification: notification, className: className });
850
+ });
851
+ }
852
+
853
+ /**
854
+ * Render
855
+ * @returns {XML}
856
+ */
857
+
858
+ }, {
859
+ key: 'render',
860
+ value: function render() {
861
+ var _props$theme$notifica = this.props.theme.notificationsContainer,
862
+ className = _props$theme$notifica.className,
863
+ _props$theme$notifica2 = _props$theme$notifica.transition,
864
+ name = _props$theme$notifica2.name,
865
+ enterTimeout = _props$theme$notifica2.enterTimeout,
866
+ leaveTimeout = _props$theme$notifica2.leaveTimeout;
867
+ var position = this.props.position;
868
+
869
+
870
+ return _react2.default.createElement(
871
+ 'div',
872
+ { className: className.main + ' ' + className.position(position) },
873
+ _react2.default.createElement(
874
+ _react2.default.addons.CSSTransitionGroup,
875
+ { transitionName: name, transitionEnterTimeout: enterTimeout,
876
+ transitionLeaveTimeout: leaveTimeout },
877
+ this._renderNotifications()
878
+ )
879
+ );
880
+ }
881
+ }]);
882
+
883
+ return NotificationsContainer;
884
+ }(_react.Component);
885
+
886
+ NotificationsContainer.defaultProps = {
887
+ notifications: []
888
+ };
889
+ NotificationsContainer.propTypes = {
890
+ notifications: _react2.default.PropTypes.array.isRequired,
891
+ position: _react2.default.PropTypes.string.isRequired,
892
+ defaultValues: _react2.default.PropTypes.shape({
893
+ status: _react2.default.PropTypes.string.isRequired,
894
+ position: _react2.default.PropTypes.oneOf((0, _helpers.mapObjectValues)(_constants.POSITIONS)),
895
+ dismissible: _react2.default.PropTypes.bool.isRequired,
896
+ dismissAfter: _react2.default.PropTypes.number.isRequired,
897
+ closeButton: _react2.default.PropTypes.bool.isRequired,
898
+ allowHTML: _react2.default.PropTypes.bool.isRequired
899
+ }).isRequired,
900
+ theme: _react2.default.PropTypes.shape({
901
+ notificationsContainer: _react2.default.PropTypes.shape({
902
+ className: _react2.default.PropTypes.shape({
903
+ main: _react2.default.PropTypes.string.isRequired,
904
+ position: _react2.default.PropTypes.func.isRequired
905
+ }).isRequired,
906
+ transition: _react2.default.PropTypes.shape({
907
+ name: _react2.default.PropTypes.object.isRequired,
908
+ enterTimeout: _react2.default.PropTypes.number.isRequired,
909
+ leaveTimeout: _react2.default.PropTypes.number.isRequired
910
+ }).isRequired
911
+ }).isRequired,
912
+ notification: _react2.default.PropTypes.shape({
913
+ className: _react2.default.PropTypes.object.isRequired
914
+ }).isRequired
915
+ }).isRequired
916
+ };
917
+ exports.default = NotificationsContainer;
918
+
919
+ /***/ },
920
+ /* 8 */
921
+ /***/ function(module, exports, __webpack_require__) {
922
+
923
+ 'use strict';
924
+
925
+ Object.defineProperty(exports, "__esModule", {
926
+ value: true
927
+ });
928
+ exports.NotificationsSystem = exports.defaultValues = undefined;
929
+
930
+ var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
931
+
932
+ var _react = __webpack_require__(3);
933
+
934
+ var _react2 = _interopRequireDefault(_react);
935
+
936
+ var _reactRedux = __webpack_require__(5);
937
+
938
+ var _helpers = __webpack_require__(2);
939
+
940
+ var _NotificationsContainer = __webpack_require__(7);
941
+
942
+ var _NotificationsContainer2 = _interopRequireDefault(_NotificationsContainer);
943
+
944
+ var _constants = __webpack_require__(1);
945
+
946
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
947
+
948
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
949
+
950
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
951
+
952
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
953
+
954
+ // default value for notifications
955
+ var defaultValues = exports.defaultValues = {
956
+ status: _constants.STATUS.default,
957
+ position: _constants.POSITIONS.topRight,
958
+ dismissible: true,
959
+ dismissAfter: 5000,
960
+ allowHTML: false,
961
+ closeButton: false
962
+ };
963
+
964
+ var NotificationsSystem = exports.NotificationsSystem = function (_Component) {
965
+ _inherits(NotificationsSystem, _Component);
966
+
967
+ // default properties
968
+ function NotificationsSystem(props) {
969
+ _classCallCheck(this, NotificationsSystem);
970
+
971
+ var _this = _possibleConstructorReturn(this, (NotificationsSystem.__proto__ || Object.getPrototypeOf(NotificationsSystem)).call(this, props));
972
+
973
+ _this._updateWindowWidth = _this._updateWindowWidth.bind(_this);
974
+ _this._renderNotificationsContainers = _this._renderNotificationsContainers.bind(_this);
975
+ _this.state = {
976
+ windowWidth: window.innerWidth
977
+ };
978
+ return _this;
979
+ }
980
+
981
+ /**
982
+ * Update window width
983
+ * @returns {void}
984
+ * @private
985
+ */
986
+
987
+
988
+ // properties types
989
+
990
+
991
+ _createClass(NotificationsSystem, [{
992
+ key: '_updateWindowWidth',
993
+ value: function _updateWindowWidth() {
994
+ this.setState({ windowWidth: window.innerWidth });
995
+ }
996
+
997
+ /**
998
+ * Add resize listener to update window width when the window is resized
999
+ * @returns {void}
1000
+ */
1001
+
1002
+ }, {
1003
+ key: 'componentDidMount',
1004
+ value: function componentDidMount() {
1005
+ window.addEventListener('resize', this._updateWindowWidth);
1006
+ }
1007
+
1008
+ /**
1009
+ * Remove resize listener
1010
+ * @returns {void}
1011
+ */
1012
+
1013
+ }, {
1014
+ key: 'componentWillUnmount',
1015
+ value: function componentWillUnmount() {
1016
+ window.removeEventListener('resize', this._updateWindowWidth);
1017
+ }
1018
+
1019
+ /**
1020
+ * Render notifications containers
1021
+ * @returns {XML}
1022
+ * @private
1023
+ */
1024
+
1025
+ }, {
1026
+ key: '_renderNotificationsContainers',
1027
+ value: function _renderNotificationsContainers() {
1028
+ var _props = this.props,
1029
+ notifications = _props.notifications,
1030
+ position = _props.defaultValues.position,
1031
+ theme = _props.theme;
1032
+ var windowWidth = this.state.windowWidth;
1033
+ // render all notifications in the same container at the top for small screens
1034
+
1035
+ if (windowWidth < theme.smallScreenMin) {
1036
+ return _react2.default.createElement(_NotificationsContainer2.default, { key: 't', position: 't', defaultValues: defaultValues,
1037
+ theme: theme, notifications: notifications });
1038
+ }
1039
+ var positions = (0, _helpers.mapObjectValues)(_constants.POSITIONS);
1040
+ // extract the default position of all positions
1041
+ positions.splice(positions.indexOf(position), 1);
1042
+ var notifs = notifications.filter(function (notif) {
1043
+ return !notif.position || notif.position === position;
1044
+ });
1045
+ // init array with all notifications with default position
1046
+ var JSX = [_react2.default.createElement(_NotificationsContainer2.default, { key: position, position: position, defaultValues: defaultValues,
1047
+ theme: theme, notifications: notifs })];
1048
+ // fill array with others containers
1049
+ JSX = JSX.concat(positions.map(function (position) {
1050
+ var notifs = notifications.filter(function (notif) {
1051
+ return position === notif.position;
1052
+ });
1053
+ return _react2.default.createElement(_NotificationsContainer2.default, { key: position, position: position, defaultValues: defaultValues,
1054
+ theme: theme, notifications: notifs });
1055
+ }));
1056
+ return JSX;
1057
+ }
1058
+
1059
+ /**
1060
+ * Render
1061
+ * @returns {XML}
1062
+ */
1063
+
1064
+ }, {
1065
+ key: 'render',
1066
+ value: function render() {
1067
+ var className = this.props.theme.notificationsSystem.className;
1068
+
1069
+ return _react2.default.createElement(
1070
+ 'div',
1071
+ { className: className },
1072
+ this._renderNotificationsContainers()
1073
+ );
1074
+ }
1075
+ }]);
1076
+
1077
+ return NotificationsSystem;
1078
+ }(_react.Component);
1079
+
1080
+ /**
1081
+ * Map state to props
1082
+ * @param {Object} state
1083
+ * @returns {{notifications: {Array}}}
1084
+ */
1085
+
1086
+
1087
+ NotificationsSystem.defaultProps = {
1088
+ notifications: [],
1089
+ defaultValues: defaultValues
1090
+ };
1091
+ NotificationsSystem.propTypes = {
1092
+ notifications: _react2.default.PropTypes.array.isRequired,
1093
+ defaultValues: _react2.default.PropTypes.object.isRequired,
1094
+ theme: _react2.default.PropTypes.shape({
1095
+ smallScreenMin: _react2.default.PropTypes.number.isRequired,
1096
+ notificationsSystem: _react2.default.PropTypes.shape({
1097
+ className: _react2.default.PropTypes.string.isRequired
1098
+ })
1099
+ }).isRequired
1100
+ };
1101
+ function mapStateToProps(state) {
1102
+ return {
1103
+ notifications: state.notifications
1104
+ };
1105
+ }
1106
+
1107
+ exports.default = (0, _reactRedux.connect)(mapStateToProps)(NotificationsSystem);
1108
+
1109
+ /***/ }
1110
+ /******/ ])
1111
+ });
1112
+ ;