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.

39 lines
952 B

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