Button.svelte (1209B)
1 <script lang="ts"> 2 import { navigationHref } from '../../navigation-url'; 3 type Props = { 4 label: string; 5 variant?: 'primary' | 'secondary'; 6 } & ( 7 | { 8 kind?: 'button'; 9 type?: 'button' | 'submit' | 'reset'; 10 disabled?: boolean; 11 onclick?: () => void; 12 href?: never; 13 } 14 | { 15 kind: 'link'; 16 href: string; 17 type?: never; 18 disabled?: never; 19 onclick?: never; 20 } 21 ); 22 let { 23 label, 24 variant = 'secondary', 25 kind = 'button', 26 type = 'button', 27 disabled = false, 28 onclick, 29 href 30 }: Props = $props(); 31 function invoke() { 32 if (!disabled && kind === 'button') onclick?.(); 33 } 34 </script> 35 36 {#if kind === 'link' && navigationHref(href)} 37 <a 38 href={navigationHref(href)} 39 class="button" 40 class:button--primary={variant === 'primary'} 41 class:button--secondary={variant === 'secondary'}>{label}</a 42 > 43 {:else if kind === 'link'} 44 <span class="button">{label}</span> 45 {:else} 46 <button 47 {type} 48 {disabled} 49 onclick={invoke} 50 class="button" 51 class:button--primary={variant === 'primary'} 52 class:button--secondary={variant === 'secondary'}>{label}</button 53 > 54 {/if}