{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "peeping-button",
  "title": "Peeping Button",
  "description": "Add a shy, cursor-tracking surprise behind a familiar button face.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "src/registry/components/peeping-button/peeping-button.tsx",
      "content": "\"use client\";\n\nimport {\n\tMotionConfig,\n\tmotion,\n\tuseMotionTemplate,\n\tuseMotionValue,\n\tuseReducedMotion,\n\tuseSpring,\n} from \"motion/react\";\nimport {\n\ttype ComponentPropsWithoutRef,\n\ttype FocusEvent,\n\tforwardRef,\n\ttype PointerEvent as ReactPointerEvent,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface PeepingButtonProps extends ComponentPropsWithoutRef<\"button\"> {\n\t/** Classes applied to the hinged, visible face of the button. */\n\tcoverClassName?: string;\n\t/** Delay before each peek, or a random range in milliseconds. */\n\tpeekDelay?: number | readonly [min: number, max: number];\n\t/** How long the eyes remain visible in milliseconds. */\n\tpeekDuration?: number;\n\t/** Disable the automatic peeking behavior while keeping a usable button. */\n\tautoPeek?: boolean;\n}\n\nconst DEFAULT_PEEK_DELAY = [2800, 5200] as const;\nconst DEFAULT_PEEK_DURATION = 2200;\n\nfunction resolvePeekDelay(min: number, max: number) {\n\treturn min + Math.random() * (max - min);\n}\n\nexport const PeepingButton = forwardRef<HTMLButtonElement, PeepingButtonProps>(\n\t(\n\t\t{\n\t\t\tautoPeek = true,\n\t\t\tchildren,\n\t\t\tclassName,\n\t\t\tcoverClassName,\n\t\t\tdisabled,\n\t\t\tonBlur,\n\t\t\tonFocus,\n\t\t\tonPointerEnter,\n\t\t\tonPointerLeave,\n\t\t\tpeekDelay = DEFAULT_PEEK_DELAY,\n\t\t\tpeekDuration = DEFAULT_PEEK_DURATION,\n\t\t\ttype = \"button\",\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst eyesRef = useRef<HTMLSpanElement>(null);\n\t\tconst [autoOpen, setAutoOpen] = useState(false);\n\t\tconst [isEngaged, setIsEngaged] = useState(false);\n\t\tconst [isPageVisible, setIsPageVisible] = useState(true);\n\t\tconst reduceMotion = useReducedMotion();\n\n\t\tconst pupilX = useMotionValue(0);\n\t\tconst pupilY = useMotionValue(0);\n\t\tconst smoothPupilX = useSpring(pupilX, {\n\t\t\tduration: 0.35,\n\t\t\tbounce: 0.16,\n\t\t});\n\t\tconst smoothPupilY = useSpring(pupilY, {\n\t\t\tduration: 0.35,\n\t\t\tbounce: 0.16,\n\t\t});\n\t\tconst pupilTransform = useMotionTemplate`translate3d(calc(-50% + ${smoothPupilX}px), calc(-50% + ${smoothPupilY}px), 0)`;\n\t\tconst peekDelayStart =\n\t\t\ttypeof peekDelay === \"number\" ? peekDelay : peekDelay[0];\n\t\tconst peekDelayEnd =\n\t\t\ttypeof peekDelay === \"number\" ? peekDelay : peekDelay[1];\n\t\tconst peekDelayMin = Math.min(peekDelayStart, peekDelayEnd);\n\t\tconst peekDelayMax = Math.max(peekDelayStart, peekDelayEnd);\n\n\t\tconst canPeek =\n\t\t\tautoPeek && !disabled && isPageVisible && reduceMotion !== true;\n\t\tconst isOpen = canPeek && autoOpen && !isEngaged;\n\n\t\tuseEffect(() => {\n\t\t\tfunction handleVisibilityChange() {\n\t\t\t\tconst visible = document.visibilityState === \"visible\";\n\t\t\t\tsetIsPageVisible(visible);\n\t\t\t\tif (!visible) setAutoOpen(false);\n\t\t\t}\n\n\t\t\thandleVisibilityChange();\n\t\t\tdocument.addEventListener(\"visibilitychange\", handleVisibilityChange);\n\t\t\treturn () =>\n\t\t\t\tdocument.removeEventListener(\n\t\t\t\t\t\"visibilitychange\",\n\t\t\t\t\thandleVisibilityChange,\n\t\t\t\t);\n\t\t}, []);\n\n\t\tuseEffect(() => {\n\t\t\tif (!canPeek || isEngaged) {\n\t\t\t\tsetAutoOpen(false);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst timeout = window.setTimeout(\n\t\t\t\t() => setAutoOpen((open) => !open),\n\t\t\t\tautoOpen ? peekDuration : resolvePeekDelay(peekDelayMin, peekDelayMax),\n\t\t\t);\n\n\t\t\treturn () => window.clearTimeout(timeout);\n\t\t}, [\n\t\t\tautoOpen,\n\t\t\tcanPeek,\n\t\t\tisEngaged,\n\t\t\tpeekDelayMax,\n\t\t\tpeekDelayMin,\n\t\t\tpeekDuration,\n\t\t]);\n\n\t\tconst pointEyesAt = useCallback(\n\t\t\t(clientX: number, clientY: number) => {\n\t\t\t\tconst eyes = eyesRef.current;\n\t\t\t\tif (!eyes) return;\n\n\t\t\t\tconst bounds = eyes.getBoundingClientRect();\n\t\t\t\tconst deltaX = clientX - (bounds.left + bounds.width / 2);\n\t\t\t\tconst deltaY = clientY - (bounds.top + bounds.height / 2);\n\t\t\t\tconst distance = Math.hypot(deltaX, deltaY);\n\t\t\t\tconst strength = Math.min(distance / 240, 1);\n\t\t\t\tconst angle = Math.atan2(deltaY, deltaX);\n\n\t\t\t\tpupilX.set(Math.cos(angle) * 2.25 * strength);\n\t\t\t\tpupilY.set(Math.sin(angle) * 1.75 * strength);\n\t\t\t},\n\t\t\t[pupilX, pupilY],\n\t\t);\n\n\t\tuseEffect(() => {\n\t\t\tif (!isOpen) {\n\t\t\t\tpupilX.set(0);\n\t\t\t\tpupilY.set(0);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfunction handlePointerMove(event: PointerEvent) {\n\t\t\t\tif (event.pointerType === \"touch\") return;\n\t\t\t\tpointEyesAt(event.clientX, event.clientY);\n\t\t\t}\n\n\t\t\twindow.addEventListener(\"pointermove\", handlePointerMove, {\n\t\t\t\tpassive: true,\n\t\t\t});\n\t\t\treturn () => window.removeEventListener(\"pointermove\", handlePointerMove);\n\t\t}, [isOpen, pointEyesAt, pupilX, pupilY]);\n\n\t\tfunction handlePointerEnter(event: ReactPointerEvent<HTMLButtonElement>) {\n\t\t\tonPointerEnter?.(event);\n\t\t\tif (!event.defaultPrevented && event.pointerType !== \"touch\") {\n\t\t\t\tsetIsEngaged(true);\n\t\t\t}\n\t\t}\n\n\t\tfunction handlePointerLeave(event: ReactPointerEvent<HTMLButtonElement>) {\n\t\t\tonPointerLeave?.(event);\n\t\t\tif (!event.defaultPrevented) setIsEngaged(false);\n\t\t}\n\n\t\tfunction handleFocus(event: FocusEvent<HTMLButtonElement>) {\n\t\t\tonFocus?.(event);\n\t\t\tif (!event.defaultPrevented) setIsEngaged(true);\n\t\t}\n\n\t\tfunction handleBlur(event: FocusEvent<HTMLButtonElement>) {\n\t\t\tonBlur?.(event);\n\t\t\tif (!event.defaultPrevented) setIsEngaged(false);\n\t\t}\n\n\t\treturn (\n\t\t\t<MotionConfig reducedMotion=\"user\">\n\t\t\t\t<button\n\t\t\t\t\tref={ref}\n\t\t\t\t\ttype={type}\n\t\t\t\t\tdata-slot=\"peeping-button\"\n\t\t\t\t\tdata-peeking={isOpen ? \"true\" : \"false\"}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\tonBlur={handleBlur}\n\t\t\t\t\tonFocus={handleFocus}\n\t\t\t\t\tonPointerEnter={handlePointerEnter}\n\t\t\t\t\tonPointerLeave={handlePointerLeave}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\"group/peeping-button relative inline-grid min-w-36 touch-manipulation select-none place-items-center rounded-lg bg-muted text-sm outline-none\",\n\t\t\t\t\t\t\"transition-transform duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] active:scale-[0.97] motion-reduce:transform-none motion-reduce:transition-none\",\n\t\t\t\t\t\t\"focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50\",\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t\t{...props}\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tref={eyesRef}\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tclassName=\"pointer-events-none absolute right-[0.9em] bottom-[0.55em] flex items-center gap-[0.35em]\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{[\"left\", \"right\"].map((eye) => (\n\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\tkey={eye}\n\t\t\t\t\t\t\t\tclassName=\"relative size-[0.72em] overflow-hidden rounded-full bg-foreground\"\n\t\t\t\t\t\t\t\tanimate={\n\t\t\t\t\t\t\t\t\treduceMotion === true || !isOpen\n\t\t\t\t\t\t\t\t\t\t? { transform: \"scaleY(1)\" }\n\t\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\t\ttransform: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"scaleY(1)\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"scaleY(1)\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"scaleY(0.12)\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"scaleY(1)\",\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\ttransition={{\n\t\t\t\t\t\t\t\t\tduration: 4,\n\t\t\t\t\t\t\t\t\ttimes: [0, 0.92, 0.96, 1],\n\t\t\t\t\t\t\t\t\trepeat: Number.POSITIVE_INFINITY,\n\t\t\t\t\t\t\t\t\tease: \"linear\",\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute top-1/2 left-1/2 size-[0.34em] rounded-full bg-background\"\n\t\t\t\t\t\t\t\t\tstyle={{ transform: pupilTransform }}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</motion.span>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</span>\n\n\t\t\t\t\t<motion.span\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"pointer-events-none absolute inset-0 flex origin-[1.25em_50%] items-center justify-center rounded-[inherit] border border-border bg-card px-5 py-3 font-medium text-card-foreground shadow-xs\",\n\t\t\t\t\t\t\tcoverClassName,\n\t\t\t\t\t\t)}\n\t\t\t\t\t\tanimate={{\n\t\t\t\t\t\t\ttransform: isOpen ? \"rotate(-11deg)\" : \"rotate(0deg)\",\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ttransition={\n\t\t\t\t\t\t\tisOpen\n\t\t\t\t\t\t\t\t? { type: \"spring\", duration: 0.45, bounce: 0.18 }\n\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\tduration: 0.2,\n\t\t\t\t\t\t\t\t\t\tease: [0.23, 1, 0.32, 1],\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</motion.span>\n\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tclassName=\"invisible block px-5 py-3 font-medium\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t</MotionConfig>\n\t\t);\n\t},\n);\n\nPeepingButton.displayName = \"PeepingButton\";\n\nexport default PeepingButton;\n",
      "type": "registry:component",
      "target": "@components/peeping-button.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-07-22",
    "image": "https://cdn.tentui.com/images/components/peeping-button",
    "video": "https://cdn.tentui.com/videos/components/peeping-button"
  },
  "docs": "https://tentui.com/components/peeping-button",
  "categories": [
    "buttons"
  ],
  "type": "registry:component"
}