source: imaps-frontend/src/components/Profile/Profile.jsx

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[d565449]1import React, { useState, useRef, useEffect } from "react";
2import profile from "../../assets/person_icon.png";
3import styles from "./Profile.module.css";
4
5function Profile() {
6 const menus = ["Profile", "Settings", "Support", "Logout"];
7 const [open, setOpen] = useState(false);
8 const menuRef = useRef(null);
9 const imgRef = useRef(null);
10
11 useEffect(() => {
12 const handleClickOutside = (e) => {
13 if (menuRef.current && imgRef.current) {
14 if (!menuRef.current.contains(e.target) && !imgRef.current.contains(e.target)) {
15 setOpen(false);
16 }
17 }
18 };
19
20 document.addEventListener("click", handleClickOutside);
21
22 return () => {
23 document.removeEventListener("click", handleClickOutside);
24 };
25 }, []);
26
27 return (
28 <div className={styles.profileContainer}>
29 <div className={styles.profileWrapper}>
30 <img
31 onClick={() => setOpen(!open)}
32 src={profile}
33 alt="profile"
34 className={styles.profileImage}
35 ref={imgRef}
36 />
37 {open && (
38 <div ref={menuRef} className={styles.dropdownMenu}>
39 <ul className={styles.menuList}>
40 {menus.map((menu) => (
41 <li key={menu} onClick={() => setOpen(false)} className={styles.menuItem}>
42 {menu}
43 </li>
44 ))}
45 </ul>
46 </div>
47 )}
48 </div>
49 </div>
50 );
51}
52
53export default Profile;
Note: See TracBrowser for help on using the repository browser.