Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
import type { Variants } from "motion/react";
import { motion, useAnimation } from "motion/react";
import type { HTMLAttributes, MouseEvent } from "react";
import { forwardRef, useCallback, useImperativeHandle, useRef } from "react";
import { cn } from "@/lib/utils";
export interface FolderOpenIconHandle {
startAnimation: () => void;
stopAnimation: () => void;
}
interface FolderOpenIconProps extends HTMLAttributes<HTMLDivElement> {
size?: number;
}
const VARIANTS: Variants = {
normal: { rotate: 0 },
animate: {
rotate: [0, -8, 6, -4, 0],
transition: {
ease: "easeInOut",
rotate: {
duration: 0.6,
},
},
},
};
const FolderOpenIcon = forwardRef<FolderOpenIconHandle, FolderOpenIconProps>(
({ 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: MouseEvent<HTMLDivElement>) => {
if (isControlledRef.current) {
onMouseEnter?.(e);
} else {
controls.start("animate");
}
},
[controls, onMouseEnter]
);
const handleMouseLeave = useCallback(
(e: MouseEvent<HTMLDivElement>) => {
if (isControlledRef.current) {
onMouseLeave?.(e);
} else {
controls.start("normal");
}
},
[controls, onMouseLeave]
);
return (
<div
className={cn(className)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
{...props}
>
<motion.svg
fill="none"
height={size}
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width={size}
xmlns="http://www.w3.org/2000/svg"
>
<motion.path
animate={controls}
d="m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"
initial="normal"
style={{ transformOrigin: "12px 12px" }}
variants={VARIANTS}
/>
</motion.svg>
</div>
);
}
);
FolderOpenIcon.displayName = "FolderOpenIcon";
export { FolderOpenIcon };