This repository has been archived by the owner on Mar 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
72 lines (64 loc) · 1.36 KB
/
main.ts
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
import { props, withComponent } from "skatejs";
import withLitHtml from "@skatejs/renderer-lit-html";
import { html } from "lit-html";
interface IPosition {
x: number;
y: number;
}
interface IProps {
name: string;
}
interface IState {
value: string;
position: IPosition
}
class WithLitHtml extends withComponent(withLitHtml()) {
state: IState = {
value: "",
position: {
x: 0,
y: 0
}
};
static get props() {
return {
name: props.string
};
}
connecting() {
this.addEventListener('mousemove', (e: MouseEvent) => {
this.state = {
...this.state,
position: {
x: e.clientX,
y: e.clientY
}
}
})
}
shouldUpdate(prevProps: IProps, prevState: IState) {
return prevState !== this.state
}
change() {
this.state = { ...this.state, value: "Hey There!" };
}
render({ props, state }: { props: IProps, state: IState }) {
return html`
<section>
<h1>Hello, ${props.name}!</h1>
<h2>X: ${state.position.x}, Y:${state.position.y}</h2>
<p>${state.value}</p>
</section>
<style>
section {
width: 100vw;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
`;
}
}
customElements.define("with-lit-html", WithLitHtml);