Skip to content

Commit 537c95b

Browse files
committed
feat(lenis): Add LenisProvider for smooth scrolling and update dependencies
1 parent 56c2e2f commit 537c95b

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

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!} />
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)