mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-19 01:24:18 +00:00
66 lines
1.3 KiB
JavaScript
66 lines
1.3 KiB
JavaScript
const React = require('react')
|
|
const PropTypes = require('prop-types')
|
|
const StatusBarPlugin = require('@uppy/status-bar')
|
|
const uppyPropType = require('./propTypes').uppy
|
|
|
|
const h = React.createElement
|
|
|
|
/**
|
|
* React component that renders a status bar containing upload progress and speed,
|
|
* processing progress and pause/resume/cancel controls.
|
|
*/
|
|
|
|
class StatusBar extends React.Component {
|
|
componentDidMount () {
|
|
this.installPlugin()
|
|
}
|
|
|
|
componentDidUpdate (prevProps) {
|
|
if (prevProps.uppy !== this.props.uppy) {
|
|
this.uninstallPlugin(prevProps)
|
|
this.installPlugin()
|
|
}
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
this.uninstallPlugin()
|
|
}
|
|
|
|
installPlugin () {
|
|
const uppy = this.props.uppy
|
|
const options = Object.assign(
|
|
{ id: 'react:StatusBar' },
|
|
this.props,
|
|
{ target: this.container }
|
|
)
|
|
delete options.uppy
|
|
|
|
uppy.use(StatusBarPlugin, options)
|
|
|
|
this.plugin = uppy.getPlugin(options.id)
|
|
}
|
|
|
|
uninstallPlugin (props = this.props) {
|
|
const uppy = props.uppy
|
|
|
|
uppy.removePlugin(this.plugin)
|
|
}
|
|
|
|
render () {
|
|
return h('div', {
|
|
ref: (container) => {
|
|
this.container = container
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
StatusBar.propTypes = {
|
|
uppy: uppyPropType,
|
|
hideAfterFinish: PropTypes.bool,
|
|
showProgressDetails: PropTypes.bool
|
|
}
|
|
StatusBar.defaultProps = {
|
|
}
|
|
|
|
module.exports = StatusBar
|