diff --git a/src/common-components/AuthnValidationFormGroup.jsx b/src/common-components/AuthnValidationFormGroup.jsx new file mode 100644 index 00000000..909db75b --- /dev/null +++ b/src/common-components/AuthnValidationFormGroup.jsx @@ -0,0 +1,148 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; +import { injectIntl } from '@edx/frontend-platform/i18n'; +import { + Form, + Input, + ValidationFormGroup, +} from '@edx/paragon'; + +const AuthnCustomValidationFormGroup = (props) => { + const { onClick, onChange, onBlur } = props; + const [showHelpText, setShowHelpText] = useState(false); + const [showLabelText, setShowLabelText] = useState(false); + const [showPlaceholder, setShowPlaceHolder] = useState(true); + + // handler code that need to be invoked via input + const onClickHandler = (e, clickCb) => { + setShowHelpText(true); + setShowLabelText(true); + setShowPlaceHolder(false); + if (clickCb) { + clickCb(e); + } + }; + const onBlurHandler = (e, blurCb) => { + setShowHelpText(false); + setShowLabelText(false); + setShowPlaceHolder(true); + if (blurCb) { + blurCb(e); + } + }; + const onChangeHandler = (e, changeCb) => { + if (changeCb) { + changeCb(e); + } + }; + const onOptionalHandler = (e, clickCb) => { clickCb(e); }; + + const showLabel = () => { + const fieldLabel = (!props.optionalFieldCheckbox && showLabelText) ? ( +
onOptionalHandler(e, onClick)}> + {props.checkboxMessage} +
+ ) : ; + return additionalField; + }; + + const inputProps = { + name: props.name, + id: props.for, + type: props.type, + value: props.value, + }; + inputProps.placeholder = showPlaceholder ? props.label : ''; + inputProps.onChange = (e) => onChangeHandler(e, onChange); + inputProps.onClick = (e) => onClickHandler(e, onClick); + inputProps.onBlur = (e) => onBlurHandler(e, onBlur); + inputProps.onFocus = (e) => onClickHandler(e, null); + + if (props.type === 'select') { + inputProps.options = props.selectOptions; + } + if (props.type === 'checkbox') { + inputProps.checked = props.isChecked; + } + + const validationGroupProps = { + for: props.for, + }; + if (!props.optionalFieldCheckbox) { + validationGroupProps.invalid = props.invalid; + validationGroupProps.invalidMessage = props.invalidMessage; + validationGroupProps.helpText = showHelpText ? props.helpText : ''; + } else { + validationGroupProps.className = props.optionalFieldCheckbox ? 'custom-control pt-10 mb-0' : ''; + } + if (props.className) { + validationGroupProps.className = props.className; + } + + return ( +{intl.formatMessage(messages['forgot.password.page.instructions'])}
-