diff --git a/src/components/ui/back-to-top.tsx b/src/components/ui/back-to-top.tsx new file mode 100644 index 0000000..b76f816 --- /dev/null +++ b/src/components/ui/back-to-top.tsx @@ -0,0 +1,46 @@ +import { ArrowUp } from "lucide-react"; +import { Button } from "./button"; +import { useEffect, useState } from "react"; + +export default function BackToTop() { + const [isVisible, setIsVisible] = useState(false); + + useEffect(() => { + const toggleVisibility = () => { + if (window.scrollY > 300) { + setIsVisible(true); + } else { + setIsVisible(false); + } + }; + + window.addEventListener("scroll", toggleVisibility); + return () => window.removeEventListener("scroll", toggleVisibility); + }, []); + + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: "smooth", + }); + }; + + return ( +