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

@paprika/uploader

v7.0.1

Published

The Uploader component lets you upload files and see progress.

Downloads

1,404

Readme

@paprika/uploader

Description

The Uploader component lets you upload files and see progress.

Installation

yarn add @paprika/uploader

or with npm:

npm install @paprika/uploader

Props

Uploader

| Prop | Type | required | default | Description | | ------------------ | ------- | -------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | a11yText | string | false | null | Accessible message for the input[type="file"]. | | supportedMimeTypes | arrayOf | false | ["/"] | An array of accepted file extensions and/or MIME types. Note that Microsoft MIME types don't seem to be enforced. | | canChooseMultiple | bool | false | true | When false the uploader only accept one file per upload. | | children | node | true | - | children nodes | | isDisabled | bool | false | false | Is uploader disabled. | | endpoint | string | true | - | The url that will be use to upload the files. | | hasAutoUpload | bool | false | true | On true will upload the file as soon they are selected or dropped | | isBodyDroppable | bool | false | true | When true the user will be able to drop files at any part of the document.body. On false will only receive files dropped exactly on the FileInput area. | | maxFileSize | number | false | oneMebibyte * 10 | Size in Mebibytes which is used for comparing each file that will be uploaded. | | onChange | func | false | () => {} | This callback fires every time the input value has been changed. | | onCompleted | func | false | () => {} | Will fire once all files have been processed with the files as parameter. | | headers | arrayOf | false | [] | you can pass an array of header objects. | | onProcessed | func | false | () => {} | This callback fires when uploading is about to start (all files have been processed to see if they are valid type/size). | | onRequest | func | false | null | Let you to take over the request method | | onError | func | false | null | Callback fired whenever an error occurs while uploading a file. It receives the raw server error as an argument. Whatever this function returns is what is displayed in the UI. If nothing is returned, it will display the raw server error. | | onCancel | func | false | () => {} | Callback fired when the user cancels an uploading file. | | zIndex | number | false | 1 | z-index for popovers inside the uploader. |

Usage

import { UploaderContext } from "@paprika/uploader/lib/Uploader"

function YourUI() {
  const {
    /*provided by context*/
    cancelFile,
    FileInput,
    files,
    isCompleted,
    isDisabled,
    isDraggingOver,
    isDragLeave,
    removeFile,
    upload,
  } = React.useContext(UploaderContext);

  return (
    <>
      <FileInput>
        <div css={yourStyle}>FILE INPUT ZONE</div>
      </FileInput>
      {files.length ? (
        <ul>
          {files.map(file => (
            <li>{file.filename}</li>
          ))}
        </ul>
      ) : null}
    </>
  );
}

function App() {
  return (
    <Uploader>
     <YourUI />
    </Uploader>;
  )
}

Note

maxFileSize

Size in Mebibytes which is used for comparing each file that will be uploaded you can make use of Uploader.convertUnitsToMebibytes() for easily converting units to Mebibyes ex. Uploader.convertUnitsToMebibytes(4) => 4194304 (close to 4MB);

headers:

You can pass an array of header objects ex.

   <Uploader headers={[{ "API-Key": "your-api-key" }, { Accept: "application/json" }, { "X-CSRF-Token": "your-token"} ]} ...>
     {({...}) => <YourUI />}
   </Uploader>

Context

import { UploaderContext } from "@paprika/uploader";

  • children you can pass a component which can consume the Context provided.
  • FileInput The input[type="file"] element ready to be consumed
  • files A enhance list of the user selected files
  • isCompleted Is true when all files have been processed
  • isDisabled Describe the status of the component
  • isDragLeave Will be true if a dragOver event occurred and leave the droppable area
  • isDraggingOver Is True when detecting the user is dragging files over the droppable area
  • removeFile removeFile(key) will remove a file from the files list, this function doesn't work while the file is on PROCESSING state.
  • cancelFile cancelFile(key) stop the request cycle keep in mind that if it's on WAITINGFORSERVER state the server might save the file even if - the request has been cancel
  • upload upload() give you the option to manually upload the files if the consumer decided to not use hasAutoUpload

FileInput Component

The <FileInput>{children}</FileInput> is a ready to use component which is passed down by the <Uploader /> context. This component has attached accessibility and attributes required to make it work correctly, you can pass any children to beautify their aspect, keep in mind that is already an input[type='file'] so avoid putting a <Button /> component or a <button /> element as a children, just make it look like one.

Endpoint

The Uploader provides a endpoint prop which you can use to point the url of the service you want to reach, Ex. <Uploader endpoint="https://yoururl.com/api/upload" ...

Accessibility

The Uploader automatically handle the on focus circle when using the <FileInput /> component on it.

  • it should notify when start uploading the files and when finishing processing the files.

Links