import { useState, forwardRef } from "react"; import type { InputHTMLAttributes, ReactElement } from "react"; export interface InputProps extends Omit, "size"> { label?: string; error?: string; helperText?: string; fullWidth?: boolean; } export const Input = forwardRef(function Input( { label, error, helperText, fullWidth = false, className = "", id, style, onFocus, onBlur, ...props }, ref ): ReactElement { const [isFocused, setIsFocused] = useState(false); const inputId = id ?? `input-${Math.random().toString(36).substring(2, 11)}`; const errorId = error ? `${inputId}-error` : undefined; const helperId = helperText ? `${inputId}-helper` : undefined; const inputStyle: React.CSSProperties = { background: "var(--bg-mid)", border: error ? `1px solid var(--danger)` : isFocused ? `1px solid var(--primary)` : `1px solid var(--border)`, color: "var(--text)", outline: "none", boxShadow: isFocused ? `0 0 0 2px rgba(47,128,255,0.2)` : "none", ...style, }; const widthClass = fullWidth ? "w-full" : ""; return (
{label && ( )} { setIsFocused(true); onFocus?.(e); }} onBlur={(e) => { setIsFocused(false); onBlur?.(e); }} {...props} /> {error && ( )} {helperText && !error && (

{helperText}

)}
); });