blob: 0e9e1aceb536951cd8b949880d3d7928179d803a (
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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<script lang="ts">
import '../app.css';
import { enhance } from '$app/forms';
let { data, form } = $props();
let name = $state('');
</script>
<h1>Groceries</h1>
<form class="add-form" method="POST" action="?/add" use:enhance>
<input
type="text"
name="name"
bind:value={name}
placeholder="Add an item..."
autocomplete="off"
/>
<button type="submit">Add</button>
</form>
{#if form?.error}
<p class="error">{form.error}</p>
{/if}
<hr />
<form method="POST" action="?/toggle" use:enhance>
<ul class="item-list">
{#each data?.items ?? [] as item (item.id)}
<li>
<button name="id" value={item.id} type="submit">
{item.name}
</button>
</li>
{/each}
</ul>
</form>
<style>
.add-form {
display: flex;
gap: 0.5rem;
margin-bottom: 1rem;
}
input {
flex: 1;
padding: 0.75rem;
border: 1px solid #ccc;
border-radius: 0.5rem;
font-size: 1rem;
}
.add-form button[type='submit'] {
padding: 0.75rem 1.25rem;
border: none;
border-radius: 0.5rem;
background: #333;
color: #fff;
font-size: 1rem;
}
.error {
color: #d00;
margin-top: -0.5rem;
margin-bottom: 1rem;
}
hr {
border: none;
border-top: 1px solid #ddd;
margin: 1.5rem 0;
}
.item-list {
list-style: none;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.item-list li button {
width: 100%;
text-align: left;
padding: 0.75rem;
border: 1px solid #e0e0e0;
border-radius: 0.5rem;
background: #fff;
font-size: 1rem;
transition: background 0.15s;
}
.item-list li button:hover {
background: #f5f5f5;
}
</style>
|