/
ProgressBar.jsx
58 lines (49 loc) · 1.43 KB
/
ProgressBar.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { h } from 'preact'
import { UIPlugin } from '@uppy/core'
import packageJson from '../package.json'
/**
* Progress bar
*
*/
export default class ProgressBar extends UIPlugin {
static VERSION = packageJson.version
constructor (uppy, opts) {
super(uppy, opts)
this.id = this.opts.id || 'ProgressBar'
this.title = 'Progress Bar'
this.type = 'progressindicator'
// set default options, must kept in sync with @uppy/react/src/ProgressBar.js
const defaultOptions = {
target: 'body',
fixed: false,
hideAfterFinish: true,
}
// merge default options with the ones set by user
this.opts = { ...defaultOptions, ...opts }
this.render = this.render.bind(this)
}
render (state) {
const progress = state.totalProgress || 0
// before starting and after finish should be hidden if specified in the options
const isHidden = (progress === 0 || progress === 100) && this.opts.hideAfterFinish
return (
<div
className="uppy uppy-ProgressBar"
style={{ position: this.opts.fixed ? 'fixed' : 'initial' }}
aria-hidden={isHidden}
>
<div className="uppy-ProgressBar-inner" style={{ width: `${progress}%` }} />
<div className="uppy-ProgressBar-percentage">{progress}</div>
</div>
)
}
install () {
const { target } = this.opts
if (target) {
this.mount(target, this)
}
}
uninstall () {
this.unmount()
}
}