2017-04-21 14:05:35 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 11:15:17 -04:00
|
|
|
|
2017-04-25 11:37:51 -04:00
|
|
|
import { length } from 'stringz';
|
2016-08-31 10:15:12 -04:00
|
|
|
|
2024-01-25 10:41:31 -05:00
|
|
|
export const CharacterCounter = ({ text, max }) => {
|
|
|
|
const diff = max - length(text);
|
2016-08-31 10:15:12 -04:00
|
|
|
|
2024-01-25 10:41:31 -05:00
|
|
|
if (diff < 0) {
|
|
|
|
return <span className='character-counter character-counter--over'>{diff}</span>;
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2017-04-17 04:34:33 -04:00
|
|
|
|
2024-01-25 10:41:31 -05:00
|
|
|
return <span className='character-counter'>{diff}</span>;
|
|
|
|
};
|
2016-08-25 13:52:55 -04:00
|
|
|
|
2024-01-25 10:41:31 -05:00
|
|
|
CharacterCounter.propTypes = {
|
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
max: PropTypes.number.isRequired,
|
|
|
|
};
|