import { Ripple } from '../Ripple'; import { paddingInput } from '../../context'; import { StyleProp, StyleSheet, TouchableOpacity, ViewStyle } from 'react-native'; import createSxStyle from '../../lib/sx'; import { Box } from '../Box'; import React, { cloneElement, ReactNode } from 'react'; import { Text } from '../Text'; import { InputProps } from './types'; import { SizeType } from '../../@types/input'; import { SxProps } from '../../lib/styleDictionary'; import useTheme from '../../context/theme/useTheme'; import { HelperText } from '../../utils/HelperText'; export type InputBoxProps = Pick< InputProps, | 'background' | 'borderColor' | 'color' | 'shape' | 'size' | 'style' | 'error' | 'helperText' | 'placeholder' | 'isDisabled' | 'startContent' | 'endContent' > & { text?: ReactNode; size?: SizeType; onPress?: () => void; sx?: SxProps & { container?: SxProps; toggle?: SxProps; wrapperIcon?: SxProps; icon?: SxProps; text?: SxProps; helperText?: SxProps; }; styles?: { root?: StyleProp; container?: StyleProp; toggle?: StyleProp; wrapperIcon?: StyleProp; icon?: StyleProp; text?: StyleProp; helperText?: StyleProp; }; }; export function InputBox({ sx, isDisabled, styles, onPress: onPressProp, shape, size, background, error, borderColor, startContent, endContent, style, color, placeholder, text, helperText }: InputBoxProps) { const theme = useTheme(); const { colors, sizes, borderWidth } = theme; const onPress = () => { !isDisabled && onPressProp?.(); }; return ( <> {startContent && ( {cloneElement(startContent, { color: colors.border, ...startContent.props })} )} {text || placeholder} {endContent && ( {React.cloneElement(endContent, { color: colors.get('border'), ...endContent.props })} )} {(error || helperText) && ( {helperText} )} ); } const _styles = StyleSheet.create({ relative: { position: 'relative' }, wrapper: { justifyContent: 'center' }, wrapperIcon: { position: 'absolute', backgroundColor: 'transparent' }, icon: {}, modal: { flex: 1, justifyContent: 'center' } });