import React from 'react'; import type { IconName } from '@hero-design/rn'; import { Icon } from '@hero-design/rn'; import type { ViewProps } from 'react-native'; import { View } from 'react-native'; import { StyledPrefixComponentWrapper, type State } from './StyledTextInput'; interface PrefixComponentProps extends ViewProps { /** Current input state for styling decisions */ state: State; /** Icon name string or custom React element to display */ prefix?: IconName | React.ReactElement; } /** * PrefixComponent * * Renders prefix content (icons or custom elements) on the left side of the TextInput, * before the user's input cursor. * * Key Features: * - Icon rendering: supports string icon names from the design system * - Custom element support: can render any React element as prefix * - State-aware styling: adjusts icon intent based on input state * - Consistent sizing: uses 'xsmall' size for visual balance * - Proper test IDs for automated testing * * Rendering Logic: * 1. String icon name: Renders Icon component with state-based intent * 2. Custom element: Renders the provided React element as-is * 3. No prefix: Renders null * * Icon Intent Logic: * - Disabled state: Uses 'disabled-text' intent for muted appearance * - All other states: Uses 'text' intent for normal appearance * * Visual Positioning: * - Positioned before the text input cursor * - Uses smaller 'xsmall' size to avoid overwhelming the input * - Maintains proper spacing via parent container * * @param props - The component props (see PrefixComponentProps interface for details) */ const PrefixComponent: React.FC = ({ state, prefix, ...rest }) => { const actualPrefix = typeof prefix === 'string' ? prefix : ''; if (actualPrefix) { return ( ); } if (React.isValidElement(prefix)) { return ( {prefix} ); } return null; }; PrefixComponent.displayName = 'PrefixComponent'; export default React.memo(PrefixComponent);