2016-08-31 23:15:12 +09:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
|
2016-08-26 02:52:55 +09:00
|
|
|
const CharacterCounter = React.createClass({
|
2016-08-31 23:15:12 +09:00
|
|
|
|
2016-08-26 02:52:55 +09:00
|
|
|
propTypes: {
|
2016-09-25 22:26:56 +09:00
|
|
|
text: React.PropTypes.string.isRequired,
|
|
|
|
max: React.PropTypes.number.isRequired
|
2016-08-26 02:52:55 +09:00
|
|
|
},
|
|
|
|
|
2016-08-31 23:15:12 +09:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-08-26 02:52:55 +09:00
|
|
|
render () {
|
2017-02-27 21:32:41 +09:00
|
|
|
const diff = this.props.max - this.props.text.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "_").length;
|
2016-09-25 22:26:56 +09:00
|
|
|
|
2016-08-26 02:52:55 +09:00
|
|
|
return (
|
|
|
|
<span style={{ fontSize: '16px', cursor: 'default' }}>
|
2016-09-25 22:26:56 +09:00
|
|
|
{diff}
|
2016-08-26 02:52:55 +09:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default CharacterCounter;
|