mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-19 01:24:18 +00:00
67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
const PropTypes = require('prop-types')
|
|
const React = require('react')
|
|
const FileInputPlugin = require('@uppy/file-input')
|
|
const propTypes = require('./propTypes')
|
|
|
|
const h = React.createElement
|
|
|
|
/**
|
|
* React component that renders an area in which files can be dropped to be
|
|
* uploaded.
|
|
*/
|
|
|
|
class FileInput extends React.Component {
|
|
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:FileInput',
|
|
...this.props,
|
|
target: this.container,
|
|
}
|
|
delete options.uppy
|
|
|
|
uppy.use(FileInputPlugin, 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
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
FileInput.propTypes = {
|
|
uppy: propTypes.uppy,
|
|
locale: propTypes.locale,
|
|
pretty: PropTypes.bool,
|
|
inputName: PropTypes.string,
|
|
}
|
|
FileInput.defaultProps = {
|
|
}
|
|
|
|
module.exports = FileInput
|