import { useState } from 'react'; import { Text } from '../../components/wui-text'; import { InputText, type InputTextProps } from '../wui-input-text'; import { LoadingSpinner } from '../../components/wui-loading-spinner'; import { IconLink } from '../wui-icon-link'; import styles from './styles'; import { View } from 'react-native'; import { InputElement } from '../wui-input-element'; export type EmailInputProps = InputTextProps & { errorMessage?: string; loading?: boolean; onSubmit?: (value: string) => any; initialValue?: string; showClear?: boolean; submitEnabled?: boolean; }; function RightIcon({ loading, showChevron, onPress }: { loading?: boolean; showChevron: boolean; onPress?: () => void; }) { if (loading) { return ; } if (showChevron) { return ; } return null; } export function EmailInput({ errorMessage, onSubmit, onChangeText, loading, disabled, style, initialValue, submitEnabled = true, ...rest }: EmailInputProps) { const [email, setEmail] = useState(initialValue ?? ''); const handleSubmit = (value: string) => { if (submitEnabled) { onSubmit?.(value); } }; const handleChevronPress = () => { handleSubmit(email); }; const handleSubmitEditing = ({ nativeEvent: { text } }: { nativeEvent: { text: string } }) => { handleSubmit(text); }; const handleChangeText = (text: string) => { setEmail(text); onChangeText?.(text); }; const rightIconTemplate = () => { if (email === initialValue) { return ( { handleChangeText(''); }} /> ); } return ( ); }; return ( {rightIconTemplate()} {errorMessage && ( {errorMessage} )} ); }