-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathcodewars-badge.js
More file actions
44 lines (36 loc) · 1.1 KB
/
codewars-badge.js
File metadata and controls
44 lines (36 loc) · 1.1 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
// This native web component fetches data from the Codewars API and renders it as a badge
// Here is some information about web component https://developer.mozilla.org/en-US/docs/Web/Web_Components
// Here is the link to the Codewars API Docs: https://dev.codewars.com/#get-user
class CodeWarsBadge extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this._userData = null;
}
set userData(value) {
this._userData = value;
this.render();
}
get userData() {
return this._userData;
}
render() {
if (!this._userData) return;
this.shadowRoot.innerHTML = `
<style>
:host {
--rank: ${this._userData.ranks.overall.color};
font: 600 100%/1 system-ui, sans-serif;
}
data {
color: var(--rank);
border: 3px solid;
padding: .25em .5em;
}
</style>
<data value="${this._userData.ranks.overall.score}">
${this._userData.ranks.overall.name}
</data>`;
}
}
customElements.define("codewars-badge", CodeWarsBadge);