import React, { FC, FocusEvent, KeyboardEvent, ClipboardEvent, ChangeEvent, useState } from 'react'; import { Input as InputControl } from 'antd'; import { InputProps as InputControlProps } from 'antd/lib/input'; import cn from 'classnames'; import { Icon } from 'Common/ui'; import theme from 'Lib/theme'; interface AdminInterfaceProps { autoComplete?: InputControlProps['autoComplete']; autoFocus?: InputControlProps['autoFocus']; className?: string; description?: string; disabled?: boolean; error?: boolean; id?: string; inputMode?: InputControlProps['inputMode']; label?: string; wrapperClassName?: string; name: string; onBlur?: (e: FocusEvent) => void; onChange?: (data: string, e?: ChangeEvent) => void; onFocus?: (e: FocusEvent) => void; onKeyDown?: (e: KeyboardEvent) => void; onPaste?: (e: ClipboardEvent) => void; pattern?: InputControlProps['pattern']; placeholder: string; prefix?: InputControlProps['prefix']; size?: InputControlProps['size']; suffix?: InputControlProps['suffix']; type: InputControlProps['type']; value: string | number; } const InputComponent: FC = ({ autoComplete, autoFocus, className, description, disabled, error, id, inputMode, label, wrapperClassName, name, onBlur, onChange, onFocus, onKeyDown, onPaste, pattern, placeholder, prefix, size = 'middle', suffix, type, value, }) => { const [inputType, setInputType] = useState(type); const inputClass = cn( 'input', { input_big: size === 'large' }, { input_medium: size === 'middle' }, { input_small: size === 'small' }, className, ); const handleBlur = (e: FocusEvent) => { if (onBlur) { onBlur(e); } }; const showPassword = () => { if (inputType === 'password') { setInputType('text'); } else { setInputType('password'); } }; const showPasswordIcon = () => { const icon = inputType === 'password' ? 'visibility_disable' : 'visibility_enable'; return ( ); }; const validSuffix = ( <> {!!suffix && suffix} {(type === 'password') && showPasswordIcon()} ); let descriptionView = null; if (description) { descriptionView = (
{description}
); } return ( ); }; export default InputComponent;