You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
599 B

  1. import PropTypes from 'prop-types';
  2. import { length } from 'stringz';
  3. class CharacterCounter extends React.PureComponent {
  4. checkRemainingText (diff) {
  5. if (diff < 0) {
  6. return <span className='character-counter character-counter--over'>{diff}</span>;
  7. }
  8. return <span className='character-counter'>{diff}</span>;
  9. }
  10. render () {
  11. const diff = this.props.max - length(this.props.text);
  12. return this.checkRemainingText(diff);
  13. }
  14. }
  15. CharacterCounter.propTypes = {
  16. text: PropTypes.string.isRequired,
  17. max: PropTypes.number.isRequired
  18. }
  19. export default CharacterCounter;