Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for React 16 compatibility #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ Usage is pretty simple: just use react-input-file instead of `<input type="file"
app.jsx
```js
var React = require('react'),
FileInput = require('react-input-file');
createReactClass = require('create-react-class');
FileInput = require('react-input-file'),

var Form = React.createClass({

var Form = createReactClass({
handleChange: function(event) {
console.log('Selected file:', event.target.files[0]);
},
Expand Down
22 changes: 11 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var React = require('react');

var FileInput = React.createClass({
getInitialState: function() {
var createReactClass = require('create-react-class');
var FileInput = createReactClass({
getInitialState: function () {
return {
value: '',
styles: {
Expand All @@ -24,20 +24,20 @@ var FileInput = React.createClass({
};
},

handleChange: function(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.createElement('div', {
style: this.state.styles.parent
},

// Actual file input
React.DOM.input({
React.createElement('input', {
type: 'file',
name: this.props.name,
className: this.props.className,
Expand All @@ -48,13 +48,13 @@ var FileInput = React.createClass({
}),

// Emulated file input
React.DOM.input({
React.createElement('input', {
type: 'text',
tabIndex: -1,
name: this.props.name + '_filename',
value: this.state.value,
className: this.props.className,
onChange: function() {},
onChange: function () { },
placeholder: this.props.placeholder,
disabled: this.props.disabled,
style: this.state.styles.text
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-input-file",
"version": "0.2.6",
"version": "0.3.0",
"description": "Simple file input component for React",
"main": "./lib",
"scripts": {
Expand All @@ -18,13 +18,21 @@
"input"
],
"author": "Captivation Software",
"contributors": ["Data-Meister", "Andi Neck"],
"contributors": [
"Data-Meister",
"Andi Neck"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/intesso/react-input-file/issues"
},
"homepage": "https://github.com/intesso/react-input-file",
"peerDependencies": {
"react": "0.x || 15.x"
"react": "0.x || 15.x || 16.x",
"create-react-class": "*"
},
"dependencies": {
"create-react-class": "^15.6.3",
"react": "^16.4.2"
}
}