123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import React, { FC, useState } from 'react';
- import {
- TextInput,
- Text,
- View,
- InputModeOptions,
- NativeSyntheticEvent,
- TextInputFocusEventData
- } from 'react-native';
- import { styling } from './style';
- type Props = {
- placeholder?: string;
- onChange?: (text: string) => void;
- header?: string;
- isPrivate?: boolean;
- inputMode?: InputModeOptions;
- isFocused?: (boolean: boolean) => void;
- value?: string;
- active?: boolean;
- onBlur?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void;
- formikError?: string | boolean;
- };
- export const Input: FC<Props> = ({
- onChange,
- placeholder,
- header,
- isPrivate,
- inputMode,
- isFocused,
- onBlur,
- value,
- formikError
- }) => {
- const [focused, setFocused] = useState(false);
- const styles = styling(focused);
- return (
- <View>
- {header ? <Text style={styles.text}>{header}</Text> : null}
- <TextInput
- value={value}
- inputMode={inputMode ?? 'text'}
- secureTextEntry={isPrivate ?? false}
- placeholder={placeholder}
- onChangeText={onChange}
- onFocus={() => {
- setFocused(true);
- if (isFocused) {
- isFocused(true);
- }
- }}
- onBlur={(e) => {
- setFocused(false);
- if (onBlur) {
- onBlur(e);
- }
- }}
- style={[styles.wrapper, formikError ? styles.inputError : null]}
- />
- {formikError ? <Text style={styles.errorText}>{formikError}</Text> : null}
- </View>
- );
- };
|