import React from 'react'; import { Icon } from '@hero-design/rn'; import { StyledErrorRow, StyledError, StyledHelperText, } from './StyledTextInput'; interface ErrorOrHelpTextProps { /** Error message to display (takes priority) */ error?: string; /** Helper text to display when no error */ helpText?: string; } /** * ErrorOrHelpText Component * * Displays either error messages or help text below the TextInput. * Shows error messages with a danger icon when present, otherwise displays help text. * * Key Features: * - Conditional rendering: error takes priority over help text * - Error messages include a danger icon for visual clarity * - Uses styled components for consistent theming * - Includes proper test IDs for testing * * Rendering Logic: * 1. If error exists: Show error message with danger icon * 2. If no error but helpText exists: Show help text * 3. If neither exists: Render nothing * * @param props - The component props (see ErrorOrHelpTextProps interface for details) */ const ErrorOrHelpText: React.FC = ({ error, helpText, }) => { return error ? ( // Error state: Show error message with danger icon {error} ) : ( // Help text state: Show help text if provided !!helpText && {helpText} ); }; ErrorOrHelpText.displayName = 'ErrorOrHelpText'; export default React.memo(ErrorOrHelpText);