Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/components/Backtotop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useEffect, useState } from "react";
import { ArrowUp } from "lucide-react";

const BackToTopButton: React.FC = () => {
const [isVisible, setIsVisible] = useState(false);

useEffect(() => {
const toggleVisibility = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};

window.addEventListener("scroll", toggleVisibility);

return () => {
window.removeEventListener("scroll", toggleVisibility);
};
}, []);
Comment thread
Souradeep858 marked this conversation as resolved.

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

return (
<>
{isVisible && (
<button
onClick={scrollToTop}
aria-label="Back to top"
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"
>
<ArrowUp size={22} />
</button>
)}
</>
);
};

export default BackToTopButton;
2 changes: 2 additions & 0 deletions src/pages/Contributors/Contributors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FaGithub } from "react-icons/fa";
import { Link } from "react-router-dom";
import axios from "axios";
import { GITHUB_REPO_CONTRIBUTORS_URL } from "../../utils/constants";
import BackToTopButton from "../../components/Backtotop";

interface Contributor {
id: number;
Expand Down Expand Up @@ -136,6 +137,7 @@ const ContributorsPage = () => {
</Grid>
))}
</Grid>
<BackToTopButton/>
</Container>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Hero from "../../components/Hero";
import HowItWorks from "../../components/HowItWorks";
import Features from "../../components/Features";
import BackToTopButton from "../../components/Backtotop";

function Home() {
return (
<div className="">
<Hero />
<Features />
<HowItWorks />

<BackToTopButton/>
</div>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Tracker/Tracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useTheme } from "@mui/material/styles";
import { useGitHubAuth } from "../../hooks/useGitHubAuth";
import { useGitHubData } from "../../hooks/useGitHubData";
import { KeyIcon } from "lucide-react";
import BackToTopButton from "../../components/Backtotop";

const ROWS_PER_PAGE = 10;

Expand Down Expand Up @@ -396,6 +397,7 @@ const Home: React.FC = () => {
</TableContainer>
</Box>
)}
<BackToTopButton/>
</Container>
);
};
Expand Down
Loading