Badge
React data-displaySmall inline label for status, counts, or tags — sits beside other content, not as a standalone control. Seven variants: `default`, `secondary`, `destructive`, `outline`, `success`, `warning`, `info`.
Also available for Vue ->Installation
$ pnpm dlx shadcn@latest add https://react.uipkge.dev/r/react/badge.json$ npx shadcn@latest add https://react.uipkge.dev/r/react/badge.json$ yarn dlx shadcn@latest add https://react.uipkge.dev/r/react/badge.json$ bunx shadcn@latest add https://react.uipkge.dev/r/react/badge.json
Or with the named registry:
npx shadcn@latest add @uipkge-react/badge
Examples
Props
| Name | Type / Values | Default | Required |
|---|---|---|---|
variant | 'default''secondary''destructive''outline''success''warning''info' | default | optional |
asChild Render the child element as the badge (e.g. an <a>) instead of a <span>. | boolean | false | optional |
Dependencies
Used by
Files (3)
-
components/ui/badge/Badge.tsx 0.8 kB
import * as React from 'react' import { Slot } from '@radix-ui/react-slot' import { cn } from '@/lib/utils' import { badgeVariants, type BadgeVariants } from './badge.variants' export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement>, BadgeVariants { /** Render the child element as the badge (e.g. an <a>) instead of a <span>. */ asChild?: boolean } const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>( ({ className, variant, asChild = false, ...props }, ref) => { const Comp = asChild ? Slot : 'span' return ( <Comp ref={ref} data-uipkge="" data-slot="badge" className={cn(badgeVariants({ variant }), className)} {...props} /> ) }, ) Badge.displayName = 'Badge' export { Badge } -
components/ui/badge/badge.variants.ts 1.9 kB
import type { VariantProps } from 'class-variance-authority' import { cva } from 'class-variance-authority' /** * Variant definitions live in their own file (rather than the package * `index.ts`) so consuming Vue SFCs can import without creating a circular * dependency through the index. See card.variants.ts for the canonical * example + the SSR symptom that motivated the split. */ export const badgeVariants = cva( 'inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>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 transition-colors duration-200 overflow-hidden', { variants: { variant: { default: 'border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90', secondary: 'border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90', destructive: 'border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60', outline: 'text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground', success: 'border-transparent bg-[var(--success)]/10 text-[var(--success)] dark:text-[var(--success)] [a&]:hover:bg-[var(--success)]/20', warning: 'border-transparent bg-[var(--warning)]/10 text-[var(--warning)] dark:text-[var(--warning)] [a&]:hover:bg-[var(--warning)]/20', info: 'border-transparent bg-[var(--info)]/10 text-[var(--info)] dark:text-[var(--info)] [a&]:hover:bg-[var(--info)]/20', }, }, defaultVariants: { variant: 'default', }, }, ) export type BadgeVariants = VariantProps<typeof badgeVariants> -
components/ui/badge/index.ts 0.1 kB
export { Badge, type BadgeProps } from './Badge' export { badgeVariants, type BadgeVariants } from './badge.variants'
Raw manifest: https://react.uipkge.dev/r/react/badge.json