diff --git a/src/app/(client-components)/(HeroSearchForm2Mobile)/LocationInput.tsx b/src/app/(client-components)/(HeroSearchForm2Mobile)/LocationInput.tsx new file mode 100644 index 0000000..008f340 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm2Mobile)/LocationInput.tsx @@ -0,0 +1,112 @@ +"use client"; + +import { MapPinIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; +import React, { useState, useEffect, useRef, FC } from "react"; + +interface Props { + onClick?: () => void; + onChange?: (value: string) => void; + className?: string; + defaultValue?: string; + headingText?: string; +} + +const LocationInput: FC = ({ + onChange = () => {}, + className = "", + defaultValue = "United States", + headingText = "Where to?", +}) => { + const [value, setValue] = useState(""); + const containerRef = useRef(null); + const inputRef = useRef(null); + + useEffect(() => { + setValue(defaultValue); + }, [defaultValue]); + + const handleSelectLocation = (item: string) => { + // DO NOT REMOVE SETTIMEOUT FUNC + setTimeout(() => { + setValue(item); + onChange && onChange(item); + }, 0); + }; + + const renderSearchValues = ({ + heading, + items, + }: { + heading: string; + items: string[]; + }) => { + return ( + <> +

+ {heading || "Destinations"} +

+
+ {items.map((item) => { + return ( +
handleSelectLocation(item)} + key={item} + > + + {item} +
+ ); + })} +
+ + ); + }; + + return ( +
+
+ + {headingText} + +
+ setValue(e.currentTarget.value)} + ref={inputRef} + /> + + + +
+
+ {value + ? renderSearchValues({ + heading: "Locations", + items: [ + "Afghanistan", + "Albania", + "Algeria", + "American Samao", + "Andorra", + ], + }) + : renderSearchValues({ + heading: "Popular destinations", + items: [ + "Australia", + "Canada", + "Germany", + "United Kingdom", + "United Arab Emirates", + ], + })} +
+
+
+ ); +}; + +export default LocationInput;