basic.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from "react";
  2. import Dropzone from "../../";
  3. import { FileWithPath } from "file-selector";
  4. export default class Basic extends React.Component {
  5. state = { files: [] };
  6. onDrop = (files: FileWithPath[]) => {
  7. this.setState({
  8. files,
  9. });
  10. };
  11. render() {
  12. return (
  13. <section>
  14. <div className="dropzone">
  15. <Dropzone onDrop={this.onDrop}>
  16. {({ getRootProps, getInputProps }) => (
  17. <div {...getRootProps()}>
  18. <input {...getInputProps()} />
  19. <p>
  20. Try dropping some files here, or click to select files to
  21. upload.
  22. </p>
  23. </div>
  24. )}
  25. </Dropzone>
  26. </div>
  27. <aside>
  28. <h2>Dropped files</h2>
  29. <ul>
  30. {this.state.files.map((f) => (
  31. <li key={f.name}>
  32. {f.name} - {f.size} bytes
  33. </li>
  34. ))}
  35. </ul>
  36. </aside>
  37. </section>
  38. );
  39. }
  40. }
  41. export const optional = (
  42. <Dropzone>
  43. {({ getRootProps, getInputProps }) => (
  44. <div {...getRootProps()}>
  45. <input {...getInputProps()} />
  46. </div>
  47. )}
  48. </Dropzone>
  49. );