-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@uppy/progress-bar: refactor to ESM (#3706)
- Loading branch information
Showing
4 changed files
with
61 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1 @@ | ||
const { UIPlugin } = require('@uppy/core') | ||
const { h } = require('preact') | ||
|
||
/** | ||
* Progress bar | ||
* | ||
*/ | ||
module.exports = class ProgressBar extends UIPlugin { | ||
static VERSION = require('../package.json').version | ||
|
||
constructor (uppy, opts) { | ||
super(uppy, opts) | ||
this.id = this.opts.id || 'ProgressBar' | ||
this.title = 'Progress Bar' | ||
this.type = 'progressindicator' | ||
|
||
// set default options | ||
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() | ||
} | ||
} | ||
export { default } from './ProgressBar.jsx' |