import React from 'react'; import type { IconName } from '@hero-design/rn'; import { Icon } from '@hero-design/rn'; import type { State } from './StyledTextInput'; interface SuffixComponentProps { /** Current input state for styling decisions */ state: State; /** Whether to show loading spinner instead of suffix */ loading: boolean; /** Icon name string or custom React element to display */ suffix?: IconName | React.ReactElement; } /** * SuffixComponent * * Renders suffix content (icons or custom elements) on the right side of the TextInput. * Handles loading states and custom elements. * * Key Features: * - Loading state handling: shows spinner when loading is true * - Icon rendering: supports string icon names from the design system * - Custom element support: can render any React element as suffix * - State-aware styling: adjusts icon intent based on input state * - Spinning animation: loading icons automatically spin * - Proper test IDs for automated testing * * Rendering Priority: * 1. Loading state: Shows 'loading' icon with spin animation * 2. String icon name: Renders Icon component with state-based intent * 3. Custom element: Renders the provided React element as-is * 4. No suffix: Renders null * * Icon Intent Logic: * - Disabled state: Uses 'disabled-text' intent * - All other states: Uses 'text' intent * * @param props - The component props (see SuffixComponentProps interface for details) */ const SuffixComponent: React.FC = ({ state, loading, suffix, }) => { // Loading state overrides suffix const actualSuffix = loading ? 'loading' : suffix; if (typeof actualSuffix === 'string') { // Render icon from design system return ( ); } if (actualSuffix) { // Render custom element return suffix as React.ReactElement; } return null; }; SuffixComponent.displayName = 'SuffixComponent'; export default React.memo(SuffixComponent);