How to use react-dropzone - 10 common examples

To help you get started, we’ve selected a few react-dropzone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codefordenver / ideaLab / Frontend / src / components / Upload / components / Upload.jsx View on Github external
function Upload(props) {
  const onDrop = useCallback(acceptedFiles => {
    props.setFilename(acceptedFiles[0].name);
    props.callback(acceptedFiles);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });

  return (
    <div>
      <input>
      {isDragActive ? <p>upload or drag STL files</p> : <p>upload STL files</p>}
      {props.filename ? <p>Filename: {props.filename}</p> : null}
    </div>
  );
}
github captbaritone / webamp / modern / src / debugger / index.js View on Github external
function Wrapper() {
  const [maki, setMaki] = React.useState(null);
  const onDrop = React.useCallback(async acceptedFiles =&gt; {
    if (acceptedFiles.length !== 1) {
      alert("Only drop one file at a time");
      return;
    }
    const file = acceptedFiles[0];
    const arrayBuffer = await readFileAsArrayBuffer(file);
    setMaki(arrayBuffer);
    // Do something with the files
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
  return (
    <div style="{{">
      {maki == null ? (
        &lt;&gt;
          <h1 style="{{">
            Drop a .maki file here to debug
          </h1>
          <input type="file">
        </div>
github Swizec / modern-webapp-starter-sep-2019 / web / src / components / ImageUpload.js View on Github external
if (response.status !== 200) {
      // The upload failed, so let's notify the caller.
      setUploading(false)
      onError && onError()
      return
    }
    // Let the caller know that the upload is done, so that it can send the URL
    // to the backend again, persisting it to the database.

    setUploading(false)
    onUploadReady && onUploadReady()
  }

  return {
    ...useDropzone({
      accept: "image/*",
      disabled: typeof presignedUploadUrl !== "string",
      onDrop,
    }),
    uploading,
  }
}
github btzr-io / Villain / packages / villain-web / src / routes / reader / view.js View on Github external
setFile(url)
  })

  // Update source
  React.useEffect(() =&gt; {
    setSource(query.src || file)
  }, [file, query])

  const onDrop = React.useCallback(
    acceptedFiles =&gt; {
      handleFileChange(acceptedFiles)
    },
    [handleFileChange]
  )

  const { getRootProps, isDragActive } = useDropzone({ onDrop })

  return !source ? (
    
      <section>
        {!isDragActive ? (
          <div>
            <div>
              <b>Select</b> comic book or <b>drop</b> it here
            </div>
            <div>
              
              <button>Try example</button>
            </div>
            <div>
              <b>Enter</b> a valid url of the comic book
            </div></div></section>
github codefordenver / ideaLab / Frontend / src / components / Upload / components / Upload.jsx View on Github external
function Upload(props) {
  const onDrop = useCallback(acceptedFiles =&gt; {
    props.setFilename(acceptedFiles[0].name);
    props.callback(acceptedFiles);
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });

  return (
    <div>
      <input>
      {isDragActive ? <p>upload or drag STL files</p> : <p>upload STL files</p>}
      {props.filename}
    </div>
  );
}
github kleros / tokens-on-trial / src / components / file-picker / index.js View on Github external
) : (
      <div>
        {' '}
        {file.name}
      </div>
    )}
  
)

FilePicker.propTypes = {
  // React Dropzone
  ...Dropzone.propTypes,

  // State
  message: PropTypes.node
}

FilePicker.defaultProps = {
  // State
  message: 'Drag file or click here'
}

export default FilePicker
github kleros / doges-on-trial / src / components / file-picker / index.js View on Github external
<small>{message}</small>
    <button size="small" type="ternary">
      {buttonMessage}
    </button>
    {imageFilePreviewURL &amp;&amp; (
      <div style="{{">
    )}
  
)

FilePicker.propTypes = {
  // React Dropzone
  ...Dropzone.propTypes,

  // State
  message: PropTypes.node,
  buttonMessage: PropTypes.node,
  imageFilePreviewURL: PropTypes.string
}

FilePicker.defaultProps = {
  // State
  message: 'Drag file here or',
  buttonMessage: 'Browse Image',
  imageFilePreviewURL: null
}

export default FilePicker
</div>
github swagger-api / swagger-editor / src / layout.jsx View on Github external
import React from "react"
import PropTypes from "prop-types"
import Dropzone from "react-dropzone"

Dropzone.displayName = "Dropzone" // For testing

export default class EditorLayout extends React.Component {

  static propTypes = {
    errSelectors: PropTypes.object.isRequired,
    errActions: PropTypes.object.isRequired,
    specActions: PropTypes.object.isRequired,
    getComponent: PropTypes.func.isRequired,
    layoutSelectors: PropTypes.object.isRequired,
    layoutActions: PropTypes.object.isRequired
  }

  onChange = (newYaml, origin="editor") => {
    this.props.specActions.updateSpec(newYaml, origin)
  }
github AntlerVC / firetable / www / src / components / ImportCSV.tsx View on Github external
const [columnKey, setColumnKey] = useState();
  const [csvData, setCsvData] = useState([]);
  const onDrop = useCallback(async acceptedFiles =&gt; {
    const file = acceptedFiles[0];
    var reader = new FileReader();
    reader.onload = function(event: any) {
      const csvString = event.target.result;
      parse(csvString, {}, function(err, output) {
        const keys = output.shift();
        setCsvData(output);
        setCsvKeys(keys);
      });
    };
    reader.readAsText(file);
  }, []);
  const { getRootProps, getInputProps, isDragActive } = useDropzone({
    onDrop,
    multiple: false,
  });
  function handleClickOpen() {
    setOpen(true);
  }

  function handleClose() {
    setOpen(false);
    setKeyPairs([]);
    setCsvKeys([]);
    setCsvKey(null);
    setColumnKey(null);
  }
  function handleImport() {
    const newDocs = csvData.map((row: any[]) =&gt; {
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / components / file-dropzone.jsx View on Github external
data: b64data,
          };
          return fileData;
        })
        .then(fileData =&gt; {
          props.onFilePicked({ file: fileData });
        });
    });
  }, []);
  const {
    getRootProps,
    getInputProps,
    isDragActive,
    isDragReject,
    isDragAccept,
  } = useDropzone({ onDrop });

  const icon = isDragReject ? "#ico36_close" : "#illu_drag_here";

  return (
    
      <div>
        </div>

react-dropzone

Simple HTML5 drag-drop zone with React.js

MIT
Latest version published 2 years ago

Package Health Score

85 / 100
Full package analysis