import { type RequireOneOrNone } from 'type-fest'; import { Input, type InputLabelVariantProps, type InputProps, InputWrapper, type InputWrapperProps, } from '@suite-native/atoms'; import { CopyButton } from '../components/CopyButton'; import { useField } from '../hooks/useField'; import { type FieldName } from '../types'; type AllowedTextInputFieldProps = Omit< Partial, keyof ReturnType | 'defaultValue' | 'label' | 'placeholder' | 'labelType' >; type AllowedInputWrapperProps = Pick; export type FieldProps = RequireOneOrNone< AllowedTextInputFieldProps & AllowedInputWrapperProps & InputLabelVariantProps & { name: FieldName; onBlur?: () => void; defaultValue?: string; valueTransformer?: (value: string) => string; showCopyButton?: boolean; }, 'rightIcon' | 'showCopyButton' >; export const TextInputField = ({ name, hint, label, readOnly, placeholder, onBlur, valueTransformer, onChangeText, defaultValue = '', labelType = 'innerLabel', rightIcon, showCopyButton = false, ref, ...otherProps }: FieldProps) => { const field = useField({ name, defaultValue, valueTransformer, }); const { errorMessage, onBlur: hookFormOnBlur, onChange, value, hasError } = field; const handleOnBlur = () => { hookFormOnBlur(); onBlur?.(); }; const handleOnChange = (text: string) => { onChange(text); onChangeText?.(text); }; const innerLabelOrPlaceholderProps = labelType === 'innerLabel' ? { labelType, label } : { labelType, placeholder }; const wrapperLabel = labelType === 'outsideLabel' ? label : undefined; return ( : rightIcon} /> ); };