1 | const React = require('react')
|
2 | const PropTypes = require('prop-types')
|
3 | const ProgressBarPlugin = require('@uppy/progress-bar')
|
4 | const uppyPropType = require('./propTypes').uppy
|
5 |
|
6 | const h = React.createElement
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | class ProgressBar extends React.Component {
|
13 | componentDidMount () {
|
14 | this.installPlugin()
|
15 | }
|
16 |
|
17 | componentDidUpdate (prevProps) {
|
18 | if (prevProps.uppy !== this.props.uppy) {
|
19 | this.uninstallPlugin(prevProps)
|
20 | this.installPlugin()
|
21 | }
|
22 | }
|
23 |
|
24 | componentWillUnmount () {
|
25 | this.uninstallPlugin()
|
26 | }
|
27 |
|
28 | installPlugin () {
|
29 | const uppy = this.props.uppy
|
30 | const options = Object.assign(
|
31 | { id: 'react:ProgressBar' },
|
32 | this.props,
|
33 | { target: this.container }
|
34 | )
|
35 | delete options.uppy
|
36 |
|
37 | uppy.use(ProgressBarPlugin, options)
|
38 |
|
39 | this.plugin = uppy.getPlugin(options.id)
|
40 | }
|
41 |
|
42 | uninstallPlugin (props = this.props) {
|
43 | const uppy = props.uppy
|
44 |
|
45 | uppy.removePlugin(this.plugin)
|
46 | }
|
47 |
|
48 | render () {
|
49 | return h('div', {
|
50 | ref: (container) => {
|
51 | this.container = container
|
52 | }
|
53 | })
|
54 | }
|
55 | }
|
56 |
|
57 | ProgressBar.propTypes = {
|
58 | uppy: uppyPropType,
|
59 | fixed: PropTypes.bool,
|
60 | hideAfterFinish: PropTypes.bool
|
61 | }
|
62 | ProgressBar.defaultProps = {
|
63 | }
|
64 |
|
65 | module.exports = ProgressBar
|