import { InputHTMLAttributes, forwardRef, useId } from 'react'; import { getFormInputClasses, defaultLayoutConfig, type LayoutConfig } from '~/lib/layout-utils'; interface InputProps extends Omit, 'className'> { className?: string; config?: Partial; label?: string; error?: string; helperText?: string; fullWidth?: boolean; startIcon?: React.ReactNode; endIcon?: React.ReactNode; } export const Input = forwardRef(({ className = '', config = {}, label, error, helperText, fullWidth = true, startIcon, endIcon, id, ...props }, ref) => { const layoutConfig = { ...defaultLayoutConfig, ...config }; const inputClasses = getFormInputClasses(!!error); const fullWidthClass = fullWidth ? 'w-full' : ''; const hasIconsClass = (startIcon || endIcon) ? 'relative' : ''; const generatedId = useId(); const inputId = id || generatedId; return ( {label && ( {label} )} {startIcon && ( {startIcon} )} {endIcon && ( {endIcon} )} {error && ( {error} )} {helperText && !error && ( {helperText} )} ); });
{error}
{helperText}