dispatch/client/src/js/components/ui/FileInput.js

30 lines
692 B
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
2016-01-11 20:04:57 +00:00
export default class FileInput extends PureComponent {
2016-01-11 20:04:57 +00:00
componentWillMount() {
this.input = window.document.createElement('input');
this.input.setAttribute('type', 'file');
this.input.addEventListener('change', e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = () => {
this.props.onChange(file.name, reader.result);
};
reader.readAsArrayBuffer(file);
});
}
handleClick = () => this.input.click();
render() {
return (
2018-04-05 23:46:22 +00:00
<button className="input-file" onClick={this.handleClick}>
{this.props.name}
</button>
2016-01-11 20:04:57 +00:00
);
}
}