Display
Badge
A small label for status, counts or categories.
LiveRev. 01
DefaultSecondaryOutline ActiveFailed
Installation
CLI
$ npx shadcn@latest add https://konsa.rohitxyz.me/r/badge.jsonManual
Install the dependencies
npm install radix-ui class-variance-authorityCopy the source into your project
components/ui/badge.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(
"inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-colors [&>svg]:pointer-events-none [&>svg]:size-3",
{
variants: {
variant: {
default: "border-transparent bg-primary text-primary-foreground",
secondary: "border-transparent bg-secondary text-secondary-foreground",
outline: "text-foreground",
success: "border-success/20 bg-success/10 text-success",
destructive: "border-destructive/20 bg-destructive/10 text-destructive",
},
},
defaultVariants: { variant: "default" },
},
);
function Badge({
className,
variant,
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 }), className)}
{...props}
/>
);
}
export { Badge, badgeVariants };Update the import paths to match your project
The file imports cn from @/lib/utils. See installation.
Usage
import { Badge } from "@/components/ui/badge";<Badge variant="success">Active</Badge>