import { DateRangePicker as AriaDateRangePicker, Button, Dialog, Group, OverlayArrow, Popover, } from 'react-aria-components'; import dayjs from 'dayjs'; import { tv } from 'tailwind-variants'; import { CalendarIcon } from '@/components/icons'; import { RangeCalendar } from '../calendar/RangeCalendar'; import { calendarDateToDate, dateToCalendarDate } from '../calendar/utils'; const trigger = tv({ base: 'flex h-9 w-[260px] cursor-pointer items-center border border-dabeeo-gray-be bg-white text-left outline-none transition', variants: { isHovered: { true: 'border-dabeeo-black-34', }, isFocused: { true: 'border-dabeeo-black-34', }, isDisabled: { true: 'cursor-default border-dabeeo-gray-99 bg-dabeeo-gray-eb', }, isFocusVisible: { true: 'ring-2 ring-offset-2 ring-primary', }, }, }); export type DateRangePickerProps = { value: { start: Date; end: Date } | null; onChange: (value: { start: Date; end: Date } | null) => void; maxValue?: Date | null; minValue?: Date | null; isDisabled?: boolean; className?: string; startName?: string; endName?: string; }; export function DateRangePicker({ value, onChange, maxValue, minValue, isDisabled, className, startName, endName, }: DateRangePickerProps) { const ariaValue = value ? { start: dateToCalendarDate(value.start)!, end: dateToCalendarDate(value.end)! } : null; return ( { if (!range) { onChange(null); } else { onChange({ start: calendarDateToDate(range.start)!, end: calendarDateToDate(range.end)!, }); } }} maxValue={maxValue !== undefined ? dateToCalendarDate(maxValue) : undefined} minValue={minValue !== undefined ? dateToCalendarDate(minValue) : undefined} isDisabled={isDisabled} granularity="day" firstDayOfWeek="sun" className={className} startName={startName} endName={endName} > ); }