blob: a11538645e6ce8382fd92a82a9c851e6ccd0379d (
plain) (
blame)
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
|
<script lang="ts">
import type { Snippet } from 'svelte';
interface Props {
children?: Snippet
}
let { children }: Props = $props();
let count = $state(0);
function add() {
count += 1;
}
function subtract() {
count -= 1;
}
</script>
<div class="counter">
<button onclick={subtract}>-</button>
<pre>{count}</pre>
<button onclick={add}>+</button>
</div>
<div class="message">
{@render children?.()}
</div>
<style>
.counter {
display: grid;
font-size: 2em;
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-top: 2em;
place-items: center;
}
.message {
text-align: center;
}
</style>
|