Notifications.js
7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import React from 'react';
import {
Row, Col, Button,
} from 'reactstrap';
/* eslint-disable */
import 'imports-loader?$=jquery,this=>window!messenger/build/js/messenger';
/* eslint-enable */
import Widget from '../../../components/Widget';
import s from './Notifications.module.scss';
// todo @franckeeva what about server side rendering? this will fail unless launched as lazy route
const Messenger = window.Messenger;
/* eslint-disable */
function initializationMessengerCode() {
(function () {
let $,
FlatMessage,
spinner_template,
__hasProp = {}.hasOwnProperty,
__extends = function (child, parent) {
for (const key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
};
$ = jQuery;
spinner_template = '<div class="messenger-spinner">\n <span class="messenger-spinner-side messenger-spinner-side-left">\n <span class="messenger-spinner-fill"></span>\n </span>\n <span class="messenger-spinner-side messenger-spinner-side-right">\n <span class="messenger-spinner-fill"></span>\n </span>\n</div>';
FlatMessage = (function (_super) {
__extends(FlatMessage, _super);
function FlatMessage() {
return FlatMessage.__super__.constructor.apply(this, arguments);
}
FlatMessage.prototype.template = function (opts) {
let $message;
$message = FlatMessage.__super__.template.apply(this, arguments);
$message.append($(spinner_template));
return $message;
};
return FlatMessage;
}(Messenger.Message));
Messenger.themes.air = {
Message: FlatMessage,
};
}).call(window);
}
/* eslint-enable */
class Notifications extends React.Component {
constructor() {
super();
this.addSuccessNotification = this.addSuccessNotification.bind(this);
this.addInfoNotification = this.addInfoNotification.bind(this);
this.addErrorNotification = this.addErrorNotification.bind(this);
this.toggleLocation = this.toggleLocation.bind(this);
this.state = {
locationClasses: 'messenger-fixed messenger-on-bottom messenger-on-right',
};
}
componentDidMount() {
initializationMessengerCode();
Messenger.options = {
extraClasses: this.state.locationClasses,
theme: 'air',
};
Messenger().post('Thanks for checking out Messenger!');
}
addSuccessNotification() {
Messenger().post({
extraClasses: this.state.locationClasses,
message: 'Showing success message was successful!',
type: 'success',
showCloseButton: true,
});
return false;
}
addInfoNotification() {
const msg = Messenger().post({
extraClasses: this.state.locationClasses,
message: 'Launching thermonuclear war...',
actions: {
cancel: {
label: 'cancel launch',
action: () => msg.update({
message: 'Thermonuclear war averted', type: 'success', actions: false,
}),
},
},
});
return false;
}
addErrorNotification() {
let i = 0;
Messenger().run({
errorMessage: 'Error destroying alien planet',
successMessage: 'Alien planet destroyed!',
extraClasses: this.state.locationClasses,
action(opts) {
/* eslint-disable */
if (++i < 3) {
return opts.error({
status: 500,
readyState: 0,
responseText: 0,
});
}
/* eslint-enable */
return opts.success();
},
});
}
toggleLocation(vertical = 'top', horizontal = '') {
let className = `messenger-fixed messenger-on-${vertical}`;
className += (horizontal === '') ? '' : ` messenger-on-${horizontal}`;
this.setState({
locationClasses: className,
});
Messenger.options = {
extraClasses: className,
theme: 'air',
};
Messenger();
}
render() {
return (
<div className={s.root}>
<ol className="breadcrumb">
<li className="breadcrumb-item">YOU ARE HERE</li>
<li className="breadcrumb-item active">UI Notifications</li>
</ol>
<h1 className="page-title">Messages - <span className="fw-semi-bold">Notifications</span>
</h1>
<Widget title={<h6> Messenger </h6>} close collapse settings>
<Row>
<Col lg="4" xs="12">
<h5 className="m-t-1">Layout options</h5>
<p>There are few position options available for notifications. You can click any of
them
to change notifications position:</p>
<div className="location-selector">
{ /* eslint-disable */}
<div
className="bit top left" onClick={() => {
this.toggleLocation('top', 'left');
}}
/>
<div
className="bit top right" onClick={() => {
this.toggleLocation('top', 'right');
}}
/>
<div
className="bit top" onClick={() => {
this.toggleLocation('top', '');
}}
/>
<div
className="bit bottom left" onClick={() => {
this.toggleLocation('bottom', 'left');
}}
/>
<div
className="bit bottom right" onClick={() => {
this.toggleLocation('bottom', 'right');
}}
/>
<div
className="bit bottom" onClick={() => {
this.toggleLocation('bottom', '');
}}
/>
{ /* eslint-enable */}
</div>
</Col>
<Col lg="4" xs="12">
<h5 className="m-t-1">Notification Types</h5>
<p>Different types of notifications for lost of use cases. Custom classes are also
supported.</p>
<p><Button color="info" id="show-info-message" onClick={this.addInfoNotification}>Info
Message</Button></p>
<p><Button color="danger" id="show-error-message" onClick={this.addErrorNotification}>Error
+ Retry Message</Button></p>
<p><Button
color="success" id="show-success-message" onClick={this.addSuccessNotification}
>Success
Message</Button></p>
</Col>
<Col lg="4" xs="12">
<h5 className="m-t-1">Dead Simple Usage</h5>
<p>Just few lines of code to instantiate a notifications object. Does not require
passing any options:</p>
<pre><code>{'Messenger().post("Thanks for checking out Messenger!");'}</code></pre>
<p>More complex example:</p>
<pre>
<code>{'\nMessenger().post({\n message: \'There was an explosion while processing your request.\',\n type: \'error\',\n showCloseButton: true\n});\n\n'}
</code>
</pre>
</Col>
</Row>
</Widget>
</div>
);
}
}
export default Notifications;