import React, { forwardRef, type ElementRef } from 'react'; import { useDateRangePicker, type RangeCalendarProps, type UseDateRangePickerProps } from 'react-calendar-kit'; import { useMergedRef } from '../../hooks'; import { cn } from '../../utils/cn'; import { PopperFreeSolo, type PopperProps } from '../popper'; import CalendarButton, { type CalendarButtonProps } from './calendar-button'; import { DateRangeInput, TimeInput, type DateRangeInputProps } from './calendar-input'; import { RangeCalendar } from './calendar-primitives'; export interface DateRangePickerProps extends UseDateRangePickerProps, Pick { triggerProps?: CalendarButtonProps; inputProps?: Partial; popperProps?: PopperProps; withTimeInput?: boolean; /** When this true, visible month will be forced to be 1 */ withPicker?: boolean; /** Styles for time input container*/ timeInputContainerClassName?: string; /** Styles for time input */ timeInputWrapperClassName?: string; /** Styles for label of time input */ timeInputLabelClassName?: string; /** Label for start time input, hidden when visible month = 1 or with Picker true */ startTimeInputLabel?: string; /** Label for end time input, hidden when visible month = 1 or with Picker true */ endTimeInputLabel?: string; } const DateRangePicker = forwardRef, DateRangePickerProps>( ( { triggerProps, inputProps, popperProps, timeInputLabelClassName, timeInputWrapperClassName, timeInputContainerClassName, withTimeInput, withPicker, startTimeInputLabel = 'Start', endTimeInputLabel = 'End', weekdayStyle = 'short', visibleMonths = 1, ...props }, forwardedRef ) => { const { ref, state, getCalendarProps, getDateRangeProps, getDialogProps, getTriggerProps, getTimeInputRangeProps } = useDateRangePicker(props); const inputRef = useMergedRef(forwardedRef, ref); const visibleM = withPicker ? 1 : visibleMonths; return ( } /> } {...popperProps} >
1 ? 'gap-6' : 'gap-2', timeInputContainerClassName )} >
{visibleM > 1 ? (
{startTimeInputLabel}
) : null}
{visibleM > 1 ? (
{endTimeInputLabel}
) : null}
) : null } />
); } ); export default DateRangePicker;