-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleElement.js
More file actions
72 lines (62 loc) · 2 KB
/
singleElement.js
File metadata and controls
72 lines (62 loc) · 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
(function(){
/**
* The template that is used for the shadow root for every copy of your element,
* which houses the styles and layout for the element.
*/
const template = document.createElement("template");
template.innerHTML = `
<style>
:host {
display: block;
}
</style>
`;
/**
* This is the class that controls each instance of your custom element.
*/
class /* {className} */ extends HTMLElement {
/**
* Part of the custom element spec. Returns an array of strings that are
* the names of attributes that this element observes/listens to.
*
* @returns {Array} an array of strings, each of which representing an
* attribute.
*/
static get observedAttributes() {
return [];
};
constructor() {
super();
// create shadow root for any children context
this.attachShadow({mode: "open"});
this.shadowRoot.appendChild(template.content.cloneNode(true));
// add any initial variables here
}
/**
* Part of the custom element spec. Called after your element is attached to
* the DOM. Do anything related to the element or its children here in most
* cases.
*/
connectedCallback() {
}
/**
* Part of the custom element spec. Called after your element is remove from
* the DOM. Disconnect any listeners or anything else here.
*/
disconnectedCallback() {
}
/**
* Part of the custom element spec. Called when one of the observed
* attributes changes, either via setAttribute() or with the attribute being
* manually set in the HTML.
*
* @param {String} name the name of the attribute that changed
* @param {Mixed} oldValue the previous value of the attribute
* @param {Mixed} newValue the new value of the attribute
*/
attributeChangedCallback(name, oldValue, newValue) {
// respond to a changed attribute here
}
}
customElements.define("/* {tagName} */", /* {className} */);
})();