From 559b5d40570bc51e29e08ca8297d4d26c895df9a Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:46:54 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20Implemented=20date=20picker=20co?= =?UTF-8?q?mponent=20=F0=9F=9A=97=20Added=20date=20range=20selection=20fun?= =?UTF-8?q?ctionality=20=F0=9F=93=85=20Updated=20date=20formatting=20?= =?UTF-8?q?=F0=9F=94=A7=20Fixed=20minor=20UI=20issues=20=F0=9F=93=9D=20Imp?= =?UTF-8?q?roved=20code=20readability=20and=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RentalCarDatesRangeInput.tsx | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm)/(car-search-form)/RentalCarDatesRangeInput.tsx diff --git a/src/app/(client-components)/(HeroSearchForm)/(car-search-form)/RentalCarDatesRangeInput.tsx b/src/app/(client-components)/(HeroSearchForm)/(car-search-form)/RentalCarDatesRangeInput.tsx new file mode 100644 index 0000000..1c8b013 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(car-search-form)/RentalCarDatesRangeInput.tsx @@ -0,0 +1,134 @@ +"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"; +import ButtonSubmit from "../ButtonSubmit"; + +export interface RentalCarDatesRangeInputProps { + className?: string; + fieldClassName?: string; + hasButtonSubmit?: boolean; +} + +const RentalCarDatesRangeInput: FC = ({ + className = "", + fieldClassName = "[ nc-hero-field-padding ]", + hasButtonSubmit = true, +}) => { + 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", + }) || "Add dates"} + {endDate + ? " - " + + endDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) + : ""} + + + {"Pick up - Drop off"} + +
+ + ); + }; + + return ( + <> + + {({ open }) => ( + <> +
+ + {renderInput()} + + {startDate && open && ( + onChangeDate([null, null])} /> + )} + + + {/* BUTTON SUBMIT OF FORM */} + {hasButtonSubmit && ( +
+ +
+ )} +
+ + {open && ( +
+ )} + + + +
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+ + )} +
+ + ); +}; + +export default RentalCarDatesRangeInput;