TextInputComponent.js 3.57 KB
Newer Older
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
1 2
/* eslint-disable prettier/prettier */
import React from 'react';
3 4 5 6 7 8
import {
  Image,
  StyleSheet,
  TextInput,
  TouchableOpacity,
  View,
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
9 10 11 12 13
} from 'react-native';
import {HelperText} from 'react-native-paper';
import styles from '../screens/authentication/login/styles';
import colors from '../values/colors';
import AppText from './AppText';
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
const TextInputComponent = ({
  placeholder,
  style,
  placeholderTextColor,
  keyboardType,
  autoCapitalize,
  onChangeText,
  onBlur,
  value,
  errors,
  rightIcon,
  onPressRightIcon,
  leftIcon,
  onPressLeftIcon,
  styleAreaInput,
  secureTextEntry,
  label,
  require,
  styleLabel,
  maxLength,
  onFocus,
  disable,
  noBorder,
  autoCompleteType,
  borderColor,
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
39
  type,
40 41
}) => {
  return (
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
42 43 44 45 46 47
    <View style={stylesTextInput.container}>
      {label && (
        <View style={stylesTextInput.containerLabel}>
          <AppText
            children={`${label}`}
            style={[stylesTextInput.textLabel, styleLabel]}
48
          />
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
49
          {require && <AppText children={' *'} style={{color: colors.red}} />}
50
        </View>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
      )}
      <View
        style={[
          noBorder
            ? stylesTextInput.containerAreaInputNoBorder
            : stylesTextInput.containerAreaInput,
          styleAreaInput,
          {borderColor: borderColor},
        ]}>
        {leftIcon && (
          <TouchableOpacity
            onPress={() => {
              onPressLeftIcon && onPressLeftIcon();
            }}
            style={stylesTextInput.leftIcon}>
            <Image source={leftIcon} style={stylesTextInput.icon} />
          </TouchableOpacity>
        )}
        <TextInput
          style={[stylesTextInput.textInput, style]}
          placeholder={placeholder}
          placeholderTextColor={placeholderTextColor ?? colors.grayC4}
          keyboardType={keyboardType}
          autoCapitalize={autoCapitalize}
          onChangeText={onChangeText}
          onBlur={onBlur}
          value={value}
          secureTextEntry={secureTextEntry}
          maxLength={maxLength}
          onFocus={onFocus}
          editable={!disable}
          autoComplete={autoCompleteType}
        />
        {rightIcon && (
          <TouchableOpacity
            onPress={() => {
              onPressRightIcon && onPressRightIcon();
            }}>
            <Image source={rightIcon} style={stylesTextInput.icon} />
          </TouchableOpacity>
        )}
92
      </View>
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
93 94 95 96 97 98
      <HelperText type="error" visible={Boolean(errors)}>
        {errors}
      </HelperText>
    </View>
  );
};
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
const stylesTextInput = StyleSheet.create({
  container: {
    width: '100%',
  },
  containerAreaInput: {
    justifyContent: 'space-between',
    flexDirection: 'row',
    alignItems: 'center',
    height: 50,
    width: '100%',
    ...styles.inputBox2,
    marginTop: 5,
    paddingHorizontal: 8,
    paddingRight: 12,
    borderColor: colors.black1,
    borderWidth: 1,
  },
  containerAreaInputNoBorder: {
    justifyContent: 'space-between',
    flexDirection: 'row',
    alignItems: 'center',
    height: 50,
    width: '100%',
    ...styles.inputBox2,
    marginTop: 5,
    paddingHorizontal: 8,
    paddingRight: 12,
126
    borderBottomWidth: 0.5,
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  },
  icon: {
    width: 20,
    height: 20,
  },
  textInput: {
    flex: 1,
    color: colors.royal_blue,
    // marginLeft: 10,
    height: 45,
  },
  textLabel: {
    color: colors.black1,
    fontSize: 16,
    fontFamily: 'SegoeUI',
  },
  leftIcon: {
    height: 50,
    paddingHorizontal: 5,
    justifyContent: 'center',
  },
  containerLabel: {
    flexDirection: 'row',
    alignItems: 'center',
  },
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
152 153
});
export default TextInputComponent;