import React, { useState } from 'react'; import { TextInput, View, Text, Pressable, TextInputProps } from 'react-native'; import { Icon } from './Icon'; export interface InputProps extends TextInputProps { label?: string; error?: string; leftIcon?: string; rightIcon?: string; onLeftIconPress?: () => void; onRightIconPress?: () => void; containerClassName?: string; inputClassName?: string; type?: 'text' | 'email' | 'password'; } export const Input = React.forwardRef( ( { label, error, leftIcon, rightIcon, onLeftIconPress, onRightIconPress, containerClassName = '', inputClassName = '', type = 'text', secureTextEntry, ...props }, ref ) => { const [showPassword, setShowPassword] = useState(false); const isPassword = type === 'password'; const getKeyboardType = () => { if (type === 'email') return 'email-address'; return props.keyboardType || 'default'; }; const getAutoCapitalize = () => { if (type === 'email') return 'none'; return props.autoCapitalize || 'sentences'; }; return ( {label && {label}} {leftIcon && ( pressed && { opacity: 0.7 }]}> )} {isPassword && ( setShowPassword(!showPassword)} className="p-1" style={({ pressed }) => pressed && { opacity: 0.7 }}> )} {rightIcon && !isPassword && ( pressed && { opacity: 0.7 }}> )} {error && {error}} ); } ); Input.displayName = 'Input';