{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "badge",
  "title": "Badge",
  "description": "A short label for a status, category or count: \"Draft\", \"Vegan\", \"3\".",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/lib-appearance-hints",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-router-link",
    "@ouro/lib-tones",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/badge/badge.tsx",
      "content": "\"use client\";\n\nimport { Button as BaseButton } from \"@base-ui/react/button\";\nimport type { AnchorHTMLAttributes, ButtonHTMLAttributes, ComponentType, JSX, HTMLAttributes, MouseEventHandler, ReactNode, Ref, SVGProps } from \"react\";\nimport { fontFor, radiusFor, toneFor } from \"@/registry/ouro/lib/ouro/appearance-hints\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { RouterLink } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { toneWarning } from \"@/registry/ouro/lib/ouro/tones\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** An icon component, such as one from `lucide-react` or `@heroicons/react`. */\nexport type BadgeIcon = ComponentType<SVGProps<SVGSVGElement>>;\n\n/**\n * Props shared by every kind of Badge (`href` makes a link, `onClick` a button).\n *\n * @claim \"Props shared by every kind of\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > renders a button with onClick, with a touch target and press feedback)\n * @claim \"Props shared by every kind of\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > renders a link with href through the provider's linkComponent)\n */\nexport interface BadgeBaseProps {\n  /**\n   * Color role from the theme, named after its token. `secondary` is a quiet neutral\n   * label; use `success`, `warning` and `destructive` for status.\n   * shadcn's `variant=\"destructive\"` is `tone=\"destructive\"`.\n   * @default \"secondary\"\n   */\n  tone?:\n    | \"primary\"\n    | \"secondary\"\n    | \"destructive\"\n    | \"success\"\n    | \"warning\"\n    | (string & { 'danger is \"destructive\"; accent is \"primary\"; neutral is \"secondary\"': never })\n    | undefined;\n  /**\n   * Visual weight: `solid` fills the badge with the tone, `soft` tints it, `outline`\n   * draws only the border. shadcn's `default` is `tone=\"primary\"`, its `secondary` and\n   * `destructive` are tones, and `ghost` is `soft`.\n   * @default \"solid\"\n   */\n  variant?:\n    | \"solid\"\n    | \"soft\"\n    | \"outline\"\n    | (string & { 'From shadcn? secondary and destructive are tones; default is tone=\"primary\"; ghost is \"soft\"': never })\n    | undefined;\n  /**\n   * Runs when the badge is pressed. Without `href` it makes the badge a `<button>`\n   * (pass `aria-pressed` too when it toggles a filter); with `href` it runs before the\n   * link navigates.\n   */\n  onClick?: MouseEventHandler<HTMLElement> | undefined;\n  /** Icon before the label. Pass the component, not an element: `icon={CheckIcon}`. */\n  icon?: BadgeIcon | undefined;\n  /**\n   * A status dot before the label, in the tone's colour: `<Badge tone=\"success\" dot>Published</Badge>`.\n   * The dot is decorative; the label names the status.\n   * @default false\n   * @claim \"A status dot before the label, in the tone's colour\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > shows a status dot before its label, in the tone's colour)\n   */\n  dot?: boolean | undefined;\n  /** The label: a short word, or a count. */\n  children: ReactNode;\n  /** Layout only: margins, grid placement (`ms-2`). Appearance classes warn in development; use `tone` and `variant`. */\n  className?: string | undefined;\n\n  /** Not a prop. Ouro UI uses `tone`: `<Badge tone=\"destructive\">`. */\n  color?: { 'Use <Badge tone=\"destructive\">': never };\n  /** Not a prop. To render a link, pass `href`: `<Badge href=\"/tags/vegan\">`. */\n  asChild?: { 'Use <Badge href=\"/path\">': never };\n}\n\n/** The props only a link Badge takes: `href` and the anchor's own attributes (`target`, `rel`, `download`). */\nexport type BadgeLinkModeProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof HTMLAttributes<HTMLAnchorElement> | \"type\"> & {\n  /**\n   * Where the link goes. Internal paths render through `OuroProvider`'s\n   * `linkComponent` (your router's link); absolute URLs render as a plain `<a>`, and\n   * with `target=\"_blank\"` always get `rel=\"noopener noreferrer\"`.\n   * @claim \"Internal paths render through `OuroProvider`'s `linkComponent`\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > renders an absolute URL as a plain <a> with a safe rel in a new tab)\n   * @claim \"Internal paths render through `OuroProvider`'s `linkComponent`\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > renders a link with href through the provider's linkComponent)\n   */\n  href: string;\n  /**\n   * Links have no `type`. Remove `href` and pass `onClick` for a button.\n   *\n   * @claim \"Links have no `type`\" registry/ouro/components/ouro/badge/badge.tsx verify:fileLine(registry/ouro/components/ouro/badge/badge.tsx, /^\\s+type\\?:\\snever;/)\n   */\n  type?: never;\n  /** A link cannot be disabled. Remove `href` and pass `onClick` for a button. */\n  disabled?: never;\n  ref?: Ref<HTMLAnchorElement> | undefined;\n};\n\n/** The props only a Badge without `href` takes: the button's own attributes (`type`, `disabled`). */\nexport type BadgeButtonModeProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof HTMLAttributes<HTMLButtonElement> | \"type\"> & {\n  /** Not set: a static badge or, with `onClick`, a button. Pass `href` for a link. */\n  href?: never;\n  /** With `onClick`, the button's role in a form. @default \"button\" */\n  type?: \"button\" | \"submit\" | \"reset\" | undefined;\n  ref?: Ref<HTMLButtonElement & HTMLSpanElement> | undefined;\n};\n\n/**\n * The HTML attributes every kind of Badge passes through, outside the mode union so the editor keeps their hover docs.\n *\n * @claim \"The HTML attributes every kind of\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > passes aria-pressed through for a filter badge)\n * @claim \"The HTML attributes every kind of\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge development messages > keeps button attributes off a static badge)\n */\ntype BadgeCommonProps = Omit<HTMLAttributes<HTMLElement>, keyof BadgeBaseProps> & BadgeBaseProps;\n\n/** A Badge with `href`: a link that looks like a badge, such as a tag that opens its list. */\nexport type BadgeLinkProps = BadgeCommonProps & BadgeLinkModeProps;\n\n/**\n * A Badge without `href`: a `<button>` when it has `onClick`, such as a filter chip (pass\n * `aria-pressed` for a toggle), and otherwise a static `<span>` label.\n */\nexport type BadgeButtonProps = BadgeCommonProps & BadgeButtonModeProps;\n\n/** Props for {@link Badge}: `href` makes it a link, `onClick` a button, and neither a `<span>`. */\nexport type BadgeProps = BadgeCommonProps & (BadgeLinkModeProps | BadgeButtonModeProps);\n\n// Class strings are literal so the app's Tailwind finds them when it compiles.\nconst base =\n  \"relative isolate box-border inline-flex shrink-0 items-center gap-1 align-middle \" +\n  // Stryker disable next-line StringLiteral: a class string in a class position, unchanged but for the joining plus\n  \"h-6 rounded-ouro-md border border-solid px-2 text-xs/none font-medium whitespace-nowrap no-underline \" +\n  // Where corner-shape is missing, the surface slot paints the background, border and state layer instead (see ouro-base.css).\n  \"bg-(--ouro-bg) border-(--ouro-bd) [--ouro-sq-w:1px] [--ouro-sq-r:calc(var(--radius)*var(--ouro-radius-scale,1)*0.8)]\";\n\n// Only for the link and button kinds: press feedback, a state layer and the focus ring,\n// as on Button.\nconst interactive =\n  \"press cursor-pointer select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"before:pointer-events-none before:absolute before:-inset-px before:rounded-[inherit] before:[corner-shape:inherit] before:bg-current \" +\n  \"before:opacity-0 before:transition-opacity before:duration-(--ouro-duration-fast) before:ease-[ease] \" +\n  \"not-data-disabled:not-active:pointer-fine:hover:before:opacity-8 not-data-disabled:active:before:opacity-14 \" +\n  // Stryker disable next-line StringLiteral: a class string in a class position, which no test reads\n  \"not-data-disabled:not-active:pointer-fine:hover:[--ouro-state:0.08] not-data-disabled:active:[--ouro-state:0.14] \" +\n  \"motion-safe:not-data-disabled:active:scale-(--ouro-press-scale) \" +\n  \"disabled:cursor-not-allowed disabled:opacity-50\";\n\n// `soft` text is the tone mixed 20% toward the foreground, as on Button, so it keeps\n// 4.5:1 on the tint under shadcn's stock values too. `secondary` is shadcn's quiet surface.\nconst looks = {\n  solid: {\n    primary: \"[--ouro-bd:transparent] [--ouro-bg:var(--primary)] text-primary-foreground\",\n    secondary: \"[--ouro-bd:transparent] [--ouro-bg:var(--secondary)] text-secondary-foreground\",\n    destructive: \"[--ouro-bd:transparent] [--ouro-bg:var(--destructive)] text-destructive-foreground\",\n    success: \"[--ouro-bd:transparent] [--ouro-bg:var(--success)] text-success-foreground\",\n    warning: \"[--ouro-bd:transparent] [--ouro-bg:var(--warning)] text-warning-foreground\",\n  },\n  soft: {\n    primary: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--primary)_10%,transparent)] text-[color-mix(in_oklab,var(--primary)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n    secondary: \"[--ouro-bd:transparent] [--ouro-bg:var(--muted)] text-foreground contrast-more:[--ouro-bd:currentColor]\",\n    destructive: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--destructive)_10%,transparent)] text-[color-mix(in_oklab,var(--destructive)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n    success: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--success)_10%,transparent)] text-[color-mix(in_oklab,var(--success)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n    warning: \"[--ouro-bd:transparent] [--ouro-bg:color-mix(in_oklab,var(--warning)_10%,transparent)] text-[color-mix(in_oklab,var(--warning)_80%,var(--foreground))] contrast-more:[--ouro-bd:currentColor]\",\n  },\n  outline: {\n    primary: \"[--ouro-bd:color-mix(in_oklab,var(--primary)_45%,transparent)] [--ouro-bg:transparent] text-primary\",\n    secondary: \"[--ouro-bd:var(--border)] [--ouro-bg:transparent] text-foreground\",\n    destructive: \"[--ouro-bd:color-mix(in_oklab,var(--destructive)_45%,transparent)] [--ouro-bg:transparent] text-destructive\",\n    success: \"[--ouro-bd:color-mix(in_oklab,var(--success)_45%,transparent)] [--ouro-bg:transparent] text-success\",\n    warning: \"[--ouro-bd:color-mix(in_oklab,var(--warning)_45%,transparent)] [--ouro-bg:transparent] text-warning\",\n  },\n} as const;\n\n/** shadcn's Badge variants, with the Ouro UI props that do the same job. Development only. */\nconst shadcnVariants: Readonly<Record<string, string>> = {\n  default: '<Badge tone=\"primary\" variant=\"solid\">',\n  secondary: '<Badge tone=\"secondary\">',\n  destructive: '<Badge tone=\"destructive\">',\n  ghost: '<Badge variant=\"soft\">',\n  link: '<Badge href=\"/path\">',\n};\n\nfunction badgeHint(token: string): string {\n  if (/^text-(xs|sm|base|lg|xl|\\dxl)$/.test(token)) return `remove \"${token}\"; Badge sets its own size`;\n  if (token.startsWith(\"font-\")) return fontFor(\"Badge\", token);\n  if (token.startsWith(\"rounded\")) return radiusFor(token);\n  if (/^border-/.test(token)) return `variant=\"outline\" tone=\"${toneFor(token)}\"`;\n  return `tone=\"${toneFor(token)}\"`;\n}\n\n/**\n * A short label for a status, category or count: \"Draft\", \"Vegan\", \"3\". With `href` it\n * becomes a link and with `onClick` a button, with press feedback and a 44px touch\n * target on phones, the same way `Button` does. Without `onClick` or `href` a Badge is\n * not a button: it is a static `<span>`, and `disabled` and `type` do nothing.\n *\n * Use `Button` instead for an action that needs a clear call to action, and `Alert` for\n * a message the reader must notice.\n *\n * @group Display\n * @see https://ui.ouroboros.bot/docs/badge\n *\n * @example\n * <Badge>Draft</Badge>\n * <Badge tone=\"success\" variant=\"soft\">Published</Badge>\n * <Badge href=\"/tags/vegan\">Vegan</Badge>\n * <Badge onClick={toggle} aria-pressed={active}>Quick</Badge>\n * @claim \"With `href` it becomes a link\" registry/ouro/components/ouro/badge/badge.test.tsx verify:testExists(registry/ouro/components/ouro/badge/badge.test.tsx::Badge > renders a button with onClick, with a touch target and press feedback)\n */\nexport function Badge(props: BadgeProps): JSX.Element {\n  const {\n    tone: toneProp = \"secondary\",\n    variant: variantProp = \"solid\",\n    icon: Icon,\n    dot = false,\n    onClick,\n    children,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    color,\n    asChild,\n    ...rest\n  } = props;\n  // A tone or variant that is not one of Ouro UI's (a type error) warns and renders the default.\n  const tone = Object.hasOwn(looks.solid, toneProp) ? (toneProp as keyof typeof looks.solid) : \"secondary\";\n  const variant = Object.hasOwn(looks, variantProp) ? (variantProp as keyof typeof looks) : \"solid\";\n  useAppearanceClassNameCheck(\n    \"Badge\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? badgeHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Badge\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => {\n          const kind = rest as { href?: string; type?: string; disabled?: boolean };\n          const isStatic = kind.href === undefined && onClick === undefined;\n          return [\n            tone !== toneProp && toneWarning(\"Badge\", String(toneProp), Object.keys(looks.solid)),\n            variant !== variantProp &&\n              (Object.hasOwn(shadcnVariants, variantProp)\n                ? [`variant=\"${variantProp}\" is not a variant`, shadcnVariants[variantProp]!]\n                : [`variant=\"${String(variantProp)}\" is not a variant; use \"solid\", \"soft\", \"outline\"`, '<Badge variant=\"solid\">']),\n            color !== undefined && [\"color is not a prop\", `<Badge tone=\"${toneFor(`bg-${String(color)}`)}\">`],\n            asChild !== undefined && [\"asChild is not a prop\", '<Badge href=\"/path\">'],\n            kind.href !== undefined &&\n              kind.type !== undefined && [`a link has no type, so type=\"${kind.type}\" is ignored`, `<Badge onClick={…} type=\"${kind.type}\"> without href`],\n            isStatic &&\n              kind.disabled !== undefined && [\n                \"disabled does nothing on a Badge without onClick, because a static Badge is not a button\",\n                \"<Badge onClick={…} disabled>\",\n              ],\n            isStatic &&\n              kind.type !== undefined && [\n                `type=\"${kind.type}\" does nothing on a Badge without onClick, because a static Badge is not a button`,\n                `<Button type=\"${kind.type}\">`,\n              ],\n          ];\n        }\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const look = looks[variant][tone];\n  // The icon and the label go in as siblings of the surface, not in a fragment, which would be a component of its own.\n  const icon = Icon && <Icon aria-hidden=\"true\" className=\"relative -ms-0.5 size-3.5 shrink-0\" />;\n  const statusDot = dot && <span data-ouro-dot=\"\" aria-hidden=\"true\" className=\"relative size-1.5 shrink-0 rounded-full bg-current\" />;\n\n  if (rest.href !== undefined) {\n    const { type: _type, disabled: _disabled, ...anchorProps } = rest as Omit<BadgeLinkProps, keyof BadgeBaseProps>;\n    return (\n      <RouterLink data-ouro-control=\"badge\" data-ouro-part=\"root\" {...anchorProps} onClick={onClick} data-ouro=\"badge\" data-ouro-squircle=\"\" className={cn(base, interactive, look, className)}>\n        <TouchTarget />\n        <span data-ouro-surface=\"\" aria-hidden=\"true\" style={{ zIndex: -1 }} />\n        {statusDot}\n        {icon}\n        {children}\n      </RouterLink>\n    );\n  }\n  const { ref, type = \"button\", disabled, ...buttonProps } = rest as Omit<BadgeButtonProps, keyof BadgeBaseProps>;\n  if (onClick !== undefined) {\n    return (\n      <BaseButton data-ouro-control=\"badge\" data-ouro-part=\"root\" {...buttonProps} onClick={onClick} disabled={disabled} ref={ref as Ref<HTMLElement> | undefined} type={type} data-ouro=\"badge\" data-ouro-squircle=\"\" className={cn(base, interactive, look, className)}>\n        <TouchTarget />\n        <span data-ouro-surface=\"\" aria-hidden=\"true\" style={{ zIndex: -1 }} />\n        {statusDot}\n        {icon}\n        {children}\n      </BaseButton>\n    );\n  }\n  // A static Badge is a <span>, not a button: the button's own attributes are dropped.\n  const { name: _name, value: _value, form: _form, ...spanProps } = buttonProps;\n  return (\n    <span {...(spanProps as HTMLAttributes<HTMLSpanElement>)} ref={ref} data-ouro=\"badge\" data-ouro-squircle=\"\" className={cn(base, look, className)}>\n      <span data-ouro-surface=\"\" aria-hidden=\"true\" style={{ zIndex: -1 }} />\n      {statusDot}\n      {icon}\n      {children}\n    </span>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/badge/badge.tsx"
    }
  ],
  "docs": "A short label for a status, category or count: \"Draft\", \"Vegan\", \"3\". Import: import { Badge } from \"@/components/ouro/badge/badge\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/badge.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}