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; isInvalid?: boolean; errorMessage?: string; } export default function Input(props: InputProps) { const { label, labelHidden, className, isInvalid: customIsInvalid, errorMessage } = props; const ref = useRef(null); const id = useId(props.id); const { labelProps, inputProps, descriptionProps, errorMessageProps, isInvalid: ariaIsInvalid, validationErrors, } = useTextField( { ...props, label, "aria-label": label, }, ref, ); const isInvalid = customIsInvalid ?? ariaIsInvalid; return (
{props.description && (
{props.description}
)} {isInvalid ? (
{errorMessage ?? validationErrors.join(" ")}
) : null}
); }