1.2.5 • Published 1 year ago

react-drag-n-drop-image v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Drag and Drop Images

Version code style: prettier npm download

drag & drop image file upload library.

Demo

Edit react-drag-n-drop-image

Installation

Install it from npm (using NPM).

npm i --save react-drag-n-drop-image

or:

yarn add react-drag-n-drop-image

Usage

Using react component just as simple as:

import React, { useState } from 'react';
import FileUpload from 'react-drag-n-drop-image';

function FileUpload() {
  const [files, setFiles] = useState([]);
  const onChange = file => {
    setFiles(file);
  };
  const onRemoveImage = id => {
    setFiles(prev => prev.filter(i => i.id !== id));
  };
  const onError = error => {
    console.error(error);
  };
  return (
    <div>
      <FileUpload onError={onError} body={<CustomBody />} overlap={false} fileValue={files} onChange={onChange} />
      <div className='upload-image-box'>
        {files.map(item => {
          return (
            <div onClick={() => onRemoveImage(item.id)} aria-hidden style={{ width: 150, height: 150, margin: 10 }} key={item.id}>
              <img style={{ width: 150, height: 150 }} src={item.preview} alt='images' />
            </div>
          );
        })}
      </div>
    </div>
  );
}

export default FileUpload;

drag in box css

  .dragging {
      background-color: red;
  }

Options

OptionTypeDescriptionvalue example
onChangeFnfile upload onChange Eventconst onChange = (files) => {}
fileValueArrayfile state value[{ id: string, file:File, preview:string }]
bodyJSX Elementjsx<div>Drag & Drop</div>
loadingBodyJSX ELementjsx<div>...Loading</div>
maxSizeNumbersize(MB)defalut maxSize=5
onErrorFntype, maxSize, overlab Errorconst onError = (error) => {}
typeArrayimage typedefalut type = ['jpg', 'jpeg', 'png']
overlapBooleanoverlap true or falsedefalut overlap = true
classNameStringcontainer div className

License

MIT

1.2.5

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.2

1 year ago