index.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, { FC, useState } from 'react';
  2. import {
  3. TextInput,
  4. Text,
  5. View,
  6. InputModeOptions,
  7. NativeSyntheticEvent,
  8. TextInputFocusEventData
  9. } from 'react-native';
  10. import { styling } from './style';
  11. type Props = {
  12. placeholder?: string;
  13. onChange?: (text: string) => void;
  14. header?: string;
  15. isPrivate?: boolean;
  16. inputMode?: InputModeOptions;
  17. isFocused?: (boolean: boolean) => void;
  18. value?: string;
  19. active?: boolean;
  20. onBlur?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void;
  21. formikError?: string | boolean;
  22. };
  23. export const Input: FC<Props> = ({
  24. onChange,
  25. placeholder,
  26. header,
  27. isPrivate,
  28. inputMode,
  29. isFocused,
  30. onBlur,
  31. value,
  32. formikError
  33. }) => {
  34. const [focused, setFocused] = useState(false);
  35. const styles = styling(focused);
  36. return (
  37. <View>
  38. {header ? <Text style={styles.text}>{header}</Text> : null}
  39. <TextInput
  40. value={value}
  41. inputMode={inputMode ?? 'text'}
  42. secureTextEntry={isPrivate ?? false}
  43. placeholder={placeholder}
  44. onChangeText={onChange}
  45. onFocus={() => {
  46. setFocused(true);
  47. if (isFocused) {
  48. isFocused(true);
  49. }
  50. }}
  51. onBlur={(e) => {
  52. setFocused(false);
  53. if (onBlur) {
  54. onBlur(e);
  55. }
  56. }}
  57. style={[styles.wrapper, formikError ? styles.inputError : null]}
  58. />
  59. {formikError ? <Text style={styles.errorText}>{formikError}</Text> : null}
  60. </View>
  61. );
  62. };