gab-social/app/javascript/gabsocial/features/compose/components/character_counter/character_counter.js

28 lines
597 B
JavaScript

import { length } from 'stringz';
import classNames from 'classnames';
import './character_counter.scss';
export default class CharacterCounter extends PureComponent {
static propTypes = {
text: PropTypes.string.isRequired,
max: PropTypes.number.isRequired,
};
render () {
const diff = this.props.max - length(this.props.text);
const classes = classNames('character-counter', {
'character-counter--over': (diff < 0),
});
return (
<div className='character-counter__wrapper'>
<span className={classes}>{diff}</span>
</div>
)
}
}