-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (61 loc) · 1.52 KB
/
index.js
File metadata and controls
68 lines (61 loc) · 1.52 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var React = require('react');
var FileInput = React.createClass({
getInitialState: function() {
return {
value: '',
styles: {
parent: {
position: 'relative'
},
// "invisible" above the text
file: {
position: 'absolute',
top: 0,
left: 0,
opacity: 0,
width: '100%',
zIndex: 1
},
text: {
position: 'relative',
zIndex: -1
}
}
};
},
handleChange: function(e) {
this.setState({
value: e.target.value.split(/(\\|\/)/g).pop()
});
if (this.props.onChange) this.props.onChange(e);
},
render: function() {
return React.DOM.div({
style: this.state.styles.parent
},
// Actual file input
React.DOM.input({
type: 'file',
name: this.props.name,
className: this.props.className,
onChange: this.handleChange,
disabled: this.props.disabled,
accept: this.props.accept,
style: this.state.styles.file
}),
// Emulated file input for when there are no children
this.props.children || React.DOM.input({
type: 'text',
tabIndex: -1,
name: this.props.name + '_filename',
value: this.state.value,
className: this.props.className,
onChange: function() {},
placeholder: this.props.placeholder,
disabled: this.props.disabled,
style: this.state.styles.text
})
);
}
});
module.exports = FileInput;