1 | const React = require('react')
|
2 | const PropTypes = require('prop-types')
|
3 | const StatusBarPlugin = require('@uppy/status-bar')
|
4 | const uppyPropType = require('./propTypes').uppy
|
5 |
|
6 | const h = React.createElement
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class 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 |
|
58 | StatusBar.propTypes = {
|
59 | uppy: uppyPropType,
|
60 | hideAfterFinish: PropTypes.bool,
|
61 | showProgressDetails: PropTypes.bool
|
62 | }
|
63 | StatusBar.defaultProps = {
|
64 | }
|
65 |
|
66 | module.exports = StatusBar
|