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

highlighted current page in nav bar #89

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 19 additions & 1 deletion src/componets/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ body.menu-open {
color: rgba(222, 184, 135, 0.6);
pointer-events: none;
animation: steam 2s infinite;
}
}

/* Highlighting current page */
.nav a.active {
position: relative;
color: #D2691E;
font-weight: bold;
}

.nav a.active::after {
content: '';
position: absolute;
bottom: -5px;
left: 0;
right: 0;
height: 2px;
background-color: #D2691E;
transition: width 0.3s ease;
}
41 changes: 33 additions & 8 deletions src/componets/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React, { useState, useEffect } from 'react';
import { Link, useLocation} from 'react-router-dom';
import { useSelector, useDispatch } from 'react-redux';
import { logout } from '../Store/authSlice';
import styled from 'styled-components';
import { motion, AnimatePresence } from 'framer-motion';
import React, { useState, useEffect } from "react";
import { Link } from "react-router-dom";
import { useSelector, useDispatch } from "react-redux";
import { logout } from "../Store/authSlice";
import styled from "styled-components";
import { motion, AnimatePresence } from "framer-motion";


const NavbarContainer = styled(motion.nav)`
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -84,6 +91,10 @@ const NavLink = styled(motion.div)`
color: #ffe4b5;
}
}
&.active a {
text-decoration: underline;
color: #D2691E;
}

&::after {
content: "☕";
Expand Down Expand Up @@ -168,6 +179,7 @@ function Navbar() {
const [scrolled, setScrolled] = useState(false);
const isLoggedIn = useSelector((state) => state.auth.isLoggedIn);
const dispatch = useDispatch();
const location = useLocation();

useEffect(() => {
const handleScroll = () => {
Expand Down Expand Up @@ -198,40 +210,53 @@ function Navbar() {
<Link to="/">MsCafe</Link>
</Logo>
<NavLinks>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/">Home</Link>
</NavLink>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/shop' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/shop">Shop</Link>
</NavLink>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/about' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/about">About</Link>
</NavLink>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/testimonial' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/testimonial">Testimonial</Link>
</NavLink>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/contact' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/contact">Contact</Link>
</NavLink>

{isLoggedIn ? (
<>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/profile' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/profile">Profile</Link>
</NavLink>
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink
whileHover={{ scale: 1.05 }}>
<Link to="/cart">Cart</Link>
</NavLink>

<NavLink className={location.pathname === '/cart' ? 'active' : ''}
whileHover={{ scale: 1.05 }}

<NavLink
whileHover={{ scale: 1.05 }}

onClick={handleLogout}
style={{ cursor: "pointer" }}
>
Logout
</NavLink>
</>
) : (
<NavLink whileHover={{ scale: 1.05 }}>
<NavLink className={location.pathname === '/login' ? 'active' : ''}
whileHover={{ scale: 1.05 }}>
<Link to="/login">Login</Link>
</NavLink>
)}
Expand Down
Loading