generated from adamrybinski/haunted-snow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulHeart.html
76 lines (72 loc) · 1.79 KB
/
mulHeart.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
<!DOCTYPE html>
<html lang="en">
<!-- <script type="importmap">
{
"imports": {
"./": "https://deno.land/x/mulink@0.0.29/"
}
}
</script> -->
<script type="module">
import { iconColor } from './cssTokens.js'
import { heartLiked, heartLiking, heartUnliked, heartUnliking } from './mulHeartIcon.js'
import { html, component, css, useCSS, assign,createMachine } from './deps.js'
import { useMachine } from './useMachine.js'
import { inspect } from './browser.js'
inspect({
url: "https://statecharts.io/inspect",
iframe: false
});
function MulHeart(element) {
const likeMachine = createMachine({
id: 'heart',
initial: 'unliked',
states: {
unliked: { on: { toggle: 'liking' }},
liking: { after: { 600: 'liked' }},
liked: { on: { toggle: 'unliking'}},
unliking: { after: { 600: 'unliked'}}
}
});
const { state, send } = useMachine(likeMachine, { devTools: true })
const onClick = () => send('toggle')
const hearts = {
unliked: heartUnliked,
unliking: heartUnliking,
liked: heartLiked,
liking: heartLiking,
};
const heart = hearts[state.value]
useCSS(element, [mulHeart])
return html`
<span @click=${onClick} class="heart">
${heart}
</span>
`
}
const mulHeart = css`
.heart {
cursor: pointer;
opacity: 0.6;
}
.heartIcon {
fill: ${iconColor};
}
.heart:hover {
opacity: 1;
}
`
customElements.define("mul-heart", component(MulHeart))
</script>
<mul-heart></mul-heart>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
background-color: #1a1212;
height: 100vh;
}
</style>
<script async src="https://ga.jspm.io/npm:es-module-shims@0.12.8/dist/es-module-shims.min.js" crossorigin="anonymous"></script>
</html>