{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "expanding-arrow-button",
  "type": "registry:ui",
  "title": "Expanding Arrow Button",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "An interactive pill button featuring a spring-expanding accent block that morphs from an idle dotted chevron into a kinetic ordered Bayer dither pattern on hover and keyboard focus.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/expanding-arrow-button.tsx",
      "content": "\"use client\";\n\nimport React, {\n  forwardRef,\n  useState,\n  useId,\n  useEffect,\n  type FocusEvent,\n  type MouseEvent,\n  type ReactNode,\n} from \"react\";\nimport {\n  motion,\n  useReducedMotion,\n  type HTMLMotionProps,\n  type Transition,\n} from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\n// ============================================================================\n// CONSTANTS & SPRING PHYSICS\n// ============================================================================\n\nexport const EASE_OUT = [0.16, 1, 0.3, 1] as const;\n\nexport const SPRING_LAYOUT: Transition = {\n  type: \"spring\",\n  stiffness: 420,\n  damping: 30,\n  mass: 0.8,\n};\n\nexport const SPRING_PRESS: Transition = {\n  type: \"spring\",\n  stiffness: 600,\n  damping: 35,\n};\n\n// ============================================================================\n// HOOKS\n// ============================================================================\n\n/**\n * Detects whether the current device supports hover interactions.\n * Prevents sticky hover states on touch screens.\n */\nexport function useHoverCapable(): boolean {\n  const [canHover, setCanHover] = useState(true);\n\n  useEffect(() => {\n    if (typeof window === \"undefined\") return;\n    const mql = window.matchMedia(\"(hover: hover)\");\n    setCanHover(mql.matches);\n\n    const handler = (e: MediaQueryListEvent) => setCanHover(e.matches);\n    mql.addEventListener(\"change\", handler);\n    return () => mql.removeEventListener(\"change\", handler);\n  }, []);\n\n  return canHover;\n}\n\n// ============================================================================\n// SUB-COMPONENTS\n// ============================================================================\n\n/**\n * Clean 5-dot chevron icon displayed in the idle collapsed pill.\n */\nfunction DottedChevron({ className }: { className?: string }) {\n  return (\n    <svg\n      viewBox=\"0 0 20 28\"\n      fill=\"none\"\n      aria-hidden=\"true\"\n      className={className}\n    >\n      <circle cx=\"4\" cy=\"4\" r=\"2\" fill=\"currentColor\" />\n      <circle cx=\"10\" cy=\"9\" r=\"2\" fill=\"currentColor\" />\n      <circle cx=\"16\" cy=\"14\" r=\"2\" fill=\"currentColor\" />\n      <circle cx=\"10\" cy=\"19\" r=\"2\" fill=\"currentColor\" />\n      <circle cx=\"4\" cy=\"24\" r=\"2\" fill=\"currentColor\" />\n    </svg>\n  );\n}\n\n/**\n * Kinetic ordered Bayer dithering matrix and pulsing stipple waves.\n */\nfunction AnimatedDitherPattern({\n  active,\n  reduce,\n  className,\n}: {\n  active: boolean;\n  reduce: boolean | null;\n  className?: string;\n}) {\n  const patternId = useId();\n\n  return (\n    <div\n      className={cn(\n        \"pointer-events-none absolute inset-0 overflow-hidden select-none\",\n        className\n      )}\n      aria-hidden=\"true\"\n    >\n      <svg className=\"h-full w-full\" preserveAspectRatio=\"none\">\n        <defs>\n          {/* Bayer 4x4 matrix ordered stipple dither pattern */}\n          <pattern\n            id={patternId}\n            width=\"16\"\n            height=\"16\"\n            patternUnits=\"userSpaceOnUse\"\n          >\n            {/* Core Bayer matrix coordinates with dynamic dot radiuses */}\n            <circle cx=\"2\" cy=\"2\" r=\"1.5\" fill=\"currentColor\" opacity=\"0.35\" />\n            <circle cx=\"10\" cy=\"2\" r=\"1.1\" fill=\"currentColor\" opacity=\"0.25\" />\n            <circle cx=\"6\" cy=\"6\" r=\"0.9\" fill=\"currentColor\" opacity=\"0.2\" />\n            <circle cx=\"14\" cy=\"6\" r=\"1.6\" fill=\"currentColor\" opacity=\"0.4\" />\n            <circle cx=\"2\" cy=\"10\" r=\"1.2\" fill=\"currentColor\" opacity=\"0.3\" />\n            <circle cx=\"10\" cy=\"10\" r=\"1.7\" fill=\"currentColor\" opacity=\"0.45\" />\n            <circle cx=\"6\" cy=\"14\" r=\"1.4\" fill=\"currentColor\" opacity=\"0.35\" />\n            <circle cx=\"14\" cy=\"14\" r=\"1.0\" fill=\"currentColor\" opacity=\"0.25\" />\n\n            {/* Intermediate threshold points */}\n            <circle cx=\"6\" cy=\"2\" r=\"0.75\" fill=\"currentColor\" opacity=\"0.15\" />\n            <circle cx=\"14\" cy=\"2\" r=\"1.3\" fill=\"currentColor\" opacity=\"0.3\" />\n            <circle cx=\"2\" cy=\"6\" r=\"1.4\" fill=\"currentColor\" opacity=\"0.35\" />\n            <circle cx=\"10\" cy=\"6\" r=\"0.8\" fill=\"currentColor\" opacity=\"0.18\" />\n            <circle cx=\"6\" cy=\"10\" r=\"1.5\" fill=\"currentColor\" opacity=\"0.38\" />\n            <circle cx=\"14\" cy=\"10\" r=\"0.9\" fill=\"currentColor\" opacity=\"0.2\" />\n            <circle cx=\"2\" cy=\"14\" r=\"1.1\" fill=\"currentColor\" opacity=\"0.25\" />\n            <circle cx=\"10\" cy=\"14\" r=\"1.5\" fill=\"currentColor\" opacity=\"0.38\" />\n          </pattern>\n        </defs>\n\n        {/* Scrolling tiled Bayer dither background */}\n        <motion.rect\n          x=\"0\"\n          y=\"0\"\n          width=\"200%\"\n          height=\"100%\"\n          fill={`url(#${patternId})`}\n          animate={\n            active && !reduce\n              ? { x: [0, -16] }\n              : { x: 0 }\n          }\n          transition={{\n            duration: 0.9,\n            repeat: Infinity,\n            ease: \"linear\",\n          }}\n        />\n      </svg>\n\n      {/* Kinetic Stipple Wave Columns across the pill width */}\n      <div className=\"absolute inset-0 flex items-center justify-around px-2\">\n        {Array.from({ length: 14 }).map((_, colIdx) => (\n          <motion.div\n            key={colIdx}\n            initial={{ opacity: 0, scaleY: 0.5 }}\n            animate={\n              active\n                ? {\n                    opacity: reduce ? 0.35 : [0.15, 0.45, 0.15],\n                    scaleY: reduce ? 1 : [0.7, 1.15, 0.7],\n                  }\n                : { opacity: 0, scaleY: 0.5 }\n            }\n            transition={\n              reduce\n                ? { duration: 0.1 }\n                : {\n                    duration: 1.6,\n                    repeat: Infinity,\n                    delay: colIdx * 0.07,\n                    ease: \"easeInOut\",\n                  }\n            }\n            className=\"flex flex-col items-center gap-1\"\n          >\n            <span className=\"h-1 w-1 rounded-full bg-current opacity-60\" />\n            <span className=\"h-1.5 w-1.5 rounded-full bg-current opacity-80\" />\n            <span className=\"h-2 w-2 rounded-full bg-current opacity-95\" />\n            <span className=\"h-1.5 w-1.5 rounded-full bg-current opacity-80\" />\n            <span className=\"h-1 w-1 rounded-full bg-current opacity-60\" />\n          </motion.div>\n        ))}\n      </div>\n\n      {/* Shimmer sweep gradient highlight */}\n      <motion.div\n        animate={\n          active && !reduce\n            ? { x: [\"-100%\", \"200%\"] }\n            : { x: \"-100%\" }\n        }\n        transition={{\n          duration: 1.8,\n          repeat: Infinity,\n          repeatDelay: 0.5,\n          ease: \"easeInOut\",\n        }}\n        className=\"absolute inset-y-0 w-1/3 bg-gradient-to-r from-transparent via-white/20 to-transparent\"\n      />\n    </div>\n  );\n}\n\n// ============================================================================\n// TYPES\n// ============================================================================\n\nexport interface ExpandingArrowButtonProps\n  extends Omit<HTMLMotionProps<\"button\">, \"children\"> {\n  /** Text or content displayed inside the button */\n  children: ReactNode;\n  /** Custom classes for the expanding accent pill. Default: \"bg-lime-300 text-neutral-950\" */\n  accentClassName?: string;\n  /** Custom classes for the default (unexpanded) label text */\n  labelClassName?: string;\n  /** Custom classes for the label text when expanded over the dither surface */\n  expandedLabelClassName?: string;\n  /** Whether to show the text label over the dither pattern when expanded. Default: true */\n  showLabelOnExpand?: boolean;\n  /** Custom classes for the animated dither pattern container */\n  ditherClassName?: string;\n  /** Spring stiffness for the expansion physics. Default: 420 */\n  stiffness?: number;\n  /** Spring damping for the expansion physics. Default: 30 */\n  damping?: number;\n}\n\n// ============================================================================\n// COMPONENT\n// ============================================================================\n\nexport const ExpandingArrowButton = forwardRef<\n  HTMLButtonElement,\n  ExpandingArrowButtonProps\n>(function ExpandingArrowButton(\n  {\n    children,\n    className,\n    accentClassName,\n    labelClassName,\n    expandedLabelClassName,\n    showLabelOnExpand = true,\n    ditherClassName,\n    stiffness = 420,\n    damping = 30,\n    disabled,\n    onMouseEnter,\n    onMouseLeave,\n    onFocus,\n    onBlur,\n    ...rest\n  },\n  ref\n) {\n  const reduce = useReducedMotion();\n  const canHover = useHoverCapable();\n  const [hovered, setHovered] = useState(false);\n  const [focused, setFocused] = useState(false);\n\n  const active = !disabled && ((canHover && hovered) || focused);\n\n  const layoutTransition: Transition = reduce\n    ? { duration: 0 }\n    : {\n        type: \"spring\",\n        stiffness,\n        damping,\n        mass: 0.8,\n      };\n\n  const handleMouseEnter = (event: MouseEvent<HTMLButtonElement>) => {\n    setHovered(true);\n    onMouseEnter?.(event);\n  };\n\n  const handleMouseLeave = (event: MouseEvent<HTMLButtonElement>) => {\n    setHovered(false);\n    onMouseLeave?.(event);\n  };\n\n  const handleFocus = (event: FocusEvent<HTMLButtonElement>) => {\n    setFocused(true);\n    onFocus?.(event);\n  };\n\n  const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {\n    setFocused(false);\n    onBlur?.(event);\n  };\n\n  return (\n    <motion.button\n      ref={ref}\n      type=\"button\"\n      disabled={disabled}\n      onMouseEnter={handleMouseEnter}\n      onMouseLeave={handleMouseLeave}\n      onFocus={handleFocus}\n      onBlur={handleBlur}\n      whileTap={reduce || disabled ? undefined : { scale: 0.97 }}\n      transition={SPRING_PRESS}\n      className={cn(\n        \"relative inline-flex h-16 min-w-72 items-center overflow-hidden rounded-[22px] bg-neutral-950 p-1.5 text-white select-none shadow-md\",\n        \"outline-hidden focus-visible:ring-2 focus-visible:ring-lime-300 focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n        \"disabled:pointer-events-none disabled:opacity-50\",\n        className\n      )}\n      {...rest}\n    >\n      {/* Expanding Accent Pill */}\n      <motion.span\n        layout=\"size\"\n        aria-hidden=\"true\"\n        transition={layoutTransition}\n        style={{\n          width: active ? \"calc(100% - 12px)\" : 52,\n          borderRadius: 16,\n        }}\n        className={cn(\n          \"absolute inset-y-1.5 left-1.5 z-10 overflow-hidden bg-lime-300 text-neutral-950 shadow-xs\",\n          accentClassName\n        )}\n      >\n        {/* Idle 5-Dot Chevron (fades out on expand) */}\n        <motion.span\n          animate={{\n            opacity: active ? 0 : 1,\n            scale: active ? 0.8 : 1,\n          }}\n          transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n          className=\"absolute inset-0 grid place-items-center\"\n        >\n          <DottedChevron className=\"h-7 w-5\" />\n        </motion.span>\n\n        {/* Animated Dither Pattern (activates on expand) */}\n        <AnimatedDitherPattern\n          active={active}\n          reduce={reduce}\n          className={ditherClassName}\n        />\n\n        {/* Text displayed over expanded dither pill */}\n        {showLabelOnExpand && (\n          <motion.span\n            animate={{\n              opacity: active ? 1 : 0,\n              transform:\n                active && !reduce ? \"translateX(0px)\" : \"translateX(-10px)\",\n            }}\n            transition={{\n              duration: reduce ? 0 : 0.18,\n              delay: active && !reduce ? 0.05 : 0,\n              ease: EASE_OUT,\n            }}\n            className={cn(\n              \"absolute inset-0 z-20 flex items-center justify-center px-6 text-lg font-bold tracking-[-0.02em] text-neutral-950\",\n              expandedLabelClassName\n            )}\n          >\n            {children}\n          </motion.span>\n        )}\n      </motion.span>\n\n      {/* Base unexpanded text label (fades out as pill expands) */}\n      <motion.span\n        animate={{\n          opacity: active ? 0 : 1,\n          transform: active && !reduce ? \"translateX(6px)\" : \"translateX(0px)\",\n        }}\n        transition={{ duration: reduce ? 0 : 0.12, ease: EASE_OUT }}\n        className={cn(\n          \"relative z-0 ml-[76px] mr-5 whitespace-nowrap text-lg font-medium tracking-[-0.02em]\",\n          labelClassName\n        )}\n      >\n        {children}\n      </motion.span>\n    </motion.button>\n  );\n});\n\nexport const ExpandingDitherButton = ExpandingArrowButton;\n\nexport default ExpandingArrowButton;\n",
      "type": "registry:ui",
      "target": "components/ui/expanding-arrow-button.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
