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