aboutsummaryrefslogtreecommitdiff
path: root/src/lib/components/GroceryRow.svelte
blob: 9a88e90a6cdecfb32669895c59fc83008ccef5c1 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

<script lang="ts">
	import BestRef from '$lib/components/BestRef.svelte';
	import Row from '$lib/components/Row.svelte';
	import type { EnrichedGrocery } from '$lib/server/services/groceries';

	let {
		item,
		from,
		selectable = false,
		checked = false,
		oncheck,
	}: {
		item: EnrichedGrocery;
		from: string;
		selectable?: boolean;
		checked?: boolean;
		oncheck?: () => void;
	} = $props();
</script>

<Row variant="plain" style="height: 2.75rem;">
	{#if selectable}
		<input type="checkbox" class="check" {checked} onchange={oncheck} />
	{/if}
	<button
		class="toggle"
		name="id"
		value={item.id}
		type="submit"
		aria-pressed={item.checked}
	>
		<span class="label">
			<span class:checked={item.checked}>{item.name}</span>
			{#if item.bestRef}
				<BestRef ref={item.bestRef} />
			{/if}
		</span>
	</button>
	<a class="open" href="/grocery/{item.id}?from={from}">&rarr;</a>
</Row>

<style>
	.check {
		width: 1.25rem;
		height: 1.25rem;
		accent-color: var(--accent);
		cursor: pointer;
		flex-shrink: 0;
	}

	.checked {
		text-decoration: line-through;
		color: var(--text-secondary);
		font-weight: 400;
	}

	.toggle {
		flex-grow: 1;
		width: auto;
		text-align: left;
		padding: 0 0.875rem;
		height: 100%;
		border: none;
		border-radius: 0.75rem;
		background: var(--surface);
		font-size: 1rem;
		font-weight: 500;
		display: flex;
		align-items: center;
		transition: all 0.2s ease;
		box-shadow: 0 1px 2px var(--shadow);
	}

	.toggle:hover {
		background: var(--surface-hover);
		box-shadow: 0 2px 6px var(--shadow-accent);
		transform: translateY(-1px);
	}

	.label {
		display: flex;
		flex-direction: column;
		text-align: left;
		line-height: 1.2;
		gap: 0.0625rem;
		overflow: hidden;
	}

	.open {
		width: 2.75rem;
		flex-shrink: 0;
		height: 2.75rem;
		aspect-ratio: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 0.75rem;
		background: var(--surface);
		color: var(--text-secondary);
		text-decoration: none;
		font-size: 1rem;
		transition: all 0.2s ease;
		box-shadow: 0 1px 2px var(--shadow);
	}

	.open:hover {
		background: var(--surface-hover);
		color: var(--accent);
		box-shadow: 0 2px 6px var(--shadow-accent);
		transform: translateY(-1px);
	}
</style>