{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon-action-button",
  "title": "Icon Action Button",
  "description": "A compact icon-only button for toolbars and table rows: solid, soft, outline or ghost, square or round, four sizes, a tooltip that names the action, a count badge, a loading spinner and a danger tone for destructive actions.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/icon-action-button/icon-action-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type IconActionButtonVariant = \"solid\" | \"soft\" | \"outline\" | \"ghost\";\nexport type IconActionButtonSize = \"xs\" | \"sm\" | \"md\" | \"lg\";\n\nexport interface IconActionButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\"> {\n  /** The icon. Keep it a single glyph; the button is sized around it. */\n  icon: React.ReactNode;\n  /** Accessible name, also shown as the tooltip. Required: there's no visible text. */\n  label: string;\n  variant?: IconActionButtonVariant;\n  size?: IconActionButtonSize;\n  shape?: \"square\" | \"circle\";\n  /** \"danger\" tints the button for destructive actions like delete. */\n  tone?: \"neutral\" | \"danger\";\n  /** A count (or true for a plain dot) pinned to the top-right corner. */\n  badge?: number | boolean;\n  loading?: boolean;\n  /** Show the label as a tooltip on hover and keyboard focus. */\n  tooltip?: boolean;\n  tooltipSide?: \"top\" | \"bottom\";\n  theme?: \"dark\" | \"light\";\n  /** React 19 passes ref as a regular prop. */\n  ref?: React.Ref<HTMLButtonElement>;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.7)\", solid: \"#F5F4F1\", onSolid: \"#0A0A0A\", soft: \"rgba(255,255,255,0.08)\", softHover: \"rgba(255,255,255,0.14)\", border: \"rgba(255,255,255,0.16)\", borderHover: \"rgba(255,255,255,0.3)\", ghostHover: \"rgba(255,255,255,0.08)\", danger: \"#FF7A6B\", badge: \"#FF5A4E\", tip: \"#F5F4F1\", onTip: \"#0A0A0A\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.65)\", solid: \"#0A0A0A\", onSolid: \"#FFFFFF\", soft: \"rgba(10,10,10,0.06)\", softHover: \"rgba(10,10,10,0.1)\", border: \"rgba(10,10,10,0.16)\", borderHover: \"rgba(10,10,10,0.32)\", ghostHover: \"rgba(10,10,10,0.06)\", danger: \"#E5484D\", badge: \"#E5484D\", tip: \"#0A0A0A\", onTip: \"#FFFFFF\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst SIZES: Record<IconActionButtonSize, { box: number; icon: number; radius: number }> = {\n  xs: { box: 26, icon: 14, radius: 7 },\n  sm: { box: 32, icon: 16, radius: 9 },\n  md: { box: 38, icon: 18, radius: 11 },\n  lg: { box: 46, icon: 21, radius: 13 },\n};\n\nexport function IconActionButton({ icon, label, variant = \"soft\", size = \"md\", shape = \"square\", tone = \"neutral\", badge, loading = false, tooltip = true, tooltipSide = \"top\", theme = \"dark\", className, style, disabled, onPointerEnter, onPointerLeave, onFocus, onBlur, ref, ...rest }: IconActionButtonProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const reduce = Boolean(useReducedMotion());\n  const [tip, setTip] = React.useState(false);\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const tipId = React.useId();\n\n  const accent = tone === \"danger\" ? p.danger : p.solid;\n  const colors: Record<IconActionButtonVariant, { bg: string; hover: string; fg: string; border: string; borderHover: string }> = {\n    solid: { bg: accent, hover: accent, fg: tone === \"danger\" ? \"#FFFFFF\" : p.onSolid, border: accent, borderHover: accent },\n    soft: { bg: tone === \"danger\" ? `color-mix(in srgb, ${p.danger} 14%, transparent)` : p.soft, hover: tone === \"danger\" ? `color-mix(in srgb, ${p.danger} 22%, transparent)` : p.softHover, fg: tone === \"danger\" ? p.danger : p.text, border: \"transparent\", borderHover: \"transparent\" },\n    outline: { bg: \"transparent\", hover: p.ghostHover, fg: tone === \"danger\" ? p.danger : p.text, border: tone === \"danger\" ? `color-mix(in srgb, ${p.danger} 45%, transparent)` : p.border, borderHover: tone === \"danger\" ? p.danger : p.borderHover },\n    ghost: { bg: \"transparent\", hover: tone === \"danger\" ? `color-mix(in srgb, ${p.danger} 14%, transparent)` : p.ghostHover, fg: tone === \"danger\" ? p.danger : p.muted, border: \"transparent\", borderHover: \"transparent\" },\n  };\n  const c = colors[variant];\n\n  const show = (delay: number) => {\n    if (!tooltip) return;\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = setTimeout(() => setTip(true), delay);\n  };\n  const hide = () => {\n    if (timer.current) clearTimeout(timer.current);\n    setTip(false);\n  };\n  React.useEffect(() => () => {\n    if (timer.current) clearTimeout(timer.current);\n  }, []);\n\n  const count = typeof badge === \"number\" ? (badge > 99 ? \"99+\" : String(badge)) : null;\n\n  return (\n    <span className=\"relative inline-flex\">\n      <motion.button\n        ref={ref}\n        type=\"button\"\n        aria-label={label}\n        aria-describedby={tip ? tipId : undefined}\n        aria-busy={loading || undefined}\n        disabled={disabled || loading}\n        whileTap={disabled || loading || reduce ? undefined : { scale: 0.9 }}\n        transition={{ type: \"spring\", stiffness: 600, damping: 30 }}\n        onPointerEnter={(e) => {\n          onPointerEnter?.(e);\n          show(350);\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          hide();\n        }}\n        onFocus={(e) => {\n          onFocus?.(e);\n          if (e.currentTarget.matches(\":focus-visible\")) show(0);\n        }}\n        onBlur={(e) => {\n          onBlur?.(e);\n          hide();\n        }}\n        className={cn(\n          \"relative inline-flex shrink-0 cursor-pointer items-center justify-center outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-45\",\n          \"bg-[var(--iab-bg)] [border-color:var(--iab-border)] hover:bg-[var(--iab-hover)] hover:[border-color:var(--iab-border-hover)]\",\n          variant === \"solid\" && \"hover:brightness-110\",\n          className,\n        )}\n        style={{\n          width: s.box,\n          height: s.box,\n          borderRadius: shape === \"circle\" ? 999 : s.radius,\n          borderWidth: 1,\n          borderStyle: \"solid\",\n          color: c.fg,\n          transition: \"background-color 0.15s ease, border-color 0.15s ease, filter 0.15s ease\",\n          [\"--iab-bg\" as string]: c.bg,\n          [\"--iab-hover\" as string]: c.hover,\n          [\"--iab-border\" as string]: c.border,\n          [\"--iab-border-hover\" as string]: c.borderHover,\n          [\"--tw-ring-color\" as string]: p.focus,\n          [\"--tw-ring-offset-color\" as string]: \"transparent\",\n          ...style,\n        }}\n        {...rest}\n      >\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {loading ? (\n            <motion.svg key=\"spin\" width={s.icon} height={s.icon} viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\" initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1, rotate: reduce ? 0 : 360 }} exit={{ opacity: 0, scale: 0.6 }} transition={{ rotate: { duration: 0.8, repeat: Infinity, ease: \"linear\" }, default: { duration: 0.15 } }}>\n              <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"2.5\" />\n              <path d=\"M21 12a9 9 0 0 0-9-9\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" />\n            </motion.svg>\n          ) : (\n            <motion.span key=\"icon\" className=\"flex items-center justify-center [&>svg]:h-full [&>svg]:w-full\" style={{ width: s.icon, height: s.icon }} initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={{ duration: 0.15 }}>\n              {icon}\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </motion.button>\n\n      <AnimatePresence>\n        {badge !== undefined && badge !== false && (\n          <motion.span\n            key=\"badge\"\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute flex items-center justify-center rounded-full font-semibold tabular-nums\"\n            style={{ top: count ? -5 : -2, right: count ? -6 : -2, minWidth: count ? 17 : 9, height: count ? 17 : 9, padding: count ? \"0 4.5px\" : 0, fontSize: 10, lineHeight: 1, background: p.badge, color: \"#FFFFFF\", boxShadow: `0 0 0 2px ${theme === \"dark\" ? \"#0A0A0A\" : \"#FFFFFF\"}` }}\n            initial={reduce ? false : { scale: 0 }}\n            animate={{ scale: 1 }}\n            exit={{ scale: 0 }}\n            transition={{ type: \"spring\", stiffness: 600, damping: 22 }}\n          >\n            {count}\n          </motion.span>\n        )}\n      </AnimatePresence>\n\n      <AnimatePresence>\n        {tip && (\n          <motion.span\n            key=\"tip\"\n            className=\"pointer-events-none absolute left-1/2 z-20 flex justify-center\"\n            style={{ width: 0, [tooltipSide === \"top\" ? \"bottom\" : \"top\"]: \"100%\", [tooltipSide === \"top\" ? \"marginBottom\" : \"marginTop\"]: 8 }}\n            initial={{ opacity: 0, y: tooltipSide === \"top\" ? 4 : -4 }}\n            animate={{ opacity: 1, y: 0 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: reduce ? 0 : 0.14 }}\n          >\n            <span id={tipId} role=\"tooltip\" className=\"text-[12px] font-medium whitespace-nowrap\" style={{ padding: \"4px 8px\", borderRadius: 7, background: p.tip, color: p.onTip }}>\n              {label}\n            </span>\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  );\n}\n\nconst svg = { width: 24, height: 24, viewBox: \"0 0 24 24\", fill: \"none\", stroke: \"currentColor\", strokeWidth: 1.8, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const, \"aria-hidden\": true };\n\n/** A few stroke icons for the demo and common toolbar actions. */\nexport const ActionIcons = {\n  edit: <svg {...svg}><path d=\"M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z\" /></svg>,\n  share: <svg {...svg}><path d=\"M4 12v6.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V12M12 15V3.5M7.5 8 12 3.5 16.5 8\" /></svg>,\n  copy: <svg {...svg}><rect x=\"8\" y=\"8\" width=\"12\" height=\"12\" rx=\"2.5\" /><path d=\"M16 8V5.5A2.5 2.5 0 0 0 13.5 3h-8A2.5 2.5 0 0 0 3 5.5v8A2.5 2.5 0 0 0 5.5 16H8\" /></svg>,\n  trash: <svg {...svg}><path d=\"M4 7h16M9.5 7V5a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v2M6 7l.9 12.2A2 2 0 0 0 8.9 21h6.2a2 2 0 0 0 2-1.8L18 7\" /></svg>,\n  bell: <svg {...svg}><path d=\"M5 17h14l-1.4-2a3.2 3.2 0 0 1-.6-1.9V10a5 5 0 0 0-10 0v3.1a3.2 3.2 0 0 1-.6 1.9ZM10 20a2.2 2.2 0 0 0 4 0\" /></svg>,\n  more: <svg {...svg}><path d=\"M6 12h.01M12 12h.01M18 12h.01\" strokeWidth={2.6} /></svg>,\n  plus: <svg {...svg}><path d=\"M12 5v14M5 12h14\" /></svg>,\n  refresh: <svg {...svg}><path d=\"M20 12a8 8 0 1 1-2.3-5.6L20 8.7M20 4v4.7h-4.7\" /></svg>,\n};\n\nexport function IconActionButtonDemo({ theme = \"dark\" }: { theme?: \"dark\" | \"light\" }) {\n  const [saving, setSaving] = React.useState(false);\n  return (\n    <div className=\"flex flex-col items-center\" style={{ gap: 22 }}>\n      <div className=\"flex items-center\" style={{ gap: 6, padding: 6, borderRadius: 14, border: `1px solid ${PALETTES[theme].border}` }}>\n        <IconActionButton theme={theme} variant=\"ghost\" icon={ActionIcons.edit} label=\"Edit\" />\n        <IconActionButton theme={theme} variant=\"ghost\" icon={ActionIcons.copy} label=\"Duplicate\" />\n        <IconActionButton theme={theme} variant=\"ghost\" icon={ActionIcons.share} label=\"Share\" />\n        <IconActionButton theme={theme} variant=\"ghost\" tone=\"danger\" icon={ActionIcons.trash} label=\"Delete\" />\n      </div>\n      <div className=\"flex items-center\" style={{ gap: 12 }}>\n        <IconActionButton theme={theme} variant=\"soft\" icon={ActionIcons.bell} label=\"Notifications\" badge={3} />\n        <IconActionButton theme={theme} variant=\"outline\" shape=\"circle\" icon={ActionIcons.more} label=\"More actions\" />\n        <IconActionButton\n          theme={theme}\n          variant=\"solid\"\n          icon={ActionIcons.refresh}\n          label=\"Sync now\"\n          loading={saving}\n          onClick={() => {\n            setSaving(true);\n            setTimeout(() => setSaving(false), 1400);\n          }}\n        />\n        <IconActionButton theme={theme} variant=\"solid\" shape=\"circle\" size=\"lg\" icon={ActionIcons.plus} label=\"New item\" />\n      </div>\n      <div className=\"flex items-end\" style={{ gap: 10 }}>\n        {([\"xs\", \"sm\", \"md\", \"lg\"] as const).map((sz) => (\n          <IconActionButton key={sz} theme={theme} variant=\"outline\" size={sz} icon={ActionIcons.edit} label={`Edit (${sz})`} />\n        ))}\n      </div>\n    </div>\n  );\n}\n\nexport default IconActionButton;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}