summaryrefslogtreecommitdiff
path: root/app/client/common/fileUpload.component.js
blob: bc7818461b4aa51d00479e96cc0639e352c2b686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { h, Component } from 'preact'

class FileUpload extends Component {
  constructor(props){
    super(props)
    this.handleChange = this.handleChange.bind(this)
  }
  handleChange(e){
    this.props.onChange && this.props.onChange()
    e.stopPropagation()
    e.preventDefault()
    this.setState({ thumbnails: [], images: [] })
    const files = e.dataTransfer ? e.dataTransfer.files : e.target.files
    let i, f
    for (i = 0, f; i < files.length; i++) {
      f = files[i]
      if (!f) continue
      break
      // if (!f.type.match(this.props.mime)) continue
    }
    this.props.onUpload && this.props.onUpload(f)
  }
  render() {
    return (
      <div className='fileUpload param'>
        <label>
          <span>{this.props.title}</span>
          <input
            type='file'
            accept={this.props.accept || '*/*'}
            multiple={this.props.multiple}
            onChange={this.handleChange}
          />
          <button>{this.props.label || 'Choose file...'}</button>
        </label>
      </div>
    )
  }
}

export default FileUpload