From 56e9cce0ae3eb7e3b26f2b93ebe117e1da509324 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:45:25 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Work=20in=20progress=20on=20Expe?= =?UTF-8?q?riencesDateSingleInput=20component=20=F0=9F=92=A1=20Adding=20da?= =?UTF-8?q?te=20input=20functionality=20=F0=9F=8E=A8=20Refactoring=20code?= =?UTF-8?q?=20for=20clarity=20and=20consistency=20=E2=9C=85=20Tested=20dat?= =?UTF-8?q?e=20picker=20component=20with=20various=20scenarios=20?= =?UTF-8?q?=F0=9F=94=A7=20Fixed=20minor=20bugs=20in=20date=20input=20compo?= =?UTF-8?q?nent=20=F0=9F=9A=80=20Ready=20to=20release=20the=20ExperiencesD?= =?UTF-8?q?ateSingleInput=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExperiencesDateSingleInput.tsx | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm)/(experiences-search-form)/ExperiencesDateSingleInput.tsx diff --git a/src/app/(client-components)/(HeroSearchForm)/(experiences-search-form)/ExperiencesDateSingleInput.tsx b/src/app/(client-components)/(HeroSearchForm)/(experiences-search-form)/ExperiencesDateSingleInput.tsx new file mode 100644 index 0000000..705f222 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(experiences-search-form)/ExperiencesDateSingleInput.tsx @@ -0,0 +1,119 @@ +"use client"; + +import React, { Fragment, useState } from "react"; +import { FC } from "react"; +import DatePicker from "react-datepicker"; +import { Popover, Transition } from "@headlessui/react"; +import { CalendarIcon } from "@heroicons/react/24/outline"; +import DatePickerCustomHeaderTwoMonth from "@/components/DatePickerCustomHeaderTwoMonth"; +import DatePickerCustomDay from "@/components/DatePickerCustomDay"; +import ClearDataButton from "../ClearDataButton"; + +export interface ExperiencesDateSingleInputProps { + className?: string; + fieldClassName?: string; +} + +const ExperiencesDateSingleInput: FC = ({ + className = "", + fieldClassName = "[ nc-hero-field-padding ]", +}) => { + const [startDate, setStartDate] = useState( + new Date("2023/03/01") + ); + const [endDate, setEndDate] = useState(new Date("2023/03/16")); + + const onChangeDate = (dates: [Date | null, Date | null]) => { + const [start, end] = dates; + setStartDate(start); + setEndDate(end); + }; + + const renderInput = () => { + return ( + <> +
+ +
+
+ + {startDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) || "Date"} + {endDate + ? " - " + + endDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) + : ""} + + + {startDate ? "Date" : `Add dates`} + +
+ + ); + }; + + return ( + <> + + {({ open }) => ( + <> + + {renderInput()} + {startDate && open && ( + onChangeDate([null, null])} /> + )} + + + {open && ( +
+ )} + + + +
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+ + )} +
+ + ); +}; + +export default ExperiencesDateSingleInput;