Newer
Older

Yusuf Akgül
committed
import { cn } from "@/lib/utils"
import { useEffect, useState } from "react"
import { Icons } from "./icons"
import { Button } from "./ui/button"

Yusuf Akgül
committed
const [isVisible, setIsVisible] = useState(false)

Yusuf Akgül
committed
setIsVisible(true)

Yusuf Akgül
committed
setIsVisible(false)

Yusuf Akgül
committed
}
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth"

Yusuf Akgül
committed
})
}

Yusuf Akgül
committed
window.addEventListener("scroll", toggleVisibility)
return () => window.removeEventListener("scroll", toggleVisibility)
}, [])
<div className="fixed z-50 m-3 flex justify-center">
<Button size="lg" onClick={scrollToTop}
className={cn(isVisible ? "block" : "hidden", "")}>
<Icons.arrowupline className="h-3 w-3" aria-hidden="true" />
</Button>
</div>

Yusuf Akgül
committed
)