import { useState } from 'react'; import { Form, FormGroup, TextInput, HelperText, HelperTextItem, FormHelperText } from '@patternfly/react-core'; import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; export const FormInvalid: React.FunctionComponent = () => { type validate = 'success' | 'warning' | 'error' | 'default'; const [age, setAge] = useState('Five'); const [validated, setValidated] = useState('error'); const handleAgeChange = (_event, age: string) => { setAge(age); if (age === '') { setValidated('default'); } else if (/^\d+$/.test(age)) { setValidated('success'); } else { setValidated('error'); } }; return (
{validated !== 'success' && ( } variant={validated}> {validated === 'error' ? 'Must be a number' : 'Please enter your age'} )}
); };