import { Fragment, useState, FC } from "react"; import { usePopper } from "react-popper"; import { Popover, Transition } from "@headlessui/react"; import { CalendarDays, X } from "lucide-react"; // react-datepicker import DatePicker from "react-datepicker"; // import "react-datepicker/dist/react-datepicker.css"; import { renderDateFormat, renderShortDateWithYearFormat } from "helpers/date-time.helper"; type Props = { label: string; maxDate?: Date; minDate?: Date; onChange: (val: string | null) => void; value: string | null; }; export const IssueDateSelect: FC = ({ label, maxDate, minDate, onChange, value }) => { const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-start", }); return ( {({ close }) => ( <>
{value ? ( <> {renderShortDateWithYearFormat(value)} ) : ( <> {label} )}
{ if (!val) onChange(""); else onChange(renderDateFormat(val)); close(); }} dateFormat="dd-MM-yyyy" minDate={minDate} maxDate={maxDate} inline />
)}
); };