File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
web_client/src/components/common Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ import { useEffect , useState } from 'react' ;
12import { FaArrowUp } from 'react-icons/fa' ;
23
34export const JumpToTopButton : React . FC = ( ) => {
5+ const [ isVisible , setIsVisible ] = useState ( false ) ;
6+
7+ useEffect ( ( ) => {
8+ const updateVisibility = ( ) => {
9+ const root = document . documentElement ;
10+ const canScroll = root . scrollHeight > root . clientHeight ;
11+ const isAtTop = window . scrollY <= 0 ;
12+ setIsVisible ( canScroll && ! isAtTop ) ;
13+ } ;
14+
15+ updateVisibility ( ) ;
16+ window . addEventListener ( 'scroll' , updateVisibility , { passive : true } ) ;
17+ window . addEventListener ( 'resize' , updateVisibility ) ;
18+
19+ return ( ) => {
20+ window . removeEventListener ( 'scroll' , updateVisibility ) ;
21+ window . removeEventListener ( 'resize' , updateVisibility ) ;
22+ } ;
23+ } , [ ] ) ;
24+
425 const scrollToTop = ( ) => {
526 window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
627 } ;
28+
29+ if ( ! isVisible ) {
30+ return null ;
31+ }
32+
733 return (
834 < div className = 'sticky-bottom' >
935 < button
You can’t perform that action at this time.
0 commit comments