import type { MaterialIcons } from "@expo/vector-icons"; import { styles } from "@/styles/components/textInput"; import Button from "@/components/Button"; import { useState } from "react"; import { type TextInputSubmitEditingEventData, type TextInputChangeEventData, TextInput as NativeTextInput, type NativeSyntheticEvent, type ReturnKeyTypeOptions, type KeyboardType, type ColorValue, type TextStyle, View, Text, } from "react-native"; interface Props { value?: string; defaultValue?: string; title?: string; description?: string; id?: string; onPasswordToggle?: ( visibile: boolean, id?: Props["id"], ) => void | Promise; onValueChange?: (newValue: string, id?: Props["id"]) => void | Promise; disabled?: boolean; disableContext?: boolean; showDisabledStyle?: boolean; multiline?: boolean; password?: boolean; keyboardType?: KeyboardType; placeholder?: string; sideButtonColor?: ColorValue; sideButtonIconColor?: ColorValue; onSideButtonPress?: (id?: Props["id"]) => void | Promise; sideButtonIcon?: keyof typeof MaterialIcons.glyphMap; maxLength?: number; inputStyle?: TextStyle; showSoftInputOnFocus?: boolean; onChange?: ( event: NativeSyntheticEvent, id?: Props["id"], ) => void | Promise; onSubmitEditing?: ( event: NativeSyntheticEvent, id?: Props["id"], ) => void | Promise; returnKeyType?: ReturnKeyTypeOptions; } export default function TextInput({ value, onValueChange = () => {}, onPasswordToggle = () => {}, onSideButtonPress = () => {}, disabled = false, showDisabledStyle = true, disableContext = false, multiline = false, title, description, password = false, keyboardType = "default", placeholder, sideButtonColor = "#323ea8", sideButtonIcon, sideButtonIconColor = "white", maxLength, inputStyle, showSoftInputOnFocus = true, onChange = () => {}, onSubmitEditing = () => {}, returnKeyType, id, defaultValue, }: Props) { const [displayPassword, setDisplayPassword] = useState(false); if (password) return ( {title && ( <> {title} {description && ( {description} )} )} onChange(event, id)} onSubmitEditing={(event) => onSubmitEditing(event, id)} maxLength={maxLength} style={{ ...styles.textInput, ...styles.textInputSideButton, ...(disabled && showDisabledStyle && styles.textInputDisabled), ...inputStyle, }} editable={!disabled} contextMenuHidden={disableContext} onChangeText={(text) => onValueChange(text, id)} value={value} keyboardType={displayPassword ? "visible-password" : "default"} placeholder={placeholder} placeholderTextColor="#222c47" returnKeyType={returnKeyType} defaultValue={defaultValue} />