UNPKG

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