StatusBar.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const html = require('yo-yo')
  2. module.exports = (props) => {
  3. props = props || {}
  4. const isHidden = props.totalFileCount === 0 || !props.isUploadStarted
  5. return html`
  6. <div class="UppyDashboard-statusBar
  7. ${props.isAllComplete ? 'is-complete' : ''}"
  8. aria-hidden="${isHidden}">
  9. <div class="UppyDashboard-statusBarProgress" style="width: ${props.totalProgress}%"></div>
  10. <div class="UppyDashboard-statusBarContent">
  11. ${props.isUploadStarted && !props.isAllComplete
  12. ? !props.isAllPaused
  13. ? html`<span>${pauseResumeButtons(props)} Uploading... ${props.totalProgress || 0}%・${props.complete} / ${props.inProgress}・${props.totalETA}・↑ ${props.totalSpeed}/s</span>`
  14. : html`<span>${pauseResumeButtons(props)} Paused・${props.totalProgress}%</span>`
  15. : null
  16. }
  17. ${props.isAllComplete
  18. ? html`<span><svg class="UppyDashboard-statusBarAction UppyIcon" width="18" height="17" viewBox="0 0 23 17">
  19. <path d="M8.944 17L0 7.865l2.555-2.61 6.39 6.525L20.41 0 23 2.645z" />
  20. </svg>Upload complete・${props.totalProgress}%</span>`
  21. : null
  22. }
  23. </div>
  24. </div>
  25. `
  26. }
  27. const pauseResumeButtons = (props) => {
  28. console.log(props.resumableUploads)
  29. return html`<button class="UppyDashboard-statusBarAction" type="button" onclick=${() => togglePauseResume(props)}>
  30. ${props.resumableUploads
  31. ? props.isAllPaused
  32. ? html`<svg class="UppyIcon" width="15" height="17" viewBox="0 0 11 13">
  33. <path d="M1.26 12.534a.67.67 0 0 1-.674.012.67.67 0 0 1-.336-.583v-11C.25.724.38.5.586.382a.658.658 0 0 1 .673.012l9.165 5.5a.66.66 0 0 1 .325.57.66.66 0 0 1-.325.573l-9.166 5.5z" />
  34. </svg>`
  35. : html`<svg class="UppyIcon" width="16" height="17" viewBox="0 0 12 13">
  36. <path d="M4.888.81v11.38c0 .446-.324.81-.722.81H2.722C2.324 13 2 12.636 2 12.19V.81c0-.446.324-.81.722-.81h1.444c.398 0 .722.364.722.81zM9.888.81v11.38c0 .446-.324.81-.722.81H7.722C7.324 13 7 12.636 7 12.19V.81c0-.446.324-.81.722-.81h1.444c.398 0 .722.364.722.81z"/>
  37. </svg>`
  38. : html`<svg class="UppyIcon" width="16px" height="16px" viewBox="0 0 19 19">
  39. <path d="M17.318 17.232L9.94 9.854 9.586 9.5l-.354.354-7.378 7.378h.707l-.62-.62v.706L9.318 9.94l.354-.354-.354-.354L1.94 1.854v.707l.62-.62h-.706l7.378 7.378.354.354.354-.354 7.378-7.378h-.707l.622.62v-.706L9.854 9.232l-.354.354.354.354 7.378 7.378.708-.707-7.38-7.378v.708l7.38-7.38.353-.353-.353-.353-.622-.622-.353-.353-.354.352-7.378 7.38h.708L2.56 1.23 2.208.88l-.353.353-.622.62-.353.355.352.353 7.38 7.38v-.708l-7.38 7.38-.353.353.352.353.622.622.353.353.354-.353 7.38-7.38h-.708l7.38 7.38z"/>
  40. </svg>`
  41. }
  42. </button>`
  43. }
  44. const togglePauseResume = (props) => {
  45. if (props.isAllComplete) return
  46. if (!props.resumableUploads) {
  47. return props.cancelAll()
  48. }
  49. if (props.isAllPaused) {
  50. return props.resumeAll()
  51. }
  52. return props.pauseAll()
  53. }