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

dropzone-react-sortable-dnd

v1.0.1

Published

An extended React DropZone component for file uploads with sortable drag-and-drop and image compression.

Downloads

8

Readme

DropZone Component

DropZone is a flexible and customizable React component for file uploading with sortable drag-and-drop functionality. It supports image compression, custom thumbnail rendering. Perfect for building modern file upload experiences based on tailwindcss styling.

Features

  • Drag-and-Drop: Easily drag and drop files to upload.
  • Image Compression: Optionally compress images before uploading.
  • Sortable Drag N Drop: Implemented sortable drag-and-drop functionality without relying on external libraries.
  • Custom Thumbnails: Render custom thumbnails using a provided function.
  • Multiple Files: Support for uploading multiple files.
  • Customizable File Types: Control which file types can be uploaded.
  • Lightweight: Minimal dependencies and easy to integrate.

Props

| Prop | Type | Default | Description | | ------------------- | -------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------- | | multiple | bool | true | Allows multiple files to be uploaded. | | onUpload | func | required | Callback function that receives the uploaded files. | | images | array | [] | Initial array of images to display. | | maxFiles | number | 10 | Maximum number of files allowed to be uploaded. | | maxWidth | number | 1024 | Maximum width (in pixels) for image compression. | | compressImages | bool | true | Whether to compress images before uploading. | | compressionOptions| object | {} | Options for image compression. Follows the browser-image-compression options. | | loader | elementType | Loader | Custom loader component to show while files are being processed. | | className | string | '' | Additional CSS classes for styling the container. | | acceptedFileTypes | object | { 'image/jpeg': ['.jpeg', '.jpg'], 'image/png': ['.png'] } | Specifies the accepted file types for uploading. | | renderThumbnail | func | null | Custom function to render thumbnails. Receives (file, index, handleDragStart, handleDragEnter, handleDragEnd, removeFile) as arguments. |

Example Usage

<div className="w-[80%]">
  <h1>Upload Your Images</h1>
  <DropZone
  multiple
  onUpload={setFiles}
  images={files}
  maxFiles={5}
  maxWidth={800}
  compressImages={true}
  compressionOptions={{ maxSizeMB: 0.5 }}
  acceptedFileTypes={{ 'image/jpeg': ['.jpeg', '.jpg'], 'image/png': ['.png'], 'application/pdf': ['.pdf'] }}
 // renderThumbnail={customRenderThumbnail}
/>

  <div className="uploaded-files">
    <h2>Uploaded Files:</h2>
    {files && files.length > 0 ? (
      <ul>
        {files.map((file, index) => (
          <li key={index}>{file.id}</li>
        ))}
      </ul>
    ) : (
      <p>No files uploaded yet.</p>
    )}
  </div>
</div>

Custom Render Thumbnail Function

You can pass a custom function to render the thumbnails in the DropZone component. Here's an example of a custom render thumbnail function:

const customRenderThumbnail = (file, index, handleDragStart, handleDragEnter, handleDragEnd, removeFile) => (
    <div
      key={file.id}
      draggable
      onDragStart={() => handleDragStart(index)}
      onDragEnter={() => handleDragEnter(index)}
      onDragEnd={handleDragEnd}
      className="custom-thumbnail-class"
    >
      {/* Custom thumbnail rendering logic */}
      <img src={file.preview} alt={file.file.name} />
      <button onClick={() => removeFile(file.id)}>Remove</button>
    </div>
);

Acknowledgments

This project is made possible thanks to the following libraries and tools:

  • React - A JavaScript library for building user interfaces.
  • react-dropzone - Simple React hook to create a HTML5-compliant drag'n'drop zone.
  • browser-image-compression - JavaScript library for image compression in browsers.
  • lucide-react - Beautiful & consistent icon toolkit made by the community.

Thank you to the open-source community for providing these valuable resources!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Please open an issue or submit a pull request on GitHub if you have ideas, bug reports, or improvements.

How to Contribute

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. Open a pull request.

Thank you for your contributions!