You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import IconButton from '../../../components/icon_button';
  3. import { injectIntl } from 'react-intl';
  4. const UploadButton = React.createClass({
  5. propTypes: {
  6. disabled: React.PropTypes.bool,
  7. onSelectFile: React.PropTypes.func.isRequired,
  8. style: React.PropTypes.object
  9. },
  10. mixins: [PureRenderMixin],
  11. handleChange (e) {
  12. if (e.target.files.length > 0) {
  13. this.props.onSelectFile(e.target.files);
  14. }
  15. },
  16. handleClick () {
  17. this.fileElement.click();
  18. },
  19. setRef (c) {
  20. this.fileElement = c;
  21. },
  22. render () {
  23. const { intl } = this.props;
  24. return (
  25. <div style={this.props.style}>
  26. <IconButton icon='photo' title={intl.formatMessage({ id: 'upload_button.label', defaultMessage: 'Add media' })} disabled={this.props.disabled} onClick={this.handleClick} size={24} />
  27. <input ref={this.setRef} type='file' multiple={false} onChange={this.handleChange} disabled={this.props.disabled} style={{ display: 'none' }} />
  28. </div>
  29. );
  30. }
  31. });
  32. export default injectIntl(UploadButton);