about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/ui/components/upload_button.jsx
blob: 9e9fc72981314c07c1c79e46c5443a08781cec4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import PureRenderMixin from 'react-addons-pure-render-mixin';
import Button          from '../../../components/button';

const UploadButton = React.createClass({

  propTypes: {
    disabled: React.PropTypes.bool,
    onSelectFile: React.PropTypes.func.isRequired
  },

  mixins: [PureRenderMixin],

  handleChange (e) {
    if (e.target.files.length > 0) {
      this.props.onSelectFile(e.target.files);
    }
  },

  handleClick () {
    this.refs.fileElement.click();
  },

  render () {
    return (
      <div>
        <Button disabled={this.props.disabled} onClick={this.handleClick} block={true}>
          <i className='fa fa-fw fa-photo' /> Add media
        </Button>

        <input ref='fileElement' type='file' multiple={false} onChange={this.handleChange} disabled={this.props.disabled} style={{ display: 'none' }} />
      </div>
    );
  }

});

export default UploadButton;