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

file-button-react

v0.1.3

Published

Another implementation of node module file-button. For reusing component as a file input button.

Downloads

8

Readme

Another implementation of file-button. A HOC for reusing component as a file input button. There is no limitation the wrapped component is third party component or created by ourselves.

Example

wrap material-ui's RaisedButton

const React = require('react');
const ReactDOM = require('react-dom');
const MuiThemeProvider = require('material-ui/styles/MuiThemeProvider').default;
const request = require('superagent');


const wrap = require('file-button-react');
const RaisedButton = require('material-ui/RaisedButton').default;


var mountnode = document.getElementById('mountnode');
if (mountnode) {

  let opt = { depth: 1 };
  let FileButton = wrap(RaisedButton, opt);
  
  ReactDOM.render(
    <MuiThemeProvider>
      <FileButton label="upload" primary={true} onFileInput={upload} />
      <RaisedButton label="catch me" secondary={true} style={wrap.styl} />
      <RaisedButton label="catch me too" secondary={true} style={wrap.styl} />
    </MuiThemeProvider>,
    mountnode
  )
}

function upload(fileinput) {
  var req = request.post('/upload/');
  var files = fileinput.files;
    
  for(let i = 0, len = files.length; i < len; ++i){
    let file = files[i];
    req.attach('ajaxfile-' + i, file, file.name);
  }
    
  req
    .on('progress', function(e){
      
      if (e.lengthComputable) {
        // handle progress bar here
      }
    })
    .end(function(err, res) {
      
      if (res.ok) {     
        // handle successful result here
      }
    });
}

API

wrap(ReactComponent, options)

This function returns a ReactComponet with two additional properties

options is same as file-button module with the following additional option.

depth: {Unsigned Integer}

defaults to 0.

file-button-react injects DOM element <input type="file" /> to React component, which we cannot control. This is useful if we want to re-use third-party component, although it is discouraged. So, sometimes it may fail depends on the component. In that case, we can increase depth value to append <input type="file" /> to child node's child node...

properties

All properties are sent to the wrapped component except onFileInput.

onFileInput: {function}

recieve <input type="file" />

diabled: {Boolean}

default to false The wrapped component will recieve this prop, so it can re-style itself as disabled.

wrap.styl: {position:'relative', overflow:'hidden'}

A React style object, which is the style applied to the root DOM. If layout got problem after using this component, can try to apply this style to other buttons like this example.