-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb354d
commit ca475c8
Showing
5 changed files
with
224 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,90 @@ | ||
import React, { useContext, useState } from 'react'; | ||
import './Navbar.css'; | ||
import logo from '../Assets/logo.png'; | ||
import cart_icon from '../Assets/cart_icon.png'; | ||
import cart_icon_dark from '../Assets/cart_icon_dark.png'; | ||
import moonIcon from '../Assets/dark_mode.png'; | ||
import sunIcon from '../Assets/light_mode.png'; | ||
import { Link } from 'react-router-dom'; | ||
import { ShopContext } from '../../Context/ShopContext'; | ||
import React, { useContext, useState } from "react"; | ||
import "./Navbar.css"; | ||
import logo from "../Assets/logo.png"; | ||
import cart_icon from "../Assets/cart_icon.png"; | ||
import cart_icon_dark from "../Assets/cart_icon_dark.png"; | ||
import moonIcon from "../Assets/dark_mode.png"; | ||
import sunIcon from "../Assets/light_mode.png"; | ||
import { Link } from "react-router-dom"; | ||
import { ShopContext } from "../../Context/ShopContext"; | ||
import { MdHeight } from "react-icons/md"; | ||
|
||
const Navbar = () => { | ||
const [icon, setIcon] = useState(cart_icon); | ||
const [menu, setMenu] = useState("shop"); | ||
const { getTotalCartItems, theme, setTheme } = useContext(ShopContext); | ||
const [icon, setIcon] = useState(cart_icon); | ||
const [menu, setMenu] = useState("shop"); | ||
const { getTotalCartItems, theme, setTheme } = useContext(ShopContext); | ||
|
||
const toggle = () => { | ||
if (theme === "dark") { | ||
setTheme("light"); | ||
setIcon(cart_icon_dark); | ||
const dnav = document.getElementById("nav"); | ||
dnav.classList.add("dark"); | ||
} else { | ||
setTheme("dark"); | ||
setIcon(cart_icon); | ||
const dnav = document.getElementById("nav"); | ||
dnav.classList.remove("dark"); | ||
} | ||
}; | ||
const toggle = () => { | ||
if (theme === "dark") { | ||
setTheme("light"); | ||
setIcon(cart_icon_dark); | ||
const dnav = document.getElementById("nav"); | ||
dnav.classList.add("dark"); | ||
} else { | ||
setTheme("dark"); | ||
setIcon(cart_icon); | ||
const dnav = document.getElementById("nav"); | ||
dnav.classList.remove("dark"); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={`navbar`} id="nav"> | ||
<div className="nav-logo"> | ||
<Link className="nav-logo-link" to="/"> | ||
<img src={logo} alt="ShopNex Logo" style={{ marginRight: '10px' }} /> | ||
<p className={`pnav_${theme}`}>ShopNex</p> | ||
</Link> | ||
</div> | ||
<ul className="nav-menu"> | ||
<li onClick={() => { setMenu("shop") }}> | ||
<Link to='/'>Shop</Link> | ||
{menu === "shop" ? <hr /> : <></>} | ||
</li> | ||
<li onClick={() => { setMenu("men") }}> | ||
<Link to='/men'>Men</Link> | ||
{menu === "men" ? <hr /> : <></>} | ||
</li> | ||
<li onClick={() => { setMenu("women") }}> | ||
<Link to='/women'>Women</Link> | ||
{menu === "women" ? <hr /> : <></>} | ||
</li> | ||
<li onClick={() => { setMenu("kids") }}> | ||
<Link to='/kids'>Kids</Link> | ||
{menu === "kids" ? <hr /> : <></>} | ||
</li> | ||
</ul> | ||
<div className="nav-login-cart"> | ||
<Link to='/login'><button className='log_btn'>Login</button></Link> | ||
<Link to='/cart'><img src={icon} alt="" className='cart' /></Link> | ||
<div className="nav-cart-count">{getTotalCartItems()}</div> | ||
<div className='dark_btn'> | ||
<button onClick={toggle} className={`toggle_${theme} change`}> | ||
{theme === 'light' ? <img src={sunIcon} /> : <img src={moonIcon} />} | ||
</button> | ||
</div> | ||
</div> | ||
return ( | ||
<div className={`navbar`} id="nav"> | ||
<div className="nav-logo"> | ||
<Link className="nav-logo-link" to="/"> | ||
<img src={logo} alt="ShopNex Logo" style={{ marginRight: "10px" }} /> | ||
<p className={`pnav_${theme}`}>ShopNex</p> | ||
</Link> | ||
</div> | ||
<ul className="nav-menu"> | ||
<li | ||
onClick={() => { | ||
setMenu("shop"); | ||
}}> | ||
<Link to="/"> | ||
<i class="fa-brands fa-shopify"></i> | ||
Shop | ||
</Link> | ||
{menu === "shop" ? <hr /> : <></>} | ||
</li> | ||
<li | ||
onClick={() => { | ||
setMenu("men"); | ||
}}> | ||
<Link to="/men">Men</Link> | ||
{menu === "men" ? <hr /> : <></>} | ||
</li> | ||
<li | ||
onClick={() => { | ||
setMenu("women"); | ||
}}> | ||
<Link to="/women">Women</Link> | ||
{menu === "women" ? <hr /> : <></>} | ||
</li> | ||
<li | ||
onClick={() => { | ||
setMenu("kids"); | ||
}}> | ||
<Link to="/kids">Kids</Link> | ||
{menu === "kids" ? <hr /> : <></>} | ||
</li> | ||
</ul> | ||
<div className="nav-login-cart"> | ||
<Link to="/login"> | ||
<button className="log_btn">Login</button> | ||
</Link> | ||
<Link to="/cart"> | ||
<img src={icon} alt="" className="cart" /> | ||
</Link> | ||
<div className="nav-cart-count">{getTotalCartItems()}</div> | ||
<div className="dark_btn"> | ||
<button onClick={toggle} className={`toggle_${theme} change`}> | ||
{theme === "light" ? <img src={sunIcon} /> : <img src={moonIcon} />} | ||
</button> | ||
</div> | ||
) | ||
} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Navbar; |
Oops, something went wrong.