import React from 'react';
import ReactDOM from 'react-dom';
import Upload from '..';
import { Input } from '../..';

class App extends React.Component {
  uploaderRef: any;

  onPaste = e => {
    e.preventDefault();
    const files = e.clipboardData.files;
    files.length && this.uploaderRef.selectFiles(files);
  };

  saveUploaderRef = ref => {
    if (!ref.typeahead) return;
    this.uploaderRef = ref.typeahead.getInstance();
  };

  onChange = value => {
    console.log(value);
  };

  render() {
    return (
      <div>
        <Input.TextArea
          style={{ width: '100%', marginBottom: 10 }}
          autoHeight={{ minRows: 4 }}
          onPaste={this.onPaste}
        />
        <Upload
          action="http://118.31.33.81/docs/upload"
          listType="image"
          onChange={this.onChange}
          ref={this.saveUploaderRef}
        />
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('upload-demo-7'));
