{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tag",
  "title": "Tag",
  "description": "A short label that can also be pressed or removed: soft tint, outline, solid or a status dot, with status tones that never borrow the accent.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/tag.tsx",
      "content": "import type * as React from \"react\"\r\nimport { useCallback, useEffect, useRef, useState } from \"react\"\r\nimport { X } from \"lucide-react\"\r\nimport { motion, useReducedMotion } from \"motion/react\"\r\nimport { SPRING_DEFAULT } from \"@/registry/miseui/lib/motion\"\r\nimport {\r\n  BODY_CLASS,\r\n  DOT_TONE_CLASS,\r\n  HIT_AREA_CLASS,\r\n  ROOT_CLASS,\r\n  TONE_CLASS,\r\n  type TagTone,\r\n  type TagVariant,\r\n} from \"@/registry/miseui/ui/tag-classes\"\r\nimport { cn } from \"@/registry/miseui/lib/utils\"\r\n\r\ntype TagEffect = \"collapse\"\r\n\r\n/** Comfortably past the spring. A row that is hidden or in a background tab never reports the end of its animation. */\r\nconst CLOSE_FALLBACK_MS = 600\r\n\r\n/** Removing a focused tag would drop focus onto the page; the neighbour is where a keyboard user wants to carry on. */\r\nfunction focusNeighbour(node: HTMLElement | null) {\r\n  const neighbour = node?.nextElementSibling ?? node?.previousElementSibling\r\n  neighbour?.querySelector<HTMLElement>(\"button\")?.focus()\r\n}\r\n\r\n/** Without taking the gap away too, the row would close to one gap short and then jump when the tag unmounts. */\r\nfunction parentGap(node: HTMLElement | null) {\r\n  if (!node?.parentElement) return 0\r\n  return Number.parseFloat(getComputedStyle(node.parentElement).columnGap) || 0\r\n}\r\n\r\nfunction useRemoval(collapse: boolean, onRemove?: () => void) {\r\n  const reduceMotion = useReducedMotion() ?? false\r\n  const rootRef = useRef<HTMLSpanElement>(null)\r\n  const finished = useRef(false)\r\n  const [closing, setClosing] = useState<{ gap: number } | null>(null)\r\n  const finish = useCallback(() => {\r\n    if (finished.current) return\r\n    finished.current = true\r\n    onRemove?.()\r\n  }, [onRemove])\r\n  useEffect(() => {\r\n    if (!closing) return\r\n    const timer = window.setTimeout(finish, CLOSE_FALLBACK_MS)\r\n    return () => window.clearTimeout(timer)\r\n  }, [closing, finish])\r\n  const remove = () => {\r\n    focusNeighbour(rootRef.current)\r\n    if (collapse && !reduceMotion) setClosing({ gap: parentGap(rootRef.current) })\r\n    else onRemove?.()\r\n  }\r\n  return { rootRef, closing, remove, finish }\r\n}\r\n\r\nfunction RemoveButton({ label, disabled, onClick }: { label: string; disabled?: boolean; onClick: () => void }) {\r\n  return (\r\n    <button\r\n      type=\"button\"\r\n      data-slot=\"tag-remove\"\r\n      aria-label={label}\r\n      disabled={disabled}\r\n      onClick={onClick}\r\n      className={cn(\r\n        \"ms-1 -me-1 inline-flex size-4 shrink-0 items-center justify-center rounded-full opacity-70 outline-none\",\r\n        \"transition-opacity duration-(--duration-fast) ease-(--ease-mise) hover:opacity-100\",\r\n        \"focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none\",\r\n        HIT_AREA_CLASS,\r\n      )}\r\n    >\r\n      <X aria-hidden=\"true\" className=\"size-3\" />\r\n    </button>\r\n  )\r\n}\r\n\r\ninterface TagBodyProps {\r\n  onClick?: React.MouseEventHandler<HTMLButtonElement>\r\n  pressed?: boolean\r\n  disabled?: boolean\r\n  children: React.ReactNode\r\n}\r\n\r\nfunction TagBody({ onClick, pressed, disabled, children }: TagBodyProps) {\r\n  if (!onClick) return <span className={BODY_CLASS}>{children}</span>\r\n  return (\r\n    <button\r\n      type=\"button\"\r\n      data-slot=\"tag-button\"\r\n      aria-pressed={pressed}\r\n      disabled={disabled}\r\n      onClick={onClick}\r\n      className={cn(\r\n        BODY_CLASS,\r\n        HIT_AREA_CLASS,\r\n        \"cursor-pointer rounded-[inherit] outline-none hover:opacity-80 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none\",\r\n      )}\r\n    >\r\n      {children}\r\n    </button>\r\n  )\r\n}\r\n\r\ntype TagProps = Omit<React.ComponentProps<\"span\">, \"onClick\"> & {\r\n  /** `soft` a tint, `outline` a border, `solid` full colour, `dot` a status dot beside plain text. */\r\n  variant?: TagVariant\r\n  /** Status tones use fixed hues; only `accent` follows the theme. The word in the tag has to carry the meaning too. */\r\n  tone?: TagTone\r\n  /** `collapse` closes the gap when removed, so the row slides shut. Fires onRemove once it has finished. */\r\n  effect?: TagEffect\r\n  /** Makes the label a button. */\r\n  onClick?: React.MouseEventHandler<HTMLButtonElement>\r\n  /** Reports the pressed state of a clickable tag, for filters. */\r\n  pressed?: boolean\r\n  /** Adds the remove button. */\r\n  onRemove?: () => void\r\n  /** Name of the remove button. Include the tag, such as \"Remove design\". */\r\n  removeLabel?: string\r\n  disabled?: boolean\r\n}\r\n\r\nfunction Tag({ variant = \"soft\", tone = \"neutral\", effect, onClick, pressed, onRemove, removeLabel = \"Remove\", disabled, className, children, ...props }: TagProps) {\r\n  const { rootRef, closing, remove, finish } = useRemoval(effect === \"collapse\", onRemove)\r\n  const label = (\r\n    <>\r\n      {variant === \"dot\" ? (\r\n        <span aria-hidden=\"true\" data-slot=\"tag-dot\" className={cn(\"size-1.5 shrink-0 rounded-full\", DOT_TONE_CLASS[tone])} />\r\n      ) : null}\r\n      <span className=\"min-w-0 truncate\">{children}</span>\r\n    </>\r\n  )\r\n  return (\r\n    <motion.span\r\n      {...(props as React.ComponentProps<typeof motion.span>)}\r\n      ref={rootRef}\r\n      data-slot=\"tag\"\r\n      data-variant={variant}\r\n      data-tone={tone}\r\n      data-effect={effect}\r\n      data-closing={closing ? \"true\" : undefined}\r\n      inert={closing ? true : undefined}\r\n      // Clipped only while closing, or it would cut off the focus ring and the touch hit area.\r\n      className={cn(ROOT_CLASS[variant], TONE_CLASS[variant][tone], disabled && \"opacity-50\", closing && \"overflow-hidden\", className)}\r\n      initial={false}\r\n      animate={closing ? { width: 0, opacity: 0, marginInlineEnd: -closing.gap } : undefined}\r\n      transition={SPRING_DEFAULT}\r\n      onAnimationComplete={() => {\r\n        if (closing) finish()\r\n      }}\r\n    >\r\n      <TagBody onClick={onClick} pressed={pressed} disabled={disabled}>\r\n        {label}\r\n      </TagBody>\r\n      {onRemove ? <RemoveButton label={removeLabel} disabled={disabled} onClick={remove} /> : null}\r\n    </motion.span>\r\n  )\r\n}\r\n\r\nexport { Tag, type TagProps, type TagVariant, type TagTone, type TagEffect }\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/tag-classes.ts",
      "content": "type TagVariant = \"soft\" | \"outline\" | \"solid\" | \"dot\"\r\ntype TagTone = \"neutral\" | \"accent\" | \"success\" | \"warning\" | \"error\"\r\n\r\nconst ROOT_CLASS: Record<TagVariant, string> = {\r\n  soft: \"inline-flex h-6 max-w-full min-w-0 items-center rounded-md px-2 text-[13px] font-medium\",\r\n  outline: \"inline-flex h-6 max-w-full min-w-0 items-center rounded-full border px-3 text-[13px]\",\r\n  solid: \"inline-flex h-6 max-w-full min-w-0 items-center rounded-sm px-2 text-[13px] font-semibold\",\r\n  dot: \"inline-flex h-6 max-w-full min-w-0 items-center text-[13px] text-foreground\",\r\n}\r\n\r\n/** Fixed hues for status, because the accent may itself be amber or red. Only `accent` follows the theme. */\r\nconst TONE_CLASS: Record<TagVariant, Record<TagTone, string>> = {\r\n  soft: {\r\n    neutral: \"bg-muted text-foreground\",\r\n    accent: \"bg-mise-soft text-foreground\",\r\n    success: \"bg-emerald-500/15 text-emerald-800 dark:text-emerald-300\",\r\n    warning: \"bg-amber-400/20 text-amber-800 dark:text-amber-300\",\r\n    error: \"bg-destructive/10 text-destructive dark:bg-destructive/15\",\r\n  },\r\n  outline: {\r\n    neutral: \"border-border text-foreground\",\r\n    accent: \"border-mise text-foreground\",\r\n    success: \"border-emerald-500/60 text-emerald-800 dark:text-emerald-300\",\r\n    warning: \"border-amber-500/70 text-amber-800 dark:text-amber-300\",\r\n    error: \"border-destructive/60 text-destructive\",\r\n  },\r\n  solid: {\r\n    neutral: \"bg-foreground text-background\",\r\n    accent: \"bg-mise text-mise-foreground\",\r\n    success: \"bg-emerald-600 text-white dark:bg-emerald-500 dark:text-emerald-950\",\r\n    warning: \"bg-amber-400 text-amber-950\",\r\n    // The dark theme lightens the error colour past what white text can sit on.\r\n    error: \"bg-destructive text-white dark:text-background\",\r\n  },\r\n  dot: { neutral: \"\", accent: \"\", success: \"\", warning: \"\", error: \"\" },\r\n}\r\n\r\nconst DOT_TONE_CLASS: Record<TagTone, string> = {\r\n  neutral: \"bg-muted-foreground\",\r\n  accent: \"bg-mise\",\r\n  success: \"bg-emerald-500\",\r\n  warning: \"bg-amber-500\",\r\n  error: \"bg-destructive\",\r\n}\r\n\r\nconst BODY_CLASS = \"inline-flex min-w-0 items-center gap-2\"\r\n\r\n/** The tag stays 24 px on a phone; this invisible square is what reaches 40 px, centred on the control. */\r\nconst HIT_AREA_CLASS =\r\n  \"relative pointer-coarse:after:absolute pointer-coarse:after:top-1/2 pointer-coarse:after:left-1/2 pointer-coarse:after:size-10 pointer-coarse:after:-translate-x-1/2 pointer-coarse:after:-translate-y-1/2\"\r\n\r\nexport { BODY_CLASS, DOT_TONE_CLASS, HIT_AREA_CLASS, ROOT_CLASS, TONE_CLASS, type TagTone, type TagVariant }\r\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "display"
  ],
  "type": "registry:ui"
}