import React, { type ReactNode, useState } from 'react'; import { type KeyboardType, type StyleProp, TextInput, TouchableOpacity, View, type ViewStyle, } from 'react-native'; import Text from './Text'; import Row from './Row'; import { globalStyles } from '../styles/globalStyles'; import { colors } from '../colors/colors'; import Space from './Space'; import AntDesign from 'react-native-vector-icons/AntDesign'; import IonIcons from 'react-native-vector-icons/Ionicons'; import type { TextStyle } from 'react-native'; interface Props { placeholder?: string; value: string; onChange: (val: string) => void; prefix?: ReactNode; affix?: ReactNode; clear?: boolean; password?: boolean; passwordShowHideButton?: { show: ReactNode; hide: ReactNode; }; inputStyles?: StyleProp; keyboardType?: KeyboardType; iconClear?: ReactNode; placeholderColor?: string; autoComplete?: | 'additional-name' | 'address-line1' | 'address-line2' | 'birthdate-day' | 'birthdate-full' | 'birthdate-month' | 'birthdate-year' | 'cc-csc' | 'cc-exp' | 'cc-exp-day' | 'cc-exp-month' | 'cc-exp-year' | 'cc-number' | 'cc-name' | 'cc-given-name' | 'cc-middle-name' | 'cc-family-name' | 'cc-type' | 'country' | 'current-password' | 'email' | 'family-name' | 'gender' | 'given-name' | 'honorific-prefix' | 'honorific-suffix' | 'name' | 'name-family' | 'name-given' | 'name-middle' | 'name-middle-initial' | 'name-prefix' | 'name-suffix' | 'new-password' | 'nickname' | 'one-time-code' | 'organization' | 'organization-title' | 'password' | 'password-new' | 'postal-address' | 'postal-address-country' | 'postal-address-extended' | 'postal-address-extended-postal-code' | 'postal-address-locality' | 'postal-address-region' | 'postal-code' | 'street-address' | 'sms-otp' | 'tel' | 'tel-country-code' | 'tel-national' | 'tel-device' | 'url' | 'username' | 'username-new' | 'off' | undefined; autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters' | undefined; label?: string; inline?: boolean; textAreal?: boolean; rows?: number; styles?: StyleProp; required?: boolean; helpText?: string; disable?: boolean; color?: string; labelStyleProps?: StyleProp; bordered?: boolean; radius?: number; minHeight?: number; max?: number; showCount?: boolean; } const Input = (props: Props) => { const { placeholder, keyboardType, password, value, onChange, prefix, affix, color, clear, autoComplete, autoCapitalize, label, inline, textAreal, rows, required, helpText, disable, iconClear, passwordShowHideButton, labelStyleProps, bordered, radius, styles, inputStyles, placeholderColor, max, showCount, minHeight, } = props; const [isShowPass, setIsShowPass] = useState(password); const [isFocused, setIsFocused] = useState(false); const [isError, setIsError] = useState(false); const [text, setText] = useState(value); const contentHeight = 200; return ( {label && ( {required && } )} {prefix && prefix} 200 ? contentHeight : textAreal ? 120 : 'auto', }, inputStyles, ]} autoCapitalize={autoCapitalize ?? 'none'} autoComplete={autoComplete} keyboardType={keyboardType} placeholderTextColor={placeholderColor ?? colors.gray400} placeholder={placeholder} value={text} onChangeText={(val) => { setText(val); onChange(val); }} secureTextEntry={isShowPass} onFocus={() => setIsFocused(true)} onEndEditing={() => { required && value.length === 0 ? setIsError(true) : setIsError(false); setIsFocused(false); }} multiline={textAreal} numberOfLines={rows} /> {clear && value && value.length > 0 && ( { setText(''); onChange(''); }} > {iconClear ?? ( )} )} {affix && clear && } {affix && affix} {password && ( setIsShowPass(!isShowPass)}> {!isShowPass ? ( passwordShowHideButton ? ( passwordShowHideButton.hide ?? ( ) ) : ( ) ) : passwordShowHideButton ? ( passwordShowHideButton.show ?? ( ) ) : ( )} )} {required && isError && helpText && ( )} {showCount && ( )} ); }; export default Input;