import type { TextareaHTMLAttributes } from "react"; export interface TextareaProps extends Omit, "size"> { label?: string; error?: string; helperText?: string; fullWidth?: boolean; resize?: "none" | "both" | "horizontal" | "vertical"; } export function Textarea({ label, error, helperText, fullWidth = false, resize = "vertical", className = "", id, ...props }: TextareaProps) { const textareaId = id || `textarea-${Math.random().toString(36).substr(2, 9)}`; const errorId = error ? `${textareaId}-error` : undefined; const helperId = helperText ? `${textareaId}-helper` : undefined; const baseStyles = "px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors"; const widthStyles = fullWidth ? "w-full" : ""; const resizeStyles = { none: "resize-none", both: "resize", horizontal: "resize-x", vertical: "resize-y", }; const errorStyles = error ? "border-red-500 focus:ring-red-500" : "border-gray-300"; const combinedClassName = [ baseStyles, widthStyles, resizeStyles[resize], errorStyles, className, ].filter(Boolean).join(" "); return ( {label && ( {label} )} {error && ( {error} )} {helperText && !error && ( {helperText} )} ); }
{error}
{helperText}