2022-06-22 12:24:25 +00:00
|
|
|
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';
|
2022-06-27 18:46:59 +00:00
|
|
|
import React, { useState } from 'react';
|
2022-06-22 12:24:25 +00:00
|
|
|
import { StyleProp, StyleSheet, Text, TextInput as RNTextInput, TextInputProps, TextStyle, View, ViewStyle } from 'react-native';
|
2021-10-01 20:36:59 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2018-04-01 00:45:15 +00:00
|
|
|
|
2022-06-27 18:46:59 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-06-22 12:24:25 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
import ActivityIndicator from '../ActivityIndicator';
|
|
|
|
import { CustomIcon, TIconsName } from '../CustomIcon';
|
2022-06-27 18:46:59 +00:00
|
|
|
import { TextInput } from './TextInput';
|
2018-03-29 17:55:37 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2019-12-04 16:39:53 +00:00
|
|
|
error: {
|
2020-11-30 21:47:05 +00:00
|
|
|
...sharedStyles.textAlignCenter,
|
2019-12-04 16:39:53 +00:00
|
|
|
paddingTop: 5
|
|
|
|
},
|
2018-03-29 17:55:37 +00:00
|
|
|
inputContainer: {
|
2018-11-14 21:42:03 +00:00
|
|
|
marginBottom: 10
|
2018-03-29 17:55:37 +00:00
|
|
|
},
|
|
|
|
label: {
|
2018-04-24 19:34:03 +00:00
|
|
|
marginBottom: 10,
|
|
|
|
fontSize: 14,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textSemibold
|
2018-03-29 17:55:37 +00:00
|
|
|
},
|
|
|
|
input: {
|
2018-11-14 21:42:03 +00:00
|
|
|
...sharedStyles.textRegular,
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 16,
|
2021-08-27 20:03:59 +00:00
|
|
|
padding: 14,
|
2022-09-22 21:16:25 +00:00
|
|
|
borderWidth: 2,
|
2019-12-04 16:39:53 +00:00
|
|
|
borderRadius: 2
|
2018-11-14 21:42:03 +00:00
|
|
|
},
|
|
|
|
inputIconLeft: {
|
|
|
|
paddingLeft: 45
|
|
|
|
},
|
|
|
|
inputIconRight: {
|
|
|
|
paddingRight: 45
|
2018-03-29 17:55:37 +00:00
|
|
|
},
|
2018-04-01 00:45:15 +00:00
|
|
|
wrap: {
|
2022-09-22 21:16:25 +00:00
|
|
|
position: 'relative',
|
|
|
|
justifyContent: 'center'
|
2018-04-01 00:45:15 +00:00
|
|
|
},
|
2018-11-14 21:42:03 +00:00
|
|
|
iconContainer: {
|
2022-09-22 21:16:25 +00:00
|
|
|
position: 'absolute'
|
2018-11-14 21:42:03 +00:00
|
|
|
},
|
|
|
|
iconLeft: {
|
|
|
|
left: 15
|
|
|
|
},
|
|
|
|
iconRight: {
|
|
|
|
right: 15
|
2018-03-29 17:55:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-17 16:10:39 +00:00
|
|
|
export interface IRCTextInputProps extends TextInputProps {
|
2021-10-20 16:42:44 +00:00
|
|
|
label?: string;
|
2022-03-22 18:01:54 +00:00
|
|
|
error?: any;
|
2021-10-20 16:42:44 +00:00
|
|
|
loading?: boolean;
|
|
|
|
containerStyle?: StyleProp<ViewStyle>;
|
2021-11-10 15:10:34 +00:00
|
|
|
inputStyle?: StyleProp<TextStyle>;
|
2022-02-07 15:18:37 +00:00
|
|
|
inputRef?: React.Ref<RNTextInput>;
|
2022-05-02 19:21:15 +00:00
|
|
|
iconLeft?: TIconsName;
|
|
|
|
iconRight?: TIconsName;
|
2021-10-20 16:42:44 +00:00
|
|
|
left?: JSX.Element;
|
2022-06-22 12:24:25 +00:00
|
|
|
bottomSheet?: boolean;
|
2022-06-06 13:53:02 +00:00
|
|
|
onClearInput?: () => void;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
2018-04-01 00:45:15 +00:00
|
|
|
|
2022-06-27 18:46:59 +00:00
|
|
|
export const FormTextInput = ({
|
|
|
|
label,
|
|
|
|
error,
|
|
|
|
loading,
|
|
|
|
containerStyle,
|
|
|
|
inputStyle,
|
|
|
|
inputRef,
|
|
|
|
iconLeft,
|
|
|
|
iconRight,
|
|
|
|
onClearInput,
|
|
|
|
value,
|
|
|
|
left,
|
|
|
|
testID,
|
|
|
|
secureTextEntry,
|
|
|
|
bottomSheet,
|
|
|
|
placeholder,
|
|
|
|
...inputProps
|
|
|
|
}: IRCTextInputProps): React.ReactElement => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
|
|
const showClearInput = onClearInput && value && value.length > 0;
|
|
|
|
const Input = bottomSheet ? BottomSheetTextInput : TextInput;
|
|
|
|
return (
|
|
|
|
<View style={[styles.inputContainer, containerStyle]}>
|
|
|
|
{label ? (
|
|
|
|
<Text style={[styles.label, { color: colors.titleText }, error?.error && { color: colors.dangerColor }]}>{label}</Text>
|
|
|
|
) : null}
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2022-06-27 18:46:59 +00:00
|
|
|
<View style={styles.wrap}>
|
|
|
|
<Input
|
|
|
|
style={[
|
|
|
|
styles.input,
|
|
|
|
iconLeft && styles.inputIconLeft,
|
2022-09-22 21:16:25 +00:00
|
|
|
(secureTextEntry || iconRight || showClearInput) && styles.inputIconRight,
|
2022-06-27 18:46:59 +00:00
|
|
|
{
|
|
|
|
backgroundColor: colors.backgroundColor,
|
|
|
|
borderColor: colors.separatorColor,
|
|
|
|
color: colors.titleText
|
|
|
|
},
|
|
|
|
error?.error && {
|
|
|
|
color: colors.dangerColor,
|
|
|
|
borderColor: colors.dangerColor
|
|
|
|
},
|
|
|
|
inputStyle
|
|
|
|
]}
|
|
|
|
// @ts-ignore ref error
|
|
|
|
ref={inputRef}
|
|
|
|
autoCorrect={false}
|
|
|
|
autoCapitalize='none'
|
|
|
|
underlineColorAndroid='transparent'
|
|
|
|
secureTextEntry={secureTextEntry && !showPassword}
|
|
|
|
testID={testID}
|
|
|
|
accessibilityLabel={placeholder}
|
|
|
|
placeholder={placeholder}
|
|
|
|
value={value}
|
|
|
|
{...inputProps}
|
2018-11-14 21:42:03 +00:00
|
|
|
/>
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2022-06-27 18:46:59 +00:00
|
|
|
{iconLeft ? (
|
|
|
|
<CustomIcon
|
|
|
|
name={iconLeft}
|
|
|
|
testID={testID ? `${testID}-icon-left` : undefined}
|
|
|
|
size={20}
|
|
|
|
color={colors.auxiliaryText}
|
|
|
|
style={[styles.iconContainer, styles.iconLeft]}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2022-06-27 18:46:59 +00:00
|
|
|
{showClearInput ? (
|
|
|
|
<Touchable onPress={onClearInput} style={[styles.iconContainer, styles.iconRight]} testID='clear-text-input'>
|
|
|
|
<CustomIcon name='input-clear' size={20} color={colors.auxiliaryTintColor} />
|
|
|
|
</Touchable>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{iconRight && !showClearInput ? (
|
|
|
|
<CustomIcon
|
|
|
|
name={iconRight}
|
|
|
|
testID={testID ? `${testID}-icon-right` : undefined}
|
|
|
|
size={20}
|
|
|
|
color={colors.bodyText}
|
|
|
|
style={[styles.iconContainer, styles.iconRight]}
|
|
|
|
/>
|
|
|
|
) : null}
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2022-06-27 18:46:59 +00:00
|
|
|
{secureTextEntry ? (
|
|
|
|
<Touchable onPress={() => setShowPassword(!showPassword)} style={[styles.iconContainer, styles.iconRight]}>
|
|
|
|
<CustomIcon
|
|
|
|
name={showPassword ? 'unread-on-top' : 'unread-on-top-disabled'}
|
|
|
|
testID={testID ? `${testID}-icon-password` : undefined}
|
|
|
|
size={20}
|
|
|
|
color={colors.auxiliaryText}
|
|
|
|
/>
|
|
|
|
</Touchable>
|
2019-12-04 16:39:53 +00:00
|
|
|
) : null}
|
2022-06-27 18:46:59 +00:00
|
|
|
|
|
|
|
{loading ? (
|
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.iconContainer, styles.iconRight]}
|
|
|
|
color={colors.bodyText}
|
|
|
|
testID={testID ? `${testID}-loading` : undefined}
|
2018-04-01 00:45:15 +00:00
|
|
|
/>
|
2022-06-27 18:46:59 +00:00
|
|
|
) : null}
|
|
|
|
{left}
|
2018-03-29 17:55:37 +00:00
|
|
|
</View>
|
2022-06-27 18:46:59 +00:00
|
|
|
{error && error.reason ? <Text style={[styles.error, { color: colors.dangerColor }]}>{error.reason}</Text> : null}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|