'use client'; import type { Variants } from 'motion/react'; import type { HTMLAttributes } from 'react'; import { forwardRef, useCallback, useImperativeHandle, useRef } from 'react'; import { motion, useAnimation } from 'motion/react'; import { cn } from '@/lib/utils'; export interface ArchiveIconHandle { startAnimation: () => void; stopAnimation: () => void; } interface ArchiveIconProps extends HTMLAttributes { size?: number; } const RECT_VARIANTS: Variants = { normal: { translateY: 0, transition: { duration: 0.2, type: 'spring', stiffness: 200, damping: 25, }, }, animate: { translateY: -1.5, transition: { duration: 0.2, type: 'spring', stiffness: 200, damping: 25, }, }, }; const PATH_VARIANTS: Variants = { normal: { d: 'M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8' }, animate: { d: 'M4 11v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V11' }, }; const SECONDARY_PATH_VARIANTS: Variants = { normal: { d: 'M10 12h4' }, animate: { d: 'M10 15h4' }, }; const ArchiveIcon = forwardRef(({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => { const controls = useAnimation(); const isControlledRef = useRef(false); useImperativeHandle(ref, () => { isControlledRef.current = true; return { startAnimation: () => controls.start('animate'), stopAnimation: () => controls.start('normal'), }; }); const handleMouseEnter = useCallback((e: React.MouseEvent) => { if (!isControlledRef.current) { controls.start('animate'); } else { onMouseEnter?.(e); } }, [controls, onMouseEnter]); const handleMouseLeave = useCallback((e: React.MouseEvent) => { if (!isControlledRef.current) { controls.start('normal'); } else { onMouseLeave?.(e); } }, [controls, onMouseLeave]); return (
); }); ArchiveIcon.displayName = 'ArchiveIcon'; export { ArchiveIcon };