import React, { useState } from 'react' import { TextInputProps } from 'react-native' import { Control, Controller, FieldError } from 'react-hook-form' import { ButtonIcon, CalendarIcon, Container, ErrorMessage, InputContainer, Label, InputText, EyeOffIcon, EyeIcon, } from './styles' import { MaskProps, maskAnything } from '~/utils/masks' interface InputProps extends TextInputProps { label?: string control: Control name: string mask?: MaskProps } const Input: React.FC = ({ control, name, label, secureTextEntry, mask, ...rest }) => { const [showPassword, setShowPassword] = useState(false) const insertMask = (text: string, onChange: any) => { if (!mask) return onChange(text) return onChange(maskAnything(mask, text)) } return ( ( <> {label && } insertMask(text, onChange)} secureTextEntry={secureTextEntry && !showPassword} autoCapitalize="none" {...rest} /> {secureTextEntry && ( setShowPassword(p => !p)}> {showPassword ? : } )} {name === 'birthdate' && ( )} {errors[name] && ( {errors[name].message} )} )} /> ) } export default Input