/* eslint-disable camelcase */ import React, { FC, } from 'react'; import { replace } from '../lib/helpers'; import { useCharacterCount } from '../lib/hooks'; type Props = { children: React.ReactNode; type: 'recommended' | 'allowed'; initialChars: number; maxChars: number; translations: IGenericTranslation['generics']['forms']; }; const AUCharacterCountComponent: FC = ({ children, type, initialChars, maxChars, translations, }) => { const { ref, remaining, overflow, } = useCharacterCount(type, initialChars, maxChars); const { character_count } = translations; return (
{children}
{`${replace(character_count.overflow.message[type], ['maxchars'], [maxChars.toString()])}`} {' '} {`${replace(character_count.overflow.count[type][overflow === 1 ? 'one' : 'other'], ['overflow'], [overflow.toString()])}`} {' '} {`${replace(character_count.count_down[remaining === 1 ? 'one' : 'other'], ['remaining'], [remaining.toString()])}`}
); }; AUCharacterCountComponent.displayName = 'AUCharacterCountComponent'; export default AUCharacterCountComponent;