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

enhancement on navbar to highlight current active nav #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 20 additions & 6 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
} from "react-icons/ai";

import { CgFileDocument } from "react-icons/cg";

function NavBar() {
const [expand, updateExpanded] = useState(false);
const [navColour, updateNavbar] = useState(false);
var prev_selected="home"

function scrollHandler() {
if (window.scrollY >= 20) {
Expand All @@ -27,8 +27,16 @@ function NavBar() {
updateNavbar(false);
}
}
function active_selected(id){
document.getElementById(id).style.backgroundColor="blueviolet"
document.getElementById(prev_selected).style.backgroundColor=""
prev_selected=id


}

window.addEventListener("scroll", scrollHandler);


return (
<Navbar
Expand All @@ -54,16 +62,19 @@ function NavBar() {
<Navbar.Collapse id="responsive-navbar-nav">
<Nav className="ms-auto" defaultActiveKey="#home">
<Nav.Item>
<Nav.Link as={Link} to="/" onClick={() => updateExpanded(false)}>
<AiOutlineHome style={{ marginBottom: "2px" }} /> Home
<Nav.Link as={Link} to="/" id="home" style={{backgroundColor:"blueviolet"}}
onClick={() => {updateExpanded(false);active_selected("home")}} >
<AiOutlineHome style={{ marginBottom: "2px"} } /> Home
</Nav.Link>
</Nav.Item>

<Nav.Item>
<Nav.Link
as={Link}
to="/about"
onClick={() => updateExpanded(false)}
id="about"
onClick={() => {updateExpanded(false);active_selected("about")}}

>
<AiOutlineUser style={{ marginBottom: "2px" }} /> About
</Nav.Link>
Expand All @@ -72,8 +83,9 @@ function NavBar() {
<Nav.Item>
<Nav.Link
as={Link}
id="projects"
to="/project"
onClick={() => updateExpanded(false)}
onClick={() =>{updateExpanded(false);active_selected("projects")}}
>
<AiOutlineFundProjectionScreen
style={{ marginBottom: "2px" }}
Expand All @@ -85,8 +97,9 @@ function NavBar() {
<Nav.Item>
<Nav.Link
as={Link}
id="resume"
to="/resume"
onClick={() => updateExpanded(false)}
onClick={() =>{updateExpanded(false);active_selected("resume")}}
>
<CgFileDocument style={{ marginBottom: "2px" }} /> Resume
</Nav.Link>
Expand All @@ -97,6 +110,7 @@ function NavBar() {
href="https://soumyajitblogs.vercel.app/"
target="_blank"
rel="noreferrer"

>
<ImBlog style={{ marginBottom: "2px" }} /> Blogs
</Nav.Link>
Expand Down