import React, { useState } from 'react'; import { Form, TransitionReplace, } from '@edx/paragon'; import PropTypes from 'prop-types'; const FormGroup = (props) => { const [hasFocus, setHasFocus] = useState(false); const handleFocus = (e) => { setHasFocus(true); if (props.handleFocus) { props.handleFocus(e); } }; const handleClick = (e) => { if (props.handleClick) { props.handleClick(e); } }; const handleOnBlur = (e) => { setHasFocus(false); if (props.handleBlur) { props.handleBlur(e); } }; return ( {props.options ? props.options() : null} {hasFocus && props.helpText ? ( {props.helpText.map((message, index) => ( {message}
))}
) :
} {props.errorMessage !== '' && ( {props.errorMessage} )} {props.children} ); }; FormGroup.defaultProps = { as: 'input', autoComplete: null, borderClass: '', children: null, className: '', errorMessage: '', handleBlur: null, handleChange: () => {}, handleClick: null, handleFocus: null, helpText: [], options: null, readOnly: false, spellCheck: null, trailingElement: null, type: 'text', }; FormGroup.propTypes = { as: PropTypes.string, autoComplete: PropTypes.string, borderClass: PropTypes.string, children: PropTypes.element, className: PropTypes.string, errorMessage: PropTypes.string, floatingLabel: PropTypes.string.isRequired, handleBlur: PropTypes.func, handleChange: PropTypes.func, handleClick: PropTypes.func, handleFocus: PropTypes.func, helpText: PropTypes.arrayOf(PropTypes.string), name: PropTypes.string.isRequired, options: PropTypes.func, readOnly: PropTypes.bool, spellCheck: PropTypes.string, trailingElement: PropTypes.element, type: PropTypes.string, value: PropTypes.string.isRequired, }; export default FormGroup;