2024-08-12 11:00:25 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { Label } from '$lib/components/ui/label';
|
|
|
|
|
import type { FormInput } from '$lib/utils/form-util';
|
|
|
|
|
import type { Snippet } from 'svelte';
|
|
|
|
|
import { Input } from './ui/input';
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
input = $bindable(),
|
|
|
|
|
label,
|
2024-08-13 20:51:10 +02:00
|
|
|
description,
|
2024-08-12 11:00:25 +02:00
|
|
|
children
|
|
|
|
|
}: {
|
|
|
|
|
input: FormInput<string | boolean | number>;
|
|
|
|
|
label: string;
|
2024-08-13 20:51:10 +02:00
|
|
|
description?: string;
|
2024-08-12 11:00:25 +02:00
|
|
|
children?: Snippet;
|
|
|
|
|
} = $props();
|
|
|
|
|
|
|
|
|
|
const id = label.toLowerCase().replace(/ /g, '-');
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div>
|
2024-08-13 20:51:10 +02:00
|
|
|
<Label class="mb-0" for={id}>{label}</Label>
|
|
|
|
|
{#if description}
|
|
|
|
|
<p class="text-muted-foreground text-xs mt-1">{description}</p>
|
2024-08-12 11:00:25 +02:00
|
|
|
{/if}
|
2024-08-13 20:51:10 +02:00
|
|
|
<div class="mt-2">
|
|
|
|
|
{#if children}
|
|
|
|
|
{@render children()}
|
|
|
|
|
{:else}
|
|
|
|
|
<Input {id} bind:value={input.value} />
|
|
|
|
|
{/if}
|
|
|
|
|
{#if input.error}
|
|
|
|
|
<p class="text-sm text-red-500">{input.error}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-08-12 11:00:25 +02:00
|
|
|
</div>
|