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

upload-liu-2x

v0.0.4

Published

HOC that displays a file upload on clicking children

Downloads

1

Readme

CircleCI Coverage Status

@navjobs/upload

v4

I'm working on a v4 soon that simplfies the api and removes the children-as-a-function paradigm to something more extendable. Also revamping the test suit. It'll be a complete rewrite.

What

A set of React components for handling file uploads. If you simply want to turn any component into a file upload dialog, wrap it in our <UploadField/> component that exposes the files after selection. Need to process a file upload and receive the upload progress? Wrap <UploadField/> with <Uploader/>. You can see examples inside our storybook.

Why this?

  • Any component can be an upload dialog. Wrap it in <UploadField/>. This means you have ultimate styling control.
  • Simple component API for upload progress. Pass headers, extra fields, anything.
  • Zero dependencies (other than React!)

Install

yarn add @navjobs/upload

In this library

  • UploadField gives access to files after drag and drop / clicking on the area wrapped
  • Uploader triggers an xhr upload to a url with file progress
  • SignedUploader same as above, but helps generate a signed url from your api.
  • Imperative api that lets you trigger a file upload with progress outside of react.

UploadField

import { UploadField } from '@navjobs/upload'

  <UploadField
    onFiles={files => //files object here}
    containerProps={{
      className: 'resume_import'
    }}
    uploadProps={{
      accept: '.pdf,.doc,.docx,.txt,.rtf',
    }}
  >
    <div>
      Click here to upload! This can be an image,
      or any component you can dream of.
    </div>
  </UploadField>

Uploader

Use <UploadField /> inside of this component; pass the files to it and handle the upload!

import { Uploader } from '@navjobs/upload'

<Uploader
  request={{
    fileName: 'file',
    url: 'https://upload.com',
    method: 'POST',
    fields: {
      //extra fields to pass with the request
      full_name: 'Testing extra fields',
    },
    headers: {
      //custom headers to send along
      Authorization: 'Bearer: Test',
    },
    // use credentials for cross-site requests
    withCredentials: false,
  }}
  onComplete={({ response, status }) => /*do something*/}
  //upload on file selection, otherwise use `startUpload`
  uploadOnSelection={true}
>
  {({ onFiles, progress, complete }) => (
    <div>
      <UploadField onFiles={onFiles}>
        <div>
          Click here to select a file!
        </div>
      </UploadField>
      {progress ? `Progress: ${progress}` : null}
      {complete ? 'Complete!' : null}
    </div>
  )}
</Uploader>

Signed Uploader

This is a useful component for generating signed urls on your backend for a service like AWS or Google Cloud. The workflow generally involes hitting your own api, then uploading to the url that your api returns. After the fact, you hit your api again to say that the upload is finished.

import { SignedUploader } from '@navjobs/upload'


<SignedUploader
  //grab this url from your api
  beforeRequest={() => new Promise(resolve => resolve({ url: 'http://storage.googlecloud.com' }))}
  request={({ before, files }) => ({
      url: before.url,
      method: 'PUT',
      headers: {
        'Content-Type': files[0].type
      }
    })}
  afterRequest={({ before, status }) => new Promise(resolve => {
    resolve('finished the upload!');
  })}
>

Imperative API

If you need to upload files and recieve progress, but can't wrap an Uploader around where you receive the files, feel free to use this:

import { UploadRequest } from '@navjobs/upload'

async uploadFiles() {
  let { response, error, aborted } = await UploadRequest(
    {
      request: {
        url: 'blah' //same as above request object
      },
      files, //files array
      progress: value => console.log('progress!', value)
    }  
  )
  //do something with response
}

FAQ

Q: Part of the component I'm wrapping isn't cursor pointer?

A: You may need to set

::-webkit-file-upload-button { cursor:pointer; }

In your css. For some reason file uploads aren't always pointer.

License

This project is licensed under the terms of the MIT license.