From dad52d3c937cb7cdb5680bd40cfe4493be13c14b Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 10 Sep 2023 17:49:11 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20ModalSelectDate=20component?= =?UTF-8?q?=20=F0=9F=9A=80=20Implemented=20date=20selection=20functionalit?= =?UTF-8?q?y=20=F0=9F=93=85=20Updated=20date=20picker=20styling=20?= =?UTF-8?q?=F0=9F=AA=84=20Added=20custom=20header=20to=20date=20picker=20?= =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Fixed=20Clear=20dates=20button=20functi?= =?UTF-8?q?onality=20=F0=9F=8C=9F=20Improved=20modal=20appearance=20?= =?UTF-8?q?=F0=9F=94=84=20Refactored=20code=20for=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ModalSelectDate.tsx | 142 +++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/components/ModalSelectDate.tsx diff --git a/src/components/ModalSelectDate.tsx b/src/components/ModalSelectDate.tsx new file mode 100644 index 0000000..96c8119 --- /dev/null +++ b/src/components/ModalSelectDate.tsx @@ -0,0 +1,142 @@ +"use client"; + +import DatePicker from "react-datepicker"; +import { Dialog, Transition } from "@headlessui/react"; +import { XMarkIcon } from "@heroicons/react/24/solid"; +import React, { FC, Fragment, useEffect, useState } from "react"; +import ButtonPrimary from "@/shared/ButtonPrimary"; +import DatePickerCustomHeaderTwoMonth from "./DatePickerCustomHeaderTwoMonth"; +import DatePickerCustomDay from "./DatePickerCustomDay"; + +interface ModalSelectDateProps { + renderChildren?: (p: { openModal: () => void }) => React.ReactNode; +} + +const ModalSelectDate: FC = ({ renderChildren }) => { + const [showModal, setShowModal] = useState(false); + + 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); + }; + + // FOR RESET ALL DATA WHEN CLICK CLEAR BUTTON + // + function closeModal() { + setShowModal(false); + } + + function openModal() { + setShowModal(true); + } + + const renderButtonOpenModal = () => { + return renderChildren ? ( + renderChildren({ openModal }) + ) : ( + + ); + }; + + return ( + <> + {renderButtonOpenModal()} + + +
+
+ + + <> +
+ +
+ +
+
+
+
+ + {` When's your trip?`} + +
+
+
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+
+
+
+ + { + closeModal(); + }} + > + Save + +
+ +
+
+
+
+
+
+ + ); +}; + +export default ModalSelectDate;