npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@andfk/react-images-uploading

v3.0.0

Published

A simple images uploader without UI. Building by yourself

Downloads

58

Readme

react-images-uploading

Temporary publish of package until PR

NPM JavaScript Style Guide

Images uploader

A simple images uploader without UI. Building by yourself.

#Demo

Introduce blog

Install

With npm

npm install --save react-images-uploading

With yarn

yarn add react-images-uploading

Usage

import * as React from "react";

import ImageUploading from "react-images-uploading";
// { ImageUploadingPropsType, ImageListType, ImageType } is type for typescript

const maxNumber = 10;
const maxMbFileSize = 5 * 1024 * 1024; // 5Mb

class Example extends React.Component {
  onChange = (imageList) => {
    // data for submit
    console.log(imageList);
  };
  onError = (errors, files) => {
    console.log(errors, files);
  };

  render() {
    return (
      <ImageUploading
        onChange={this.onChange}
        maxNumber={maxNumber}
        multiple
        maxFileSize={maxMbFileSize}
        acceptType={["jpg", "gif", "png"]}
        onError={this.onError}
      >
        {({ imageList, onImageUpload, onImageRemoveAll }) => (
          // write your building UI
          <div>
            <button onClick={onImageUpload}>Upload images</button>
            <button onClick={onImageRemoveAll}>Remove all images</button>

            {imageList.map((image) => (
              <div key={image.key}>
                <img src={image.dataURL} />
                <button onClick={image.onUpdate}>Update</button>
                <button onClick={image.onRemove}>Remove</button>
              </div>
            ))}
          </div>
        )}
      </ImageUploading>
    );
  }
}

Validate

...
  {({ imageList, onImageUpload, onImageRemoveAll, errors }) => (
    <div>
      {errors.maxNumber && <span>Number of selected images exceed maxNumber</span>}
      {errors.acceptType && <span>Your selected file type is not allow</span>}
      {errors.maxFileSize && <span>Selected file size exceed maxFileSize</span>}
      {errors.resolution && <span>Selected file is not match your desired resolution</span>}
    </div>
  )}
...

Resolution

  • "absolute": resolutionWidth and resolutionHeight is equal with selected image absolutely
  • "ratio": resolutionWidth/resolutionHeight ratio is equal with width/height ratio of selected image
  • "less: image width must less than resolutionWidth and image height must less than resolutionHeight
  • "more: image width must more than resolutionWidth and image height must more than resolutionHeight

Props

| parameter | type | options | default | description | | ---------------- | -------- | ----------------------------------------- | ------- | ------------------------------------------------------------------------------ | | multiple | boolean | | false | Set true for multiple choose | | maxNumber | number | | 1000 | Number of images user can select if mode = "multiple" | | onChange | function | | | Called every update | | onError | function | (errors, files) => void | | Called if have error on validate each update | | defaultValue | array | [{dataURL: ... }, ...] | | Init data | | acceptType | array | ['jpg', 'gif', 'png'] | [] | Supported image extension | | maxFileSize | number | | | Max image size(Byte) (will use in the image validation) | | resolutionType | string | "absolute" | "less" | "more" | "ratio" | | Using for validate image with your width - height resolution that you provide | | resolutionWidth | number | > 0 | | | | resolutionHeight | number | > 0 | | |

Exported options

| parameter | type | description | | ------------------------- | -------- | ------------------------------------------------------------------------- | | imageList | array | List of images for render. Each item in imageList has some options below. | | imageList[index].key | string | Generate filename | | imageList[index].dataURL | string | Url image or base64 | | imageList[index].onUpdate | function | Call function for replace a new image on current position | | imageList[index].onRemove | function | Call function for remove current image | | onImageUpload | function | Call for upload new image(s) | | onImageRemoveAll | function | Call for remove all image(s) | | errors | object | Export type of validation |

License

MIT ©