import { useState } from "react"; import type { TextareaHTMLAttributes, ReactElement } 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, style, onFocus, onBlur, ...props }: TextareaProps): ReactElement { const [isFocused, setIsFocused] = useState(false); const textareaId = id ?? `textarea-${Math.random().toString(36).substring(2, 11)}`; const errorId = error ? `${textareaId}-error` : undefined; const helperId = helperText ? `${textareaId}-helper` : undefined; const resizeStyles: Record = { none: "resize-none", both: "resize", horizontal: "resize-x", vertical: "resize-y", }; const textareaStyle: 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 && ( )}