import React, { useState } from 'react'; import PropTypes from 'prop-types'; import BaseInputField from './BaseInputField'; import PasswordStrength from './PasswordStrength'; const PasswordField = ({ field, form, label, placeholder, disabled, shouldTestPasswordStrength, autoFocus, ...props }) => { const [passwordValue, setPasswordValue] = useState(''); const [isCapsLockOn, setIsCapsLockOn] = useState(false); const onChange = (e) => { if (shouldTestPasswordStrength) { const { value } = e.target; setPasswordValue(value); } field.onChange(e); }; const onKeyDown = (keyEvent) => { if (keyEvent.getModifierState('CapsLock')) { setIsCapsLockOn(true); } else { setIsCapsLockOn(false); } }; return (
{shouldTestPasswordStrength && ( )}
); }; PasswordField.propTypes = { field: PropTypes.shape({ onChange: PropTypes.func, }), form: PropTypes.shape({}), label: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({})]), placeholder: PropTypes.string, disabled: PropTypes.bool, shouldTestPasswordStrength: PropTypes.bool, autoFocus: PropTypes.bool, }; export default PasswordField;