-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from AKSHITHA-CHILUKA/patch-11
Create NotificationBell.jsx
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// src/components/NotificationBell.jsx | ||
import React, { useState } from 'react'; | ||
import './NotificationBell.css'; // Optional: for styling | ||
const NotificationBell = () => { | ||
const [notifications, setNotifications] = useState([ | ||
{ id: 1, text: 'New comment on your post' }, | ||
{ id: 2, text: 'New follower' }, | ||
]); | ||
const [isDropdownOpen, setIsDropdownOpen] = useState(false); | ||
const handleBellClick = () => { | ||
setIsDropdownOpen(!isDropdownOpen); | ||
}; | ||
const handleNotificationClick = (id) => { | ||
// Handle notification click (e.g., mark as read, navigate to detail page) | ||
console.log(`Notification ${id} clicked`); | ||
}; | ||
return ( | ||
<div className="notification-bell"> | ||
<button className="bell-icon" onClick={handleBellClick}> | ||
<span className="bell">🔔</span> {/* Bell icon */} | ||
{notifications.length > 0 && ( | ||
<span className="notification-count">{notifications.length}</span> | ||
)} | ||
</button> | ||
{isDropdownOpen && ( | ||
<div className="dropdown-menu"> | ||
{notifications.length === 0 ? ( | ||
<div className="no-notifications">No notifications</div> | ||
) : ( | ||
notifications.map((notification) => ( | ||
<div | ||
key={notification.id} | ||
className="notification-item" | ||
onClick={() => handleNotificationClick(notification.id)} | ||
> | ||
{notification.text} | ||
</div> | ||
)) | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
export default NotificationBell; |