-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
61 lines (49 loc) · 1.28 KB
/
main.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
import { reactive, customElement, attribute, html } from 'pwc';
@customElement('child-element')
class Child extends HTMLElement {
name = 'Child';
@reactive
@attribute('data-class-name')
accessor className = 'red';
@attribute('checked')
accessor checked = false;
connectedCallback() {
super.connectedCallback();
console.log('connected');
console.log(this.className)
}
get template() {
return html`<div id="container">
Child ${this.name}
<div>parent class name is ${this.className}</div>
</div>`;
}
}
@customElement('custom-element')
class CustomElement extends HTMLElement {
@reactive
accessor #data = {
name: 'jack!',
};
@reactive
accessor #text = 'hello';
@attribute('custom')
accessor custom = false;
@reactive
accessor #className = 'red';
connectedCallback() {
super.connectedCallback();
console.log('parent connected');
}
onClick() {
this.#data.name += '!';
this.#text += '?';
this.#className = this.#className === 'green' ? 'red' : 'green';
};
get template() {
return html`<div class=${this.#className} @click=${this.onClick}>
${this.#text} - ${this.#data.name}
<child-element name=${this.#data.name} checked=${true} data-class-name=${this.#className} />
</div>`;
}
}