Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. import React from 'react';
  2. import { StyleSheet, View, TextInput, TouchableOpacity } from 'react-native';
  3. import Palette from '~/styles/palette';
  4. import MainText from '../Text/MainText';
  5. import ErrorText from '../Text/ErrorText';
  6. import FastImage from '~/components/UI/FastImageWrapper';
  7. import { createTestingProps } from '~/locators/utils';
  8.  
  9. const
  10. TITLE_MARGIN_BOTTOM = 8,
  11. INPUT_FONT_SIZE = 17;
  12.  
  13. const BorderedInput = ({ isNotRequired, title, inputStyle, value, onChangeText, isSecure, hasIcon, onPress, iconImg, isPasswordInvalid, onBlur, testIDProps = {}, ...props }) => (
  14. <View style={styles.container}>
  15. <MainText {...createTestingProps(testIDProps.label)} style={title && styles.title}>
  16. {title} {isNotRequired && <MainText style={{ color: Palette.warmGrey }}>{' (' + isNotRequired + ')'}</MainText>}
  17. </MainText>
  18. <View style={{ flexDirection: 'row', alignItems: 'center' }}>
  19. <TextInput
  20. style={[styles.input, inputStyle, hasIcon && { paddingRight: 44 }]}
  21. value={value}
  22. onChangeText={onChangeText}
  23. underlineColorAndroid='transparent'
  24. autoCapitalize={'none'}
  25. autoCorrect={false}
  26. secureTextEntry={isSecure}
  27. onBlur={onBlur}
  28. {...createTestingProps(testIDProps.input)}
  29. {...props}
  30. />
  31. {hasIcon &&
  32. <TouchableOpacity {...createTestingProps(testIDProps.icon)} hitSlop={{ top:16,left:16,bottom:16,right:16 }} onPress={onPress} style={styles.iconContainer}>
  33. <FastImage style={styles.icon} source={{ uri: iconImg }} />
  34. </TouchableOpacity>
  35. }
  36. </View>
  37. {typeof isPasswordInvalid !== 'undefined' && isPasswordInvalid && <ErrorText />}
  38. </View>
  39. );
  40.  
  41. export default BorderedInput;
  42.  
  43. const styles = StyleSheet.create({
  44. container: {
  45. alignSelf: 'stretch',
  46. },
  47. title: {
  48. marginBottom: TITLE_MARGIN_BOTTOM,
  49. fontWeight: 'bold',
  50. color: Palette.black,
  51. },
  52. input: {
  53. flex: 1,
  54. paddingVertical: 10,
  55. paddingHorizontal: 16,
  56. fontSize: INPUT_FONT_SIZE,
  57. color: Palette.black,
  58. borderWidth: 1,
  59. borderRadius: 9,
  60. borderColor: Palette.borderColor,
  61. textAlignVertical: 'center',
  62. },
  63. iconContainer: {
  64. width: 28,
  65. height: 28,
  66. position: 'absolute',
  67. right: 0,
  68. marginRight: 8,
  69. backgroundColor: Palette.white,
  70. justifyContent: 'center',
  71. alignItems: 'center',
  72. },
  73. icon: {
  74. width: 24,
  75. height: 24,
  76. },
  77. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement