From 3bb210024d232f3cbf9b6afffe435e95de06f8e9 Mon Sep 17 00:00:00 2001 From: Krishna Ayyalasomayajula Date: Mon, 1 Jun 2026 19:54:33 -0500 Subject: [PATCH] feat: add scroll-to-top button --- components/ui/ScrollToTop.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 components/ui/ScrollToTop.tsx diff --git a/components/ui/ScrollToTop.tsx b/components/ui/ScrollToTop.tsx new file mode 100644 index 0000000..a4016b2 --- /dev/null +++ b/components/ui/ScrollToTop.tsx @@ -0,0 +1,28 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { motion } from "motion/react"; + +export function ScrollToTop() { + const [visible, setVisible] = useState(false); + + useEffect(() => { + const toggle = () => setVisible(window.scrollY > 400); + toggle(); + window.addEventListener("scroll", toggle, { passive: true }); + return () => window.removeEventListener("scroll", toggle); + }, []); + + return ( + window.scrollTo({ top: 0, behavior: "smooth" })} + whileHover={{ scale: 1.1 }} + whileTap={{ scale: 0.95 }} + className="scroll-to-top" + aria-label="Scroll to top" + > + + + ); +}