starfleet-ui
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#6 · main · 2 min 01 s
0Étoiles
0Forks
0Issues
| 1 | <script lang="ts"> |
| 2 | import type { Snippet } from 'svelte'; |
| 3 | import type { HTMLButtonAttributes } from 'svelte/elements'; |
| 4 | |
| 5 | interface Props extends HTMLButtonAttributes { |
| 6 | variant?: 'primary' | 'secondary' | 'ghost' | 'danger' | 'confirm'; |
| 7 | size?: 'sm' | 'md' | 'lg'; |
| 8 | /** Keyboard shortcut shown as a hint. */ |
| 9 | kbd?: string; |
| 10 | busy?: boolean; |
| 11 | children: Snippet; |
| 12 | } |
| 13 | |
| 14 | let { variant = 'secondary', size = 'md', kbd, busy = false, class: cls = '', children, ...rest }: Props = $props(); |
| 15 | |
| 16 | const VARIANTS = { |
| 17 | primary: 'bg-cyan-500 text-slate-950 hover:bg-cyan-300 border-cyan-300/50', |
| 18 | secondary: 'bg-cyan-950/50 text-cyan-100 hover:bg-cyan-900/60 border-cyan-500/30 hover:border-cyan-300/60', |
| 19 | ghost: 'bg-transparent text-slate-400 hover:text-slate-100 border-transparent', |
| 20 | danger: 'bg-red-950/50 text-red-200 hover:bg-red-900/60 border-red-500/40', |
| 21 | confirm: 'bg-amber-400 text-slate-950 hover:bg-amber-300 border-amber-200/60' |
| 22 | }; |
| 23 | const SIZES = { sm: 'px-2.5 py-1 text-xs', md: 'px-3.5 py-2 text-sm', lg: 'px-5 py-2.5 text-base' }; |
| 24 | </script> |
| 25 | |
| 26 | <button |
| 27 | {...rest} |
| 28 | disabled={rest.disabled || busy} |
| 29 | aria-busy={busy} |
| 30 | class="inline-flex items-center justify-center gap-2 rounded-lg border font-semibold tracking-wide transition select-none disabled:cursor-not-allowed disabled:opacity-40 {VARIANTS[ |
| 31 | variant |
| 32 | ]} {SIZES[size]} {cls}" |
| 33 | > |
| 34 | {#if busy} |
| 35 | <span class="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" aria-hidden="true"></span> |
| 36 | {/if} |
| 37 | {@render children()} |
| 38 | {#if kbd} |
| 39 | <kbd class="rounded border border-current/30 px-1 font-mono text-[10px] leading-4 opacity-60">{kbd.toUpperCase()}</kbd> |
| 40 | {/if} |
| 41 | </button> |