From e3e2fe3885c4e130d3079e6e852a5370d43ecf68 Mon Sep 17 00:00:00 2001 From: kleap-admin Date: Thu, 15 Jan 2026 13:04:04 +0000 Subject: [PATCH] Update components/ui/animated-tooltip.tsx --- components/ui/animated-tooltip.tsx | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 components/ui/animated-tooltip.tsx diff --git a/components/ui/animated-tooltip.tsx b/components/ui/animated-tooltip.tsx new file mode 100644 index 0000000..202574a --- /dev/null +++ b/components/ui/animated-tooltip.tsx @@ -0,0 +1,92 @@ +"use client"; +import Image from "next/image"; +import React, { useState } from "react"; +import { + motion, + useTransform, + AnimatePresence, + useMotionValue, + useSpring, +} from "framer-motion"; + +export const AnimatedTooltip = ({ + items, +}: { + items: { + id: number; + name: string; + designation: string; + image: string; + }[]; +}) => { + const [hoveredIndex, setHoveredIndex] = useState(null); + const springConfig = { stiffness: 100, damping: 5 }; + const x = useMotionValue(0); // going to set this value on mouse move + // rotate the tooltip + const rotate = useSpring( + useTransform(x, [-100, 100], [-45, 45]), + springConfig, + ); + // translate the tooltip + const translateX = useSpring( + useTransform(x, [-100, 100], [-50, 50]), + springConfig, + ); + const handleMouseMove = (event: any) => { + const halfWidth = event.target.offsetWidth / 2; + x.set(event.nativeEvent.offsetX - halfWidth); // set the x value, which is then used in transform and rotate + }; + + return ( + <> + {items.map((item, _idx) => ( +
setHoveredIndex(item.id)} + onMouseLeave={() => setHoveredIndex(null)} + > + + {hoveredIndex === item.id && ( + +
+
+
+ {item.name} +
+
{item.designation}
+ + )} + + {item.name} +
+ ))} + + ); +};