49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { View, TextInput, Text, TouchableOpacity, TextInputProps } from 'react-native';
|
|
|
|
interface AppInputProps extends TextInputProps {
|
|
label?: string;
|
|
error?: string;
|
|
secureToggle?: boolean;
|
|
leftIcon?: React.ReactNode;
|
|
}
|
|
|
|
export const AppInput: React.FC<AppInputProps> = ({
|
|
label,
|
|
error,
|
|
secureToggle,
|
|
leftIcon,
|
|
...props
|
|
}) => {
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
|
|
return (
|
|
<View className="mb-4">
|
|
{label && (
|
|
<Text className="text-sm font-medium text-gray-700 mb-1.5">{label}</Text>
|
|
)}
|
|
<View
|
|
className={`flex-row items-center bg-white border rounded-xl px-4 h-12 ${
|
|
error ? 'border-red-500' : 'border-gray-200'
|
|
}`}
|
|
>
|
|
{leftIcon && <View className="mr-2">{leftIcon}</View>}
|
|
<TextInput
|
|
className="flex-1 text-gray-900 text-base"
|
|
placeholderTextColor="#9CA3AF"
|
|
secureTextEntry={secureToggle ? !showPassword : props.secureTextEntry}
|
|
{...props}
|
|
/>
|
|
{secureToggle && (
|
|
<TouchableOpacity onPress={() => setShowPassword(!showPassword)}>
|
|
<Text className="text-blue-600 text-sm font-medium">
|
|
{showPassword ? 'Hide' : 'Show'}
|
|
</Text>
|
|
</TouchableOpacity>
|
|
)}
|
|
</View>
|
|
{error && <Text className="text-red-500 text-xs mt-1">{error}</Text>}
|
|
</View>
|
|
);
|
|
};
|