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.

46 lines
1.2 KiB

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