logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

character_counter.js (607B)


  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { length } from 'stringz';
  4. export default 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. }