From 013653084d66fca49a437882a7d4ef5d7ca3023d Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 21:06:38 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Started=20working=20on=20Header3?= =?UTF-8?q?=20component=20=F0=9F=9B=A0=20Implemented=20basic=20structure?= =?UTF-8?q?=20=F0=9F=94=8D=20Added=20logic=20for=20handling=20scroll=20eve?= =?UTF-8?q?nts=20=F0=9F=91=81=20Implemented=20HeroSearchForm=20and=20relat?= =?UTF-8?q?ed=20components=20=F0=9F=8E=A8=20Styled=20the=20Header3=20compo?= =?UTF-8?q?nent=20=F0=9F=92=A1=20Completed=20Header3=20component=20with=20?= =?UTF-8?q?search=20functionality=20=F0=9F=8C=9F=20Added=20animation=20and?= =?UTF-8?q?=20responsiveness=20to=20Header3=20=F0=9F=94=92=20Finalized=20H?= =?UTF-8?q?eader3=20component=20for=20production?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(client-components)/(Header)/Header3.tsx | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 src/app/(client-components)/(Header)/Header3.tsx diff --git a/src/app/(client-components)/(Header)/Header3.tsx b/src/app/(client-components)/(Header)/Header3.tsx new file mode 100644 index 0000000..0f950d6 --- /dev/null +++ b/src/app/(client-components)/(Header)/Header3.tsx @@ -0,0 +1,203 @@ +"use client"; + +import React, { FC, useEffect, useRef, useState } from "react"; +import Logo from "@/shared/Logo"; +import useOutsideAlerter from "@/hooks/useOutsideAlerter"; +import NotifyDropdown from "./NotifyDropdown"; +import AvatarDropdown from "./AvatarDropdown"; +import MenuBar from "@/shared/MenuBar"; +import { SearchTab } from "../(HeroSearchForm)/HeroSearchForm"; +import HeroSearchForm2MobileFactory from "../(HeroSearchForm2Mobile)/HeroSearchForm2MobileFactory"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import HeroSearchFormSmall from "../(HeroSearchFormSmall)/HeroSearchFormSmall"; +import { StaySearchFormFields } from "../type"; +import { MagnifyingGlassIcon } from "@heroicons/react/24/outline"; + +interface Header3Props { + className?: string; +} + +let WIN_PREV_POSITION = 0; +if (typeof window !== "undefined") { + WIN_PREV_POSITION = (window as any).pageYOffset; +} + +const Header3: FC = ({ className = "" }) => { + const headerInnerRef = useRef(null); + // + const [showHeroSearch, setShowHeroSearch] = + useState(); + // + const [currentTab, setCurrentTab] = useState("Stays"); + + // + useOutsideAlerter(headerInnerRef, () => { + setShowHeroSearch(null); + setCurrentTab("Stays"); + }); + + let pathname = usePathname(); + // + + useEffect(() => { + setShowHeroSearch(null); + }, [pathname]); + + // HIDDEN WHEN SCROLL EVENT + useEffect(() => { + window.addEventListener("scroll", handleEvent); + return () => { + window.removeEventListener("scroll", handleEvent); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + const handleEvent = () => { + window.requestAnimationFrame(handleHideSearchForm); + }; + + const handleHideSearchForm = () => { + if (!document.querySelector("#nc-Header-3-anchor")) { + return; + } + // + let currentScrollPos = window.pageYOffset; + if ( + WIN_PREV_POSITION - currentScrollPos > 100 || + WIN_PREV_POSITION - currentScrollPos < -100 + ) { + setShowHeroSearch(null); + } else { + return; + } + WIN_PREV_POSITION = currentScrollPos; + }; + + // + const renderHeroSearch = () => { + return ( +
+
+ +
+
+ ); + }; + + const renderButtonOpenHeroSearch = () => { + return ( +
+
+ setShowHeroSearch("location")} + className="block pl-5 pr-4 cursor-pointer py-3" + > + Location + + + setShowHeroSearch("dates")} + className="block px-4 cursor-pointer py-3 " + > + Check In + + + { + setShowHeroSearch("guests"); + }} + className="block px-4 cursor-pointer font-normal py-3" + > + Add guests + +
+ +
setShowHeroSearch("location")} + > + + + +
+
+ ); + }; + + return ( + <> +
+ {showHeroSearch &&
} +
+
+
+
+ {/* Logo (lg+) */} +
+ +
+ +
+
+ {renderButtonOpenHeroSearch()} +
+
+ +
+ {renderHeroSearch()} +
+ + {/* NAV */} +
+
+ + List your property + + + + + +
+
+
+
+
+ + ); +}; + +export default Header3;