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
607 B
26 lines
607 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
|
export default class CharacterCounter extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
text: PropTypes.string.isRequired,
|
||
8 years ago
|
max: PropTypes.number.isRequired,
|
||
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
|
}
|
||
7 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
|
return this.checkRemainingText(diff);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
}
|