DragDrop.js 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const React = require('react')
  2. const DragDropPlugin = require('@uppy/drag-drop')
  3. const propTypes = require('./propTypes')
  4. const h = React.createElement
  5. /**
  6. * React component that renders an area in which files can be dropped to be
  7. * uploaded.
  8. */
  9. class DragDrop extends React.Component {
  10. componentDidMount () {
  11. const uppy = this.props.uppy
  12. const options = Object.assign(
  13. { id: 'react:DragDrop' },
  14. this.props,
  15. { target: this.container }
  16. )
  17. delete options.uppy
  18. uppy.use(DragDropPlugin, options)
  19. this.plugin = uppy.getPlugin(options.id)
  20. }
  21. componentWillUnmount () {
  22. const uppy = this.props.uppy
  23. uppy.removePlugin(this.plugin)
  24. }
  25. render () {
  26. return h('div', {
  27. ref: (container) => {
  28. this.container = container
  29. }
  30. })
  31. }
  32. }
  33. DragDrop.propTypes = {
  34. uppy: propTypes.uppy,
  35. locale: propTypes.locale
  36. }
  37. DragDrop.defaultProps = {
  38. }
  39. module.exports = DragDrop