feat(shopping): Rezept-Chips mit Portions-Stepper
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
75
src/lib/components/ShoppingCartChip.svelte
Normal file
75
src/lib/components/ShoppingCartChip.svelte
Normal file
@@ -0,0 +1,75 @@
|
||||
<script lang="ts">
|
||||
import { X, Minus, Plus } from 'lucide-svelte';
|
||||
import type { ShoppingCartRecipe } from '$lib/server/shopping/repository';
|
||||
|
||||
let { recipe, onServingsChange, onRemove }: {
|
||||
recipe: ShoppingCartRecipe;
|
||||
onServingsChange: (id: number, servings: number) => void;
|
||||
onRemove: (id: number) => void;
|
||||
} = $props();
|
||||
|
||||
function dec() {
|
||||
if (recipe.servings > 1) onServingsChange(recipe.recipe_id, recipe.servings - 1);
|
||||
}
|
||||
function inc() {
|
||||
if (recipe.servings < 50) onServingsChange(recipe.recipe_id, recipe.servings + 1);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="chip">
|
||||
<a class="title" href={`/recipes/${recipe.recipe_id}`}>{recipe.title}</a>
|
||||
<div class="controls">
|
||||
<button aria-label="Portion weniger" onclick={dec} disabled={recipe.servings <= 1}>
|
||||
<Minus size={16} />
|
||||
</button>
|
||||
<span class="val" aria-label="Portionen">{recipe.servings}p</span>
|
||||
<button aria-label="Portion mehr" onclick={inc} disabled={recipe.servings >= 50}>
|
||||
<Plus size={16} />
|
||||
</button>
|
||||
<button aria-label="Rezept aus Einkaufsliste entfernen" class="rm" onclick={() => onRemove(recipe.recipe_id)}>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.chip {
|
||||
flex: 0 0 auto;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: white;
|
||||
border: 1px solid #cfd9d1;
|
||||
border-radius: 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
min-width: 140px;
|
||||
}
|
||||
.title {
|
||||
color: #2b6a3d;
|
||||
font-weight: 600;
|
||||
font-size: 0.92rem;
|
||||
text-decoration: none;
|
||||
line-height: 1.2;
|
||||
max-width: 160px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.controls { display: flex; gap: 0.25rem; align-items: center; }
|
||||
.controls button {
|
||||
min-width: 32px;
|
||||
min-height: 32px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e4eae7;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #444;
|
||||
}
|
||||
.controls button:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
.controls button.rm { margin-left: auto; }
|
||||
.controls button.rm:hover { color: #c53030; border-color: #f1b4b4; background: #fdf3f3; }
|
||||
.val { min-width: 32px; text-align: center; font-weight: 600; color: #444; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user