From d9e65a36ecb05bf0cbbf3ac880cc07f795824375 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:41:42 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Added=20PropertyTypeSelect=20com?= =?UTF-8?q?ponent=20=F0=9F=94=84=20Updated=20default=20property=20types=20?= =?UTF-8?q?=E2=9C=85=20Implemented=20type=20filtering=20=F0=9F=93=9D=20Imp?= =?UTF-8?q?roved=20code=20documentation=20=F0=9F=A9=B9=20Fixed=20minor=20U?= =?UTF-8?q?I=20issues=20=F0=9F=93=A6=20Added=20PropertyTypeSelect=20to=20p?= =?UTF-8?q?roject=20=F0=9F=92=A1=20Enhanced=20user=20experience?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PropertyTypeSelect.tsx | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm)/(real-estate-search-form)/PropertyTypeSelect.tsx 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;