0.0.9 • Published 6 years ago

react-file-picker-preview v0.0.9

Weekly downloads
65
License
MIT
Repository
github
Last release
6 years ago

react-file-picker-preview

Build Status Coverage Status npm

Simple react file picker with built in preview bar. Easily styled and with default or custom file chooser button. Example included. Demo can be viewed at https://react-file-picker-preview-demo.herokuapp.com/

npm i react-file-picker-preview

Features

  • File name preview
  • Customisable file size limit
  • Restrict file upload by extensions
  • OnChange, onError and onClear callbacks
  • Programmatically clear the selected file
  • Default button or custom element
  • Custom className prop

Example

import React from 'react';
import { FilePicker } from 'react-file-picker-preview';

class Demo extends React.Component {
  state = {
    file: {},
    reset: {},
  }

  render() {
    const { file } = this.state;

    return (
        <div>
          <div onClick={() => {
            this.setState({ reset: Object.assign({}) })
          }}>Clear the picker</div>
          <FilePicker
            className="button"
            maxSize={2}
            buttonText="Upload a file!"
            extensions={["application/pdf"]}
            onChange={(file) => this.setState({ file })}
            onError={error => { alert("that's an error: " + error) }}
            onClear={() => this.setState({ file: {} })}
            triggerReset={this.state.reset}
          >
            <div className="input-button" type="button">
              The file picker
            </div>
          </FilePicker>
          <div className="file-details">
            <h3>The file</h3>
            <h4>Name: {file.name}</h4>
            <h4>Size: {file.size}{file.size ? ' bytes' : null}</h4>
            <h4>Type: {file.type}</h4>
            <h4>Modified: {file.lastModified}</h4>
          </div>
      </div>
    );
  }
}

export default Demo

Example

npm run example
0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago