Skip to content

Commit 8d7605b

Browse files
authored
Merge pull request #769 from javaistic/feat/enahnce-animations
Add LenisProvider for smooth scrolling and integrate `motion` for tab animations
2 parents 56c2e2f + 1e63391 commit 8d7605b

6 files changed

Lines changed: 49 additions & 3 deletions

File tree

bun.lock

Lines changed: 3 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"fumadocs-mdx": "11.7.0",
2323
"fumadocs-ui": "15.6.5",
2424
"latest": "^0.2.0",
25+
"lenis": "^1.3.13",
2526
"lucide-react": "^0.525.0",
2627
"motion": "^12.23.12",
2728
"next": "15.4.2",

src/app/global.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
@import "tailwindcss";
2+
23
@import "fumadocs-ui/css/shadcn.css";
34
@import "fumadocs-ui/css/preset.css";
5+
6+
@import "lenis/dist/lenis.css";
7+
48
@import "tw-animate-css";
59

610
@custom-variant dark (&:is(.dark *));

src/app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import LenisProvider from "@/components/providers/lenis-provider";
12
import SearchDialog from "@/components/search";
23
import { GoogleAnalytics } from "@next/third-parties/google";
34
import { RootProvider } from "fumadocs-ui/provider";
@@ -58,7 +59,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
5859
SearchDialog,
5960
}}
6061
>
61-
{children}
62+
<LenisProvider>{children}</LenisProvider>
6263
</RootProvider>
6364
</body>
6465
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS!} />

src/components/home/home-tabs.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type UnderlineTab,
66
} from "@/components/home/underline-tabs";
77
import { useDarkMode } from "@/hooks/useDarkMode";
8+
import { motion } from "framer-motion";
89
import Image from "next/image";
910
import { SVGProps } from "react";
1011

@@ -57,10 +58,16 @@ export default function HomeTabs() {
5758
];
5859

5960
return (
60-
<div className="flex w-full flex-col items-center">
61+
<motion.div
62+
className="flex w-full flex-col items-center"
63+
initial={{ opacity: 0, y: 20 }}
64+
whileInView={{ opacity: 1, y: 0 }}
65+
viewport={{ once: true, margin: "-100px" }}
66+
transition={{ duration: 0.8, ease: "easeOut", delay: 0.1 }}
67+
>
6168
{/* Top Tab Navigation */}
6269
<UnderlineTabs items={TAB_ITEMS} defaultValue="docs" className="w-full" />
63-
</div>
70+
</motion.div>
6471
);
6572
}
6673

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client"; // Mark as a client component
2+
3+
import React, { useEffect } from "react";
4+
import Lenis from "lenis";
5+
6+
const LenisProvider = ({ children }: { children: React.ReactNode }) => {
7+
useEffect(() => {
8+
const lenis = new Lenis({
9+
duration: 1.2, // Customize duration
10+
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // Custom easing
11+
touchMultiplier: 2, // Multiplier for touch devices
12+
wheelMultiplier: 1, // Multiplier for mouse wheel
13+
});
14+
15+
function raf(time: number) {
16+
lenis.raf(time);
17+
requestAnimationFrame(raf);
18+
}
19+
20+
requestAnimationFrame(raf);
21+
22+
return () => {
23+
lenis.destroy(); // Clean up on unmount
24+
};
25+
}, []);
26+
27+
return <>{children}</>;
28+
};
29+
30+
export default LenisProvider;

0 commit comments

Comments
 (0)