2025-09-03 16:05:08 +02:00
|
|
|
<script lang="ts">
|
2025-09-03 18:20:08 +02:00
|
|
|
import type { ExerciseConfig, ColorExercise } from '$lib/workout';
|
2025-09-03 16:05:08 +02:00
|
|
|
|
|
|
|
|
interface Props extends ExerciseConfig {
|
|
|
|
|
value: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
value = $bindable(),
|
|
|
|
|
min = 0,
|
|
|
|
|
max = 9999,
|
|
|
|
|
step = 1,
|
2025-09-03 18:20:08 +02:00
|
|
|
color = 'blue',
|
|
|
|
|
...restProps
|
2025-09-03 16:05:08 +02:00
|
|
|
}: Props = $props();
|
|
|
|
|
|
2025-09-03 18:20:08 +02:00
|
|
|
// Destructure the remaining props for easier access
|
2025-09-03 19:10:17 +02:00
|
|
|
const { icon, name, quickAddOptions, unit } = restProps;
|
2025-09-03 18:20:08 +02:00
|
|
|
|
|
|
|
|
const label = unit ? `${icon} ${name} (${unit})` : `${icon} ${name}`;
|
|
|
|
|
|
2025-09-03 16:05:08 +02:00
|
|
|
function quickAdd(amount: number) {
|
|
|
|
|
const newValue = Math.max(min, value + amount);
|
|
|
|
|
value = step < 1 ? Number(newValue.toFixed(2)) : newValue;
|
|
|
|
|
}
|
2025-09-03 18:20:08 +02:00
|
|
|
|
|
|
|
|
const colorClasses = {
|
|
|
|
|
blue: 'bg-blue-100 text-blue-700 hover:bg-blue-200 focus:ring-blue-500',
|
|
|
|
|
green: 'bg-green-100 text-green-700 hover:bg-green-200 focus:ring-green-500',
|
|
|
|
|
orange: 'bg-orange-100 text-orange-700 hover:bg-orange-200 focus:ring-orange-500',
|
|
|
|
|
red: 'bg-red-100 text-red-700 hover:bg-red-200 focus:ring-red-500',
|
|
|
|
|
purple: 'bg-purple-100 text-purple-700 hover:bg-purple-200 focus:ring-purple-500'
|
|
|
|
|
};
|
2025-09-03 16:05:08 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="mb-6">
|
|
|
|
|
<label for={name} class="mb-2 block text-sm font-medium text-gray-700">
|
|
|
|
|
{label}
|
|
|
|
|
</label>
|
|
|
|
|
<div class="flex items-center space-x-2">
|
|
|
|
|
<input
|
|
|
|
|
id={name}
|
|
|
|
|
{name}
|
|
|
|
|
type="number"
|
|
|
|
|
bind:value
|
|
|
|
|
{min}
|
|
|
|
|
{max}
|
|
|
|
|
{step}
|
|
|
|
|
required={true}
|
|
|
|
|
class="flex-1 rounded-md border border-gray-300 px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:outline-none"
|
|
|
|
|
/>
|
2025-09-03 18:20:08 +02:00
|
|
|
|
2025-09-03 16:05:08 +02:00
|
|
|
{#each quickAddOptions as option}
|
2025-09-03 18:20:08 +02:00
|
|
|
{@render quickAddButton(option.label, () => quickAdd(option.value), color)}
|
2025-09-03 16:05:08 +02:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-09-03 18:20:08 +02:00
|
|
|
|
|
|
|
|
{#snippet quickAddButton(label: string, onclick: () => void, color: ColorExercise)}
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
{onclick}
|
|
|
|
|
class="rounded px-3 py-1 text-xs focus:ring-2 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 {colorClasses[
|
|
|
|
|
color
|
|
|
|
|
]}"
|
|
|
|
|
>
|
|
|
|
|
{label}
|
|
|
|
|
</button>
|
|
|
|
|
{/snippet}
|