File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import React , { useEffect , useState } from "react" ;
2+ import { ArrowUp } from "lucide-react" ;
3+
4+ const BackToTopButton : React . FC = ( ) => {
5+ const [ isVisible , setIsVisible ] = useState ( false ) ;
6+
7+ useEffect ( ( ) => {
8+ const toggleVisibility = ( ) => {
9+ if ( window . scrollY > 300 ) {
10+ setIsVisible ( true ) ;
11+ } else {
12+ setIsVisible ( false ) ;
13+ }
14+ } ;
15+
16+ window . addEventListener ( "scroll" , toggleVisibility ) ;
17+
18+ return ( ) => {
19+ window . removeEventListener ( "scroll" , toggleVisibility ) ;
20+ } ;
21+ } , [ ] ) ;
22+
23+ const scrollToTop = ( ) => {
24+ window . scrollTo ( {
25+ top : 0 ,
26+ behavior : "smooth" ,
27+ } ) ;
28+ } ;
29+
30+ return (
31+ < >
32+ { isVisible && (
33+ < button
34+ onClick = { scrollToTop }
35+ aria-label = "Back to top"
36+ className = "fixed bottom-6 right-6 z-50 flex h-12 w-12 items-center justify-center rounded-full bg-green-500 text-white shadow-lg transition-all duration-300 hover:scale-110 hover:bg-green-600"
37+ >
38+ < ArrowUp size = { 22 } />
39+ </ button >
40+ ) }
41+ </ >
42+ ) ;
43+ } ;
44+
45+ export default BackToTopButton ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { FaGithub } from "react-icons/fa";
1515import { Link } from "react-router-dom" ;
1616import axios from "axios" ;
1717import { GITHUB_REPO_CONTRIBUTORS_URL } from "../../utils/constants" ;
18+ import BackToTopButton from "../../components/Backtotop" ;
1819
1920interface Contributor {
2021 id : number ;
@@ -136,6 +137,7 @@ const ContributorsPage = () => {
136137 </ Grid >
137138 ) ) }
138139 </ Grid >
140+ < BackToTopButton />
139141 </ Container >
140142 </ div >
141143 ) ;
Original file line number Diff line number Diff line change 11import Hero from "../../components/Hero" ;
22import HowItWorks from "../../components/HowItWorks" ;
33import Features from "../../components/Features" ;
4+ import BackToTopButton from "../../components/Backtotop" ;
45
56function Home ( ) {
67 return (
78 < div className = "" >
89 < Hero />
910 < Features />
1011 < HowItWorks />
11-
12+ < BackToTopButton />
1213 </ div >
1314 )
1415}
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import { useTheme } from "@mui/material/styles";
3333import { useGitHubAuth } from "../../hooks/useGitHubAuth" ;
3434import { useGitHubData } from "../../hooks/useGitHubData" ;
3535import { KeyIcon } from "lucide-react" ;
36+ import BackToTopButton from "../../components/Backtotop" ;
3637
3738const ROWS_PER_PAGE = 10 ;
3839
@@ -396,6 +397,7 @@ const Home: React.FC = () => {
396397 </ TableContainer >
397398 </ Box >
398399 ) }
400+ < BackToTopButton />
399401 </ Container >
400402 ) ;
401403} ;
You can’t perform that action at this time.
0 commit comments