-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSweetNotification.js
More file actions
119 lines (109 loc) · 3.8 KB
/
SweetNotification.js
File metadata and controls
119 lines (109 loc) · 3.8 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
const mlink = document.createElement('link');
mlink.rel = 'stylesheet';
mlink.href = 'https://fonts.googleapis.com/icon?family=Material+Icons';
document.head.appendChild(mlink);
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css';
document.head.appendChild(link);
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js';
document.head.appendChild(script);
(function() {
let template = document.createElement("template");
template.innerHTML = ``;
class Widget extends HTMLElement {
constructor() {
super();
let shadowRoot = this.attachShadow({
mode: "open"
});
shadowRoot.appendChild(template.content.cloneNode(true));
this._props = {};
}
async connectedCallback() {
this.initMain();
}
async initMain() {
if(this._props.success!==""){
var notyf = new Notyf();
notyf.success({
message:'<i style="vertical-align: -6px;" class="material-icons">check_circle</i> '+this._props.success,
duration: 4000,
icon: true,
dismissible:true,
position:{x:'center',y:'bottom'}
});
}
if(this._props.error!==""){
var notyf = new Notyf();
notyf.error({
message: '<i style="vertical-align: -6px;" class="material-icons">cancel</i> '+this._props.error,
duration: 600000,
icon: true,
dismissible:true,
position:{x:'center',y:'bottom'}
});
}
if(this._props.info!==""){
const notyf = new Notyf({
types: [
{
type: 'info',
background: '#3fa4fc',
icon: true,
}
]
});
notyf.open({
type: 'info',
message: '<i style="vertical-align: -6px;" class="material-icons">info</i> '+this._props.info,
duration: 4000,
dismissible:true,
position:{x:'center',y:'bottom'}
});
}
if(this._props.warning!==""){
const notyf = new Notyf({
types: [
{
type: 'warning',
background: '#e8d902',
icon: true
}
]
});
notyf.open({
type: 'warning',
message: '<i style="vertical-align: -6px;" class="material-icons">warning</i> '+this._props.warning,
duration: 4000,
dismissible:true,
position:{x:'center',y:'bottom'}
});
}
}
setValue(){
this.dispatchEvent(new CustomEvent("propertiesChanged", {
detail: {
properties: {
success: "",
error:"",
info:"",
warning:""
}
}
}));
}
onCustomWidgetBeforeUpdate(changedProperties) {
this._props = {
...this._props,
...changedProperties
};
}
onCustomWidgetAfterUpdate(changedProperties) {
this.initMain();
this.setValue();
}
}
customElements.define("com-rohitchouhan-sap-sweetnotification", Widget);
})();