{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "badge",
  "title": "Badge",
  "description": "One badge, every layer: solid, soft, outline, status dot, gradient, glass and neo in six tones, with pulse, shine, bounce-in and count-pop animations, icons, removable chips and clickable filters.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/core/badge.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { X } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens } from \"@/lib/goodui-motion\"\n\n/*\n * One badge, independent layers: every axis combines with every other.\n *   variant   how it is painted          tone      which color\n *   shadow    how it sits on the page    animation how it moves\n *   shape     corners                    size      scale\n * plus icon, removable (× with exit animation), clickable (renders a real <button>) and max (\"99+\").\n */\n\nexport type BadgeVariant = \"solid\" | \"soft\" | \"outline\" | \"dot\" | \"gradient\" | \"glass\" | \"neo\"\nexport type BadgeTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type BadgeShadow = \"none\" | \"sm\" | \"md\" | \"glow\"\nexport type BadgeAnimation = \"none\" | \"pulse\" | \"shine\" | \"bounce-in\" | \"count\"\nexport type BadgeShape = \"square\" | \"rounded\" | \"pill\"\nexport type BadgeSize = \"xs\" | \"sm\" | \"md\"\n\nexport type BadgeLabels = { remove: string }\nconst DEFAULT_LABELS: BadgeLabels = { remove: \"Remove\" }\n\nexport type BadgeProps = Omit<React.HTMLAttributes<HTMLElement>, \"color\"> & {\n  /** How it is painted: solid fill, soft tint (default), outline, neutral with a colored dot, gradient, frosted glass or neo-brutalist. */\n  variant?: BadgeVariant\n  /** Color by meaning; drives every variant through CSS variables. */\n  tone?: BadgeTone\n  /** Drop shadow; glow uses the tone color. Ignored by neo, which has its own offset shadow. */\n  shadow?: BadgeShadow\n  /** pulse pings a status dot, shine sweeps a light, bounce-in plays on mount, count pops when the content changes. */\n  animation?: BadgeAnimation\n  shape?: BadgeShape\n  size?: BadgeSize\n  /** Leading icon. On the dot variant it replaces the dot. */\n  icon?: React.ReactNode\n  /** Shows a × button; the badge animates out, then calls onRemove. */\n  removable?: boolean\n  /** Called after the exit animation (instantly with reduced motion). Remove the item from your state here. */\n  onRemove?: () => void\n  /** Renders a real <button> with hover and focus states. */\n  clickable?: boolean\n  /** Numbers above max render as \"max+\". */\n  max?: number\n  /** Dims the badge and disables its button (clickable) or × button. */\n  disabled?: boolean\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<BadgeLabels>\n}\n\nconst CSS = `\n.pc-badge{--pc-c:var(--primary);--pc-fg:var(--primary-foreground);isolation:isolate;-webkit-tap-highlight-color:transparent}\n.pc-badge[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.pc-badge[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.pc-badge[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.pc-badge[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.pc-badge[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .pc-badge[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .pc-badge[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .pc-badge[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.pc-badge{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.pc-badge[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n/* White text on the gradient needs darker fuchsia/amber stops in light mode. */\n.pc-badge:is([data-tone=success],[data-tone=info],[data-tone=danger]){--pc-g1:#a21caf;--pc-g2:#b45309}\n.dark .pc-badge:is([data-tone=success],[data-tone=info],[data-tone=danger]){--pc-g1:#d946ef;--pc-g2:#f59e0b}\n\n.pc-badge{border:1px solid transparent;box-shadow:var(--pc-hl,0 0 #0000),var(--pc-v,0 0 #0000),var(--pc-sh,0 0 #0000)}\n.pc-badge[data-variant=solid]{background:var(--pc-c);color:var(--pc-fg)}\n.pc-badge[data-variant=soft]{background:var(--pc-tint);color:var(--pc-ink)}\n.pc-badge[data-variant=outline]{border-color:color-mix(in oklab,var(--pc-c) 45%,var(--border));color:var(--pc-ink)}\n.pc-badge[data-variant=dot]{border-color:var(--border);background:var(--background);color:var(--foreground)}\n.pc-badge[data-variant=gradient]{color:var(--pc-fg);background:linear-gradient(135deg,var(--pc-c),color-mix(in oklab,var(--pc-c) 55%,var(--pc-g1,#d946ef)) 55%,color-mix(in oklab,var(--pc-c) 50%,var(--pc-g2,#f59e0b)))}\n.pc-badge[data-variant=glass]{color:var(--foreground);background:color-mix(in oklab,var(--background) 45%,transparent);border-color:color-mix(in oklab,var(--foreground) 14%,transparent);-webkit-backdrop-filter:blur(12px) saturate(1.6);backdrop-filter:blur(12px) saturate(1.6);--pc-v:inset 0 1px 0 color-mix(in oklab,white 40%,transparent)}\n.pc-badge[data-variant=neo]{background:var(--pc-c);color:var(--pc-fg);border:1.5px solid var(--foreground);--pc-v:2px 2px 0 var(--foreground)}\n\n.pc-badge-dot{position:relative;display:inline-block;flex:none;width:.5em;height:.5em;border-radius:9999px;background:var(--pc-c)}\n.pc-badge:not([data-variant=dot]) .pc-badge-dot{background:currentColor}\n\n.pc-badge[data-shadow=sm]{--pc-sh:0 1px 2px rgb(0 0 0/.14)}\n.pc-badge[data-shadow=md]{--pc-sh:0 4px 10px -3px rgb(0 0 0/.22)}\n.pc-badge[data-shadow=glow]{--pc-sh:0 4px 16px -3px color-mix(in oklab,var(--pc-c) 70%,transparent)}\n\n.pc-badge[data-clickable]{cursor:pointer;transition:box-shadow .15s,transform .15s}\n.pc-badge[data-clickable]:hover{--pc-hl:inset 0 0 0 100vmax color-mix(in oklab,currentColor 9%,transparent)}\n.pc-badge[data-clickable]:active{transform:scale(.96)}\n.pc-badge[data-clickable][data-variant=neo]:active{transform:translate(2px,2px);--pc-v:0 0 0 var(--foreground)}\n.pc-badge-x{display:inline-flex;align-items:center;justify-content:center;border-radius:9999px;opacity:.7;cursor:pointer;transition:opacity .15s,background-color .15s}\n.pc-badge-x:hover{opacity:1;background:color-mix(in oklab,currentColor 16%,transparent)}\n\n.pc-badge[data-anim=pulse] .pc-badge-dot::after{content:\"\";position:absolute;inset:0;border-radius:inherit;background:inherit;animation:pc-badge-ping 1.6s var(--pc-ease-out) infinite}\n@keyframes pc-badge-ping{75%,100%{transform:scale(2.6);opacity:0}}\n.pc-badge[data-anim=shine]{overflow:hidden}\n.pc-badge[data-anim=shine]::after{content:\"\";position:absolute;inset:0;z-index:-1;width:50%;background:linear-gradient(100deg,transparent,rgb(255 255 255/.5),transparent);transform:translateX(-160%) skewX(-18deg);animation:pc-badge-sweep 3s ease-in-out infinite;pointer-events:none}\n.pc-badge[data-anim=shine][data-variant=soft]::after,.pc-badge[data-anim=shine][data-variant=outline]::after,.pc-badge[data-anim=shine][data-variant=dot]::after{background:linear-gradient(100deg,transparent,color-mix(in oklab,var(--pc-c) 22%,transparent),transparent)}\n@keyframes pc-badge-sweep{0%{transform:translateX(-160%) skewX(-18deg)}55%,100%{transform:translateX(320%) skewX(-18deg)}}\n.pc-badge[data-anim=bounce-in]{animation:pc-badge-in .5s var(--pc-ease-spring) both}\n@keyframes pc-badge-in{0%{transform:scale(.3);opacity:0}100%{transform:scale(1);opacity:1}}\n.pc-badge-tick{display:inline-block;animation:pc-badge-tick .38s var(--pc-ease-spring) both}\n@keyframes pc-badge-tick{0%{transform:translateY(55%) scale(.8);opacity:0}100%{transform:none;opacity:1}}\n.pc-badge[data-pop=a]{animation:pc-badge-pop-a .38s var(--pc-ease-spring)}\n.pc-badge[data-pop=b]{animation:pc-badge-pop-b .38s var(--pc-ease-spring)}\n@keyframes pc-badge-pop-a{0%{transform:scale(1.18)}100%{transform:scale(1)}}\n@keyframes pc-badge-pop-b{0%{transform:scale(1.18)}100%{transform:scale(1)}}\n.pc-badge[data-leaving]{animation:pc-badge-out .18s ease-in forwards;pointer-events:none}\n@keyframes pc-badge-out{to{transform:scale(.6);opacity:0}}\n@media (prefers-reduced-motion:reduce){\n  .pc-badge,.pc-badge *{transition:none!important;animation:none!important}\n  .pc-badge::after,.pc-badge-dot::after{display:none}\n}\n`\n\nconst SIZES: Record<BadgeSize, string> = {\n  xs: \"h-5 gap-1 px-1.5 text-[10.5px] [&_svg]:size-3\",\n  sm: \"h-6 gap-1 px-2 text-xs [&_svg]:size-3.5\",\n  md: \"h-7 gap-1.5 px-2.5 text-[13px] [&_svg]:size-3.5\",\n}\nconst X_SIZES: Record<BadgeSize, string> = { xs: \"-me-0.5 size-3.5 [&_svg]:size-2.5\", sm: \"-me-1 size-4 [&_svg]:size-3\", md: \"-me-1 size-[18px] [&_svg]:size-3\" }\nconst SHAPES: Record<BadgeShape, string> = { square: \"rounded-none\", rounded: \"rounded-md\", pill: \"rounded-full\" }\n\nconst reduced = () => typeof window !== \"undefined\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n\nexport function Badge({\n  variant = \"soft\",\n  tone = \"primary\",\n  shadow = \"none\",\n  animation = \"none\",\n  shape = \"pill\",\n  size = \"sm\",\n  icon,\n  removable,\n  onRemove,\n  clickable,\n  max,\n  disabled,\n  className,\n  children,\n  labels,\n  ...props\n}: BadgeProps) {\n  const l = useLabels(\"badge\", DEFAULT_LABELS, labels)\n  const [leaving, setLeaving] = React.useState(false)\n  const [gone, setGone] = React.useState(false)\n  const content = typeof children === \"number\" && max !== undefined && children > max ? `${max}+` : children\n  const key = typeof content === \"string\" || typeof content === \"number\" ? String(content) : null\n\n  // \"count\": pop when the content changes (never on first render).\n  const [tick, setTick] = React.useState(0)\n  const first = React.useRef(true)\n  React.useEffect(() => {\n    if (first.current) {\n      first.current = false\n      return\n    }\n    if (animation === \"count\" && key !== null) setTick((t) => t + 1)\n  }, [key, animation])\n\n  // A new label or toggling removable brings a removed (uncontrolled) badge back.\n  React.useEffect(() => {\n    setGone(false)\n    setLeaving(false)\n  }, [key, removable])\n\n  if (gone) return null\n\n  const finish = () => {\n    setLeaving(false)\n    setGone(true)\n    onRemove?.()\n  }\n  const remove = (e: React.SyntheticEvent) => {\n    e.stopPropagation()\n    if (reduced()) finish()\n    else setLeaving(true)\n  }\n\n  const dot = variant === \"dot\" && !icon ? <span className=\"pc-badge-dot\" aria-hidden=\"true\" /> : null\n  const iconEl = icon ? <span data-slot=\"icon\" className=\"inline-flex\" aria-hidden=\"true\">{icon}</span> : null\n  const pulseDot = animation === \"pulse\" && variant !== \"dot\" && !icon ? <span className=\"pc-badge-dot\" aria-hidden=\"true\" /> : null\n  const label =\n    animation === \"count\" && tick > 0 ? (\n      <span key={tick} className=\"pc-badge-tick tabular-nums\">\n        {content}\n      </span>\n    ) : (\n      content\n    )\n\n  const xProps = {\n    \"aria-label\": l.remove,\n    className: cn(\"pc-press pc-badge-x outline-none focus-visible:ring-2 focus-visible:ring-current/40\", X_SIZES[size]),\n  }\n  const x = removable ? (\n    clickable ? (\n      <span\n        role=\"button\"\n        // Out of the tab order (and inert) when the badge is disabled.\n        tabIndex={disabled ? -1 : 0}\n        aria-disabled={disabled || undefined}\n        {...xProps}\n        onClick={(e) => {\n          if (disabled) e.stopPropagation()\n          else remove(e)\n        }}\n        onKeyDown={(e) => {\n          if (disabled) return\n          if (e.key === \"Enter\" || e.key === \" \") {\n            e.preventDefault()\n            remove(e)\n          }\n        }}\n      >\n        <X />\n      </span>\n    ) : (\n      <button type=\"button\" {...xProps} onClick={remove} disabled={disabled}>\n        <X />\n      </button>\n    )\n  ) : null\n\n  const shared = {\n    \"data-slot\": \"badge\",\n    \"data-variant\": variant,\n    \"data-tone\": tone,\n    \"data-shadow\": variant === \"neo\" ? \"none\" : shadow,\n    \"data-anim\": animation,\n    \"data-clickable\": clickable ? \"\" : undefined,\n    \"data-leaving\": leaving ? \"\" : undefined,\n    \"data-pop\": animation === \"count\" && tick > 0 ? (tick % 2 ? \"a\" : \"b\") : undefined,\n    onAnimationEnd: (e: React.AnimationEvent<HTMLElement>) => {\n      if (leaving && e.animationName === \"pc-badge-out\") finish()\n      props.onAnimationEnd?.(e)\n    },\n    className: cn(\n      \"pc-badge relative inline-flex w-fit shrink-0 items-center justify-center font-medium whitespace-nowrap select-none align-middle leading-none\",\n      \"[&_svg]:shrink-0 [&_svg]:pointer-events-none\",\n      clickable && \"outline-none focus-visible:ring-3 focus-visible:ring-[color-mix(in_oklab,var(--pc-c)_45%,transparent)] disabled:pointer-events-none disabled:opacity-55\",\n      !clickable && disabled && \"opacity-55\",\n      SIZES[size],\n      SHAPES[shape],\n      removable && \"pe-1\",\n      className,\n    ),\n  }\n  const inner = (\n    <>\n      {dot}\n      {pulseDot}\n      {iconEl}\n      {label}\n      {x}\n    </>\n  )\n\n  return (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-badge\" precedence=\"default\">\n        {CSS}\n      </style>\n      {clickable ? (\n        <button type=\"button\" disabled={disabled} {...props} {...shared}>\n          {inner}\n        </button>\n      ) : (\n        <span {...props} {...shared}>\n          {inner}\n        </span>\n      )}\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/badge.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}