-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
130 lines (107 loc) · 3.62 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { LitElement, html, css } from '/web_modules/lit-element.js';
import './src/01-basic/basic-demos.js';
import './src/02-charts/charts-demos.js';
import './src/03-advanced/advanced-demos.js';
// import '/web_modules/@preignition/multi-chart.js';
import '/web_modules/@preignition/multi-verse.js';
// import '@preignition/multi-chart';
// import '/web_modules/@polymer/paper-card.js';
// import '/web_modules/@vaadin/vaadin-tabs.js';
import { github } from './assets/github.js';
import { openWc } from './assets/open-wc.js';
import { Router } from '/web_modules/@vaadin/router.js';
import { installMediaQueryWatcher } from '/web_modules/pwa-helpers/media-query.js';
/**
* This component combines all the examples to be displayed. See the basic/intermediate/advanced folders for the actual examples.
*/
class OpenWcDemo extends LitElement {
static get styles() {
return [
css`
:host {
display: block;
}
h2 {
font-size: 20px;
color: #217FF9;
}
h1 {
margin-top: 0px;
color: #217FF9;
}
#header {
display: flex;
}
a {
text-decoration: none;
}
a:visited {
color: #217FF9;
}
#header h1 { flex: 1; }
#header svg { margin: 8px 0 8px 0; }
.github {transform: scale(1.2, 1.2);}
.logo {
margin-top: -3px;
margin-right: 8px;
}
.nav { margin-bottom: 20px; }
.footer { text-align: center; color: #a8a8a8;}
`,
];
}
static get properties() {
return {
activeTab: { type: String },
tabs: { type: Array },
smallScreen: { type: Boolean }
}
}
constructor(){
super();
this.activeTab = location.pathname === '/' ? 'basic' : location.pathname.replace('/', '');
this.tabs = ['basic', 'charts', 'advanced'];
installMediaQueryWatcher(`(min-width: 600px)`, (matches) => {
this.smallScreen = !matches;
});
}
firstUpdated() {
const router = new Router(this.shadowRoot.getElementById('outlet'));
router.setRoutes([
{path: '/', component: 'basic-demos'},
// {path: '/', component: 'charts-demos'},
{path: '/basic', component: 'basic-demos'},
{path: '/charts', component: 'charts-demos'},
{path: '/advanced', component: 'advanced-demos'},
{path: '(.*)', redirect: '/', action: () => {
this.activeTab = 'basic';
}
}
]);
}
switchRoute(route) {
this.activeTab = route;
Router.go(`/${route}`);
}
render() {
return html`
<div id="header">
<span class="logo"><a href="https://open-wc.org">${openWc}</a></span>
<h1>${this.capitalize(this.activeTab)} demos</h1>
<a class="github" href="https://www.github.com/open-wc/lit-demos" target="_blank">${github}</a>
</div>
<vaadin-tabs class="${this.smallScreen ? 'nav' : ''}" orientation="${this.smallScreen ? 'vertical' : 'horizontal'}" selected=${this.tabs.indexOf(this.activeTab)} theme="${this.smallScreen ? '' : 'centered'}">
<vaadin-tab @click=${() => this.switchRoute('basic')}>Basic</vaadin-tab>
<vaadin-tab @click=${() => this.switchRoute('charts')}>Charts</vaadin-tab>
<vaadin-tab @click=${() => this.switchRoute('advanced')}>Advanced</vaadin-tab>
</vaadin-tabs>
<div id="outlet">
</div>
<p class="footer">🚽 Made with love by <a target="_blank" href="https://open-wc.org/">open-wc</a>.</p>
`;
}
capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
}
customElements.define('open-wc-demo', OpenWcDemo);