/* Copyright 2026 Marimo. All rights reserved. */ import type { VariantProps } from "class-variance-authority"; import { DateField as AriaDateField, type DateFieldProps as AriaDateFieldProps, DateInput as AriaDateInput, type DateInputProps as AriaDateInputProps, DateSegment as AriaDateSegment, type DateSegmentProps as AriaDateSegmentProps, type DateValue as AriaDateValue, TimeField as AriaTimeField, type TimeFieldProps as AriaTimeFieldProps, type TimeValue as AriaTimeValue, type ValidationResult as AriaValidationResult, composeRenderProps, Text, } from "react-aria-components"; import { cn } from "@/utils/cn"; import { FieldError, fieldGroupVariants, Label } from "./field"; const DateSegment = ({ className, ...props }: AriaDateSegmentProps) => { return ( cn( "type-literal:px-0 inline rounded p-0.5 caret-transparent outline-solid outline-0", /* Placeholder */ "data-placeholder:text-muted-foreground", /* Disabled */ "data-disabled:cursor-not-allowed data-disabled:opacity-50", /* Focused */ "data-focused:bg-accent data-focused:text-accent-foreground focus:bg-accent focus:text-accent-foreground", /* Invalid */ "data-invalid:data-focused:bg-destructive data-invalid:data-focused:data-placeholder:text-destructive-foreground data-invalid:data-focused:text-destructive-foreground data-invalid:data-placeholder:text-destructive data-invalid:text-destructive", className, ), )} {...props} /> ); }; interface DateInputProps extends AriaDateInputProps, VariantProps {} const DateInput = ({ className, variant, ...props }: Omit) => { return ( cn(fieldGroupVariants({ variant }), "text-sm", className), )} {...props} > {(segment) => } ); }; interface DateFieldProps< T extends AriaDateValue, > extends AriaDateFieldProps { label?: string; description?: string; errorMessage?: string | ((validation: AriaValidationResult) => string); } const DateField = ({ label, description, className, errorMessage, ...props }: DateFieldProps) => { return ( cn("group flex flex-col gap-2", className), )} {...props} > {description && ( {description} )} {errorMessage} ); }; interface TimeFieldProps< T extends AriaTimeValue, > extends AriaTimeFieldProps { label?: string; description?: string; errorMessage?: string | ((validation: AriaValidationResult) => string); } const TimeField = ({ label, description, errorMessage, className, ...props }: TimeFieldProps) => { return ( cn("group flex flex-col gap-2", className), )} {...props} > {description && {description}} {errorMessage} ); }; export { DateSegment, DateInput, DateField, TimeField }; export type { DateInputProps, DateFieldProps, TimeFieldProps };