Dodo67

Navbar

Mar 5th, 2022
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //STYLES
  2. import styles from "./Navbar.module.scss";
  3.  
  4. //CONTEXT
  5. import { useContext } from "react";
  6. import NavContext from "../../Context/NavContext";
  7.  
  8. //REACT ROUTER
  9. import { NavLink } from "react-router-dom";
  10.  
  11. //ICONS
  12. import {
  13.   MdOutlineDashboard,
  14.   MdOutlineAnalytics,
  15.   MdOutlinedFlag,
  16.   MdPeopleOutline,
  17.   MdOutlineMessage,
  18.   MdOutlineLogout,
  19. } from "react-icons/md";
  20. import { IoMdLogIn } from "react-icons/io";
  21. import { FaReact, FaTimes } from "react-icons/fa";
  22. import { BsThreeDots } from "react-icons/bs";
  23. import { VscDashboard } from "react-icons/vsc";
  24.  
  25. const NavUrl = ({ url, icon, description }) => {
  26.   const { nav, setNav } = useContext(NavContext);
  27.   const checkWindowSize = () => {
  28.     if (window.innerWidth < 1024) setNav(!nav);
  29.   };
  30.  
  31.   return (
  32.     <li className={styles.li_navlink}>
  33.       <NavLink
  34.         to={`${url}`}
  35.         className={({ isActive }) => (isActive ? styles.active : undefined)}
  36.         onClick={() => checkWindowSize()}
  37.       >
  38.         {icon}
  39.         <span className={styles.description}>{description}</span>
  40.       </NavLink>
  41.     </li>
  42.   );
  43. };
  44.  
  45. const Navbar = () => {
  46.   const { nav, setNav } = useContext(NavContext);
  47.  
  48.   return (
  49.     <div
  50.       className={`${styles.navbar_container} ${
  51.         nav ? styles.navbar_mobile_active : undefined
  52.       }`}
  53.     >
  54.       <nav className={nav ? undefined : styles.nav_small}>
  55.         {/* LOGO */}
  56.         <div className={styles.logo}>
  57.           <VscDashboard className={styles.logo_icon} />
  58.           <FaTimes
  59.             className={styles.mobile_cancel_icon}
  60.             onClick={() => {
  61.               setNav(!nav);
  62.             }}
  63.           />
  64.         </div>
  65.  
  66.         {/* MENU */}
  67.         <ul className={styles.menu_container}>
  68.           {/* FIRST CATEGORY */}
  69.           <span className={styles.categories}>
  70.             {nav ? "Pages" : <BsThreeDots />}
  71.           </span>
  72.  
  73.           <NavUrl
  74.             url="/"
  75.             icon={<MdOutlineDashboard />}
  76.             description="Dashboard"
  77.           />
  78.           <NavUrl
  79.             url="analytics"
  80.             icon={<MdOutlineAnalytics />}
  81.             description="Analytics"
  82.           />
  83.           <NavUrl
  84.             url="campaings"
  85.             icon={<MdOutlinedFlag />}
  86.             description="Campaings"
  87.           />
  88.           <NavUrl url="team" icon={<MdPeopleOutline />} description="Team" />
  89.  
  90.           <NavUrl
  91.             url="messages"
  92.             icon={<MdOutlineMessage />}
  93.             description="Messages"
  94.           />
  95.  
  96.         </ul>
  97.  
  98.         {/* LOGOUT BUTTON */}
  99.         <div
  100.           className={`${styles.btn_logout}`}
  101.           onClick={() => {
  102.             setNav(!nav);
  103.           }}
  104.         >
  105.           <MdOutlineLogout />
  106.         </div>
  107.       </nav>
  108.  
  109.       <div
  110.         className={nav ? styles.mobile_nav_background_active : undefined}
  111.         onClick={() => {
  112.           setNav(!nav);
  113.         }}
  114.       ></div>
  115.     </div>
  116.   );
  117. };
  118.  
  119. export default Navbar;
Advertisement
Add Comment
Please, Sign In to add comment