import { ChangeEvent, ComponentPropsWithoutRef, ReactElement } from 'react'; import { HelperProps } from '../../internal/components'; import { LayoutUtilProps, FieldLabelProps } from '../../types'; import { TextareaAutosizeProps } from 'react-textarea-autosize'; /** * State object passed to onChange callback */ export type TextareaState = { /** * Current value of the textarea */ value?: string | number | readonly string[]; }; /** * Props for the Textarea component * @extends Omit, "onChange" | "required"> * @extends LayoutUtilProps * @extends FieldLabelProps */ export type TextareaProps = Omit, "onChange" | "required"> & LayoutUtilProps & FieldLabelProps & { /** * Sets error style on textarea. * If string or ReactElement provided, places it under the label and sets error style. * Note: error string replaces helpText over, if both present. */ error?: HelperProps["errorMessage"] | boolean; /** * Hint text displayed below the textarea */ hint?: ReactElement | string; /** * Description text displayed below the textarea */ description?: ReactElement | string; /** * Label for textarea is required * @accessibility This should either be a string or have text content inside for accessibility */ label?: string | ReactElement; /** * Sets textarea's element no user-controllable method for resizing * @default false */ disableResize?: boolean; /** * Fires on each change of textarea's value * @param e The change event * @param state Object containing the current value */ onChange?: (e?: ChangeEvent, state?: TextareaState) => void; } & TextareaConditionalProps & TextareaAutosizeConditionalProps & ({ /** * ARIA live region setting for error announcements */ errorAriaLive?: HelperProps["errorAriaLive"]; } | { /** * ARIA live region setting for error announcements * @deprecated Boolean value is no longer supported. Use `"off" | "assertive" | "polite"` instead */ errorAriaLive?: boolean; }); /** * Conditional props for character counter functionality */ type TextareaConditionalProps = { /** * Show character counter */ showCounter: true; /** * Maximum number of characters allowed */ maxLength: HelperProps["maxLength"]; } | { /** * Show character counter * @default false */ showCounter?: false; /** * Maximum number of characters allowed */ maxLength?: HelperProps["maxLength"]; }; /** * Conditional props for auto-height functionality */ type TextareaAutosizeConditionalProps = { /** * Auto height mode on typing */ autoHeight: true; /** * Maximum number of rows when auto-height is enabled */ maxRows?: TextareaAutosizeProps["maxRows"]; /** * Minimum number of rows when auto-height is enabled */ minRows?: TextareaAutosizeProps["minRows"]; } | { /** * Auto height mode on typing * @default false */ autoHeight?: false; maxRows?: never; minRows?: never; }; /** * Textarea component for multi-line text input with advanced features. * * Features: * - Character counter with maxLength validation * - Auto-height adjustment based on content * - Error state handling with custom error messages * - Hint and description text support * - Disable resize functionality * - Accessible with proper ARIA attributes * - Label association and required field support * - Focus and blur event handling * - Supports layout utilities for positioning and spacing * - SSR-safe auto-height implementation * * @example *