"use client"; import * as Popover from "@radix-ui/react-popover"; import { format } from "date-fns"; import * as React from "react"; import { classNames as cn } from "@calcom/lib"; import { Button } from "../../button"; import { Calendar } from "./Calendar"; type DatePickerWithRangeProps = { dates: { startDate?: Date; endDate?: Date }; onDatesChange: ({ startDate, endDate }: { startDate?: Date; endDate?: Date }) => void; disabled?: boolean; minDate?: Date | null; maxDate?: Date; withoutPopover?: boolean; "data-testid"?: string; }; export function DatePickerWithRange({ className, dates, minDate, maxDate, onDatesChange, disabled, withoutPopover, "data-testid": testId, }: React.HTMLAttributes & DatePickerWithRangeProps) { function handleDayClick(date: Date) { if (dates?.endDate) { onDatesChange({ startDate: date, endDate: undefined }); } else { const startDate = dates.startDate ? (date < dates.startDate ? date : dates.startDate) : date; const endDate = dates.startDate ? (date < dates.startDate ? dates.startDate : date) : undefined; onDatesChange({ startDate, endDate }); } } const fromDate = minDate ?? new Date(); const calendar = ( handleDayClick(day)} numberOfMonths={1} disabled={disabled} data-testid={testId} /> ); if (withoutPopover) { return calendar; } return (
{calendar}
); }