App.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* eslint-disable */
  2. const React = require('react')
  3. const Uppy = require('@uppy/core')
  4. const Tus = require('@uppy/tus')
  5. const GoogleDrive = require('@uppy/google-drive')
  6. const { Dashboard, DashboardModal, DragDrop, ProgressBar } = require('@uppy/react')
  7. module.exports = class App extends React.Component {
  8. constructor (props) {
  9. super(props)
  10. this.state = {
  11. showInlineDashboard: false,
  12. open: false
  13. }
  14. this.uppy = new Uppy({ id: 'uppy1', autoProceed: true, debug: true })
  15. .use(Tus, { endpoint: 'https://master.tus.io/files/' })
  16. .use(GoogleDrive, { companionUrl: 'https://companion.uppy.io' })
  17. this.uppy2 = new Uppy({ id: 'uppy2', autoProceed: false, debug: true })
  18. .use(Tus, { endpoint: 'https://master.tus.io/files/' })
  19. this.handleModalClick = this.handleModalClick.bind(this)
  20. }
  21. componentWillUnmount () {
  22. this.uppy.close()
  23. this.uppy2.close()
  24. }
  25. handleModalClick () {
  26. this.setState({
  27. open: !this.state.open
  28. })
  29. }
  30. render () {
  31. const { showInlineDashboard } = this.state
  32. return (
  33. <div>
  34. <h1>React Examples</h1>
  35. <h2>Inline Dashboard</h2>
  36. <label>
  37. <input
  38. type="checkbox"
  39. checked={showInlineDashboard}
  40. onChange={(event) => {
  41. this.setState({
  42. showInlineDashboard: event.target.checked
  43. })
  44. }}
  45. />
  46. Show Dashboard
  47. </label>
  48. {showInlineDashboard && (
  49. <Dashboard
  50. uppy={this.uppy}
  51. plugins={['GoogleDrive']}
  52. metaFields={[
  53. { id: 'name', name: 'Name', placeholder: 'File name' }
  54. ]}
  55. />
  56. )}
  57. <h2>Modal Dashboard</h2>
  58. <div>
  59. <button onClick={this.handleModalClick}>
  60. {this.state.open ? 'Close dashboard' : 'Open dashboard'}
  61. </button>
  62. <DashboardModal
  63. uppy={this.uppy2}
  64. open={this.state.open}
  65. target={document.body}
  66. onRequestClose={() => this.setState({ open: false })}
  67. />
  68. </div>
  69. <h2>Drag Drop Area</h2>
  70. <DragDrop
  71. uppy={this.uppy}
  72. locale={{
  73. strings: {
  74. chooseFile: 'Boop a file',
  75. orDragDrop: 'or yoink it here'
  76. }
  77. }}
  78. />
  79. <h2>Progress Bar</h2>
  80. <ProgressBar
  81. uppy={this.uppy}
  82. hideAfterFinish={false}
  83. />
  84. </div>
  85. )
  86. }
  87. }