From 368ff8abcb1fd2a176d5cb5d3478c488c7ac6014 Mon Sep 17 00:00:00 2001 From: Shayan Danish <136985581+Shayan12456@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:42:21 +0000 Subject: [PATCH] feat(components): add scroll-to-top button and tagline --- src/components/shared/footer/footer.tsx | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/components/shared/footer/footer.tsx b/src/components/shared/footer/footer.tsx index df06dbb7..32e6f2a2 100644 --- a/src/components/shared/footer/footer.tsx +++ b/src/components/shared/footer/footer.tsx @@ -1,5 +1,7 @@ import Image from 'next/image'; +import { useEffect, useState } from 'react'; + import { MENU } from '@/constants/menu'; import Link from '@/components/shared/link'; @@ -7,6 +9,31 @@ import Link from '@/components/shared/link'; import logo from '@/svgs/logo.svg'; function Footer() { + const [showButton, setShowButton] = useState(false); + + useEffect(() => { + const handleScroll = () => { + if (window.scrollY > 100) { + setShowButton(true); + } else { + setShowButton(false); + } + }; + + window.addEventListener('scroll', handleScroll); + + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); + + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }); + }; + return ( ); }