"use client"; import React, { useState } from "react"; import { motion, useTransform, AnimatePresence, useMotionValue, useSpring, } from "motion/react"; 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}
))} ); };