@blaze-react/file-upload

0.7.0 • Public • Published

Description

FileUpload component is a great draggable area, move one or multiple images to a desired location and "drop" it there using a mouse or similar device.

Usage

  • simple FileUpload
<FileUpload 
    handleDrop={({event, base64, files, canceled}) => {}}>
    // Preview files or any other logic
</FileUpload>
  • Modal with FileUpload
class ModalWithFileUpload extends Component {
      state = {
        previewImages: [],
        filesToUpload: []
      }

      handleDrop = ({ base64, canceled, files }) => {
        const { previewImages, filesToUpload } = this.state;

        if (canceled) return this.setState({previewImages: []});

        const images = base64.map(src => (
            <img key={uuidv1()} src={src} style={imageStyles}/>
        ));

        this.setState({
          previewImages: [...previewImages, ...images],
          filesToUpload: [...filesToUpload, ...files]
        })
      }

      render() {
        const { state: { previewImages }, handleDrop } = this;
        return (
          <Modal
            isActive
            buttonText="Upload Files"
            title="Add media"
            actions={[['submit', () => {}, 'rounded outline']]}
            upload>
            <FileUpload handleDrop={handleDrop} actionText="Add file">
                {previewImages}
            </FileUpload>
          </Modal>
        )
      }
    }

    <ModalWithFileUpload />

API

FileUpload can receive a number of props as follow:
NAME TYPE DEFAULT
handleDrop Function () => {}
children Single or array of nodes No content
actionText String Add files

Readme

Keywords

none

Package Sidebar

Install

npm i @blaze-react/file-upload

Weekly Downloads

404

Version

0.7.0

License

ISC

Unpacked Size

42.6 kB

Total Files

22

Last publish

Collaborators

  • mcabrerapf
  • tanane
  • daoyong
  • marekb9
  • grzegorzi
  • ishrat
  • andypail