Skip to content

Commit

Permalink
Merge pull request #188 from CoderFleet/feat/fixi-navbar-hovers-and-r…
Browse files Browse the repository at this point in the history
…otations

Fix navbar animations: resolved hover effects, rotation, and sizing issues
  • Loading branch information
shivamyadavrgipt authored Nov 1, 2024
2 parents c5050ad + 8ee7c92 commit fc882cd
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect, useRef } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faChevronUp,
faThLarge,
faPaperPlane,
faChartLine,
Expand All @@ -10,6 +9,7 @@ import {
faMoon,
faFileAlt,
faLightbulb,
faChevronDown,
} from "@fortawesome/free-solid-svg-icons";
import {
faFacebookF,
Expand All @@ -20,7 +20,7 @@ import {
faTiktok,
} from "@fortawesome/free-brands-svg-icons";
import { Link } from "react-router-dom";
import { Search } from "@mui/icons-material";
import { Height, Search } from "@mui/icons-material";

// Dropdown item component
const DropdownItem = ({ icon, title, description }) => (
Expand Down Expand Up @@ -50,6 +50,24 @@ const NavMenu = ({ isDarkMode, showSearchBar }) => {
setIsChannelsDropdownOpen(!isChannelsDropdownOpen);
setIsToolsDropdownOpen(false); // Close tools dropdown when channels dropdown opens
};

// We Only Re-rotate icons back to original, when cursor leaves both button and dropdown
useEffect(() => {
if(isToolsDropdownOpen) {
document.getElementById('toolsIcon').classList.add('rotate-[180deg]')
}
else {
document.getElementById('toolsIcon').classList.remove('rotate-[180deg]')
}

if(isChannelsDropdownOpen) {
document.getElementById('channelIcon').classList.add('rotate-[180deg]')
}
else {
document.getElementById('channelIcon').classList.remove('rotate-[180deg]')
}
}, [isToolsDropdownOpen, isChannelsDropdownOpen])

return (
<>
<button
Expand Down Expand Up @@ -85,20 +103,22 @@ const NavMenu = ({ isDarkMode, showSearchBar }) => {
isDarkMode ? "bg-gray-800 text-white" : "bg-white text-black"
} `}
>
<Link to="/dashboard" className="text-lg font-medium ">
<Link to="/dashboard" className="text-lg font-medium hover:text-blue-400 transition-colors duration-250">
Dashboard
</Link>

{/* Tools Dropdown */}
<div>
<button
className="focus:smooth-auto text-lg font-medium group transition-transform"
className="focus:smooth-auto text-lg font-medium group transition-transform hover:text-blue-400 transition-colors duration-250"
onMouseEnter={toggleToolsDropdown}
>
Tools{" "}
<FontAwesomeIcon
icon={faChevronUp}
icon={faChevronDown}
className="transition-transform duration-500 group-hover:rotate-[180deg]"
size="2xs"
id="toolsIcon"
/>
</button>

Expand Down Expand Up @@ -170,13 +190,15 @@ const NavMenu = ({ isDarkMode, showSearchBar }) => {
<div className="relative">
<button
className="focus:smooth-auto text-lg font-medium
group transition-transform"
group transition-transform hover:text-blue-400 transition-colors duration-250"
onMouseEnter={toggleChannelsDropdown}
>
Channels
<FontAwesomeIcon
icon={faChevronUp}
icon={faChevronDown}
className="transition-transform duration-500 group-hover:rotate-[180deg] ml-2"
size="2xs"
id="channelIcon"
/>
</button>

Expand All @@ -200,7 +222,7 @@ const NavMenu = ({ isDarkMode, showSearchBar }) => {
</div>

{/* Other Links */}
<Link to="/settings" className="text-lg font-medium">
<Link to="/settings" className="text-lg font-medium hover:text-blue-400 transition-colors duration-250">
Settings
</Link>
{/* Get Started Button */}
Expand Down

0 comments on commit fc882cd

Please sign in to comment.