Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import LightRays from "../components/LightRays";
import Navbar from "../components/Navbar";
import { PostHogProvider } from "./providers";
import { Toaster } from "sonner";
import BackToTop from '../components/BackToTop';


const SchibstedGrotesk = Schibsted_Grotesk({
variable: "--font-schibsted-grotesk",
Expand Down Expand Up @@ -56,10 +58,10 @@ export default function RootLayout({
<main>
{children}
</main>
<BackToTop/>
</PostHogProvider>
</Suspense>
</body>
</html>
);
}

}
51 changes: 51 additions & 0 deletions components/BackToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use client";

import { useEffect, useState } from "react";
import { ArrowUp } from "lucide-react";

export default function BackToTop() {
const [visible, setVisible] = useState(false);

useEffect(() => {
const handleScroll = () => {
setVisible(window.scrollY > 200);
};

window.addEventListener("scroll", handleScroll);
handleScroll(); // ✅ Fix for mount visibility

return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

if (!visible) return null;

return (
<button
onClick={scrollToTop}
aria-label="Back to Top"
title="Scroll to top"
className="
fixed bottom-6 right-6 z-50
p-3 rounded-full
bg-primary text-black
Comment thread
SatyamPandey-07 marked this conversation as resolved.
border border-primary
card-shadow
hover:bg-primary/90
hover:scale-110
transition-all duration-300
focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2
"
>
<ArrowUp size={20} className="h-5 w-5" />
</button>
);
}
Loading