import { useState } from 'react' import Label from './Label' import Icon from './Icon' import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons'; export interface Props { value?: string defaultValue?: string type?: string, label?: string placeholder?: string name?: string className?: string error?: string textarea?: boolean rows?: string | number required?: boolean, disabled?: boolean, autoComplete?: boolean, readOnly?: boolean, maxLength?: number | string, min?: number | string, max?: number | string, onBlur?: (...args: any[]) => any, onFocus?: (...args: any[]) => any, onInput?: (...args: any[]) => any, onChange?: (...args: any[]) => any, onKeyDown?: (...args: any[]) => any, onKeyPress?: (...args: any[]) => any, onKeyUp?: (...args: any[]) => any } const Input = ({ value, defaultValue, type, label, placeholder, name, error, className, rows, textarea, required, readOnly, disabled, autoComplete, maxLength, min, max, onBlur, onFocus, onInput, onChange, onKeyPress, onKeyDown, onKeyUp }: Props): JSX.Element => { const InputTag = textarea ? 'textarea' : 'input' const getNumber = (str: any) => { if (!str) return undefined if (typeof str === 'number') return str const num = parseInt(str) if (isNaN(num)) return undefined return num } const [ displayPassword, setDisplayPassword ] = useState(false) const getType = () => { if (type === 'password' && displayPassword) return 'text' return type } return (
{ !!error &&
{ error }
}
{ !!label && }
{ type === 'password' && }
) } export default Input