From 95a4ca4f025dd4a349f328b5a6840dc21715e542 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:38:48 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20Implemented=20date=20range=20pic?= =?UTF-8?q?ker=20component=20=F0=9F=92=A1=20Added=20custom=20header=20for?= =?UTF-8?q?=20date=20picker=20=F0=9F=8E=A8=20Styled=20the=20StayDatesRange?= =?UTF-8?q?Input=20component=20=F0=9F=90=9B=20Fixed=20a=20bug=20in=20the?= =?UTF-8?q?=20date=20selection=20logic=20=E2=9C=85=20Completed=20StayDates?= =?UTF-8?q?RangeInput=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StayDatesRangeInput.tsx | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm)/(stay-search-form)/StayDatesRangeInput.tsx diff --git a/src/app/(client-components)/(HeroSearchForm)/(stay-search-form)/StayDatesRangeInput.tsx b/src/app/(client-components)/(HeroSearchForm)/(stay-search-form)/StayDatesRangeInput.tsx new file mode 100644 index 0000000..6c26578 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(stay-search-form)/StayDatesRangeInput.tsx @@ -0,0 +1,115 @@ +"use client"; + +import React, { Fragment, useState, FC } from "react"; +import { Popover, Transition } from "@headlessui/react"; +import { CalendarIcon } from "@heroicons/react/24/outline"; +import DatePickerCustomHeaderTwoMonth from "@/components/DatePickerCustomHeaderTwoMonth"; +import DatePickerCustomDay from "@/components/DatePickerCustomDay"; +import DatePicker from "react-datepicker"; +import ClearDataButton from "../ClearDataButton"; + +export interface StayDatesRangeInputProps { + className?: string; + fieldClassName?: string; +} + +const StayDatesRangeInput: FC = ({ + className = "[ lg:nc-flex-2 ]", + fieldClassName = "[ nc-hero-field-padding ]", +}) => { + const [startDate, setStartDate] = useState( + new Date("2023/02/06") + ); + const [endDate, setEndDate] = useState(new Date("2023/02/23")); + // + + 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", + }) || "Add dates"} + {endDate + ? " - " + + endDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) + : ""} + + + {"Check in - Check out"} + +
+ + ); + }; + + return ( + + {({ open }) => ( + <> + + {renderInput()} + {startDate && open && ( + onChangeDate([null, null])} /> + )} + + + {open && ( +
+ )} + + + +
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+ + )} +
+ ); +}; + +export default StayDatesRangeInput;