Badge
blode-ui/badgeFreeComponent
A small status indicator for labelling and categorising items.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/mblode/blode-ui/main/public/r/badge.jsonSource
1import { mergeProps } from "@base-ui/react/merge-props";2import { useRender } from "@base-ui/react/use-render";3import { cva } from "class-variance-authority";4import type { VariantProps } from "class-variance-authority";5import type * as React from "react";67import { cn } from "@/lib/utils";89const badgeVariants = cva(10 "inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-full border border-transparent px-2 py-0.5 font-medium text-xs 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",11 {12 defaultVariants: {13 variant: "default",14 },15 variants: {16 variant: {17 default: "bg-primary text-primary-foreground [a&]:hover:bg-primary/90",18 destructive:19 "bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90",20 ghost: "[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",21 link: "text-primary underline-offset-4 [a&]:hover:underline",22 outline:23 "border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",24 secondary: "bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",25 success:26 "bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-300 [a&]:hover:bg-green-50/80 dark:[a&]:hover:bg-green-950/80",27 warning:28 "bg-yellow-50 text-yellow-700 dark:bg-yellow-950 dark:text-yellow-300 [a&]:hover:bg-yellow-50/80 dark:[a&]:hover:bg-yellow-950/80",29 },30 },31 },32);3334type BadgeProps = React.ComponentProps<"span"> &35 VariantProps<typeof badgeVariants> & { asChild?: boolean };3637const Badge = ({38 className,39 variant = "default",40 asChild = false,41 children,42 ...props43}: BadgeProps) =>44 useRender({45 defaultTagName: "span",46 props: mergeProps<"span">(47 {48 className: cn(badgeVariants({ variant }), className),49 },50 asChild ? props : { ...props, children },51 ),52 render: asChild ? (children as React.ReactElement) : undefined,53 state: {54 slot: "badge",55 variant,56 },57 });5859export { Badge, badgeVariants };60export type { BadgeProps };
What it pulls in
npm packages
Files it writes
More from blode/ui
All 85 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | blode/ui | Components | Free | 2 deps | |
| Alertalert | blode/ui | Components | Free | no deps | |
| Alert Dialogalert-dialog | blode/ui | Components | Free | 1 dep | |
| Ask User Questionsask-user-questions | blode/ui | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | blode/ui | Components | Free | 1 dep | |
| Attachmentattachment | blode/ui | Components | Free | 1 dep | |
| Autocompleteautocomplete | blode/ui | Components | Free | 1 dep | |
| Avataravatar | blode/ui | Components | Free | 1 dep |
