File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
frontend/src/components/common Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ "use client"
2+
3+ import { useEffect , useState } from 'react'
4+ import { ArrowUp } from 'lucide-react'
5+
6+ export default function ScrollToTop ( ) {
7+ const [ isVisible , setIsVisible ] = useState ( false )
8+
9+ useEffect ( ( ) => {
10+ const toggleVisibility = ( ) => {
11+ if ( window . pageYOffset > 300 ) {
12+ setIsVisible ( true )
13+ } else {
14+ setIsVisible ( false )
15+ }
16+ }
17+
18+ window . addEventListener ( 'scroll' , toggleVisibility )
19+ return ( ) => window . removeEventListener ( 'scroll' , toggleVisibility )
20+ } , [ ] )
21+
22+ const scrollToTop = ( ) => {
23+ window . scrollTo ( {
24+ top : 0 ,
25+ behavior : 'smooth'
26+ } )
27+ }
28+
29+ return (
30+ < >
31+ { isVisible && (
32+ < button
33+ onClick = { scrollToTop }
34+ aria-label = "Scroll to top"
35+ className = "fixed bottom-6 right-6 z-50 flex items-center justify-center w-12 h-12 bg-indigo-600 text-white rounded-full shadow-lg transition-all duration-300 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 cursor-pointer"
36+ tabIndex = { 0 }
37+ >
38+ < ArrowUp className = "w-6 h-6" />
39+ </ button >
40+ ) }
41+ </ >
42+ )
43+ }
You can’t perform that action at this time.
0 commit comments