-
Notifications
You must be signed in to change notification settings - Fork 110
/
notificationHelper.js
58 lines (48 loc) · 1.43 KB
/
notificationHelper.js
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
import { isString, isObject } from './isType';
/*
Helpers that will display the specified message in in the notification
area at the top of the page
*/
export function hideNotifications() {
$('#notification-area')
.addClass('hide')
.removeClass('notification-area--floating');
}
function renderMessage(options = {}) {
const notificationArea = $('#notification-area');
if (isString(options.message) && isObject(notificationArea)) {
notificationArea
.removeClass('alert-info', 'alert-warning')
.addClass(options.className);
if (options.floating) {
notificationArea.addClass('notification-area--floating');
}
notificationArea.find('i, span').remove();
notificationArea.append(`
<i class="fa fa-${options.icon}" aria-hidden="true"></i>
<span>${options.message}</span>
`);
notificationArea.removeClass('hide');
if (options.autoDismiss) {
setTimeout(() => { hideNotifications(); }, 5000);
}
}
}
export function renderNotice(msg, options = {}) {
renderMessage({
message: msg,
icon: 'check-circle',
className: 'alert-info',
floating: options.floating === true,
autoDismiss: options.autoDismiss === true,
});
}
export function renderAlert(msg, options = {}) {
renderMessage({
message: msg,
icon: 'times-circle',
className: 'alert-warning',
floating: options.floating === true,
autoDismiss: options.autoDismiss === true,
});
}