import React, { cloneElement, forwardRef, useMemo } from 'react'; import { TextInput, TouchableOpacity, KeyboardTypeOptions } from 'react-native'; import { HelperText } from '../../utils/HelperText'; import useTheme from '../../context/theme/useTheme'; import type { InputProps } from './types'; import useCreateRef from '../../hooks/useCreateRef'; import { Box } from '../Box'; import createSxStyle from '../../lib/sx'; import { SxProps } from '../../lib/styleDictionary'; import { paddingInput } from '../../context/theme/defaultValues'; import { EyeIcon, EyeMuteIcon } from '../../icons'; export const Input = forwardRef( ( { bg = 'input', borderColor = 'border', color = 'accents.2', defaultValue, onChange, error, editable = true, isDisabled, placeholder, shape = 'rounded', placeholderColor = 'border', startContent, size = 'middle', style = {}, helperText, type = 'default', endContent: endContentProp, withMarginBottom, Component = TextInput, sx, styles, ...rest }, _ref ) => { const theme = useTheme(); const { ref } = useCreateRef(_ref, null); // states const [show, setShow] = React.useState(false); const endContent = useMemo(() => { if (endContentProp) return endContentProp; if (type === 'password') { return !show ? ( ) : ( ); } return null; }, [borderColor, endContentProp, show, type]); const onInternalChange = (v: string) => { if (onChange) { onChange(v); } }; const propsPassword = React.useMemo(() => { if (type !== 'password') { return {}; } return { onPress: () => setShow((prev) => !prev) }; }, [type]); return ( {/* prefix icon */} {startContent && ( {cloneElement(startContent, { color: theme.colors.get('border'), ...startContent.props })} )} {endContent && ( {React.cloneElement(endContent, { color: theme.colors.get('border'), ...endContent.props })} )} {(error || helperText) && ( {helperText} )} ); } ); const wrapperIcon: SxProps = { position: 'absolute', width: 40, height: '100%', bottom: 0, alignItems: 'center', justifyContent: 'center', backgroundColor: 'transparent', zIndex: 2 };