You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.0 KiB

5 months ago
  1. import React, {useState} from 'react';
  2. import {StyleProp, Text, TextInput, View, ViewStyle} from 'react-native';
  3. import {ColorScheme} from './Design';
  4. import {CrossIcon, EyeIcon, FailIcon, SuccessIcon} from './EIcons';
  5. export enum ETextInputBorder {
  6. Nothing = 0,
  7. Border = 1,
  8. Success = 2,
  9. Fail = 3,
  10. }
  11. const borderColorScheme = [
  12. 'rgba(0,0,0,0)',
  13. ColorScheme.fill[30],
  14. ColorScheme.success.fill,
  15. ColorScheme.critical.fill,
  16. ];
  17. export default function ETextInput(props: {
  18. placeholder: string;
  19. value: string;
  20. setValue: any;
  21. passwordHidden?: boolean;
  22. setPasswordHidden?: (newState: boolean) => void;
  23. checkFailStatus?: boolean;
  24. border?: ETextInputBorder;
  25. style?: StyleProp<ViewStyle>;
  26. onChange?: (value: string) => void;
  27. }) {
  28. const border =
  29. props.border === undefined ? ETextInputBorder.Nothing : props.border;
  30. const [focused, setFocused] = useState(false);
  31. const clear = () => {
  32. props.setValue('');
  33. props.onChange !== undefined && props.onChange('');
  34. };
  35. const sideIcon = () => {
  36. if (props.setPasswordHidden !== undefined) {
  37. return (
  38. <EyeIcon
  39. fill={
  40. props.passwordHidden ? ColorScheme.fill[20] : ColorScheme.fill[10]
  41. }
  42. onPress={() =>
  43. props.setPasswordHidden &&
  44. props.setPasswordHidden(!props.passwordHidden)
  45. }
  46. />
  47. );
  48. } else if (props.checkFailStatus !== undefined) {
  49. return props.checkFailStatus ? (
  50. <SuccessIcon fill={ColorScheme.success.text} />
  51. ) : (
  52. <FailIcon fill={ColorScheme.critical.text} />
  53. );
  54. } else {
  55. return (
  56. props.value && <CrossIcon fill={ColorScheme.fill[20]} onPress={clear} />
  57. );
  58. }
  59. };
  60. return (
  61. <View
  62. style={[
  63. props.style,
  64. {
  65. borderColor:
  66. borderColorScheme[
  67. focused && border == ETextInputBorder.Nothing
  68. ? ETextInputBorder.Border
  69. : border
  70. ],
  71. borderWidth: 1,
  72. borderRadius: 8,
  73. backgroundColor: ColorScheme.frostedfill.black[20],
  74. paddingHorizontal: 16,
  75. paddingVertical: 12,
  76. flexDirection: 'row',
  77. justifyContent: 'space-between',
  78. alignItems: 'center',
  79. // these two are sketch.
  80. shadowRadius: 30,
  81. shadowColor: '#000000',
  82. },
  83. ]}>
  84. <TextInput
  85. onFocus={() => setFocused(true)}
  86. onBlur={() => setFocused(false)}
  87. onChangeText={text => {
  88. props.setValue(text);
  89. props.onChange !== undefined && props.onChange(text);
  90. }}
  91. value={props.value}
  92. placeholder={props.placeholder}
  93. placeholderTextColor={ColorScheme.fill[30]}
  94. secureTextEntry={props.passwordHidden}
  95. style={{
  96. fontFamily: 'Pretendard-SemiBold',
  97. fontSize: 17,
  98. fontWeight: '300',
  99. color: ColorScheme.fill[10],
  100. margin: 0,
  101. padding: 0,
  102. flex: 1,
  103. }}></TextInput>
  104. {sideIcon()}
  105. </View>
  106. );
  107. }