|
1 |
| -import React, { useState, useEffect, useRef } from "react"; |
| 1 | +// ProductsDropdown.jsx |
| 2 | +import React from "react"; |
2 | 3 | import { Link } from "react-router-dom";
|
3 | 4 | import { FaChevronDown } from "react-icons/fa";
|
4 | 5 |
|
5 |
| -const ProductsDropdown = () => { |
6 |
| - const [isOpen, setIsOpen] = useState(false); |
7 |
| - const dropdownRef = useRef(null); |
8 |
| - |
9 |
| - const toggleDropdown = () => setIsOpen(!isOpen); |
10 |
| - |
11 |
| - const handleClickOutside = (event) => { |
12 |
| - if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { |
13 |
| - setIsOpen(false); |
14 |
| - } |
15 |
| - }; |
16 |
| - |
17 |
| - useEffect(() => { |
18 |
| - document.addEventListener("mousedown", handleClickOutside); |
19 |
| - return () => { |
20 |
| - document.removeEventListener("mousedown", handleClickOutside); |
21 |
| - }; |
22 |
| - }, []); |
23 |
| - |
24 |
| - return ( |
25 |
| - <div className="relative" ref={dropdownRef}> |
26 |
| - <button |
27 |
| - type="button" |
28 |
| - onClick={toggleDropdown} |
29 |
| - className="text-black hover:text-gray-600 px-3 py-2 rounded-md text-lg font-medium flex items-center focus:outline-none" |
30 |
| - > |
31 |
| - <lord-icon |
32 |
| - style={{ |
33 |
| - width: "25px", |
34 |
| - height: "25px", |
35 |
| - paddingTop: "0px", |
36 |
| - paddingLeft: "1px", |
37 |
| - }} |
38 |
| - src="https://cdn.lordicon.com/pgmktfgp.json" |
39 |
| - trigger="hover" |
40 |
| - colors="primary:#15803D,secondary:#15803D" |
41 |
| - ></lord-icon>{" "} |
42 |
| - Products |
43 |
| - <FaChevronDown className="ml-1" /> |
44 |
| - </button> |
45 |
| - <div |
46 |
| - className={`${ |
47 |
| - isOpen ? "block" : "hidden" |
48 |
| - } absolute mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50`} |
49 |
| - > |
50 |
| - <div className="py-1"> |
51 |
| - <Link |
52 |
| - to="/popularCategories/fashionAccessories" |
53 |
| - className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
54 |
| - > |
55 |
| - Fashion |
56 |
| - </Link> |
57 |
| - <Link |
58 |
| - to="/popularCategories/customizedGifts" |
59 |
| - className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
60 |
| - > |
61 |
| - Gifts |
62 |
| - </Link> |
63 |
| - <Link |
64 |
| - to="/popularCategories/furnitureDecor" |
65 |
| - className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
66 |
| - > |
67 |
| - Furniture |
68 |
| - </Link> |
69 |
| - <Link |
70 |
| - to="/popularCategories/printingStationery" |
71 |
| - className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
72 |
| - > |
73 |
| - Stationary |
74 |
| - </Link> |
75 |
| - <Link |
76 |
| - to="/popularCategories/bodyCare" |
77 |
| - className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
78 |
| - > |
79 |
| - Body-Care |
80 |
| - </Link> |
81 |
| - </div> |
| 6 | +const ProductsDropdown = ({ isOpen, onMouseEnter, onMouseLeave }) => ( |
| 7 | + <div |
| 8 | + className="relative group" |
| 9 | + onMouseEnter={onMouseEnter} |
| 10 | + onMouseLeave={onMouseLeave} |
| 11 | + > |
| 12 | + <button |
| 13 | + type="button" |
| 14 | + className="text-black hover:text-gray-600 px-3 py-2 rounded-md text-lg font-medium flex items-center focus:outline-none" |
| 15 | + > |
| 16 | + <lord-icon |
| 17 | + style={{ |
| 18 | + width: "25px", |
| 19 | + height: "25px", |
| 20 | + paddingTop: "0px", |
| 21 | + paddingLeft: "1px", |
| 22 | + }} |
| 23 | + src="https://cdn.lordicon.com/pgmktfgp.json" |
| 24 | + trigger="hover" |
| 25 | + colors="primary:#15803D,secondary:#15803D" |
| 26 | + ></lord-icon>{" "} |
| 27 | + Products |
| 28 | + <FaChevronDown className="ml-1" /> |
| 29 | + </button> |
| 30 | + <div |
| 31 | + className={`${ |
| 32 | + isOpen ? "block" : "hidden" |
| 33 | + } absolute mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5`} |
| 34 | + style={{ zIndex: "20" }} |
| 35 | + > |
| 36 | + <div className="py-1"> |
| 37 | + <Link |
| 38 | + to="/popularCategories/fashionAccessories" |
| 39 | + className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
| 40 | + > |
| 41 | + Fashion |
| 42 | + </Link> |
| 43 | + <Link |
| 44 | + to="/popularCategories/customizedGifts" |
| 45 | + className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
| 46 | + > |
| 47 | + Gifts |
| 48 | + </Link> |
| 49 | + <Link |
| 50 | + to="/popularCategories/furnitureDecor" |
| 51 | + className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
| 52 | + > |
| 53 | + Furniture |
| 54 | + </Link> |
| 55 | + <Link |
| 56 | + to="/popularCategories/printingStationery" |
| 57 | + className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
| 58 | + > |
| 59 | + Stationary |
| 60 | + </Link> |
| 61 | + <Link |
| 62 | + to="/popularCategories/bodyCare" |
| 63 | + className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm" |
| 64 | + > |
| 65 | + Body-Care |
| 66 | + </Link> |
82 | 67 | </div>
|
83 | 68 | </div>
|
84 |
| - ); |
85 |
| -}; |
| 69 | + </div> |
| 70 | +); |
86 | 71 |
|
87 | 72 | export default ProductsDropdown;
|
0 commit comments