{ "name": "textarea", "displayName": "Textarea", "type": "component", "files": [ { "name": "Textarea.tsx", "content": "import {\n forwardRef,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type TextareaHTMLAttributes,\n} from 'react';\nimport { cn } from '../../utils/cn';\nimport styles from './Textarea.module.css';\n\nexport interface TextareaProps extends Omit<\n TextareaHTMLAttributes,\n 'rows'\n> {\n label: string;\n rows?: number;\n helperText?: string;\n error?: string;\n showCount?: boolean;\n autoResize?: boolean;\n wrapperClassName?: string;\n}\n\nexport const Textarea = forwardRef(\n function Textarea(\n {\n label,\n rows = 3,\n helperText,\n error,\n maxLength,\n showCount = false,\n autoResize = false,\n value,\n defaultValue,\n id,\n className,\n wrapperClassName,\n disabled,\n required,\n onChange,\n 'data-testid': dataTestId = 'tatva-textarea',\n ...rest\n }: TextareaProps & { 'data-testid'?: string },\n ref,\n ) {\n const generatedId = useId();\n const textareaId = id ?? generatedId;\n const helperId = `${textareaId}-helper`;\n const errorId = `${textareaId}-error`;\n const [inner, setInner] = useState(\n String(value ?? defaultValue ?? ''),\n );\n const internalRef = useRef(null);\n const currentLen =\n value !== undefined ? String(value).length : inner.length;\n\n useEffect(() => {\n if (value !== undefined) setInner(String(value));\n }, [value]);\n\n useLayoutEffect(() => {\n if (!autoResize) return;\n const el = internalRef.current;\n if (!el) return;\n el.style.height = 'auto';\n el.style.height = `${el.scrollHeight}px`;\n }, [autoResize, inner, value]);\n\n const describedBy =\n [error ? errorId : undefined, helperText && !error ? helperId : undefined]\n .filter(Boolean)\n .join(' ') || undefined;\n\n return (\n
\n \n {\n internalRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref)\n (\n ref as React.MutableRefObject\n ).current = node;\n }}\n id={textareaId}\n rows={rows}\n maxLength={maxLength}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n required={required}\n className={cn(styles.textarea, error && styles.hasError, className)}\n aria-invalid={error ? true : undefined}\n aria-describedby={describedBy}\n onChange={(e) => {\n setInner(e.target.value);\n onChange?.(e);\n }}\n data-testid={dataTestId}\n {...rest}\n />\n
\n
\n {helperText && !error && (\n \n {helperText}\n \n )}\n {error && (\n \n {error}\n \n )}\n
\n {showCount && maxLength && (\n \n {currentLen}/{maxLength}\n \n )}\n
\n
\n );\n },\n);\n" }, { "name": "Textarea.module.css", "content": ".wrapper {\n display: flex;\n flex-direction: column;\n gap: var(--tatva-space-1);\n font-family: var(--tatva-font-family);\n}\n\n.label {\n font-size: var(--tatva-font-size-sm);\n font-weight: var(--tatva-font-weight-medium);\n color: var(--tatva-color-fg);\n}\n\n.required {\n color: var(--tatva-color-error);\n}\n\n.textarea {\n width: 100%;\n background-color: var(--tatva-color-bg);\n color: var(--tatva-color-fg);\n border: 1px solid var(--tatva-color-border);\n border-radius: var(--tatva-radius-md);\n padding: var(--tatva-space-2) var(--tatva-space-3);\n font-family: inherit;\n font-size: var(--tatva-font-size-md);\n line-height: var(--tatva-line-height-normal);\n resize: vertical;\n transition:\n border-color var(--tatva-transition-fast),\n box-shadow var(--tatva-transition-fast);\n}\n\n.textarea:focus {\n outline: none;\n border-color: var(--tatva-color-primary-500);\n box-shadow: 0 0 0 3px var(--tatva-color-primary-200);\n}\n\n.textarea:disabled {\n background-color: var(--tatva-color-bg-subtle);\n opacity: 0.7;\n cursor: not-allowed;\n}\n\n.hasError {\n border-color: var(--tatva-color-error);\n}\n\n.footer {\n display: flex;\n justify-content: space-between;\n gap: var(--tatva-space-3);\n min-height: 1em;\n}\n\n.helper {\n font-size: var(--tatva-font-size-xs);\n color: var(--tatva-color-fg-muted);\n}\n\n.error {\n font-size: var(--tatva-font-size-xs);\n color: var(--tatva-color-error);\n}\n\n.count {\n font-size: var(--tatva-font-size-xs);\n color: var(--tatva-color-fg-muted);\n}\n" }, { "name": "index.ts", "content": "export { Textarea } from './Textarea';\nexport type { TextareaProps } from './Textarea';\n" } ], "registryDependencies": [], "dependencies": [], "devDependencies": [] }