Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import React from 'react';
import Dropzone from 'react-dropzone';
import PropTypes from 'prop-types';
export class InputFile extends React.PureComponent {
static propTypes = {
label: PropTypes.string.isRequired,
onChangeFile: PropTypes.func.isRequired,
required: PropTypes.bool,
value: PropTypes.any
};
state = {
file: {
name: '',
size: 0
}
};
onDrop = files => {
const { onChangeFile } = this.props;
files.forEach(file => {
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
reader.onabort = () => {
// ignore
};
reader.onerror = () => {
// ignore
};
reader.onload = evt => {
const data = evt.target.result;
onChangeFile && onChangeFile(evt);
this.setState({
file: {
name: file.name,
size: data.length
}
});
};
reader.readAsText(file);
});
};
render () {
const acceptedFormats = ['application/json', 'text/plain'].join(', ');
const { label } = this.props;
const { file } = this.state;
return (
<Dropzone
accept={acceptedFormats}
className='form_field'
disabled={false}
multiple={false}
onDrop={this.onDrop}
>
<div className='form_field_value'>
<label className='label'> {label} </label>