Dashboard.js 983 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const React = require('react')
  2. const DashboardPlugin = require('../plugins/Dashboard')
  3. const basePropTypes = require('./propTypes').dashboard
  4. const h = React.createElement
  5. /**
  6. * React Component that renders a Dashboard for an Uppy instance. This component
  7. * renders the Dashboard inline, so you can put it anywhere you want.
  8. */
  9. class Dashboard extends React.Component {
  10. componentDidMount () {
  11. const uppy = this.props.uppy
  12. const options = Object.assign(
  13. {},
  14. this.props,
  15. { target: this.container }
  16. )
  17. delete options.uppy
  18. uppy.use(DashboardPlugin, options)
  19. this.plugin = uppy.getPlugin('Dashboard')
  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. Dashboard.propTypes = basePropTypes
  34. Dashboard.defaultProps = {
  35. inline: true
  36. }
  37. module.exports = Dashboard