0.1.0 • Published 4 years ago

react-gallery-uploader v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

react-gallery-uploader

Simple react-component for gallery uploading

Installation

yarn add react-gallery-uploader

Example

import React, { useState } from 'react'
import GalleryUploader from 'react-gallery-uploader'
import uuid from 'uuid'

const toBase64 = file => new Promise((resolve, reject) => {
  const reader = new FileReader();
  reader.readAsDataURL(file);
  reader.onload = () => resolve(reader.result);
  reader.onerror = error => reject(error);
});

const defaultImages = [
  {id:'first',url:'https://octodex.github.com/images/boxertocat_octodex.jpg'},
  {id:'second',url:'https://octodex.github.com/images/catstello.png'},
  {id:'third',url:'https://octodex.github.com/images/yaktocat.png'},
]

const UploadBlock = () => {
	const [images,setImages] = useState(defaultImages);
    const handleUploading = async (data) => {
    const newData = images.slice();
    for (let i in data){
      const base64Url = await toBase64(data[i]);
      newData.push({
        id: uuid(),
        url: base64Url
      })
    }
    setImages(newData);
  }

	const handleReordering = (data) => {
		setImages(data);
	}

	const handleItemClicking = (item) => {
		alert('Image click!');
  }
  
  return(
		<GalleryUploader
			images={images}
			onUpload={handleUploading}
			onReorder={handleReordering}
			onItemClick={handleItemClicking}
		/>
	)
}

export default UploadBlock

Props

PropDescription
imagesArray of images
onUploadEvent on images uploading
onReorderEvent on images reordering
onItemClickEvent on image clicking

Roadmap

  • add isSingle prop
  • add noDrag prop
  • implement icons
  • add props for dropzone text
  • add opportunity of custom dropzone
  • add opportunity of custom styling
  • use react-sortable-hoc
  • implement image removing
0.1.0

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago