2022-08-31 02:35:06 -07:00
|
|
|
import classNames from 'clsx';
|
2022-04-10 03:46:25 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
|
|
|
|
interface ITextCharacterCounter {
|
|
|
|
max: number,
|
|
|
|
text: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
const TextCharacterCounter: React.FC<ITextCharacterCounter> = ({ text, max }) => {
|
|
|
|
const checkRemainingText = (diff: number) => {
|
|
|
|
return (
|
|
|
|
<span
|
2022-07-22 10:30:16 -07:00
|
|
|
className={classNames('text-sm font-medium', {
|
|
|
|
'text-gray-700': diff >= 0,
|
|
|
|
'text-secondary-600': diff < 0,
|
2022-04-10 03:46:25 -07:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
{diff}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const diff = max - length(text);
|
|
|
|
return checkRemainingText(diff);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TextCharacterCounter;
|