import * as React from "react"; import classNames from "classnames"; import { AriaDateFieldProps, AriaTimeFieldProps, DateValue, TimeValue, useDateField, useDateSegment, useTimeField, } from "react-aria"; import { DateFieldState, DateSegment, useDateFieldState, useTimeFieldState } from "react-stately"; import { createCalendar } from "@internationalized/date"; import styles from "./DateTimeField.module.css"; interface DateFieldProps extends AriaDateFieldProps {} export function DateTimeField(props: DateFieldProps) { const ref = React.useRef(null); const state = useDateFieldState({ ...props, locale: "en-US", createCalendar }); const { fieldProps } = useDateField(props, state, ref); return (
{state.segments.map((segment, i) => ( ))}
); } export interface TimeFieldProps extends AriaTimeFieldProps {} export function TimeField(props: TimeFieldProps) { const ref = React.useRef(null); const state = useTimeFieldState({ ...props, locale: "en-US" }); const { labelProps, fieldProps } = useTimeField(props, state, ref); return (
{props.label}
{state.segments.map((segment, i) => ( ))} {state.validationState === "invalid" && }
); } interface DateTimeSegmentProps { segment: DateSegment; state: DateFieldState; } function DateTimeSegment(props: DateTimeSegmentProps) { const { segment, state } = props; const ref = React.useRef(null); const { segmentProps } = useDateSegment(segment, state, ref); return ( {segment.text} ); }