import * as React from 'react'; import {Platform, Pressable, StyleSheet, Text, View} from 'react-native'; import {TextInput} from 'react-native-paper'; import Icon from 'react-native-vector-icons/MaterialIcons'; import Colors from '../../assets/styles/Colors'; import FontFamily from '../../assets/styles/FontFamily'; import DateTimePicker from '@react-native-community/datetimepicker'; import {useState} from 'react'; import {Dropdown} from 'react-native-element-dropdown'; type DropdownItem = { label: string; value: string | number; }; interface TextInputComponentProps { title?: string; placeholder?: string; isPassword?: boolean; isRequired?: boolean; isDate?: boolean; isDropdown?: boolean; dropdownItemData?: DropdownItem[]; isDisabled?: boolean; supportText?: string; containerHeight?: any; isMultiline?: boolean; } const TextInputComponent: React.FC = ({ title, placeholder, isPassword = false, isRequired = false, isDate = false, isDropdown = false, dropdownItemData, isDisabled = false, supportText, containerHeight, isMultiline = false, }) => { const [secureText, setSecureText] = useState(isPassword); const [selectedDate, setSelectedDate] = useState(undefined); const [formattedDate, setFormattedDate] = useState(''); const [showPicker, setShowPicker] = useState(false); const [genderValue, setGenderValue] = useState(null); const inputStyle = [ styles.containerBackground, styles.placeholderText, containerHeight && {height: containerHeight}, ]; const handleDateChange = (event: any, date?: Date) => { if (event.type === 'dismissed') { setShowPicker(false); return; } if (date) { setShowPicker(Platform.OS === 'ios'); setSelectedDate(date); const formatted = `${String(date.getDate()).padStart(2, '0')}/${String( date.getMonth() + 1, ).padStart(2, '0')}/${date.getFullYear()}`; setFormattedDate(formatted); } }; const renderDropdownItem = (item: any) => { return ( {item.label} ); }; const renderInput = () => { if (isDropdown) { return ( {title && ( {title} {isRequired && *} )} { setGenderValue(item.value); }} renderRightIcon={() => } renderItem={renderDropdownItem} /> ); } if (isDate) { return ( {title && {title}} {isRequired && *} setShowPicker(true)}> } multiline={false} /> {showPicker && ( )} ); } return ( {title && ( {title} {isRequired && *} )} setSecureText(prev => !prev)} forceTextInputFocus={false} /> ) : null } multiline={isMultiline} /> {supportText && {supportText}} ); }; return {renderInput()}; }; const styles = StyleSheet.create({ containerBackground: { backgroundColor: Colors.neutral100.color, marginTop: 8, }, title: { ...FontFamily.notoSansBold, fontSize: 12, }, titleContainer: { flexDirection: 'row', gap: 5, }, required: { ...FontFamily.notoSansBold, fontSize: 12, color: Colors.indicatorRed.color, }, placeholderText: { fontSize: 13, ...FontFamily.notoSansRegular, }, dropdown: { marginTop: 8, backgroundColor: 'white', borderRadius: 12, paddingVertical: 16, paddingStart: 16, paddingEnd: 8, borderWidth: 1, borderColor: Colors.primary40.color, }, placeholderDropdownStyle: { fontSize: 13, ...FontFamily.notoSansRegular, color: Colors.primary60.color, }, selectedTextStyle: { fontSize: 13, ...FontFamily.notoSansRegular, }, iconStyle: { width: 20, height: 20, }, dropdownItem: { padding: 16, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, dropdownTextItem: { flex: 1, fontSize: 13, }, supportText: { marginTop: 8, ...FontFamily.notoSansRegular, fontSize: 10, textAlign: 'right', includeFontPadding: false, color: Colors.neutral70.color, }, }); export default TextInputComponent;