-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathGrowl.js
51 lines (44 loc) · 1.01 KB
/
Growl.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
import React from 'react';
import CONST from '../CONST';
const growlRef = React.createRef();
let resolveIsReadyPromise;
const isReadyPromise = new Promise((resolve) => {
resolveIsReadyPromise = resolve;
});
function setIsReady() {
resolveIsReadyPromise();
}
/**
* Show the growl notification
*
* @param {String} bodyText
* @param {String} type
* @param {Number} [duration]
*/
function show(bodyText, type, duration = CONST.GROWL.DURATION) {
isReadyPromise.then(() => growlRef.current.show(bodyText, type, duration));
}
/**
* Show error growl
*
* @param {String} bodyText
* @param {Number} [duration]
*/
function error(bodyText, duration = CONST.GROWL.DURATION) {
show(bodyText, CONST.GROWL.ERROR, duration);
}
/**
* Show success growl
*
* @param {String} bodyText
* @param {Number} [duration]
*/
function success(bodyText, duration = CONST.GROWL.DURATION) {
show(bodyText, CONST.GROWL.SUCCESS, duration);
}
export default {
show,
error,
success,
};
export {growlRef, setIsReady};