Badge
hextaui/badgeFreeComponent
Small badge for counts or indicators.
Live preview
live · rendered by the registry
Rendered by HextaUI on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://hextaui.com/r/badge.jsonSource
1import { Slot } from "@radix-ui/react-slot";2import { cva, type VariantProps } from "class-variance-authority";3import * as React from "react";45import { cn } from "@/lib/utils";67const badgeVariants = cva(8 "inline-flex min-h-5 w-fit shrink-0 touch-manipulation items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-full border px-2 py-0.5 font-medium text-xs tabular-nums transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3",9 {10 variants: {11 variant: {12 default:13 "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",14 secondary:15 "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",16 destructive:17 "border-transparent bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90",18 outline:19 "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",20 },21 },22 defaultVariants: {23 variant: "default",24 },25 }26);2728const Badge = React.forwardRef<29 HTMLSpanElement,30 React.ComponentProps<"span"> &31 VariantProps<typeof badgeVariants> & { asChild?: boolean }32>(function Badge({ className, variant, asChild = false, ...props }, ref) {33 const Comp = asChild ? Slot : "span";3435 return (36 <Comp37 className={cn(badgeVariants({ variant }), className)}38 data-slot="badge"39 ref={ref}40 {...props}41 />42 );43});4445export { Badge, badgeVariants };
What it pulls in
npm packages
Files it writes
More from HextaUI
All 139 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | HextaUI | Components | Free | 1 dep | |
| AI Chat Historyai-chat-history | HextaUI | Components | Free | no deps | |
| AI Citationsai-citations | HextaUI | Components | Free | no deps | |
| AI Conversationai-conversation | HextaUI | Components | Free | no deps | |
| AI Error Handlerai-error-handler | HextaUI | Components | Free | no deps | |
| AI File Uploadai-file-upload | HextaUI | Components | Free | no deps | |
| AI Messageai-message | HextaUI | Components | Free | 4 deps | |
| AI Model Selectorai-model-selector | HextaUI | Components | Free | no deps |
