NavbarSearchIcon.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use client";
  2. import { useState,useEffect } from "react";
  3. import SearchPop from "./SearchPop";
  4. import { usePathname } from "next/navigation";
  5. export default function NavbarSearchIcon() {
  6. const [searchOpen, setSearchOpen] = useState(false);
  7. const pathname = usePathname();
  8. useEffect(() => {
  9. if (searchOpen) {
  10. queueMicrotask(() => {
  11. setSearchOpen(false);
  12. });
  13. }
  14. }, [pathname]);
  15. return (
  16. <>
  17. <div
  18. className="w-6 h-6 flex items-center justify-center"
  19. onClick={() => setSearchOpen(true)}
  20. >
  21. <svg
  22. xmlns="http://www.w3.org/2000/svg"
  23. width="17.7802734375"
  24. height="18.7802734375"
  25. viewBox="0 0 17.7802734375 18.7802734375"
  26. fill="none"
  27. >
  28. <circle
  29. cx="8.75"
  30. cy="8.75"
  31. r="8"
  32. stroke="rgba(0, 0, 0, 1)"
  33. strokeWidth="1.5"
  34. ></circle>
  35. <path
  36. stroke="rgba(0, 0, 0, 1)"
  37. strokeWidth="1.5"
  38. d="M14.25 15.25L17.25 18.25"
  39. ></path>
  40. </svg>
  41. </div>
  42. <SearchPop open={searchOpen} onClose={() => setSearchOpen(false)} />
  43. </>
  44. );
  45. }