闭社主体 forked from https://github.com/tootsuite/mastodon
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.

27 lines
626 B

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