Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 65 additions & 59 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
var React = require('react');

var FileInput = React.createClass({
getInitialState: function() {
return {
value: '',
styles: {
parent: {
position: 'relative'
},
file: {
position: 'absolute',
top: 0,
left: 0,
opacity: 0,
width: '100%',
zIndex: 1
},
text: {
position: 'relative',
zIndex: -1
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['React'], factory(React));
} else if (typeof exports === 'object') {
module.exports = factory(require('React'));
} else {
root.FileInput = factory(React);
}
})(this, function(React) {
return React.createClass({
getInitialState: function() {
return {
value: '',
styles: {
parent: {
position: 'relative'
},
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);
},
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
},
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
}),
// 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
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
}));
}
// Emulated file input
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;