App.jsx 2.8 KB

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