following-pointer
aceternity/following-pointerUnverifiedComponent
aceternity publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/rickhallett/becoming-diamond-nextjs/main/following-pointer.jsonSource
1import React, { useEffect, useState } from "react";23import { motion, AnimatePresence, useMotionValue } from "motion/react";4import { cn } from "@/lib/utils";56export const FollowerPointerCard = ({7 children,8 className,9 title,10}: {11 children: React.ReactNode;12 className?: string;13 title?: string | React.ReactNode;14}) => {15 const x = useMotionValue(0);16 const y = useMotionValue(0);17 const ref = React.useRef<HTMLDivElement>(null);18 const [rect, setRect] = useState<DOMRect | null>(null);19 const [isInside, setIsInside] = useState<boolean>(false); // Add this line2021 useEffect(() => {22 if (ref.current) {23 setRect(ref.current.getBoundingClientRect());24 }25 }, []);2627 const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {28 if (rect) {29 const scrollX = window.scrollX;30 const scrollY = window.scrollY;31 x.set(e.clientX - rect.left + scrollX);32 y.set(e.clientY - rect.top + scrollY);33 }34 };35 const handleMouseLeave = () => {36 setIsInside(false);37 };3839 const handleMouseEnter = () => {40 setIsInside(true);41 };42 return (43 <div44 onMouseLeave={handleMouseLeave}45 onMouseEnter={handleMouseEnter}46 onMouseMove={handleMouseMove}47 style={{48 cursor: "none",49 }}50 ref={ref}51 className={cn("relative", className)}52 >53 <AnimatePresence>54 {isInside && <FollowPointer x={x} y={y} title={title} />}55 </AnimatePresence>56 {children}57 </div>58 );59};6061export const FollowPointer = ({62 x,63 y,64 title,65}: {66 x: any;67 y: any;68 title?: string | React.ReactNode;69}) => {70 const colors = [71 "#0ea5e9",72 "#737373",73 "#14b8a6",74 "#22c55e",75 "#3b82f6",76 "#ef4444",77 "#eab308",78 ];79 return (80 <motion.div81 className="absolute z-50 h-4 w-4 rounded-full"82 style={{83 top: y,84 left: x,85 pointerEvents: "none",86 }}87 initial={{88 scale: 1,89 opacity: 1,90 }}91 animate={{92 scale: 1,93 opacity: 1,94 }}95 exit={{96 scale: 0,97 opacity: 0,98 }}99 >100 <svg101 stroke="currentColor"102 fill="currentColor"103 strokeWidth="1"104 viewBox="0 0 16 16"105 className="h-6 w-6 -translate-x-[12px] -translate-y-[10px] -rotate-[70deg] transform stroke-sky-600 text-sky-500"106 height="1em"107 width="1em"108 xmlns="http://www.w3.org/2000/svg"109 >110// … truncated
What it pulls in
npm packages
Files it writes
More from aceternity
All 89 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 3d-card3d-card | aceternity | Components | Unverified | no deps | |
| 3d Globe3d-globe | aceternity | Components | Free | 3 deps | |
| 3d-marquee3d-marquee | aceternity | Components | Unverified | no deps | |
| 3d-pin3d-pin | aceternity | Components | Unverified | 1 dep | |
| animated-modalanimated-modal | aceternity | Components | Unverified | 1 dep | |
| animated-testimonialsanimated-testimonials | aceternity | Components | Unverified | 2 deps | |
| animated-tooltipanimated-tooltip | aceternity | Components | Unverified | 1 dep | |
| apple-cards-carouselapple-cards-carousel | aceternity | Components | Unverified | 2 deps |
