1<script lang="ts" module>
2 import { type VariantProps, tv } from 'tailwind-variants';
3
4 export const badgeVariants = tv({
5 base: 'focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-md border px-2 py-0.5 text-xs font-medium transition-[color,box-shadow] focus-visible:ring-[3px] [&>svg]:pointer-events-none [&>svg]:size-3',
6 variants: {
7 variant: {
8 default: 'bg-primary text-primary-foreground [a&]:hover:bg-primary/90 border-transparent',
9 secondary:
10 'bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90 border-transparent',
11 destructive:
12 'bg-destructive [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/70 border-transparent text-white',
13 outline: 'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground'
14 }
15 },
16 defaultVariants: {
17 variant: 'default'
18 }
19 });
20
21 export type BadgeVariant = VariantProps<typeof badgeVariants>['variant'];
22</script>
23
24<script lang="ts">
25 import type { HTMLAnchorAttributes } from 'svelte/elements';
26 import { cn, type WithElementRef } from '$lib/components/ui/utils';
27
28 let {
29 ref = $bindable(null),
30 href,
31 class: className,
32 variant = 'default',
33 children,
34 ...restProps
35 }: WithElementRef<HTMLAnchorAttributes> & {
36 variant?: BadgeVariant;
37 } = $props();
38</script>
39
40<svelte:element
41 this={href ? 'a' : 'span'}
42 bind:this={ref}
43 data-slot="badge"
44 {href}
45 class={cn(badgeVariants({ variant }), className)}
46 {...restProps}
47>
48 {@render children?.()}
49</svelte:element>