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
<script lang="ts">
const count = state(0)
const doubled = derived(() => count * 2)
const parity = derived(() => (count % 2 === 0 ? 'even' : 'odd'))
</script>
<div class="counter">
<p class="value">{count}</p>
<p class="meta">doubled is {doubled} · {parity}</p>
<div class="row">
<button onClick={() => count.set(count - 1)}>−1</button>
<button onClick={() => count.set(0)} disabled={count === 0}>Reset</button>
<button class="primary" onClick={() => count.set(count + 1)}>+1</button>
</div>
</div>
<style>
.counter {
display: grid;
justify-items: center;
gap: 0.5rem;
padding: 1rem;
}
.value {
margin: 0;
font-size: 4.5rem;
font-weight: 600;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.meta {
margin: 0 0 0.75rem;
font-family: var(--font-mono);
font-size: 0.8rem;
color: var(--muted);
}
.row {
display: flex;
gap: 0.5rem;
}
.row button {
min-width: 3rem;
}
.primary {
border-color: var(--fg);
background: var(--fg);
color: var(--bg);
}
.primary:hover:not(:disabled) {
border-color: var(--fg);
background: color-mix(in srgb, var(--fg) 85%, var(--bg));
}
</style>