"use client"; import { useEffect, useState } from "react"; import { format } from "date-fns"; import { CalendarIcon } from "lucide-react"; import type { DateRange, DayPicker } from "react-day-picker"; import { cn } from "../../lib/utils"; import { Button } from "../button"; import { Calendar } from "../calendar"; import { Popover, PopoverContent, PopoverTrigger } from "../popover"; type DateRangePickerProps = React.HTMLAttributes & React.ComponentProps & { value?: DateRange; defaultValue?: DateRange; disabled?: boolean; onValueChange?: (date: DateRange | undefined) => void; }; export function DateRangePicker({ value, defaultValue, disabled, className, children, onValueChange, ...props }: DateRangePickerProps) { const [dateState, setDateState] = useState( defaultValue, ); const isControlled = value !== undefined; const dateValue = isControlled ? value : dateState; useEffect(() => { if (isControlled) { setDateState(value); } }, [isControlled, value]); const handleSelect = (date: DateRange | undefined) => { if (!isControlled) { setDateState(date); } onValueChange?.(date); }; return (
{children}
); }