1.1.3 • Published 4 years ago

@jswork/react-upload v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

react-upload

Upload component for react.

version license size download

installation

npm install -S @jswork/react-upload

properties

NameTypeRequiredDefaultDescription
classNamestringfalse-The extended className for component.
namestringfalse'file'Name for upload.
multipleboolfalsefalseIf is multiple.
maxSizenumberfalse1e10The max size of the file.
maxCountnumberfalse1e3Max size files count.
onChangefuncfalsenoopThe change handler.
onErrorfuncfalsenoopThe error handle when validate failed.

usage

  1. import css

    @import "~@jswork/react-upload/dist/style.css";
    
    // or use sass
    @import "~@jswork/react-upload/dist/style.scss";
    
    // customize your styles:
    $react-upload-options: ()
  2. import js

    import ReactDemokit from '@jswork/react-demokit';
    import React from 'react';
    import ReactDOM from 'react-dom';
    import ReactUpload from '@jswork/react-upload';
    import './assets/style.scss';
    
    const urls = [
      'https://randomuser.me/api/portraits/lego/1.jpg',
      'https://randomuser.me/api/portraits/lego/2.jpg',
      'https://randomuser.me/api/portraits/lego/3.jpg',
      'https://randomuser.me/api/portraits/lego/4.jpg',
      'https://randomuser.me/api/portraits/lego/5.jpg',
      'https://randomuser.me/api/portraits/lego/6.jpg',
      'https://randomuser.me/api/portraits/lego/7.jpg'
    ];
    
    class App extends React.Component {
      state = {
        blobs: []
      };
    
      componentDidMount() {
        setTimeout(() => {
          this.setState({ blobs: urls });
        }, 1200);
      }
    
      handleChange = (e) => {
        const blobs = e.target.value.map((item) => item.url);
        this.setState({ blobs });
      };
    
      handleError = (e) => {
        console.log('err:', e.target.value);
      };
    
      render() {
        const { blobs } = this.state;
        return (
          <ReactDemokit className="p-3 app-container" url="https://github.com/afeiship/react-upload">
            <ReactUpload
              maxCount={10}
              maxSize={1000000}
              multiple={true}
              onChange={this.handleChange}
              onError={this.handleError}
            />
            <div className="pic-list">
              {blobs.map((item, index) => {
                return <img key={index} src={item} />;
              })}
            </div>
          </ReactDemokit>
        );
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'));

documentation

license

Code released under the MIT license.