File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,15 @@ import { BrowserRouter } from 'react-router-dom';
4
4
import { Routes } from './routes/Routes' ;
5
5
import { SessionProvider } from './contexts' ;
6
6
import { Toaster } from './components/ui/toaster' ;
7
+ import { BackToTop } from '@/components/BackToTop' ;
7
8
8
9
const App = ( ) => {
9
10
return (
10
11
< Fragment >
11
12
< Toaster />
12
13
< BrowserRouter >
13
14
< SessionProvider >
15
+ < BackToTop />
14
16
< Routes />
15
17
</ SessionProvider >
16
18
</ BrowserRouter >
Original file line number Diff line number Diff line change
1
+ import { useState } from "react"
2
+
3
+ const BackToTop = ( ) => {
4
+
5
+ const [ isVisible , setVisibility ] = useState ( true )
6
+
7
+ const scrollToTop = ( ) => {
8
+ window . scrollTo ( 0 , 0 )
9
+
10
+ console . log ( "click!" )
11
+ }
12
+
13
+ const toggleVisibility = ( ) => {
14
+ if ( window . scrollY >= window . innerHeight ) {
15
+ setVisibility ( true )
16
+ } else {
17
+ setVisibility ( false )
18
+ }
19
+
20
+ console . log ( "scrooled" )
21
+ }
22
+
23
+
24
+ return ( isVisible && (
25
+ < button
26
+ className = " absolute bg-red-800/60 z-[100] right-10 bottom-10 w-12 h-12 rounded-full shadow-slate-500 font-bold shadow-md text-white select-none"
27
+ onClick = { scrollToTop }
28
+ onScroll = { toggleVisibility }
29
+
30
+
31
+ > ^</ button >
32
+ ) ) ;
33
+ }
34
+
35
+ export { BackToTop } ;
Original file line number Diff line number Diff line change
1
+ import { BackToTop } from "./BackToTop" ;
2
+
3
+ export { BackToTop } ;
You can’t perform that action at this time.
0 commit comments