Skip to content

Commit a224785

Browse files
authored
Merge pull request #73 from yashmandi/bug/notification-icon
[FIX] Fixed Notification Icon Function & Added Dropdown Close Functionality
2 parents 2b9f237 + 9af058a commit a224785

File tree

2 files changed

+107
-15
lines changed

2 files changed

+107
-15
lines changed

src/Components/Container.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,56 @@
153153
color: #f1f1f1;
154154
}
155155

156+
.notification-container {
157+
position: relative;
158+
}
159+
160+
.profileIcon {
161+
cursor: pointer;
162+
}
163+
164+
.dropdown-content {
165+
position: absolute;
166+
top: 100%;
167+
right: 0;
168+
background-color: #19162c;
169+
border-radius: 10px;
170+
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.4);
171+
padding: 8px;
172+
z-index: 1;
173+
width: 400px; /* Adjust width as needed */
174+
padding: 20px;
175+
}
176+
177+
.notification-item {
178+
padding: 8px 0;
179+
border-bottom: 1px solid #eee;
180+
}
181+
182+
.notification-item:last-child {
183+
border-bottom: none;
184+
}
185+
186+
.seeAll {
187+
text-align: center;
188+
margin-top: 10px;
189+
cursor: pointer;
190+
font-weight: bold;
191+
}
192+
193+
.notification-item {
194+
padding: 8px 0;
195+
border-bottom: 1px solid #121026;
196+
transition: background-color 0.3s ease; /* Add transition for smooth color change */
197+
cursor: pointer;
198+
}
199+
200+
.notification-item:hover {
201+
background-color: #121026; /* Change background color on hover */
202+
203+
}
204+
205+
156206
@media screen and (max-width: 525px) {
157207
.container {
158208
width: calc(100% - 68px);

src/Components/TopContainer.js

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
import React, { useEffect } from "react";
1+
import React, { useEffect, useState, useRef } from "react";
22
import { BiSearchAlt } from "react-icons/bi";
33
import { FaBell, FaChevronDown } from "react-icons/fa";
44
import women from "../img/women.jpg";
55

66
function TopContainer() {
7+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
8+
const dropdownRef = useRef(null);
9+
710
useEffect(() => {
8-
const mouseTarget = document.getElementById("menuChevron");
9-
const menuContainer = document.getElementById("menuContainer");
10-
mouseTarget.addEventListener("mouseenter", () => {
11-
mouseTarget.style.transform = "rotate(180deg)";
12-
menuContainer.style.transform = "translateX(0px)";
13-
});
14-
15-
menuContainer.addEventListener("mouseleave", () => {
16-
mouseTarget.style.transform = "rotate(0deg)";
17-
menuContainer.style.transform = "translateX(300px)";
18-
});
11+
// Add event listener to detect clicks anywhere on the page
12+
window.addEventListener("click", handleOutsideClick);
13+
14+
// Cleanup function to remove the event listener
15+
return () => {
16+
window.removeEventListener("click", handleOutsideClick);
17+
};
1918
}, []);
2019

20+
const toggleDropdown = () => {
21+
setIsDropdownOpen(!isDropdownOpen);
22+
};
23+
24+
const handleOutsideClick = (event) => {
25+
// Check if the clicked element is outside the dropdown content
26+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
27+
setIsDropdownOpen(false);
28+
}
29+
};
30+
2131
return (
2232
<div className="topContainer">
2333
<div className="inputBox">
@@ -28,12 +38,44 @@ function TopContainer() {
2838
</div>
2939

3040
<div className="profileContainer">
31-
<i className="profileIcon">
32-
<FaBell />
33-
</i>
41+
<div className="notification-container" ref={dropdownRef}>
42+
<div className="profileIcon" onClick={toggleDropdown}>
43+
<FaBell />
44+
</div>
45+
{isDropdownOpen && (
46+
<div className="dropdown-content">
47+
{/* Notification items */}
48+
<div className="notification-item">
49+
User "JohnDoe" has uploaded a new project titled "Introduction
50+
to Machine Learning." Check it out now!
51+
</div>
52+
<div className="notification-item">
53+
User "JaneSmith" has commented on your project "Data
54+
Visualization with D3.js." View the comment now.
55+
</div>
56+
<div className="notification-item">
57+
User "TechMaster" has updated the project "Web Development with
58+
React.js" with bug fixes. Explore the updated version.
59+
</div>
60+
<div className="notification-item">
61+
Congratulations! Your project "Artificial Intelligence in
62+
Robotics" has been approved by the moderators. It's now live on
63+
the platform.
64+
</div>
65+
<div className="notification-item">
66+
User "CodeNinja" has sent you a collaboration request for the
67+
project "Cybersecurity Best Practices." Accept or decline the
68+
request.
69+
</div>
70+
<p className="seeAll">See all notifications</p>
71+
</div>
72+
)}
73+
</div>
74+
3475
<div className="profileImage">
3576
<img src={women} alt="" />
3677
</div>
78+
3779
<p className="profileName">Sugam Arora</p>
3880
<i className="menuChevron" id="menuChevron">
3981
<FaChevronDown />

0 commit comments

Comments
 (0)