import { Asterisk } from 'lucide-react'; import { useRef } from 'react'; import { type AriaTextFieldProps, useId, useTextField } from 'react-aria'; import cn from '~/utils/cn'; export interface InputProps extends AriaTextFieldProps { label: string; labelHidden?: boolean; isRequired?: boolean; className?: string; } // TODO: Custom isInvalid logic for custom error messages export default function Input(props: InputProps) { const { label, labelHidden, className } = props; const ref = useRef(null); const id = useId(props.id); const { labelProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors, } = useTextField( { ...props, label, 'aria-label': label, }, ref, ); return (
{props.description && (
{props.description}
)} {isInvalid && (
{validationErrors.join(' ')}
)}
); }