diff --git a/frontend/src/ScrollToTopButton.jsx b/frontend/src/ScrollToTopButton.jsx new file mode 100644 index 000000000..bbf6295f2 --- /dev/null +++ b/frontend/src/ScrollToTopButton.jsx @@ -0,0 +1,45 @@ +import { useEffect, useState } from 'react'; +import { IconButton } from '@chakra-ui/react'; +import { ArrowUpIcon } from '@chakra-ui/icons'; + +const ScrollToTopButton = () => { + const [isVisible, setIsVisible] = useState(false); + + const toggleVisibility = () => { + if (window.scrollY > 200) { + setIsVisible(true); + } else { + setIsVisible(false); + } + }; + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }; + + useEffect(() => { + window.addEventListener('scroll', toggleVisibility); + return () => window.removeEventListener('scroll', toggleVisibility); + }, []); + + return ( + isVisible && ( + } + onClick={scrollToTop} + aria-label="Scroll to top" + size="lg" + boxShadow="lg" + zIndex="1000" + /> + ) + ); +}; + +export default ScrollToTopButton;