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.
28 lines
626 B
28 lines
626 B
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import { length } from 'stringz';
|
||
8 years ago
|
|
||
8 years ago
|
class CharacterCounter extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
checkRemainingText (diff) {
|
||
8 years ago
|
if (diff < 0) {
|
||
8 years ago
|
return <span className='character-counter character-counter--over'>{diff}</span>;
|
||
8 years ago
|
}
|
||
8 years ago
|
return <span className='character-counter'>{diff}</span>;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
render () {
|
||
8 years ago
|
const diff = this.props.max - length(this.props.text);
|
||
8 years ago
|
|
||
8 years ago
|
return this.checkRemainingText(diff);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
}
|
||
|
|
||
|
CharacterCounter.propTypes = {
|
||
|
text: PropTypes.string.isRequired,
|
||
|
max: PropTypes.number.isRequired
|
||
|
}
|
||
8 years ago
|
|
||
|
export default CharacterCounter;
|