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-file-input-previews-base64

v1.0.8

Published

This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.

Downloads

2,094

Readme

react-file-input-previews-base64

This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.

demo

Installation

npm install --save react-file-input-previews-base64

Basic Usage

import FileInputComponent from 'react-file-input-previews-base64'

Example Code

<FileInputComponent
  labelText="Select file"
  labelStyle={{fontSize:14}}
  multiple={true}
  callbackFunction={(file_arr)=>{console.log(file_arr)}}
  accept="image/*" 
/>

Options

| Prop | Type | Effect | Default Value | | ------------- |-------------| -----| -----| | labelText | string | The text to show in label | "File Upload" | | multiple | boolean | Whether multiple files can be selected or not | true | | accept | string | string which is passed to accept field of input tag, to specify the types of files that can be selected | "*" | | imagePreview | boolean | Whether preview section is shown or not | true | | textBoxVisible | boolean | Whether a controlled text field showing information be shown | false | | useTapEventPlugin | boolean | Whether to use onTouchTap or onClick | false | | callbackFunction | function | The function to be called when files are processed, can take either array of file describing objects or single object depending on if multiple files are allowed | ()=>{} | | nonPreviewComponent | component | Component to show in preview section for non-image files, title, size and type are passed to this as props | included <NonPreviewDefaultComponent /> | | buttonComponent | component | The component to show for button, onClick or onTouchTap will be merged to its props to trigger the file selector box to show internally | <button type="button">Attach</button> | | textFieldComponent | component | The component to show for controlled text field, onClick or onTouchTap will be merged to its props to trigger the file selector box to show internally, along with value prop for showing information like "foobar.jpg", "2 files selected", "No file selected" etc | <input type="text" /> | | imageContainerStyle | object | Object passed to style prop of image preview section container div | {display:"flex", flexDirection:"row", width:"100%", flexWrap:"wrap"} | | imageStyle | object | Object passed to style prop of image previews | {marginTop: 5, marginBottom: 5, marginRight: 5, width: "auto", height: "30vmin", boxShadow:"rgba(0, 0, 0, 0.188235) 0px 10px 30px, rgba(0, 0, 0, 0.227451) 0px 6px 10px"} | | parentStyle | object | Object passed to style prop of container div of whole component | {marginTop:14} | | labelStyle | object | Object passed to style prop of label | {fontSize: 16,color:'rgba(0, 0, 0, 0.298039)',display:'block'} | | inputId | string | String passed to id prop of input and htmlFor tag of label components, if not present clicking on label won't trigger the file sector to show | none | | inputName | string | String passed to name prop of input, if not present, using this component as part of form will not work. | none | | defaultFiles | array | Array consisting of urls of files to show as pre-selections, useful for edit forms, currently only supports urls to image files | [] |

Note

  • onTouchTap is implmented by react-tap-event-plugin and is used in the amazing material-ui.
  • I am using this with material-ui library and the default props for styles follows the material design pattern.
  • The structure of file describing object is:
{
  name: "IMG_20160813_102226.jpg",
  type: "image/jpeg",
  size: 645,
  base64: "data:image/jpeg;base64,/9j/4SzyRXhpZgAATU0AKgA...",
  file: File
}