# Variants

Components in this registry define their variants with [`tailwind-variants`](https://www.tailwind-variants.org), declared inline in the `<script module>` block of the `.svelte` file — see [`button.svelte`](/components/button) for the reference example. There's no separate `*.variants.ts` file; keeping `tv()` next to the markup it styles keeps the two in sync.

## Pattern

```svelte
<script lang="ts" module>
  import { type VariantProps, tv } from "tailwind-variants";
  import { cn, type WithElementRef } from "$lib/utils.js";

  export const buttonVariants = tv({
    base: "inline-flex items-center rounded-md font-medium disabled:opacity-50",
    variants: {
      variant: {
        default: "bg-primary text-primary-foreground hover:bg-primary/80",
        outline: "border-border bg-background hover:bg-muted",
      },
      size: {
        default: "h-9 px-4 text-sm",
        sm: "h-8 px-3 text-xs",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "default",
    },
  });

  export type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
  export type ButtonSize = VariantProps<typeof buttonVariants>["size"];
</script>

<script lang="ts">
  let { class: className, variant = "default", size = "default", ...restProps } = $props();
</script>

<button class={cn(buttonVariants({ variant, size }), className)} {...restProps} />
```

- Export the `tv()` result (`buttonVariants`) so consumers and stories can call it directly.
- Derive prop types from `VariantProps<typeof buttonVariants>`, not a hand-written string union.
- Compose the final class list with `cn()` from `$lib/utils.js` so caller-supplied `class` can still override the recipe.

## Checklist

- Use only `tv` from `tailwind-variants` — not `class-variance-authority` / `cva`.
- Keep the recipe in the same file as the component; don't split it into a sibling `.variants.ts` unless a future item genuinely needs to share one recipe across multiple components.
- Export `VariantProps` type aliases next to the recipe.
- List every source file the item needs (component + any shared recipe) in `_registry.svx`'s `files`.