-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
64 lines (54 loc) · 1.59 KB
/
index.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
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
import MakeupSwitch from 'makeup-switch';
import style from './style.js';
import template from './template.js';
class MakeupSwitchElement extends HTMLElement {
static get observedAttributes() {
return [
'checked',
'disabled',
'label',
'labelledby'
];
}
connectedCallback(e) {
this.removeAttribute('skeleton');
this.model._observeEvents();
}
disconnectedCallback(e) {
this.model._destroy();
}
attributeChangedCallback(attr, oldVal, newVal) {
switch (attr) {
case 'checked':
this.model.checked = (newVal !== null);
break;
case 'disabled':
this.model.disabled = (newVal !== null);
break;
case 'label':
this.model.label = newVal;
break;
case 'labelledby':
this.model.labelledby = newVal;
break;
default:
break;
}
}
constructor() {
super();
if (!this.shadowRoot) {
const shadowRoot = this.attachShadow({ mode: 'open' });
const tmpl = document.createElement('template');
tmpl.innerHTML = `
${style}
${template}
`;
shadowRoot.appendChild(tmpl.content.cloneNode(true));
}
this.model = new MakeupSwitch(this.shadowRoot.querySelector('.switch'), {
customElementMode: true
});
}
}
window.customElements.define('makeup-switch', MakeupSwitchElement);