Badge.svelte 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <script lang="ts">
  2. import type { Snippet } from 'svelte';
  3. import { cn } from '$lib/utils/cn.js';
  4. type Variant = 'default' | 'outline' | 'active' | 'paused' | 'error' | 'warning' | 'info' | 'debug' | 'trace' | 'write' | 'delete';
  5. interface Props {
  6. variant?: Variant;
  7. class?: string;
  8. children?: Snippet;
  9. }
  10. let { variant = 'default', class: className = '', children }: Props = $props();
  11. const base = 'inline-flex items-center rounded-[9999px] border px-2 py-0.5 text-xs font-medium transition-colors cursor-crosshair';
  12. const variants: Record<Variant, string> = {
  13. default: 'bg-[var(--muted)] text-[var(--foreground)] border-transparent',
  14. outline: 'bg-transparent text-[var(--foreground)] border-[var(--border)]',
  15. active: 'badge-active',
  16. paused: 'badge-paused',
  17. error: 'badge-error',
  18. warning: 'badge-warning',
  19. info: 'badge-info',
  20. debug: 'badge-debug',
  21. trace: 'badge-trace',
  22. write: 'badge-write',
  23. delete: 'badge-delete',
  24. };
  25. </script>
  26. <span class={cn(base, variants[variant], className)}>
  27. {#if children}{@render children()}{/if}
  28. </span>