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" + > + + + ); +}