2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2022-04-10 03:46:25 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
|
|
|
|
interface ITextCharacterCounter {
|
2023-02-15 13:26:27 -08:00
|
|
|
max: number
|
|
|
|
text: string
|
2022-04-10 03:46:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const TextCharacterCounter: React.FC<ITextCharacterCounter> = ({ text, max }) => {
|
|
|
|
const checkRemainingText = (diff: number) => {
|
|
|
|
return (
|
|
|
|
<span
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx('text-sm font-medium', {
|
2022-07-22 10:30:16 -07:00
|
|
|
'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;
|