UNPKG

1.3 kBJavaScriptView Raw
1const React = require('react')
2const PropTypes = require('prop-types')
3const ProgressBarPlugin = require('@uppy/progress-bar')
4const uppyPropType = require('./propTypes').uppy
5
6const h = React.createElement
7
8/**
9 * React component that renders a progress bar at the top of the page.
10 */
11
12class 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
57ProgressBar.propTypes = {
58 uppy: uppyPropType,
59 fixed: PropTypes.bool,
60 hideAfterFinish: PropTypes.bool
61}
62ProgressBar.defaultProps = {
63}
64
65module.exports = ProgressBar