()
| 3 | import smoothscroll from "smoothscroll-polyfill"; |
| 4 | |
| 5 | const ScrollToTop = () => { |
| 6 | const [scroll, setScroll] = useState(false); |
| 7 | |
| 8 | const scrollToTop = () => { |
| 9 | window.scrollTo({ |
| 10 | top: 0, |
| 11 | behavior: "smooth", |
| 12 | }); |
| 13 | }; |
| 14 | |
| 15 | useEffect(() => { |
| 16 | smoothscroll.polyfill(); // Apply smoothscroll polyfill for older browsers |
| 17 | const handleScroll = () => { |
| 18 | let height = 580; |
| 19 | const scrollCheck = |
| 20 | document.documentElement.scrollTop || |
| 21 | document.body.scrollTop; |
| 22 | if (scrollCheck > height) { |
| 23 | setScroll(true); |
| 24 | } else { |
| 25 | setScroll(false); |
| 26 | } |
| 27 | }; |
| 28 | window.addEventListener("scroll", handleScroll); |
| 29 | return () => { |
| 30 | window.removeEventListener("scroll", handleScroll); |
| 31 | }; |
| 32 | }, []); |
| 33 | |
| 34 | return ( |
| 35 | scroll && ( |
| 36 | <div |
| 37 | className="fixed cursor-pointer bg-[#13161B] bottom-10 left-10 p-4 rounded-full shadow-lg text-white hover:bg-gradient-to-br from-[#FF008A] to-[#6100FF] transition duration-300 ease-in-out transform hover:-translate-y-1 hover:scale-110 hover:shadow-xl" |
| 38 | onClick={scrollToTop} |
| 39 | > |
| 40 | <FiArrowUp size={28} /> |
| 41 | </div> |
| 42 | ) |
| 43 | ); |
| 44 | }; |
| 45 | |
| 46 | export default ScrollToTop; |
nothing calls this directly
no outgoing calls
no test coverage detected