Initial commit
This commit is contained in:
45
src/components/sections/AnimationContainer.tsx
Normal file
45
src/components/sections/AnimationContainer.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
"use client";
|
||||
import { useState, useEffect, useRef, ReactNode } from "react";
|
||||
|
||||
interface AnimationContainerProps {
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
animationDuration?: number;
|
||||
animationType?: "full" | "fade";
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
||||
const AnimationContainer = ({
|
||||
children,
|
||||
className = "w-full h-fit flex flex-col gap-6",
|
||||
animationDuration = 800,
|
||||
animationType = "full",
|
||||
style,
|
||||
}: AnimationContainerProps) => {
|
||||
const animationClass =
|
||||
animationType === "full"
|
||||
? "animation-container"
|
||||
: "animation-container-fade";
|
||||
const [activeClass, setActiveClass] = useState(animationClass);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setActiveClass("");
|
||||
}, animationDuration);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [animationDuration]);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`${className} ${activeClass}`.trim()}
|
||||
style={style}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AnimationContainer;
|
||||
Reference in New Issue
Block a user