"use client"; import type { Transition } from "motion/react"; import { motion, useAnimation } from "motion/react"; import type { HTMLAttributes } from "react"; import { forwardRef, useCallback, useImperativeHandle, useRef } from "react"; import { cn } from "@/lib/utils"; export interface LayersIconHandle { startAnimation: () => void; stopAnimation: () => void; } interface LayersIconProps extends HTMLAttributes { size?: number; } const DEFAULT_TRANSITION: Transition = { type: "spring", stiffness: 100, damping: 14, mass: 1, }; const LayersIcon = forwardRef( ({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => { const controls = useAnimation(); const isControlledRef = useRef(false); useImperativeHandle(ref, () => { isControlledRef.current = true; return { startAnimation: async () => { await controls.start("firstState"); await controls.start("secondState"); }, stopAnimation: () => controls.start("normal"), }; }); const handleMouseEnter = useCallback( async (e: React.MouseEvent) => { if (isControlledRef.current) { onMouseEnter?.(e); } else { await controls.start("firstState"); await controls.start("secondState"); } }, [controls, onMouseEnter] ); const handleMouseLeave = useCallback( (e: React.MouseEvent) => { if (isControlledRef.current) { onMouseLeave?.(e); } else { controls.start("normal"); } }, [controls, onMouseLeave] ); return (
); } ); LayersIcon.displayName = "LayersIcon"; export { LayersIcon };