{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tag",
  "title": "Tag",
  "description": "Dismissible label for a value the user has committed, such as a recipient or a keyword.",
  "dependencies": [
    "class-variance-authority@^0.7.1",
    "lucide-react@^1.27.0"
  ],
  "registryDependencies": [
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/ui/tag.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { XIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Dismissible label — carries a value the user already committed to (a recipient,\n   a keyword, an applied filter's result). Distinct from Chip, which is the filter\n   control itself. Tags are pills; the trailing X is an icon button, so it squircles. */\nconst tagVariants = cva(\n  \"group/tag inline-flex w-fit shrink-0 items-center rounded-full border border-transparent font-medium whitespace-nowrap transition-all [&>svg]:pointer-events-none [&>svg]:shrink-0\",\n  {\n    variants: {\n      variant: {\n        default: \"bg-primary text-primary-foreground\",\n        secondary: \"bg-secondary text-secondary-foreground\",\n        info: \"bg-info/10 text-info\",\n        success: \"bg-success/10 text-success\",\n        /* warning-foreground is near-black — readable on the light wash only,\n           so dark mode falls back to the hue itself */\n        warning: \"bg-warning/15 text-warning-ink\",\n        destructive:\n          \"bg-destructive/10 text-destructive dark:bg-destructive/20\",\n        outline: \"border-border bg-card text-foreground\",\n      },\n      size: {\n        default:\n          \"h-7 gap-1.5 px-3 text-caption has-data-[slot=tag-dismiss]:pr-1 has-data-[slot=tag-leading]:pl-1.5 [&>svg]:size-3.5\",\n        sm: \"h-6 gap-1 px-2.5 text-caption-sm has-data-[slot=tag-dismiss]:pr-0.5 has-data-[slot=tag-leading]:pl-1 [&>svg]:size-3\",\n      },\n    },\n    defaultVariants: {\n      variant: \"default\",\n      size: \"default\",\n    },\n  }\n)\n\n/* Arrival pop — 0.90 → 1 with the opacity, on the bouncy spring. Same shape as\n   Badge, and for the same reason: a tag that arrives is a value the user just\n   committed to (a recipient typed, a filter applied), which is exactly the\n   small, low-frequency moment overshoot is reserved for.\n\n   Opt-in, because the animation fires on mount. Ten tags rehydrated from stored\n   state have not *arrived*, and a whole row of them popping on first paint is\n   the failure mode — reach for it on the tag being added, not on the list.\n\n   `anim-*` rather than `duration-*`: the pill already carries `transition-all`\n   for its colour, and the entrance runs long while that stays short. */\nconst tagAppear =\n  \"animate-in fade-in zoom-in-90 anim-spring-bouncy ease-spring-bouncy\"\n\n/* Departure, and deliberately not the entrance played backwards: a short tween\n   over a shorter distance (1 → 0.95, against the enter's 0.90 → 1), so removal\n   reads as decisive rather than as arrival rewound. `fill-mode-forwards` holds\n   the last frame for the beat between the animation ending and the consumer\n   dropping the tag, and `pointer-events-none` stops a leaving tag from taking\n   a second click. */\nconst tagDismiss =\n  \"pointer-events-none animate-out fade-out zoom-out-95 anim-exit ease-out-expo fill-mode-forwards\"\n\nfunction Tag({\n  className,\n  variant = \"default\",\n  size = \"default\",\n  leading,\n  onDismiss,\n  dismissLabel = \"Remove\",\n  appear = false,\n  onAnimationEnd,\n  children,\n  ...props\n}: React.ComponentProps<\"span\"> &\n  VariantProps<typeof tagVariants> & {\n    /* leading dot, avatar or mark — sized for you when it is a bare svg/img */\n    leading?: React.ReactNode\n    onDismiss?: () => void\n    /* a row of tags all announcing \"Remove\" is useless — name the value */\n    dismissLabel?: string\n    /* Play the arrival pop on mount. For a tag that shows up in response to\n       something, not one that has been on screen since first paint. */\n    appear?: boolean\n  }) {\n  /* A tag does not own its own removal — the consumer drops it from a list when\n     onDismiss fires — so the exit has to run *before* the callback, not after.\n     The flag plays the animation and animationend hands control back. Under\n     reduced motion the duration tokens collapse to 1ms rather than 0 precisely\n     so this event still fires and the tag still goes away. */\n  const [dismissing, setDismissing] = React.useState(false)\n\n  return (\n    <span\n      data-slot=\"tag\"\n      data-variant={variant}\n      data-size={size}\n      className={cn(\n        tagVariants({ variant, size }),\n        /* mutually exclusive on purpose — both set `animation`, and leaving the\n           two `anim-*` durations to fight it out in stylesheet order is not a\n           tie cn() can break */\n        dismissing ? tagDismiss : appear && tagAppear,\n        className\n      )}\n      onAnimationEnd={(event: React.AnimationEvent<HTMLSpanElement>) => {\n        onAnimationEnd?.(event)\n        /* a leading avatar or an animated child would bubble its own end event\n           through here — only the tag's own exit completes the dismissal */\n        if (dismissing && event.target === event.currentTarget) onDismiss?.()\n      }}\n      {...props}\n    >\n      {leading ? (\n        <span\n          data-slot=\"tag-leading\"\n          className=\"inline-flex shrink-0 items-center justify-center [&>img]:size-5 [&>img]:rounded-full [&>img]:object-cover [&>svg]:size-3.5 group-data-[size=sm]/tag:[&>img]:size-4.5 group-data-[size=sm]/tag:[&>svg]:size-3\"\n        >\n          {leading}\n        </span>\n      ) : null}\n      {children}\n      {onDismiss ? (\n        <button\n          type=\"button\"\n          data-slot=\"tag-dismiss\"\n          aria-label={dismissLabel}\n          onClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n            /* the X owns its click — it must never also fire the tag's onClick */\n            event.stopPropagation()\n            setDismissing(true)\n          }}\n          /* squircle, not a circle: rounded-full on a 20px box collapses to a dot.\n             The box stays 20px for the hit area; the glyph is chrome, so it sits\n             a step under the label rather than competing with it.\n\n             Motion: hover wash resolves fast enough to read as instant, and the\n             press is a spring scale timed only for the length of `:active`, so\n             the push settles on the spring and the release runs back on the\n             shorter tween. The dip is proportionally deeper than a Button's\n             because the target is a fifth of the size — equal percentages do\n             not read as equal movement at this scale. */\n          className=\"inline-flex size-5 shrink-0 items-center justify-center rounded-[7px] opacity-70 transition-all duration-fast ease-out-expo outline-none hover:bg-current/15 hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-3 focus-visible:ring-ring/50 active:scale-90 active:duration-spring-press active:ease-spring-press group-data-[size=sm]/tag:size-4.5 group-data-[size=sm]/tag:rounded-[6px] [&>svg]:size-3 group-data-[size=sm]/tag:[&>svg]:size-2.5\"\n        >\n          <XIcon aria-hidden=\"true\" />\n        </button>\n      ) : null}\n    </span>\n  )\n}\n\nexport { Tag, tagVariants }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}