import React from 'react'; import { StyledCharacterCount } from './StyledTextInput'; import type { State } from './StyledTextInput'; interface MaxLengthMessageProps { /** Maximum allowed characters (undefined = no limit) */ maxLength?: number; /** Current input state for styling */ state: State; /** Current number of characters entered */ currentLength: number; /** Whether to hide the counter display */ hideCharacterCount: boolean; } /** * MaxLengthMessage Component * * Displays character count information for TextInput fields with maximum length restrictions. * Shows current/max character count with state-aware styling. * * Key Features: * - Character count display: Shows "currentLength/maxLength" format * - Conditional rendering: Only shows when maxLength is set and not hidden * - State-aware styling: Colors change based on input state (error, disabled, etc.) * - Real-time updates: Updates as user types to show current progress * - Hide capability: Can be hidden via hideCharacterCount prop * * Display Logic: * - Shows only when: maxLength is defined AND hideCharacterCount is false * - Format: "currentLength/maxLength" (e.g., "25/100") * - Hidden when: maxLength is undefined OR hideCharacterCount is true * * State-based Styling: * - Uses themeState to apply appropriate colors from theme * - Error state: Shows error color to indicate validation issues * - Disabled state: Shows muted color for disabled inputs * - Normal states: Shows standard text colors * * Usage Example: * - Input with 25 characters and 100 max: displays "25/100" * - Input approaching limit: color may change based on theme * - Input over limit: error state styling applied * * @param props - The component props (see MaxLengthMessageProps interface for details) */ const MaxLengthMessage: React.FC = ({ maxLength, state, currentLength, hideCharacterCount, }) => { if (!maxLength || hideCharacterCount) { return null; } return ( {currentLength}/{maxLength} ); }; MaxLengthMessage.displayName = 'MaxLengthMessage'; export default React.memo(MaxLengthMessage);