'use client'; import { useEffect, useState } from 'react'; // @mui import Fab from '@mui/material/Fab'; import Box from '@mui/material/Box'; // @third-party import { motion } from 'framer-motion'; import SvgIcon from './SvgIcon'; /*************************** COMMON - SCROLL TO TOP BUTTON ***************************/ export default function ScrollFab() { const [isVisible, setIsVisible] = useState(false); useEffect(() => { // if the user scrolls down, show the button const toggleVisibility = () => setIsVisible(window.scrollY > 400); // attach scroll event listener window.addEventListener('scroll', toggleVisibility); // remove event listener on component unmount return () => window.removeEventListener('scroll', toggleVisibility); }, []); // handles the animation when scrolling to the top const scrollToTop = () => isVisible && window.scrollTo({ top: 0, behavior: 'smooth' }); return ( <> {isVisible && ( )} ); }