App.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.handleModalClick = this.handleModalClick.bind(this)
  15. }
  16. componentWillMount () {
  17. this.uppy = new Uppy({ id: 'uppy1', autoProceed: true, debug: true })
  18. .use(Tus, { endpoint: 'https://master.tus.io/files/' })
  19. .use(GoogleDrive, { serverUrl: 'https://server.uppy.io' })
  20. this.uppy2 = new Uppy({ id: 'uppy2', autoProceed: false, debug: true })
  21. .use(Tus, { endpoint: 'https://master.tus.io/files/' })
  22. }
  23. componentWillUnmount () {
  24. this.uppy.close()
  25. this.uppy2.close()
  26. }
  27. handleModalClick () {
  28. this.setState({
  29. open: !this.state.open
  30. })
  31. }
  32. render () {
  33. const { showInlineDashboard } = this.state
  34. return (
  35. <div>
  36. <h1>React Examples</h1>
  37. <h2>Inline Dashboard</h2>
  38. <label>
  39. <input
  40. type="checkbox"
  41. checked={showInlineDashboard}
  42. onChange={(event) => {
  43. this.setState({
  44. showInlineDashboard: event.target.checked
  45. })
  46. }}
  47. />
  48. Show Dashboard
  49. </label>
  50. {showInlineDashboard && (
  51. <Dashboard
  52. uppy={this.uppy}
  53. plugins={['GoogleDrive']}
  54. metaFields={[
  55. { id: 'name', name: 'Name', placeholder: 'File name' }
  56. ]}
  57. />
  58. )}
  59. <h2>Modal Dashboard</h2>
  60. <div>
  61. <button onClick={this.handleModalClick}>
  62. {this.state.open ? 'Close dashboard' : 'Open dashboard'}
  63. </button>
  64. <DashboardModal
  65. uppy={this.uppy2}
  66. open={this.state.open}
  67. target={document.body}
  68. onRequestClose={() => this.setState({ open: false })}
  69. />
  70. </div>
  71. <h2>Drag Drop Area</h2>
  72. <DragDrop
  73. uppy={this.uppy}
  74. locale={{
  75. strings: {
  76. chooseFile: 'Boop a file',
  77. orDragDrop: 'or yoink it here'
  78. }
  79. }}
  80. />
  81. <h2>Progress Bar</h2>
  82. <ProgressBar
  83. uppy={this.uppy}
  84. hideAfterFinish={false}
  85. />
  86. </div>
  87. )
  88. }
  89. }