bigbuffet-rw/app/soapbox/features/compose/components/text_character_counter.js

32 lines
684 B
JavaScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { length } from 'stringz';
export default class TextCharacterCounter extends React.PureComponent {
static propTypes = {
text: PropTypes.string.isRequired,
max: PropTypes.number.isRequired,
};
checkRemainingText(diff) {
2022-03-21 11:09:01 -07:00
return (
<span
className={classNames('text-sm font-semibold', {
'text-gray-400': diff >= 0,
'text-danger-600': diff < 0,
})}
>
{diff}
</span>
);
}
render() {
const diff = this.props.max - length(this.props.text);
return this.checkRemainingText(diff);
}
}