Skip to content

Commit b1fb262

Browse files
committed
feat: added framer-motion and defined BlurFade effect
1 parent cbbbdb1 commit b1fb262

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"buildgh": "next build && next export"
1111
},
1212
"dependencies": {
13+
"class-variance-authority": "^0.7.0",
1314
"clsx": "^2.1.1",
1415
"devicons-react": "^1.3.0",
16+
"framer-motion": "^11.11.8",
1517
"lucide-react": "^0.445.0",
1618
"next": "^14.2.15",
1719
"next-themes": "^0.3.0",

src/components/ui/BlurFade.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use client";
2+
3+
import { AnimatePresence, motion, useInView, Variants } from "framer-motion";
4+
import { useRef } from "react";
5+
6+
type MarginValue = `${number}${'px' | '%'}`;
7+
type MarginType = MarginValue | `${MarginValue} ${MarginValue}` | `${MarginValue} ${MarginValue} ${MarginValue}` | `${MarginValue} ${MarginValue} ${MarginValue} ${MarginValue}`;
8+
9+
interface BlurFadeProps {
10+
children: React.ReactNode;
11+
className?: string;
12+
variant?: {
13+
hidden: { y: number };
14+
visible: { y: number };
15+
};
16+
duration?: number;
17+
delay?: number;
18+
yOffset?: number;
19+
inView?: boolean;
20+
inViewMargin?: MarginType;
21+
blur?: string;
22+
}
23+
const BlurFade = ({
24+
children,
25+
className,
26+
variant,
27+
duration = 0.4,
28+
delay = 0,
29+
yOffset = 6,
30+
inView = false,
31+
inViewMargin = "-50px",
32+
blur = "6px",
33+
}: BlurFadeProps) => {
34+
const ref = useRef(null);
35+
const inViewResult = useInView(ref, { once: true, margin: inViewMargin });
36+
const isInView = !inView || inViewResult;
37+
const defaultVariants: Variants = {
38+
hidden: { y: yOffset, opacity: 0, filter: `blur(${blur})` },
39+
visible: { y: -yOffset, opacity: 1, filter: `blur(0px)` },
40+
};
41+
const combinedVariants = variant || defaultVariants;
42+
return (
43+
<AnimatePresence>
44+
<motion.div
45+
ref={ref}
46+
initial="hidden"
47+
animate={isInView ? "visible" : "hidden"}
48+
exit="hidden"
49+
variants={combinedVariants}
50+
transition={{
51+
delay: 0.04 + delay,
52+
duration,
53+
ease: "easeOut",
54+
}}
55+
className={className}
56+
>
57+
{children}
58+
</motion.div>
59+
</AnimatePresence>
60+
);
61+
};
62+
63+
export const BLUR_FADE_DELAY = 0.04;
64+
65+
export default BlurFade;

0 commit comments

Comments
 (0)