diff --git a/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx new file mode 100644 index 0000000..de3b2ba --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx @@ -0,0 +1,152 @@ +"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 FlightDateRangeInputProps { + className?: string; + fieldClassName?: string; + hasButtonSubmit?: boolean; + selectsRange?: boolean; +} + +const FlightDateRangeInput: FC = ({ + className = "", + fieldClassName = "[ nc-hero-field-padding ]", + hasButtonSubmit = true, + selectsRange = true, +}) => { + const [startDate, setStartDate] = useState( + new Date("2023/05/01") + ); + const [endDate, setEndDate] = useState(new Date("2023/05/16")); + + const onChangeRangeDate = (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"} + {selectsRange && endDate + ? " - " + + endDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) + : ""} + + + {selectsRange ? "Pick up - Drop off" : "Pick up date"} + +
+ + ); + }; + + return ( + <> + + {({ open }) => ( + <> +
+ + {renderInput()} + + {startDate && open && ( + onChangeRangeDate([null, null])} + /> + )} + + + {/* BUTTON SUBMIT OF FORM */} + {hasButtonSubmit && ( +
+ +
+ )} +
+ + {open && ( +
+ )} + + + +
+ {selectsRange ? ( + ( + + )} + renderDayContents={(day, date) => ( + + )} + /> + ) : ( + setStartDate(date)} + monthsShown={2} + showPopperArrow={false} + inline + renderCustomHeader={(p) => ( + + )} + renderDayContents={(day, date) => ( + + )} + /> + )} +
+
+
+ + )} +
+ + ); +}; + +export default FlightDateRangeInput;