UNPKG

@nexara/nativeflow

Version:

Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.

116 lines (115 loc) 3.82 kB
"use strict"; import { forwardRef, useMemo } from 'react'; import { TextInput, StyleSheet } from 'react-native'; import { responsiveFontSize, verticalScale, horizontalScale } from "../../helpers/ResponsiveCalculations.js"; import { useTheme } from "../../hooks/index.js"; import { StyledText, StyledView } from "../StyledComponents/index.js"; import generateColors from "./generateColors.js"; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; const UserInput = /*#__PURE__*/forwardRef(({ variant = 'standard', label, bg, br = 10, stroke = 1, labelColor, textVariant = { label: 'h5', inputText: 'h5', helperText: 'h6' }, inputTextColor, strokeColor, cursorColor, placeholderColor, inputFs = 13, labelFs, helperTextFS, placeholder = 'Please enter...', disabled = false, isError = false, helperText = '', multiline = false, renderLeftIcon, renderRightIcon, styles, ...rest }, ref) => { const theme = useTheme(); const STYLES = useMemo(Styles, []); const { computedCursorColor, computedPlaceholderColor, computedLabelColor } = useMemo(() => generateColors(theme, isError, cursorColor, placeholderColor, labelColor), [theme, isError, cursorColor, placeholderColor, labelColor]); const dynamicStyles = { INPUT_CONT: { alignItems: multiline ? 'flex-start' : 'center', backgroundColor: disabled ? theme.colors.disable : bg ?? theme.colors.inputBgColor, borderColor: isError ? theme.colors.error : strokeColor ?? theme.colors.outline, borderWidth: variant === 'standard' ? 0 : stroke, borderBottomWidth: stroke, borderRadius: verticalScale(br), height: multiline ? undefined : verticalScale(48), paddingVertical: multiline ? horizontalScale(10) : undefined }, INPUT: { color: disabled ? theme.colors.textDisable : isError ? theme.colors.error : inputTextColor ?? theme.colors.textPrimary, //@ts-ignore fontSize: responsiveFontSize(theme.typography.variantSizes[textVariant.inputText] ?? inputFs), textAlignVertical: multiline ? 'top' : 'center', minHeight: multiline ? 100 : undefined, maxHeight: multiline ? 150 : undefined }, ERROR_HELPER_TEXT: { color: theme.colors.error } }; return /*#__PURE__*/_jsx(_Fragment, { children: /*#__PURE__*/_jsxs(StyledView, { gap: verticalScale(5), style: styles?.mainContainer, w: "100%", children: [label && /*#__PURE__*/_jsx(StyledText, { variant: textVariant?.label, fs: labelFs, color: computedLabelColor, style: styles?.label, children: label }), /*#__PURE__*/_jsxs(StyledView, { style: [STYLES.INPUT_CONT, dynamicStyles.INPUT_CONT, styles?.inputContainer], children: [renderLeftIcon, /*#__PURE__*/_jsx(TextInput, { ref: ref, style: [STYLES.INPUT, dynamicStyles.INPUT, styles?.input], placeholder: placeholder, placeholderTextColor: computedPlaceholderColor, editable: !disabled, multiline: multiline, cursorColor: computedCursorColor, ...rest }), renderRightIcon] }), isError && helperText && /*#__PURE__*/_jsx(StyledText, { variant: textVariant?.helperText, fs: helperTextFS, style: [STYLES.ERROR_HELPER_TEXT, dynamicStyles.ERROR_HELPER_TEXT, styles?.helperText], children: helperText })] }) }); }); export default UserInput; const Styles = () => StyleSheet.create({ INPUT_CONT: { flexDirection: 'row', paddingHorizontal: horizontalScale(14), gap: horizontalScale(10) }, INPUT: { padding: 0, flex: 1 }, ERROR_HELPER_TEXT: { paddingHorizontal: 5 } }); //# sourceMappingURL=UserInput.js.map