2020-02-14 00:40:04 +00:00
|
|
|
import { length } from 'stringz'
|
2019-08-09 17:06:27 +01:00
|
|
|
|
2019-07-29 20:20:00 +01:00
|
|
|
export default class CharacterCounter extends PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
text: PropTypes.string.isRequired,
|
|
|
|
max: PropTypes.number.isRequired,
|
2020-02-14 00:40:04 +00:00
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
render () {
|
2020-02-14 00:40:04 +00:00
|
|
|
const radius = 12
|
|
|
|
const circumference = 2 * Math.PI * radius
|
|
|
|
const diff = length(this.props.text) / this.props.max
|
|
|
|
const dashoffset = circumference * (1 - diff)
|
2019-08-09 17:06:27 +01:00
|
|
|
|
2020-01-27 19:46:42 +00:00
|
|
|
return (
|
2020-02-19 23:57:07 +00:00
|
|
|
<div className={[_s.default, _s.marginRight10PX, _s.justifyContentCenter, _s.alignItemsCenter].join(' ')}>
|
2020-02-14 00:40:04 +00:00
|
|
|
<svg width="32" height="32" viewBox="0 0 32 32">
|
2020-02-19 23:57:07 +00:00
|
|
|
<circle fill='none' cx="16" cy="16" r="12" fill="none" stroke="#e6e6e6" strokeWidth="2" />
|
2020-02-14 00:40:04 +00:00
|
|
|
<circle style={{
|
|
|
|
// transform: 'rotate(-90deg)',
|
|
|
|
strokeDashoffset: dashoffset,
|
|
|
|
strokeDasharray: circumference,
|
|
|
|
}}
|
|
|
|
fill='none'
|
|
|
|
cx="16"
|
|
|
|
cy="16"
|
|
|
|
r="12"
|
|
|
|
strokeWidth="2"
|
|
|
|
strokeLinecap='round'
|
|
|
|
stroke='#21cf7a'
|
|
|
|
/>
|
|
|
|
</svg>
|
2020-01-27 19:46:42 +00:00
|
|
|
</div>
|
|
|
|
)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|