import { useEffect, useState } from 'react'; import { TextField } from '@mui/material'; import handleEvent from '@pega/react-sdk-components/lib/components/helpers/event-utils'; import { getComponentFromMap } from '@pega/react-sdk-components/lib/bridge/helpers/sdk_component_map'; import type { PConnFieldProps } from '@pega/react-sdk-components/lib/types/PConnProps'; import useStatus from '@pega/react-sdk-components/lib/hooks/useStatus'; import { getFieldSx } from '@pega/react-sdk-components/lib/components/helpers/field-utils'; interface TextAreaProps extends PConnFieldProps { // If any, enter additional props that only exist on TextArea here fieldMetadata?: any; showFieldMessage?: boolean; messageConfig?: { content?: string; visibility?: boolean; }; variant?: string; } export default function TextArea(props: TextAreaProps) { // Get emitted components from map (so we can get any override that may exist) const FieldValueList = getComponentFromMap('FieldValueList'); const { getPConnect, label, required, disabled, value = '', validatemessage, readOnly, testId, fieldMetadata, helperText, displayMode, hideLabel, placeholder, showFieldMessage, messageConfig = {} } = props; const eligibleForFieldWarning = showFieldMessage && messageConfig.visibility && !readOnly; const helperTextToDisplay = validatemessage || (eligibleForFieldWarning ? messageConfig.content : helperText); const pConn = getPConnect(); const actions = pConn.getActionsApi(); const propName = (pConn.getStateProps() as any).value; const maxLength = fieldMetadata?.maxLength; const status = useStatus({ showFieldMessage, messageVisibility: messageConfig.visibility, validatemessage, readOnly }); const [inputValue, setInputValue] = useState(''); let readOnlyProp = {}; useEffect(() => { setInputValue(value); }, [value]); if (displayMode === 'DISPLAY_ONLY') { return ; } if (displayMode === 'STACKED_LARGE_VAL') { return ; } if (readOnly) { // Not just emitting a read only Textfield like some other components do // since we want to preserve the minRows, maxRows info. readOnlyProp = { readOnly: true }; } const testProps: any = { 'data-test-id': testId }; function handleChange(event) { // update internal value setInputValue(event?.target?.value); } function handleBlur() { handleEvent(actions, 'changeNblur', propName, inputValue); } return ( ); }