Skip to content
This repository was archived by the owner on Jun 5, 2022. It is now read-only.

Latest commit

History

126 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Images uploader UI component

Simple component for upload and validate (client side) images with preview built with React.js. This package use 'react-flip-move' for animate the file preview images.

Installation

npm install --save react-images-upload

Usage

Using Classes

importReactfrom"react";importImageUploaderfrom"react-images-upload";classAppextendsReact.Component{constructor(props){super(props);this.state={pictures: []};this.onDrop=this.onDrop.bind(this);}onDrop(pictureFiles,pictureDataURLs){this.setState({pictures: this.state.pictures.concat(pictureFiles)});}render(){return(<ImageUploaderwithIcon={true}buttonText="Choose images"onChange={this.onDrop}imgExtension={[".jpg",".gif",".png",".gif"]}maxFileSize={5242880}/>);}}

Using Hooks

importReact,{useState}from"react";importImageUploaderfrom"react-images-upload";constApp=props=>{const[pictures,setPictures]=useState([]);constonDrop=picture=>{setPictures([...pictures,picture]);};return(<ImageUploader{...props}withIcon={true}onChange={onDrop}imgExtension={[".jpg",".gif",".png",".gif"]}maxFileSize={5242880}/>);};exportdefaultApp;

Available Options

parametertypedefaultdescription
classNameString-Class name for the input.
onChangeFunction-On change handler for the input.
buttonClassNameString-Class name for upload button.
buttonStylesObject-Inline styles for upload button.
withPreviewBooleanfalseShow preview of selected images.
defaultImagesArray['imgUrl1', 'imgUrl2']Pre-populate with default images.
acceptString"accept=image/*"Accept attribute for file input.
nameString-Input name.
withIconBooleantrueIf true, show upload icon on top
buttonTextString'Choose images'The text that display in the button.
buttonTypeString'submit'The value of the button's "type" attribute.
withLabelBooleantrueShow instruction label
labelString'Max file size: 5mb, accepted: jpg, gif, pngLabel text
labelStylesObject-Inline styles for the label.
labelClassstring-Class name for the label
imgExtensionArray['.jpg', '.gif', '.png', '.gif']Supported image extension (will use in the image validation).
maxFileSizeNumber5242880Max image size.
fileSizeErrorString" file size is too big"Label for file size error message.
fileTypeErrorString" is not supported file extension"Label for file extension error message.
errorClassString-Class for error messages
errorStyleObject-Inline styles for errors
singleImageBooleanfalseUpload one single image

Development

Clone the repo and run npm ci. Start development server with npm start.

License

MIT

About

React input file component with images preview

Resources

Stars

339 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages