/* eslint-disable lines-around-comment */ import React, { forwardRef, useCallback, useState } from 'react'; import { KeyboardTypeOptions, NativeSyntheticEvent, ReturnKeyTypeOptions, StyleProp, Text, TextInput, TextInputChangeEventData, TextInputFocusEventData, TextInputKeyPressEventData, TextInputSubmitEditingEventData, TouchableOpacity, View, ViewStyle } from 'react-native'; import Icon from '../../../icons/components/Icon'; import { IconCloseCircle } from '../../../icons/svg'; import BaseTheme from '../../../ui/components/BaseTheme.native'; import { IInputProps } from '../types'; import styles from './inputStyles'; interface IProps extends IInputProps { accessibilityLabel?: any; autoCapitalize?: string | undefined; autoFocus?: boolean; blurOnSubmit?: boolean | undefined; customStyles?: ICustomStyles; editable?: boolean | undefined; keyboardType?: KeyboardTypeOptions; maxLength?: number | undefined; minHeight?: number | string | undefined; multiline?: boolean | undefined; numberOfLines?: number | undefined; onBlur?: ((e: NativeSyntheticEvent) => void) | undefined; onFocus?: ((e: NativeSyntheticEvent) => void) | undefined; onKeyPress?: ((e: NativeSyntheticEvent) => void) | undefined; onSubmitEditing?: (value: string) => void; returnKeyType?: ReturnKeyTypeOptions | undefined; secureTextEntry?: boolean | undefined; textContentType?: any; } interface ICustomStyles { container?: Object; input?: Object; } const Input = forwardRef(({ accessibilityLabel, autoCapitalize, autoFocus, blurOnSubmit, clearable, customStyles, disabled, error, icon, keyboardType, label, maxLength, minHeight, multiline, numberOfLines, onBlur, onChange, onFocus, onKeyPress, onSubmitEditing, placeholder, returnKeyType, secureTextEntry, textContentType, value }: IProps, ref) => { const [ focused, setFocused ] = useState(false); const handleChange = useCallback((e: NativeSyntheticEvent) => { const { nativeEvent: { text } } = e; onChange?.(text); }, []); const clearInput = useCallback(() => { onChange?.(''); }, []); const handleBlur = useCallback((e: NativeSyntheticEvent) => { setFocused(false); onBlur?.(e); }, []); const handleFocus = useCallback((e: NativeSyntheticEvent) => { setFocused(true); onFocus?.(e); }, []); const handleKeyPress = useCallback((e: NativeSyntheticEvent) => { onKeyPress?.(e); }, []); const handleSubmitEditing = useCallback((e: NativeSyntheticEvent) => { const { nativeEvent: { text } } = e; onSubmitEditing?.(text); }, []); return ( {label && { label }} }> {icon && } { clearable && !disabled && value !== '' && ( }> )} ); }); export default Input;