1
- import { html , PolymerElement } from '@polymer/polymer' ;
2
-
3
1
/**
4
2
* Theme switcher component for the charts examples.
5
3
*/
6
- class ThemeSwitcher extends PolymerElement {
7
- static get template ( ) {
8
- return html `
4
+ class ThemeSwitcher extends HTMLElement {
5
+ constructor ( ) {
6
+ super ( ) ;
7
+
8
+ this . attachShadow ( { mode : 'open' } ) ;
9
+ this . shadowRoot . innerHTML = `
9
10
<style>
10
11
.theme-switcher {
11
12
display: flex;
@@ -22,14 +23,7 @@ class ThemeSwitcher extends PolymerElement {
22
23
<button>Monotone theme</button>
23
24
</div>
24
25
` ;
25
- }
26
26
27
- static get is ( ) {
28
- return 'theme-switcher' ;
29
- }
30
-
31
- ready ( ) {
32
- super . ready ( ) ;
33
27
const buttons = this . shadowRoot . querySelectorAll ( 'button' ) ;
34
28
buttons [ 0 ] . addEventListener ( 'click' , ( ) => this . changeTheme ( '' ) ) ;
35
29
buttons [ 1 ] . addEventListener ( 'click' , ( ) => this . changeTheme ( 'gradient' ) ) ;
@@ -38,13 +32,10 @@ class ThemeSwitcher extends PolymerElement {
38
32
39
33
// Crappy theme switcher that doesn't clear the previous theme
40
34
changeTheme ( theme ) {
41
- const charts = document . getElementsByTagName ( 'vaadin-chart' ) ;
42
- for ( let i = 0 ; i < charts . length ; i ++ ) {
43
- charts [ i ] . setAttribute ( 'theme' , theme ) ;
44
- }
35
+ [ ...document . getElementsByTagName ( 'vaadin-chart' ) ] . forEach ( ( chart ) => {
36
+ chart . setAttribute ( 'theme' , theme ) ;
37
+ } ) ;
45
38
}
46
39
}
47
40
48
- customElements . define ( ThemeSwitcher . is , ThemeSwitcher ) ;
49
-
50
- export { ThemeSwitcher } ;
41
+ customElements . define ( 'theme-switcher' , ThemeSwitcher ) ;
0 commit comments