0.2.4 • Published 5 years ago

react-images-browse v0.2.4

Weekly downloads
17
License
-
Repository
github
Last release
5 years ago

Demo

Images uploader UI component

Simple component for browsing, uploading and validating (client side) images with preview built with React.js. This package uses 'react-flip-move' for animating the preview image files. This is a modified version of 'react-images-upload' from JakeHartnell/react-images-upload.

Installation

npm install --save react-images-browse

Usage

import React from 'react';
import ImageUploader from 'react-images-upload';

class App extends React.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 (
            <ImageUploader
                	withIcon={true}
                	buttonText='Choose images'
                	onChange={this.onDrop}
                	imgExtension={['.jpg', '.gif', '.png', '.gif']}
                	maxFileSize={5242880}
            />
        );
    }
}

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: jpggifpnggif'Label 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

Development

Make sure you have yarn installed. Clone the repo and run yarn.

License

MIT