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