Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved Issue #482 [style]: Make the navbar sticky and prominent #623

Merged
merged 6 commits into from
May 22, 2023
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
48 changes: 26 additions & 22 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const Navbar = () => {
const switchTrackColor = theme.mode === "dark" ? "#9CA3AF" : undefined

return (
<nav aria-label="Site Nav" className="mx-auto p-5 lg:w-1/2">
<div className="flex flex-row justify-between">
<nav
aria-label="Site Nav"
className="sticky top-0 z-[100] backdrop-blur-sm"
style={{ backgroundColor: theme.mode === "dark" ? "#00000080" : "#f5f6fa80" }}
>
<div className="flex flex-row justify-between mx-auto p-5 lg:w-1/2">
{/* Logo for project Hut */}
<div className="item-navbar block md:hidden" id="dropdown-menu">
<IconButton aria-label="open drawer" edge="start" onClick={handleDrawerToggle}>
Expand All @@ -44,28 +48,28 @@ const Navbar = () => {
<ul className="flex items-center gap-5 text-[1rem]">
<li>
<NavLink
to="/" className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}

className={`inline-block py-2 px-3 text-center font-bold rounded-md focus:outline-none focus:ring ${
theme.name === "light" ? "hover:text-white hover:bg-black" : "hover:text-black hover:bg-white"
to="/"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
activestyle={{
fontWeight: "bold",
color: navbar.color,
backgroundColor: "white",
}}>
}}
>
Home
</NavLink>
</li>
<li>
<NavLink

to="/ProjectsPage"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}

to="/projectspage"
className={`inline-block py-2 px-3 text-center font-bold rounded-md focus:outline-none focus:ring ${
theme.name === "light" ? "hover:text-white hover:bg-black" : "hover:text-black hover:bg-white"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
activestyle={{
fontWeight: "bold",
Expand All @@ -78,20 +82,17 @@ const Navbar = () => {
</li>
<li>
<NavLink

to="/AddYourProjectsGuide"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}

to="/docs"
className={`inline-block py-2 px-3 text-center font-bold rounded-md focus:outline-none focus:ring ${
theme.name === "light" ? "hover:text-white hover:bg-black" : "hover:text-black hover:bg-white"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
activestyle={{
fontWeight: "bold",
color: navbar.color,
backgroundColor: "white",
}}

>
Docs
</NavLink>
Expand All @@ -100,12 +101,15 @@ const Navbar = () => {
<li>
<NavLink
to="/ContributorsPage"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
>
Contributors
</NavLink>
</li>

</ul>
</div>

Expand Down
91 changes: 45 additions & 46 deletions src/components/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
import React, { useState, useEffect } from "react";
import { AiOutlineArrowUp } from 'react-icons/ai';

const ScrollToTop = () => {
const [isVisible, setIsVisible] = useState(false); // State to track the visibility of the scroll-to-top button

const toggleVisibility = () => {
// Function to toggle the visibility of the button based on scroll position

if (window.pageYOffset > window.innerHeight * 0.25) {
setIsVisible(true); // Set visibility to true if scrolled more than 25% of the viewport height
} else {
setIsVisible(false); // Set visibility to false otherwise
}
};

const scrollToTop = () => {
// Function to scroll to the top when the button is clicked
window.scrollTo({
top: 0,
behavior: "smooth", // Scroll behavior is set to smooth for a smooth scrolling effect
});
};

useEffect(() => {
// Effect hook to add and remove event listeners on scroll
window.addEventListener("scroll", toggleVisibility); // Add event listener to track scroll position
return () => {
window.removeEventListener("scroll", toggleVisibility); // Remove event listener when component is unmounted
};
}, []);

return (
<>
<button
className={`fixed p-2 bg-gray-400 bg-opacity-25 rounded-full ${isVisible ? " bottom-4 right-4" : "hidden"}`}
onClick={scrollToTop}
>
<AiOutlineArrowUp size={25} />
</button>
</>
);
};

export default ScrollToTop;

import React, { useState, useEffect } from "react"
import { AiOutlineArrowUp } from "react-icons/ai"

const ScrollToTop = () => {
const [isVisible, setIsVisible] = useState(false) // State to track the visibility of the scroll-to-top button

const toggleVisibility = () => {
// Function to toggle the visibility of the button based on scroll position

if (window.pageYOffset > window.innerHeight * 0.25) {
setIsVisible(true) // Set visibility to true if scrolled more than 25% of the viewport height
} else {
setIsVisible(false) // Set visibility to false otherwise
}
}

const scrollToTop = () => {
// Function to scroll to the top when the button is clicked
window.scrollTo({
top: 0,
behavior: "smooth", // Scroll behavior is set to smooth for a smooth scrolling effect
})
}

useEffect(() => {
// Effect hook to add and remove event listeners on scroll
window.addEventListener("scroll", toggleVisibility) // Add event listener to track scroll position
return () => {
window.removeEventListener("scroll", toggleVisibility) // Remove event listener when component is unmounted
}
}, [])

return (
<>
<button
className={`fixed p-2 bg-gray-400 bg-opacity-25 rounded-full ${isVisible ? " bottom-4 right-4" : "hidden"}`}
onClick={scrollToTop}
>
<AiOutlineArrowUp size={25} />
</button>
</>
)
}

export default ScrollToTop
30 changes: 25 additions & 5 deletions src/components/SideMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export default function SideMenu(props) {
<li>
<NavLink
to="/"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
onClick={() => props.handleDrawerToggle()}
>
{"Home"}
Expand All @@ -55,7 +59,11 @@ export default function SideMenu(props) {
<li>
<NavLink
to="/ProjectsPage"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
onClick={() => props.handleDrawerToggle()}
>
{"Projects"}
Expand All @@ -64,7 +72,11 @@ export default function SideMenu(props) {
<li>
<NavLink
to="/ContributorsPage"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
onClick={() => props.handleDrawerToggle()}
>
{"Contributers"}
Expand All @@ -73,7 +85,11 @@ export default function SideMenu(props) {
<li>
<NavLink
to="/AddYourProjectsGuide"
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
onClick={() => props.handleDrawerToggle()}
>
{"Documentation"}
Expand All @@ -84,7 +100,11 @@ export default function SideMenu(props) {
href="https://github.com/priyankarpal/ProjectsHut"
target={"_blank"}
rel={"noreferrer"}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${theme.mode === "light" ? "hover:text-white hover:bg-black focus:text-white focus:bg-black": "hover:text-black hover:bg-white focus:text-black focus:bg-white"}`}
className={`inline-block py-2 px-3 text-center font-bold rounded-md ${
theme.mode === "light"
? "hover:text-white hover:bg-black focus:text-white focus:bg-black"
: "hover:text-black hover:bg-white focus:text-black focus:bg-white"
}`}
aria-label="Github"
>
{"GitHub"}
Expand Down