import { StyleSheet, View, Text, TextInput, TouchableOpacity, TouchableWithoutFeedback, StyleProp, TextStyle, ViewStyle, } from 'react-native'; import React, { ComponentType } from 'react'; import Icon from './Icon'; import { useTheme } from './ThemeContext'; import noop from '../helpers/noop'; export const isEmpty = (str: string): boolean => str.length === 0; const emptyStyle = {}; export type keyboardType = | 'default' | 'number-pad' | 'decimal-pad' | 'numeric' | 'email-address' | 'phone-pad' | 'ascii-capable' | 'numbers-and-punctuation' | 'url' | 'name-phone-pad' | 'twitter' | 'web-search' | 'visible-password'; export type Props = { readonly children?: React.ReactNode; readonly disabled?: boolean; readonly error?: string; readonly errorStyle?: StyleProp; readonly iconStyle?: StyleProp<{ color?: string }>; readonly inputStyle?: StyleProp; readonly inputTestID?: string; readonly keyboardType?: keyboardType; readonly label?: string; readonly labelStyle?: StyleProp; readonly multiline?: boolean; readonly onPressIcon?: () => void; readonly onTouch?: () => void; readonly placeholder?: string; readonly rightIcon?: string; readonly secureTextEntry?: boolean; readonly testID?: string; readonly value?: string; readonly wrapperStyle?: StyleProp; }; const TouchableTextInput: ComponentType = ({ testID, inputTestID, label = '', placeholder = '', keyboardType = 'default', value, onTouch = noop, onPressIcon = noop, rightIcon = '', disabled = false, error = '', secureTextEntry = false, multiline = false, wrapperStyle = emptyStyle, labelStyle = emptyStyle, inputStyle = emptyStyle, iconStyle = emptyStyle, errorStyle = emptyStyle, children = null, }: Props) => { const theme = useTheme(); const displayedPlaceholder = placeholder === '' ? label : placeholder; const displayedLabel = value !== undefined && !isEmpty(value) ? label : ''; const inputStyleColor = StyleSheet.flatten(inputStyle).color; return ( {displayedLabel} {children} ([ theme.textInput.icon, !isEmpty(error) ? theme.textInput.errorIcon : emptyStyle, iconStyle, ]).color } wrapperStyle={theme.textInput.icon} /> {error} ); }; export default TouchableTextInput;