Badge
uiable/badgeFreeComponent
Badge component.
Live preview
live · rendered by the registry
Rendered by uiable on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://uiable.com/r/badge.jsonSource
1"use client";23import { mergeProps } from "@base-ui/react/merge-props";4import { useRender } from "@base-ui/react/use-render";5import { cva, type VariantProps } from "class-variance-authority";67import { cn } from "@/lib/utils";89const badgeVariants = cva(10 "gap-1 rounded-lg border border-transparent px-[0.8em] py-[0.45em] text-[.75em] font-medium leading-[0.9] transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive overflow-hidden group/badge",11 {12 variants: {13 variant: {14 default: "bg-primary text-white [a]:hover:bg-primary/80",15 secondary:16 "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",17 destructive:18 "bg-destructive/10 [a]:hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 text-destructive dark:bg-destructive/20",19 outline:20 "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",21 ghost:22 "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",23 link: "text-primary underline-offset-4 hover:underline"24 }25 },26 defaultVariants: {27 variant: "default"28 }29 }30);3132function Badge({33 className,34 variant = "default",35 render,36 ...props37}: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>) {38 return useRender({39 defaultTagName: "span",40 props: mergeProps<"span">(41 {42 className: cn(badgeVariants({ variant }), className)43 },44 props45 ),46 render,47 state: {48 slot: "badge",49 variant50 }51 });52}5354export { Badge, badgeVariants };
What it pulls in
npm packages
Files it writes
More from uiable
All 712 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | uiable | Components | Free | 2 deps | |
| Alertalert | uiable | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | uiable | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | uiable | Components | Free | no deps | |
| Attachmentattachment | uiable | Components | Free | 2 deps | |
| Avataravatar | uiable | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | uiable | Components | Free | 2 deps | |
| Bubblebubble | uiable | Components | Free | 2 deps |
