FormField.svelte (785B)
1 <script lang="ts"> 2 import type { Snippet } from 'svelte'; 3 let { 4 id, 5 label, 6 hint, 7 error, 8 control 9 }: { 10 id: string; 11 label: string; 12 hint?: string; 13 error?: string; 14 control: Snippet< 15 [{ id: string; describedby: string | undefined; invalid: boolean }] 16 >; 17 } = $props(); 18 const describedby = $derived( 19 [hint ? `${id}-hint` : '', error ? `${id}-error` : ''] 20 .filter(Boolean) 21 .join(' ') || undefined 22 ); 23 </script> 24 25 <div class="field"> 26 <label class="label" for={id}>{label}</label> 27 {#if hint}<p class="text-small text-muted" id={`${id}-hint`}>{hint}</p>{/if} 28 {#if error}<p class="text-error" id={`${id}-error`}>{error}</p>{/if} 29 {@render control({ 30 id, 31 describedby, 32 invalid: Boolean(error) 33 })} 34 </div>