# Badge

Small raised chips for status and counts.

Docs: https://cozy-ui.solo.engineer/docs/components/badge/

Install: `npx shadcn@latest add @cozy/badge`

### Usage

```tsx
import { Badge } from "@/components/ui/badge"

<Badge variant="success">Ripe</Badge>
```

### Props

| Prop | Type | Default | Description |
|---|---|---|---|
| variant | `"default" \| "primary" \| "secondary" \| "success" \| "info" \| "accent" \| "destructive" \| "outline"` | `"default"` | Default is the reward colour. |
| bounce | `boolean` | `false` | Idle bobbing motion. |

### Example

```tsx
import { Badge } from "@/components/ui/badge";

export default function BadgeDemo() {
  return (
    <div className="flex flex-wrap justify-center gap-2">
      <Badge>Reward</Badge>
      <Badge variant="primary">New</Badge>
      <Badge variant="secondary">Level 7</Badge>
      <Badge variant="success">Ripe</Badge>
      <Badge variant="info">Rain soon</Badge>
      <Badge variant="accent">Sunny</Badge>
      <Badge variant="destructive">Wilted</Badge>
      <Badge variant="outline">Plot 4</Badge>
    </div>
  );
}
```

### Source (components/ui/badge.tsx)

```tsx
import * as React from "react";
import { Slot } from "radix-ui";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";

const badgeVariants = cva("cz-badge", {
  variants: {
    variant: {
      default: "",
      primary: "cz-badge--primary",
      secondary: "cz-badge--secondary",
      success: "cz-badge--success",
      info: "cz-badge--info",
      accent: "cz-badge--accent",
      destructive: "cz-badge--destructive",
      outline: "cz-badge--outline",
    },
    bounce: { true: "cz-badge--bounce", false: "" },
  },
  defaultVariants: { variant: "default", bounce: false },
});

function Badge({
  className,
  variant,
  bounce,
  asChild = false,
  ...props
}: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
  const Comp = asChild ? Slot.Root : "span";
  return <Comp data-slot="badge" className={cn(badgeVariants({ variant, bounce }), className)} {...props} />;
}

export { Badge, badgeVariants };
```

npm: `import { Badge, badgeVariants } from "@0xtrou/cozy-ui"` (after `npm install @0xtrou/cozy-ui` and `import "@0xtrou/cozy-ui/styles.css"`).
