diff --git a/src/app/(client-components)/(HeroSearchForm)/(real-estate-search-form)/PropertyTypeSelect.tsx b/src/app/(client-components)/(HeroSearchForm)/(real-estate-search-form)/PropertyTypeSelect.tsx new file mode 100644 index 0000000..055d3cc --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(real-estate-search-form)/PropertyTypeSelect.tsx @@ -0,0 +1,126 @@ +"use client"; +import React, { Fragment, FC } from "react"; +import { Popover, Transition } from "@headlessui/react"; +import Checkbox from "@/shared/Checkbox"; +import { ClassOfProperties } from "../../type"; +import { HomeIcon } from "@heroicons/react/24/outline"; + +const defaultPropertyType: ClassOfProperties[] = [ + { + name: "Duplex House", + description: "Have a place to yourself", + checked: true, + }, + { + name: "Ferme House", + description: "Have your own room and share some common spaces", + checked: false, + }, + { + name: "Chalet House", + description: + "Have a private or shared room in a boutique hotel, hostel, and more", + checked: false, + }, + { + name: "Maison House", + description: "Stay in a shared space, like a common room", + checked: false, + }, +]; + +export interface PropertyTypeSelectProps { + onChange?: (data: any) => void; + fieldClassName?: string; +} + +const PropertyTypeSelect: FC = ({ + onChange, + fieldClassName = "[ nc-hero-field-padding ]", +}) => { + const [typeOfProperty, setTypeOfProperty] = + React.useState(defaultPropertyType); + + let typeOfPropertyText = ""; + if (typeOfProperty && typeOfProperty.length > 0) { + typeOfPropertyText = typeOfProperty + .filter((item) => item.checked) + .map((item) => { + return item.name; + }) + .join(", "); + } + return ( + + {({ open, close }) => ( + <> + document.querySelector("html")?.click()} + > +
+ +
+
+ + + {typeOfPropertyText || `Type`} + + + + Property type + +
+
+ + {open && ( +
+ )} + + + +
+
+ {typeOfProperty.map((item, index) => ( +
+ { + const newState = typeOfProperty.map((item, i) => { + if (i === index) { + return { ...item, checked: e }; + } + return item; + }); + setTypeOfProperty(() => { + return newState; + }); + onChange && onChange(newState); + }} + /> +
+ ))} +
+
+
+
+ + )} +
+ ); +}; + +export default PropertyTypeSelect;