import React, { useEffect, useState } from 'react'; import { HelperText, HelperTextItem, TextArea, TextAreaProps, TextInput, TextInputProps, } from '@patternfly/react-core'; import type { StepValidation } from './utilities/useValidation'; type ValidatedTextInputPropTypes = TextInputProps & { dataTestId?: string; ariaLabel: string | undefined; helperText: string | undefined; validator: (value: string | undefined) => boolean; value: string; placeholder?: string; }; type ValidationInputProp = TextInputProps & TextAreaProps & { value: string; placeholder: string; stepValidation: StepValidation; dataTestId?: string; fieldName: string; inputType?: 'textInput' | 'textArea'; ariaLabel: string; onChange: ( event: React.FormEvent, value: string ) => void; isRequired?: boolean; warning?: string; }; type ErrorMessageProps = { errorMessage: string; }; type ValidationResult = 'default' | 'success' | 'error'; export const ValidatedInputAndTextArea = ({ value, stepValidation, fieldName, placeholder, dataTestId, onChange, ariaLabel, inputType = 'textInput', isRequired, warning = undefined, }: ValidationInputProp) => { const errorMessage = stepValidation.errors[fieldName] || ''; const hasError = errorMessage !== ''; const [isPristine, setIsPristine] = useState(!value); const validated = getValidationState(isPristine, errorMessage, isRequired); const handleBlur = () => { if (value) { setIsPristine(false); } }; useEffect(() => { if (!value) { setIsPristine(true); } }, [value, setIsPristine]); return ( <> {inputType === 'textArea' ? (