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

@gfnork/react-images-uploading

v3.1.7

Published

The simple images uploader applied Render Props pattern. This approach allows you to fully control UI component and behaviours.

Downloads

12

Readme

react-images-uploading

The simple images uploader applied Render Props pattern. (You can read more about this pattern here).

This approach allows you to fully control UI component and behaviours.

See the intro blog post

tested with jest Github_Actions NPM NPM License: MIT PRs Welcome Package Quality code style: prettier

All Contributors

Package Quality

Installation

npm

npm install --save react-images-uploading

yarn

yarn add react-images-uploading

Usage

You can check out the basic demo here:

Basic

import React from 'react';
import ImageUploading from 'react-images-uploading';

export function App() {
  const [images, setImages] = React.useState([]);
  const maxNumber = 69;

  const onChange = (imageList, addUpdateIndex) => {
    // data for submit
    console.log(imageList, addUpdateIndex);
    setImages(imageList);
  };

  return (
    <div className="App">
      <ImageUploading
        multiple
        value={images}
        onChange={onChange}
        maxNumber={maxNumber}
        dataURLKey="data_url"
      >
        {({
          imageList,
          onImageUpload,
          onImageRemoveAll,
          onImageUpdate,
          onImageRemove,
          isDragging,
          dragProps,
        }) => (
          // write your building UI
          <div className="upload__image-wrapper">
            <button
              style={isDragging ? { color: 'red' } : undefined}
              onClick={onImageUpload}
              {...dragProps}
            >
              Click or Drop here
            </button>
            &nbsp;
            <button onClick={onImageRemoveAll}>Remove all images</button>
            {imageList.map((image, index) => (
              <div key={index} className="image-item">
                <img src={image['data_url']} alt="" width="100" />
                <div className="image-item__btn-wrapper">
                  <button onClick={() => onImageUpdate(index)}>Update</button>
                  <button onClick={() => onImageRemove(index)}>Remove</button>
                </div>
              </div>
            ))}
          </div>
        )}
      </ImageUploading>
    </div>
  );
}

Validation

...
  {({ imageList, onImageUpload, onImageRemoveAll, errors }) => (
    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>
  )}
...

Drag and Drop

...
  {({ imageList, dragProps, isDragging }) => (
    <div {...dragProps}>
      {isDragging ? "Drop here please" : "Upload space"}
      {imageList.map((image, index) => (
        <img key={index} src={image.data_url} />
      ))}
    </div>
  )}
...

Props

| parameter | type | options | default | description | | ---------------- | ----------------------------------- | ----------------------------------------- | ------- | ------------------------------------------------------------------ | | value | array | | [] | List of images | | onChange | function | (imageList, addUpdateIndex) => void | | Called when add, update or delete action is called | | dataURLKey | string | | dataURL | Customized field name that base64 of selected image is assigned to | | multiple | boolean | | false | Set true for multiple chooses | | maxNumber | number | | 1000 | Number of images user can select if mode = multiple | | onError | function | (errors, files) => void | | Called when it has errors | | acceptType | array | ['jpg', 'gif', 'png'] | [] | The file extension(s) to upload | | maxFileSize | number | | | Max image size (Byte) and it is used in validation | | resolutionType | string | 'absolute' | 'less' | 'more' | 'ratio' | | Using for image validation with provided width & height | | resolutionWidth | number | > 0 | | | | resolutionHeight | number | > 0 | | | | inputProps | React.HTMLProps<HTMLInputElement> | | | |

Note

resolutionType

| value | description | | :------- | :----------------------------------------------------------------------- | | absolute | image's width === resolutionWidth && image's height === resolutionHeight | | ratio | (resolutionWidth / resolutionHeight) === (image width / image height) | | less | image's width < resolutionWidth && image's height < resolutionHeight | | more | image's width > resolutionWidth && image's height > resolutionHeight |

Exported options

| parameter | type | description | | :--------------- | :---------------------------------------- | :------------------------------------------------------------------ | | imageList | array | List of images to render. | | onImageUpload | function | Called when an element is clicks and triggers to open a file dialog | | onImageRemoveAll | function | Called when removing all images | | onImageUpdate | (updateIndex: number) => void | Called when updating an image at updateIndex. | | onImageRemove | (deleteIndex: number | number[]) => void | Called when removing one or list image. | | errors | object | Exported object of validation | | dragProps | object | Native element props for drag and drop feature | | isDragging | boolean | "true" if an image is being dragged |

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!