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