import React, { useRef } from "react"; import { AriaDatePickerProps, useDateField, useDateSegment, } from "@react-aria/datepicker"; import { useLocale } from "@react-aria/i18n"; import { DateFieldState, useDateFieldState, DateSegment, } from "@react-stately/datepicker"; import { createCalendar, DateValue } from "@internationalized/date"; import classNames from "classnames"; import { Button } from ":/components/Button"; import { useCunningham } from ":/components/Provider"; interface DateSegmentProps { currentSegment: DateSegment; previousSegment: DateSegment; state: DateFieldState; } export const DateSegmentInput = ({ currentSegment, previousSegment, state, }: DateSegmentProps) => { const ref = useRef(null); const { segmentProps } = useDateSegment(currentSegment, state, ref); return (
{currentSegment.text}
); }; export const DateField = (props: AriaDatePickerProps) => { const { locale } = useLocale(); const state = useDateFieldState({ ...props, locale, createCalendar, }); const ref = useRef(null); const { fieldProps } = useDateField(props, state, ref); return (
{state.segments.map((segment, i, segments) => ( ))}
); };