forked from mul-ink/mulink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulLight.html
85 lines (81 loc) · 2.05 KB
/
mulLight.html
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
<!DOCTYPE html>
<html lang="en">
<script type="importmap">
{
"imports": {
"./": "https://deno.land/x/[email protected]/"
}
}
</script>
<script type="module">
import { html, component, createMachine } from './deps.js'
import { useMachine } from './useMachine.js'
const lightsMachine = createMachine({
initial: 'red',
states: {
green: { after: { 1000: 'greenyellow' } },
greenyellow: { after: { 1000: 'red' } },
red: { after: { 1000: 'redyellow'}},
redyellow: { after: { 2000: 'green' },}
}
});
function road() {
return html`
🛣️
<style>
:host {
font-size: 7.5rem;
}
</style>
`
}
function light() {
const { state } = useMachine(lightsMachine)
return html`
<div class="red light" aria-label="Red light"></div>
<div class="yellow light" aria-label="Yellow light"></div>
<div class="green light" aria-label="Green light"></div>
<div class="pole" aria-label="Traffic light pole"</object>
<style>
.red{
background-color: ${state.value === 'red' ? 'red' : 'grey'}
}
.yellow{
background-color: ${state.value === 'redyellow' || state.value === 'greenyellow' ? 'yellow' : 'grey'}
}
.green{
background-color: ${state.value === 'green' ? 'green' : 'grey'}
}
.light {
margin-top: 2px;
width: 14px;
height: 11px;
}
.pole {
width: 2px;
margin-left: 6px;
height: 100px;
background-color: white;
}
</style>
`
}
customElements.define('a-light', component(light))
customElements.define('a-road', component(road))
</script>
<a-road></a-road>
<a-light></a-light>
<style>
:root {
--dark-background: #1a1212;
}
body {
display: flex;
justify-content: center;
align-items: center;
background-color: var(--dark-background);
height: 100vh;
}
</style>
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.min.js" crossorigin="anonymous"></script>
</html>