-
Notifications
You must be signed in to change notification settings - Fork 1
/
theme-handler.js
82 lines (73 loc) · 1.67 KB
/
theme-handler.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { LitElement, css, html } from "lit";
class ThemeToggler extends LitElement {
static get properties() {
return {
brand: { state: true },
color: { state: true },
};
}
static get styles() {
return [
css`
:host {
padding: 10px;
background-color: lightgrey;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
label {
font-size: 14px;
}
select {
display: block;
font-size: 16px;
width: 100px;
}
`,
];
}
constructor() {
super();
this.color = "green";
this.brand = "casual";
}
updated() {
// adjustAdoptedStylesheetsMixin responds to this event
// by dynamically importing the right stylesheet and applying it
// to the host's shadowRoot adoptedStyleSheets
this.dispatchEvent(
new CustomEvent("theme-change", {
detail: { brand: this.brand, color: this.color },
})
);
}
render() {
return html`
<label>
Color
<select @change=${this.onColorChange}>
<option>green</option>
<option>blue</option>
<option>purple</option>
</select>
</label>
<label>
Brand
<select @change=${this.onBrandChange}>
<option>casual</option>
<option>business</option>
</select>
</label>
`;
}
onColorChange(ev) {
const val = ev.target.selectedOptions[0].value;
this.color = val;
}
onBrandChange(ev) {
const val = ev.target.selectedOptions[0].value;
this.brand = val;
}
}
customElements.define("theme-toggler", ThemeToggler);