ProgressBar.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const Plugin = require('../core/Plugin')
  2. const { h } = require('preact')
  3. /**
  4. * Progress bar
  5. *
  6. */
  7. module.exports = class ProgressBar extends Plugin {
  8. constructor (uppy, opts) {
  9. super(uppy, opts)
  10. this.id = this.opts.id || 'ProgressBar'
  11. this.title = 'Progress Bar'
  12. this.type = 'progressindicator'
  13. // set default options
  14. const defaultOptions = {
  15. target: 'body',
  16. replaceTargetContent: false,
  17. fixed: false,
  18. hideAfterFinish: true
  19. }
  20. // merge default options with the ones set by user
  21. this.opts = Object.assign({}, defaultOptions, opts)
  22. this.render = this.render.bind(this)
  23. }
  24. render (state) {
  25. const progress = state.totalProgress || 0
  26. const isHidden = progress === 100 && this.opts.hideAfterFinish
  27. return <div class="uppy uppy-ProgressBar" style={{ position: this.opts.fixed ? 'fixed' : 'initial' }} aria-hidden={isHidden}>
  28. <div class="uppy-ProgressBar-inner" style={{ width: progress + '%' }} />
  29. <div class="uppy-ProgressBar-percentage">{progress}</div>
  30. </div>
  31. }
  32. install () {
  33. const target = this.opts.target
  34. if (target) {
  35. this.mount(target, this)
  36. }
  37. }
  38. uninstall () {
  39. this.unmount()
  40. }
  41. }