-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
54 lines (48 loc) · 1.37 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* react-file - index.js
* Created by mengdesen on 15/5/15.
*/
'use strict';
var React = require('react/addons');
var File = React.createClass({
componentDidMount: function () {
this.input = this.refs.input.getDOMNode();
this.form = this.refs.form.getDOMNode();
window.onmessage = this.props.onMessage;
},
onClick: function () {
this.input.click();
},
onChange: function () {
this.form.submit();
},
getDefaultProps: function () {
return {
inputStyle: {
visibility: 'hidden',
width: '1px'
},
style: {
display: 'inline-block'
}
}
},
render: function () {
return (
<div onClick={this.onClick} style={this.props.style}>
{this.props.children}
<form
encType="multipart/form-data"
action={this.props.action}
method="post"
target="file_upload"
ref="form"
>
<input type="file" name="file" style={this.props.inputStyle} ref='input' onChange={this.onChange}/>
</form>
<iframe name="file_upload" style={{display:'none'}}></iframe>
</div>
)
}
});
module.exports = File;