2019-07-02 08:10:25 +01:00
|
|
|
import { length } from 'stringz';
|
2019-08-09 17:06:27 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import './character_counter.scss';
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2019-07-29 20:20:00 +01:00
|
|
|
export default class CharacterCounter extends PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
max: PropTypes.number.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const diff = this.props.max - length(this.props.text);
|
2019-08-09 17:06:27 +01:00
|
|
|
|
|
|
|
const classes = classNames('character-counter', {
|
|
|
|
'character-counter--over': (diff < 0),
|
|
|
|
});
|
|
|
|
|
|
|
|
<div className='character-counter__wrapper'>
|
|
|
|
<span className={classes}>{diff}</span>
|
|
|
|
</div>
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|