mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-19 01:24:18 +00:00
* Allowed HTML Attributes to be passed via props This fix still needs some work, as certain attributes could be passed to Uppy or as an HTML attribute, such as target When this is fixed, this will resolve #2403 * Removed shared attributes I removed the ability to use certain attributes ('width', 'height', and 'target') and pass them down as Props to the div due to that fact that Uppy relies on them * Add typescript types for the HTML attributes * Moved common.js to getHTMLProps.js * Fixed import * Converted `possibleStandardNames` to an Array * Fix import * Fix tests
72 lines
1.4 KiB
JavaScript
72 lines
1.4 KiB
JavaScript
const React = require('react')
|
|
const PropTypes = require('prop-types')
|
|
const ProgressBarPlugin = require('@uppy/progress-bar')
|
|
const uppyPropType = require('./propTypes').uppy
|
|
const getHTMLProps = require('./getHTMLProps')
|
|
|
|
const h = React.createElement
|
|
|
|
/**
|
|
* React component that renders a progress bar at the top of the page.
|
|
*/
|
|
|
|
class ProgressBar extends React.Component {
|
|
constructor (props) {
|
|
super(props)
|
|
this.validProps = getHTMLProps(props)
|
|
}
|
|
|
|
componentDidMount () {
|
|
this.installPlugin()
|
|
}
|
|
|
|
componentDidUpdate (prevProps) {
|
|
if (prevProps.uppy !== this.props.uppy) {
|
|
this.uninstallPlugin(prevProps)
|
|
this.installPlugin()
|
|
}
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
this.uninstallPlugin()
|
|
}
|
|
|
|
installPlugin () {
|
|
const { uppy } = this.props
|
|
const options = {
|
|
id: 'react:ProgressBar',
|
|
...this.props,
|
|
target: this.container,
|
|
}
|
|
delete options.uppy
|
|
|
|
uppy.use(ProgressBarPlugin, options)
|
|
|
|
this.plugin = uppy.getPlugin(options.id)
|
|
}
|
|
|
|
uninstallPlugin (props = this.props) {
|
|
const { uppy } = props
|
|
|
|
uppy.removePlugin(this.plugin)
|
|
}
|
|
|
|
render () {
|
|
return h('div', {
|
|
ref: (container) => {
|
|
this.container = container
|
|
},
|
|
...this.validProps,
|
|
})
|
|
}
|
|
}
|
|
|
|
ProgressBar.propTypes = {
|
|
uppy: uppyPropType,
|
|
fixed: PropTypes.bool,
|
|
hideAfterFinish: PropTypes.bool,
|
|
}
|
|
ProgressBar.defaultProps = {
|
|
}
|
|
|
|
module.exports = ProgressBar
|