import { TextInput, View, StyleSheet, Animated, Pressable } from 'react-native'; import { Typography, styled } from '@hero-design/rn'; export type State = 'default' | 'filled' | 'disabled' | 'readonly' | 'error'; type Variant = 'text' | 'textarea'; const getZIndexByState = ({ themeFocused, themeHasError, }: { themeFocused: boolean; themeHasError: boolean; }) => { if (themeFocused) { return 2; } if (themeHasError) { return 1; } return 0; }; const StyledContainer = styled(Pressable)<{ themeFocused: boolean; themeHasError: boolean; themeGroupStyleEnabled: boolean; }>(({ theme, themeFocused, themeHasError, themeGroupStyleEnabled }) => ({ width: '100%', flexDirection: 'row', paddingHorizontal: theme.__hd__.textInput.space.containerPadding, minHeight: theme.__hd__.textInput.sizes.containerMinHeight, marginTop: theme.__hd__.textInput.space.containerMarginTop, ...(themeGroupStyleEnabled && { zIndex: getZIndexByState({ themeFocused, themeHasError }), }), })); const StyledFloatingLabelContainer = styled(Animated.View)<{ themeVariant: Variant; }>(({ themeVariant }) => ({ flexDirection: 'row', alignItems: themeVariant === 'text' ? 'center' : 'flex-start', backgroundColor: 'transparent', })); const StyledLabel = styled(Typography.Caption)<{ themeState: State; }>(({ theme, themeState }) => ({ color: theme.__hd__.textInput.colors.labels[themeState], })); const StyledErrorRow = styled(View)(({ theme }) => ({ marginRight: theme.__hd__.textInput.space.errorContainerMarginRight, flexDirection: 'row', alignItems: 'center', flex: 1, flexGrow: 4, })); const StyledError = styled(Typography.Caption)(({ theme }) => ({ color: theme.__hd__.textInput.colors.error, marginLeft: theme.__hd__.textInput.space.errorMarginLeft, })); const StyledCharacterCount = styled(Typography.Caption)<{ themeState: State; }>(({ theme, themeState }) => ({ color: theme.__hd__.textInput.colors.maxLengthLabels[themeState], flex: 1, flexGrow: 1, textAlign: 'right', })); const StyledHelperText = Typography.Caption; const StyledTextInput = styled(TextInput)<{ themeVariant: Variant }>( ({ theme, themeVariant }) => ({ textAlignVertical: themeVariant === 'text' ? 'center' : 'top', fontSize: theme.__hd__.textInput.fontSizes.text, flexGrow: 2, paddingVertical: 0, maxHeight: theme.__hd__.textInput.sizes.textInputMaxHeight, minHeight: theme.__hd__.textInput.sizes.textInputMinHeight, height: themeVariant === 'text' ? undefined : theme.__hd__.textInput.sizes.textareaHeight, fontFamily: theme.__hd__.textInput.fonts.text, }) ); const StyledBorder = styled(View)<{ themeState: State; themeFocused: boolean; }>(({ theme, themeFocused, themeState }) => ({ ...StyleSheet.absoluteFillObject, borderWidth: theme.__hd__.textInput.borderWidths.container.normal, borderRadius: theme.__hd__.textInput.radii.container, borderColor: themeFocused ? theme.__hd__.textInput.colors.borders.focused : theme.__hd__.textInput.colors.borders[themeState], })); const StyledInputWrapper = styled(View)(({ theme }) => ({ flexDirection: 'column', flex: 1, backgroundColor: 'transparent', borderRadius: theme.__hd__.textInput.radii.container, marginBottom: theme.__hd__.textInput.space.inputWrapperMarginVertical, marginTop: theme.__hd__.textInput.space.inputWrapperMarginVertical, overflow: 'hidden', })); const StyledInputRow = styled(Pressable)<{ themeOpacity: number }>( ({ themeOpacity }) => ({ flexDirection: 'row', alignItems: 'center', flexGrow: 2, flexShrink: 1, opacity: themeOpacity, }) ); const StyledPrefixComponentWrapper = styled(View)(({ theme }) => ({ marginRight: theme.__hd__.textInput.space.prefixAndInputContainerGap, })); const StyledBottomContainer = styled(View)(() => ({ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', })); const StyledSuffixContainer = styled(View)(() => ({ flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', })); export { StyledInputWrapper, StyledTextInput, StyledError, StyledCharacterCount, StyledContainer, StyledErrorRow, StyledHelperText, StyledInputRow, StyledFloatingLabelContainer, StyledBorder, StyledBottomContainer, StyledSuffixContainer, StyledLabel, StyledPrefixComponentWrapper, };