import React from 'react'; import { View, StyleSheet, Text, TextInput } from 'react-native'; import PropTypes from 'prop-types'; import { BorderlessButton } from 'react-native-gesture-handler'; import sharedStyles from '../views/Styles'; import { COLOR_DANGER, COLOR_TEXT_DESCRIPTION, COLOR_TEXT, COLOR_BORDER } from '../constants/colors'; import { CustomIcon } from '../lib/Icons'; const styles = StyleSheet.create({ inputContainer: { marginBottom: 10 }, label: { marginBottom: 10, fontSize: 14, ...sharedStyles.textSemibold, ...sharedStyles.textColorNormal }, input: { ...sharedStyles.textRegular, ...sharedStyles.textColorNormal, height: 48, fontSize: 16, paddingLeft: 14, paddingRight: 14, borderWidth: 1, borderRadius: 2, backgroundColor: 'white', borderColor: COLOR_BORDER }, inputIconLeft: { paddingLeft: 45 }, inputIconRight: { paddingRight: 45 }, labelError: { color: COLOR_DANGER }, inputError: { color: COLOR_DANGER, borderColor: COLOR_DANGER }, wrap: { position: 'relative' }, iconContainer: { position: 'absolute', top: 14 }, iconLeft: { left: 15 }, iconRight: { right: 15 }, icon: { color: COLOR_TEXT }, password: { color: COLOR_TEXT_DESCRIPTION } }); export default class RCTextInput extends React.PureComponent { static propTypes = { label: PropTypes.string, error: PropTypes.object, secureTextEntry: PropTypes.bool, containerStyle: PropTypes.any, inputStyle: PropTypes.object, inputRef: PropTypes.func, testID: PropTypes.string, iconLeft: PropTypes.string, placeholder: PropTypes.string } static defaultProps = { error: {} } state = { showPassword: false } get iconLeft() { const { testID, iconLeft } = this.props; return ( ); } get iconPassword() { const { showPassword } = this.state; const { testID } = this.props; return ( ); } tooglePassword = () => { this.setState(prevState => ({ showPassword: !prevState.showPassword })); } render() { const { showPassword } = this.state; const { label, error, secureTextEntry, containerStyle, inputRef, iconLeft, inputStyle, testID, placeholder, ...inputProps } = this.props; return ( {label ? {label} : null} {iconLeft ? this.iconLeft : null} {secureTextEntry ? this.iconPassword : null} {error.error ? {error.reason} : null} ); } }