Sha256: 34fe18d6dc99fdfa55344f6a081edb89738a9aff0b76a2d44f8dd4c0e23f8fa7

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

import React, { useRef } from "react";
import PropTypes from "prop-types";

export default function FileUploadButton(props) {
  const inputRef = useRef();

  const handleChange = (evt) => {
    let fileList = evt.target.files;
    let files = [];
    for (var i = 0; i < fileList.length; i++) {
      files.push(fileList[i]);
    }
    if (files.length > 0) {
      props.callback(files);
    }
  };

  const triggerDialog = (evt) => {
    evt.preventDefault();
    inputRef.current.click();
  };

  return (
    <div className="upload-button">
      <span>
        Drag and drop {props.type || "file"}
        {props.multiple && "s"} here, or
        {props.multiline && <br />}
        <button onClick={triggerDialog}>
          choose a file
        </button>
      </span>
      <input type="file"
             onChange={handleChange}
             ref={inputRef}
             style={{ display: "none" }}
             multiple={props.multiple || false} />
    </div>
  );
}

FileUploadButton.propTypes = {
  callback: PropTypes.func,
  type: PropTypes.string,
  multiple: PropTypes.bool,
  multiline: PropTypes.bool
};

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pages_core-3.12.1 app/javascript/components/FileUploadButton.jsx
pages_core-3.12.0 app/javascript/components/FileUploadButton.jsx
pages_core-3.11.3 app/javascript/components/FileUploadButton.jsx
pages_core-3.11.2 app/javascript/components/FileUploadButton.jsx
pages_core-3.11.1 app/javascript/components/FileUploadButton.jsx
pages_core-3.11.0 app/javascript/components/FileUploadButton.jsx
pages_core-3.10.2 app/javascript/components/FileUploadButton.jsx
pages_core-3.10.1 app/javascript/components/FileUploadButton.jsx
pages_core-3.9.2 app/javascript/components/FileUploadButton.jsx
pages_core-3.9.1 app/javascript/components/FileUploadButton.jsx
pages_core-3.9.0 app/javascript/components/FileUploadButton.jsx
pages_core-3.8.3 app/javascript/components/FileUploadButton.jsx
pages_core-3.8.2 app/javascript/components/FileUploadButton.jsx