import { View, TextInput, StyleProp, TextInputProps } from "react-native"; import React, { ReactNode } from "react"; // Styles Import import styles from "./InputStyles"; import { colors } from "../../assets/colors"; import AppText from "../Text/AppText"; import { errorStyle } from "../../Styles/BaseStyles"; import { BaseProps } from "../../Utils/BaseProps"; export interface InputProps extends BaseProps, TextInputProps { value?: string; onChangeText?: (e: React.ChangeEvent | string) => void; editable?: boolean; inputStyle?: StyleProp; autoFocus?: boolean; renderIcon?: () => ReactNode; iconPlacement?: "LEFT" | "RIGHT"; } const Input = (props: InputProps) => { const { value, onChangeText, disabled, label, containerStyle, labelStyle, hideLabel, autoFocus = false, assistiveText, assistiveTextStyle, renderIcon, iconPlacement = "LEFT", placeholder = label, errorMessage, errorVisibility, showErrorMessage = true, inputStyle, testID, placeholderColor = colors.grey, } = props; const styleInputWithIcon: StyleProp = { flexDirection: iconPlacement === "RIGHT" ? "row-reverse" : "row", alignItems: "center", }; return ( {hideLabel ? null : ( {label} )} {renderIcon ? renderIcon() : null} {assistiveText && !errorVisibility ? ( {assistiveText} ) : null} {errorVisibility && showErrorMessage && errorMessage ? ( {errorMessage} ) : null} ); }; export default Input;