Skip to content

Commit 11d59fd

Browse files
Criado botao
1 parent e17170f commit 11d59fd

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { BrowserRouter } from 'react-router-dom';
44
import { Routes } from './routes/Routes';
55
import { SessionProvider } from './contexts';
66
import { Toaster } from './components/ui/toaster';
7+
import { BackToTop } from '@/components/BackToTop';
78

89
const App = () => {
910
return (
1011
<Fragment>
1112
<Toaster />
1213
<BrowserRouter>
1314
<SessionProvider>
15+
<BackToTop/>
1416
<Routes />
1517
</SessionProvider>
1618
</BrowserRouter>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 };

src/components/BackToTop/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { BackToTop } from "./BackToTop";
2+
3+
export { BackToTop };

0 commit comments

Comments
 (0)