| 15 | }; |
| 16 | |
| 17 | export default function HeaderLogo({ className, href }: HeaderLogoProps) { |
| 18 | const pathname = usePathname(); |
| 19 | const [isHovered, setIsHovered] = useState(false); |
| 20 | |
| 21 | const shouldReduceMotion = useReducedMotion(); |
| 22 | |
| 23 | const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => { |
| 24 | if (pathname === href) { |
| 25 | e.preventDefault(); |
| 26 | window.scrollTo({ top: 0, behavior: 'smooth' }); |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | const logoContent = ( |
| 31 | <> |
| 32 | <motion.div |
| 33 | className="relative flex size-12 flex-none items-center justify-center overflow-hidden font-bold" |
| 34 | aria-hidden="true" |
| 35 | animate={shouldReduceMotion ? {} : { rotate: isHovered ? 90 : 0 }} |
| 36 | transition={shouldReduceMotion ? {} : { duration: 0.3, ease: 'easeInOut' }} |
| 37 | style={{ transformStyle: 'preserve-3d' }} |
| 38 | > |
| 39 | <AnimatePresence> |
| 40 | <motion.div |
| 41 | key="animated" |
| 42 | initial={{ opacity: isHovered ? 1 : 0 }} |
| 43 | animate={{ |
| 44 | opacity: isHovered ? 1 : 0, |
| 45 | rotate: isHovered ? +270 : 0, |
| 46 | }} |
| 47 | exit={{ opacity: isHovered ? 1 : 0 }} |
| 48 | transition={{ duration: 0.2 }} |
| 49 | className="absolute top-0 left-0 size-12" |
| 50 | // style={{ transform: 'rotateY(360deg)' }} |
| 51 | > |
| 52 | <AnimatedKiloLogo /> |
| 53 | </motion.div> |
| 54 | <motion.div |
| 55 | key="static" |
| 56 | initial={{ opacity: isHovered ? 0 : 1 }} |
| 57 | animate={{ opacity: isHovered ? 0 : 1 }} |
| 58 | exit={{ opacity: isHovered ? 0 : 1 }} |
| 59 | transition={{ duration: 0.2 }} |
| 60 | className="absolute top-0 left-0 size-12" |
| 61 | > |
| 62 | <KiloLogo /> |
| 63 | </motion.div> |
| 64 | </AnimatePresence> |
| 65 | </motion.div> |
| 66 | <span className="font-jetbrains text-3xl font-bold whitespace-nowrap">Kilo</span> |
| 67 | </> |
| 68 | ); |
| 69 | |
| 70 | return ( |
| 71 | <motion.div |
| 72 | className="mt-px" |
| 73 | onHoverStart={() => setIsHovered(true)} |
| 74 | onHoverEnd={() => setIsHovered(false)} |