"use client"; import { type DateValue, getLocalTimeZone, now } from "@internationalized/date"; import { useDateRangePicker } from "@react-aria/datepicker"; import { useDateRangePickerState } from "@react-stately/datepicker"; import type { Granularity } from "@react-types/datepicker"; import type { RangeValue } from "@react-types/shared"; import clsx from "clsx"; import { PropsWithChildren, useRef } from "react"; import { OverlayContainer, useOverlayPosition } from "react-aria"; import { useDateFormatter } from "react-aria"; import CalendarIcon from "../../icons/calendar"; import { Button } from "../Button"; import { Label } from "../Label"; import { Spacer } from "../Spacer"; import styles from "./calendar.module.css"; import { DateField } from "./date-field"; import { Popover } from "./popover"; import { RangeCalendar } from "./range-calendar"; export { type DateValue }; export { type RangeValue }; export interface DateRangePickerProps { minValue?: DateValue; maxValue?: DateValue; isDateUnavailable?: (date: DateValue) => boolean; placeholderValue?: DateValue; hourCycle?: 12 | 24; granularity?: Granularity; hideTimeZone?: boolean; isDisabled?: boolean; isReadOnly?: boolean; validationState?: "valid" | "invalid"; isRequired?: boolean; autoFocus?: boolean; isOpen?: boolean; defaultOpen?: boolean; allowsNonContiguousRanges?: boolean; value?: RangeValue | null; defaultValue?: RangeValue | null; // label?: string; } export function DateRangePicker({ granularity = "minute", // This causes DateField to render a TimeField hideTimeZone = false, ...props }: DateRangePickerProps) { let formatter = useDateFormatter({ month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", hour12: true, }); let state = useDateRangePickerState({ ...props, granularity, hideTimeZone: false, }); let ref = useRef(); let overlayRef = useRef(); let { groupProps, labelProps, startFieldProps, endFieldProps, buttonProps, dialogProps, calendarProps, } = useDateRangePicker({ ...props, granularity, hideTimeZone }, state, ref); // Get popover positioning props relative to the trigger let triggerRef = useRef(); let { overlayProps: positionProps } = useOverlayPosition({ targetRef: triggerRef, overlayRef, placement: "bottom start", offset: 8, isOpen: state.isOpen, }); return (
{props.label}
{state.isOpen && (
)}
); }