likeopera-frontend/ProgressBar.js

41 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2018-12-02 19:27:22 +03:00
import React from 'react';
2016-10-03 16:55:14 +03:00
2018-12-02 19:27:22 +03:00
export default class ProgressBar extends React.PureComponent
{
state = { width: '' }
render()
2016-10-03 16:55:14 +03:00
{
return <div className="progress-bar" ref="pbar" style={{ display: this.props.text ? '' : 'none' }}>
<div className="pending" style={{ width: this.state.width }}>{this.props.text} ({this.props.progress||0}%)</div>
<div className="clip" style={{ width: (this.props.progress||0)+'%', overflow: 'hidden' }}>
<div className="done" ref="pdone" style={{ width: this.state.width }}>{this.props.text} ({this.props.progress||0}%)</div>
</div>
</div>
2018-12-02 19:27:22 +03:00
}
componentDidUpdate(prevProps, prevState)
2016-10-03 16:55:14 +03:00
{
if (!prevState.width)
{
setTimeout(this.onResize, 50);
}
2018-12-02 19:27:22 +03:00
}
onResize = () =>
2016-10-03 16:55:14 +03:00
{
this.setState({ width: this.refs.pbar.offsetWidth });
2018-12-02 19:27:22 +03:00
}
componentDidMount()
2016-10-03 16:55:14 +03:00
{
window.addEventListener('resize', this.onResize);
this.onResize();
2018-12-02 19:27:22 +03:00
}
componentWillUnmount()
2016-10-03 16:55:14 +03:00
{
window.removeEventListener('resize', this.onResize);
}
2018-12-02 19:27:22 +03:00
}