-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleProgressBarWidget.js
More file actions
94 lines (85 loc) · 2.2 KB
/
CircleProgressBarWidget.js
File metadata and controls
94 lines (85 loc) · 2.2 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
(function () {
let template = document.createElement("template");
template.innerHTML = `
<style>
:host {
display: inline-block;
position: relative;
width: 100px;
height: 100px;
}
#progress-spinner {
border-radius: 50%;
height: 100px;
width: 100px;
}
#middle-circle {
position: absolute;
border-radius: 50%;
height: 80px;
width: 80px;
background-color: rgb(248, 248, 248);
display: flex;
align-items: center;
justify-content: center;
font-size: large;
font-weight: bold;
}
</style>
<div
style="
position: relative;
display: flex;
justify-content: center;
align-items: center;
"
>
<div id="middle-circle">10%</div>
<div id="progress-spinner"></div>
</div>
`;
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() {
const progressBar = this.shadowRoot.querySelector("#progress-spinner");
const progressText = this.shadowRoot.querySelector("#middle-circle");
const barColor = this._props.barColor || "#03ff4f";
const emptyBarColor = this._props.emptyBarColor || "#ededed";
const percentage = this._props.percentage || 75;
var i = 0;
var interval = setInterval(function () {
progressBar.style.background =
"conic-gradient(" + barColor + " " +
i +
"%," + emptyBarColor + " " +
i +
"%)";
progressText.innerText = `${i}%`;
if (i == percentage || i >= 100) {
clearInterval(interval);
}
i++;
}, 20);
}
onCustomWidgetBeforeUpdate(changedProperties) {
this._props = {
...this._props,
...changedProperties
};
}
onCustomWidgetAfterUpdate(changedProperties) {
this.initMain();
}
}
customElements.define("com-rohitchouhan-sap-circleprogressbarwidget", Widget);
})();