StatusBar.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. const h = React.createElement
  6. /**
  7. * React component that renders a status bar containing upload progress and speed,
  8. * processing progress and pause/resume/cancel controls.
  9. */
  10. class StatusBar extends React.Component {
  11. componentDidMount () {
  12. this.installPlugin()
  13. }
  14. componentDidUpdate (prevProps) {
  15. if (prevProps.uppy !== this.props.uppy) {
  16. this.uninstallPlugin(prevProps)
  17. this.installPlugin()
  18. }
  19. }
  20. componentWillUnmount () {
  21. this.uninstallPlugin()
  22. }
  23. installPlugin () {
  24. const uppy = this.props.uppy
  25. const options = Object.assign(
  26. { id: 'react:StatusBar' },
  27. this.props,
  28. { target: this.container }
  29. )
  30. delete options.uppy
  31. uppy.use(StatusBarPlugin, options)
  32. this.plugin = uppy.getPlugin(options.id)
  33. }
  34. uninstallPlugin (props = this.props) {
  35. const uppy = props.uppy
  36. uppy.removePlugin(this.plugin)
  37. }
  38. render () {
  39. return h('div', {
  40. ref: (container) => {
  41. this.container = container
  42. }
  43. })
  44. }
  45. }
  46. StatusBar.propTypes = {
  47. uppy: uppyPropType,
  48. hideAfterFinish: PropTypes.bool,
  49. showProgressDetails: PropTypes.bool
  50. }
  51. StatusBar.defaultProps = {
  52. }
  53. module.exports = StatusBar