-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.svelte
67 lines (58 loc) · 1.42 KB
/
Cell.svelte
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
<script lang="ts">
import { createEventDispatcher } from 'svelte';
export let id: number;
export let isHidden = true
export let isBomb = false
export let hasFlag = false
export let bombsNearby = 0
const dispatch = createEventDispatcher()
function step() {
if (!hasFlag) {
dispatch('stepInto', { id })
}
}
function flag(event) {
event.preventDefault()
if (isHidden) {
dispatch('toggleFlag', { id })
}
}
</script>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class="cell"
class:hidden={isHidden}
on:click={step}
on:contextmenu={flag}
>
{#if isBomb && !isHidden}
💥
{:else if hasFlag}
🚩
{:else if !isHidden && bombsNearby > 0}
{bombsNearby}
{/if}
</div>
<style>
:root {
--cell-bg-color: rgba(120, 118, 122, 0.267);
--cell-color: #333333;
--hidden-bg-color: #024E68;
--hidden-color: #DDDDDD;
}
.cell {
background-color: var(--cell-bg-color);
color: var(--cell-color);
margin: 0.5px;
display: flex;
text-align: center;
justify-content: center;
align-content: center;
flex-direction: column;
user-select: none;
}
.cell.hidden {
background-color: var(--hidden-bg-color);
color: var(--hidden-color);
}
</style>