import { Tooltip, Button, Spacer } from '@geist-ui/core' import ChevronUp from '@geist-ui/icons/chevronUpCircleFill' import { useEffect, useState } from 'react' import styles from './scroll.module.css' const ScrollToTop = () => { const [shouldShow, setShouldShow] = useState(false) useEffect(() => { // if user is scrolled, set visible const handleScroll = () => { setShouldShow(window.scrollY > 100) } window.addEventListener('scroll', handleScroll) return () => window.removeEventListener('scroll', handleScroll) }, []) const isReducedMotion = typeof window !== 'undefined' ? window.matchMedia('(prefers-reduced-motion: reduce)').matches : false const onClick = (e: React.MouseEvent) => { // blur the button e.currentTarget.blur() window.scrollTo({ top: 0, behavior: isReducedMotion ? 'auto' : 'smooth' }) } return (
) } export default ScrollToTop