// @flow strict import * as React from 'react'; import {classify} from '../../utils/classify'; import {BodySmall, FormLabelSmall} from '../Text'; import css from './Textarea.module.css'; type ClassNames = $ReadOnly<{box?: string, textarea?: string}>; export type TextareaProps = { value?: string, onChange?: ( evt: SyntheticInputEvent, isEnter?: boolean, ) => mixed, onFocus?: (e: SyntheticInputEvent) => mixed, onBlur?: (e: SyntheticInputEvent) => mixed, onKeyDown?: (e: SyntheticKeyboardEvent) => mixed, name?: string, disabled?: boolean, placeholder?: string, locked?: boolean, error?: boolean, errorText?: string, label?: string | React.Node, helperText?: string | React.Node, classNames?: ClassNames, size?: 'medium' | 'small', required?: boolean, textCountLimit?: number, ... }; const Textarea_ = (props: TextareaProps, ref): React.Node => { const { value, onChange, onFocus, onBlur, name, disabled, placeholder, error, locked, errorText, label, helperText, classNames, size = 'medium', required, textCountLimit, ...textareaProps } = props; const [textCountError, setTextCountError] = React.useState(false); React.useEffect(() => { if (textCountLimit) { if (value && value.length > textCountLimit) { setTextCountError(true); } else { setTextCountError(false); } } }, [value]); const controlledTextareaFilled = value !== ''; return (
{Boolean(label) && (
{label ?? ''}   {required && {'*'}}
{!!textCountLimit && ((value && value.length) || 0) + '/' + textCountLimit}
)}
{(Boolean(helperText) || error) && (
{error && errorText ? errorText : helperText ?? ''}
)}
); }; export const Textarea = (React.forwardRef( Textarea_, ): React$AbstractComponent);