import { forwardRef, useId, type InputHTMLAttributes, type ReactNode } from "react"; function cx(...parts: Array): string { return parts.filter(Boolean).join(" "); } export interface InputProps extends InputHTMLAttributes { label: string; /** Guidance shown under the field when there is no error. */ helperText?: ReactNode; /** When set, the field renders its error state and announces this message. */ error?: string; /** Controls the "(required)"/"(optional)" hint next to the label. */ requiredHint?: boolean; } export const Input = forwardRef(function Input( { label, helperText, error, required, requiredHint = true, id, className, disabled, // text-base = 16px, so iOS Safari won't zoom the viewport on focus. type = "text", ...rest }, ref ) { const autoId = useId(); const inputId = id ?? autoId; const describeId = `${inputId}-desc`; const hasError = Boolean(error); const message = error ?? helperText; return (
{message && ( )}
); }); /* Usage: */