import React, { ChangeEvent, FC, useCallback, useState } from 'react'; import classNames from 'classnames'; import { Icon } from '~/components/input/Icon'; import { InputWrapper } from '~/components/input/InputWrapper'; import { useTranslatedError } from '~/hooks/data/useTranslatedError'; import { useFocusEvent } from '~/hooks/dom/useFocusEvent'; import { IInputTextProps } from '~/types'; import styles from './styles.module.scss'; const InputText: FC = ({ className = '', handler, required = false, title, error, value = '', suffix, prefix, ...props }) => { const { focused, onFocus, onBlur } = useFocusEvent(); const [revealed, setRevealed] = useState(false); const onInput = useCallback( ({ target }: ChangeEvent) => { if (!handler) { return; } handler(target.value); }, [handler] ); const toggleRevealed = useCallback(() => setRevealed(!revealed), [setRevealed, revealed]); const translatedError = useTranslatedError(error); const type = props.type === 'password' && revealed ? 'text' : props.type; return (
{!!prefix &&
{prefix}
} {(!!suffix || props.type === 'password') && (
{suffix} {props.type === 'password' && ( )}
)}
); }; export { InputText };