summaryrefslogtreecommitdiff
path: root/examples/framework-alpine/src/components/Counter.astro
blob: 00182f0069b1caad355a414e8f8b2beb0214de04 (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
---
// Full Astro Component Syntax:
// https://docs.astro.build/basics/astro-components/

interface Props {
	initialCount?: number;
}

const { initialCount = 0 } = Astro.props;
---

<div class="counter" x-data={`{ count: ${initialCount} }`}>
	<button x-on:click="count--">-</button>
	<pre x-text="count">{ initialCount }</pre>
	<button x-on:click="count++">+</button>
</div>

<div class="counter-message">
	<slot />
</div>

<style>
	.counter {
		display: grid;
		font-size: 2em;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		margin-top: 2em;
		place-items: center;
	}

	.counter-message {
		text-align: center;
	}
</style>