-
Notifications
You must be signed in to change notification settings - Fork 0
/
component-template.js
36 lines (27 loc) · 1.07 KB
/
component-template.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
let template = document.createElement("template");
template.innerHTML = `<div id="__COMPONENT_TAG__" class="__COMPONENT_TAG__"> Hello from __COMPONENT_NAME__... ! </div>`;
class __COMPONENT_NAME__ extends HTMLElement {
constructor() {
super();
this.shadow = this.attachShadow({ mode: 'open' });
this.shadow.appendChild(template.content.cloneNode(true));
const linkElem = document.createElement('link');
linkElem.setAttribute('rel', 'stylesheet');
linkElem.setAttribute('href', 'src/assets/style/__COMPONENT_TAG__.css');
this.shadow.appendChild(linkElem);
}
connectedCallback() {
console.log("__COMPONENT_NAME__ is Connected");
}
disconnectedCallback() {
console.log('__COMPONENT_NAME__ is Disonnected');
}
static get observedAttributes() {
return[/* array of attribute names to monitor for changes */];
}
attributeChangedCallback(name, oldValue, newValue) {
// called when one of attributes listed above is modified
}
}
customElements.define('__COMPONENT_TAG__', __COMPONENT_NAME__);
export default __COMPONENT_NAME__;