import zxcvbn from 'zxcvbn'; import React, { useCallback, useMemo } from 'react'; import PropTypes from 'prop-types'; import { Icon, Input, Progress } from 'semantic-ui-react'; import { useToggle } from '../../../hooks'; import styles from './InputPassword.module.css'; const STRENGTH_SCORE_COLORS = ['red', 'orange', 'yellow', 'olive', 'green']; const InputPassword = React.forwardRef( ({ value, withStrengthBar, minStrengthScore, className, ...props }, ref) => { const [isVisible, toggleVisible] = useToggle(); const strengthScore = useMemo(() => { if (!withStrengthBar) { return undefined; } return zxcvbn(value).score; }, [value, withStrengthBar]); const handleToggleClick = useCallback(() => { toggleVisible(); }, [toggleVisible]); const inputProps = { ...props, ref, type: isVisible ? 'text' : 'password', icon: , }; if (!withStrengthBar) { return ( ); } return (
); }, ); InputPassword.propTypes = { value: PropTypes.string.isRequired, withStrengthBar: PropTypes.bool, minStrengthScore: PropTypes.number, className: PropTypes.string, }; InputPassword.defaultProps = { withStrengthBar: false, minStrengthScore: 2, className: undefined, }; export default React.memo(InputPassword);