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

react-dfb

v1.0.4

Published

A button to allow to download file without href link

Downloads

40

Readme

REACT Download File Button

codecov

Installation

yarn add -D react-dfb

or

npm i --save-dev react-dfb

Usage

import DownloadButton from 'react-dfb';
// you can also import flow type if needed
import type { DownloadData } from 'react-dfb';

Two required props:

  • onClick: Function to call on button click
  • downloadData: Object having html5 file informations (can be empty):
    • mime: the mime type of the file to download
    • fileName: the name (with extension) of the file to download
    • contentBase64: the base-64 encoded content of the file to download

Optionnal props:

  • label: text to be displayed on the button
  • disabled: set true to disable button (default false) - Note that will also disable onClick propagation
  • className: set a value to specify class (default empty)
  • style: set a value to specify style (default empty)

You can have a simple html button

<DownloadButton onClick={...} downloadData={...}/>

Or use it with any other component, for example with a RaisedButton from material-ui:

import RaisedButton from 'material-ui/RaisedButton';

<DownloadButton onClick={...} downloadData={...}>
  <RaisedButton
    id="downloadButton"
    label={...}
    primary={true}
  />
</DownloadButton>

In this case, no need to set RaisedButton onClick, it will be retrieved from DownloadButton one.

Simple use case

  1. Set downloadData as an empty oject ()
  2. When file content has been retrieved, update downloadData and set type mime, file name and content File will automatically be proposed to download

How it works

The idea of this component is to create a http <a> tag, with a download attribute and simulate a click on it. Using URL.createObjectURL() function, a file content can be transformed into a link an put into the href of this <a> tag.

This implementation require that the service retrieving your file content return it base-64 encoded. Ideally, it should have the same parameters as the DonwloadData type