Skip to content

Commit 195411d

Browse files
authored
Update the demo to use an <app-root> component (#3)
This makes it easier to create module demos since you can use Typescript all the way down.
1 parent fad036c commit 195411d

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

demo/app-root.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { html, css, LitElement, customElement } from 'lit-element';
2+
import '../src/your-webcomponent';
3+
4+
@customElement('app-root')
5+
export class AppRoot extends LitElement {
6+
render() {
7+
return html`
8+
<your-webcomponent title="Hello">
9+
<div slot="my-slot">Some LightDOM Content</div>
10+
</your-webcomponent>
11+
`;
12+
}
13+
14+
static styles = css`
15+
:host {
16+
display: block;
17+
padding: 25px;
18+
color: var(--your-webcomponent-text-color, #000);
19+
}
20+
`;
21+
}

demo/index.html

+2-16
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,9 @@
1313
</style>
1414
</head>
1515
<body>
16-
<div id="demo"></div>
16+
<app-root></app-root>
1717

18-
<script type="module">
19-
import { html, render } from 'lit-html';
20-
import '../dist/index.js';
21-
22-
const title = 'Hello owc World!';
23-
render(
24-
html`
25-
<your-webcomponent .title=${title}>
26-
<div slot="my-slot">
27-
Some lightDOM slotted content
28-
</div>
29-
</your-webcomponent>
30-
`,
31-
document.querySelector('#demo')
32-
);
18+
<script type="module" src="../dist/demo/app-root.js">
3319
</script>
3420
</body>
3521
</html>

src/your-webcomponent.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ import { html, css, LitElement, property, customElement } from 'lit-element';
22

33
@customElement('your-webcomponent')
44
export class YourWebComponent extends LitElement {
5-
static styles = css`
6-
:host {
7-
display: block;
8-
padding: 25px;
9-
color: var(--your-webcomponent-text-color, #000);
10-
}
11-
`;
12-
135
@property({ type: String }) title = 'Hey there';
146

157
@property({ type: Number }) counter = 5;
168

17-
__increment() {
9+
private increment() {
1810
this.counter += 1;
1911
}
2012

2113
render() {
2214
return html`
2315
<h2>${this.title}, Number: ${this.counter}!</h2>
24-
<button @click=${this.__increment}>increment</button>
16+
<button @click=${this.increment}>increment</button>
2517
<slot name="my-slot"> </slot>
2618
`;
2719
}
20+
21+
static styles = css`
22+
:host {
23+
display: block;
24+
padding: 25px;
25+
color: var(--your-webcomponent-text-color, #000);
26+
}
27+
`;
2828
}

0 commit comments

Comments
 (0)