App.jsx 3.0 KB

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