2016-09-07 19:17:15 +03:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2016-11-13 20:08:52 +02:00
|
|
|
import IconButton from '../../../components/icon_button';
|
2016-11-16 18:20:52 +02:00
|
|
|
import { injectIntl } from 'react-intl';
|
2016-09-07 19:17:15 +03:00
|
|
|
|
|
|
|
const UploadButton = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
disabled: React.PropTypes.bool,
|
2016-11-13 20:08:52 +02:00
|
|
|
onSelectFile: React.PropTypes.func.isRequired,
|
|
|
|
style: React.PropTypes.object
|
2016-09-07 19:17:15 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
|
|
|
handleChange (e) {
|
|
|
|
if (e.target.files.length > 0) {
|
|
|
|
this.props.onSelectFile(e.target.files);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleClick () {
|
2016-11-13 20:08:52 +02:00
|
|
|
this.fileElement.click();
|
|
|
|
},
|
|
|
|
|
|
|
|
setRef (c) {
|
|
|
|
this.fileElement = c;
|
2016-09-07 19:17:15 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
2016-11-16 18:20:52 +02:00
|
|
|
const { intl } = this.props;
|
|
|
|
|
2016-09-07 19:17:15 +03:00
|
|
|
return (
|
2016-11-13 20:08:52 +02:00
|
|
|
<div style={this.props.style}>
|
2016-11-16 18:20:52 +02:00
|
|
|
<IconButton icon='photo' title={intl.formatMessage({ id: 'upload_button.label', defaultMessage: 'Add media' })} disabled={this.props.disabled} onClick={this.handleClick} size={24} />
|
2016-11-13 20:08:52 +02:00
|
|
|
<input ref={this.setRef} type='file' multiple={false} onChange={this.handleChange} disabled={this.props.disabled} style={{ display: 'none' }} />
|
2016-09-07 19:17:15 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-11-16 18:20:52 +02:00
|
|
|
export default injectIntl(UploadButton);
|