Badge
cubby-ui/badgeFreeComponent
A badge component.
Live preview
live · rendered by the registry
Rendered by cubby-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://cubby-ui.dev/r/badge.jsonSource
1import * as React from "react";2import { cva, type VariantProps } from "class-variance-authority";34import { cn } from "@/lib/utils";56const badgeVariants = cva(7 "inline-flex items-center justify-center rounded-md border px-2.5 py-1 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-2 [&>svg]:pointer-events-none focus-visible:outline-ring/50 outline-0 outline-offset-0 outline-transparent transition-[outline-width,outline-offset,outline-color] duration-100 ease-out outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 aria-invalid:outline-destructive/50 aria-invalid:outline-2 aria-invalid:outline-offset-2 aria-invalid:outline-solid",8 {9 variants: {10 variant: {11 default:12 "bg-primary border-transparent text-primary-foreground shadow-[0_1px_3px_0_oklch(0.22_0_0_/_0.12)]",13 neutral: "bg-neutral border-transparent text-neutral-foreground",14 outline: "text-foreground bg-background border",15 secondary: "bg-secondary border-secondary/40 text-secondary-foreground",16 success: "bg-success border-success-border text-success-foreground",17 warning: "bg-warning border-warning-border text-warning-foreground",18 info: "bg-info border-info-border text-info-foreground",19 danger: "bg-danger border-danger-border text-danger-foreground",20 },21 },22 defaultVariants: {23 variant: "default",24 },25 },26);2728function Badge({29 className,30 variant,31 ...props32}: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants>) {33 return (34 <span35 data-slot="badge"36 data-variant={variant}37 className={cn(badgeVariants({ variant }), className)}38 {...props}39 />40 );41}4243export { Badge, badgeVariants };
What it pulls in
npm packages
Files it writes
More from cubby-ui
All 79 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | cubby-ui | Components | Free | 2 deps | |
| Alertalert | cubby-ui | Components | Free | 1 dep | |
| Alert-dialogalert-dialog | cubby-ui | Components | Free | 2 deps | |
| Aspect-ratioaspect-ratio | cubby-ui | Components | Free | no deps | |
| Autocompleteautocomplete | cubby-ui | Components | Free | 2 deps | |
| Avataravatar | cubby-ui | Components | Free | 1 dep | |
| Base Drawerbase-drawer | cubby-ui | Components | Free | 2 deps | |
| Breadcrumbsbreadcrumbs | cubby-ui | Components | Free | 2 deps |
