Skip to content

Commit d7154d6

Browse files
committed
v0.1.0 release
1 parent 3cd40ac commit d7154d6

File tree

6 files changed

+100
-34
lines changed

6 files changed

+100
-34
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ from file reading.
99
- **as** (React.PropTypes.string): what format the FileReader should read the
1010
file as (i.e., ```buffer```, ```binary```, ```url```, ```text```). Defaults
1111
to ```url```.
12+
- **children** (React.PropTypes.any): if children is passed into
13+
FileReaderInput, then the component will hide the native file input and
14+
instead display ```children```. Whenever the custom ```children``` are
15+
clicked, the component will trigger the native file input prompt. This
16+
allows complete control over styling an display.
1217
- **onChange** (React.PropTypes.func): callback ```function(event, results)```.
1318
Results will be an array of arrays, the size of which depending on how many
1419
files were selected. Each result will be an array of two items:

karma.conf.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(config) {
1010

1111
// frameworks to use
1212
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13-
frameworks: ['mocha', 'browserify'],
13+
frameworks: ['browserify', 'mocha'],
1414

1515

1616
// list of files / patterns to load in the browser
@@ -19,7 +19,6 @@ module.exports = function(config) {
1919
'lib/*.js'
2020
],
2121

22-
2322
// list of files to exclude
2423
exclude: [
2524
],
@@ -28,7 +27,7 @@ module.exports = function(config) {
2827
// preprocess matching files before serving them to the browser
2928
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
3029
preprocessors: {
31-
'lib/*.js': [ 'browserify' ],
30+
'lib/index.js': [ 'browserify' ],
3231
'test.js': [ 'browserify' ]
3332
},
3433

@@ -63,6 +62,6 @@ module.exports = function(config) {
6362

6463
// Continuous Integration mode
6564
// if true, Karma captures browsers, runs the tests and exits
66-
singleRun: false
65+
singleRun: false,
6766
})
6867
}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
22
"name": "react-file-reader-input",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"description": "React file input component for complete control over styling and abstraction from file reading.",
55
"main": "./lib/index.js",
66
"devDependencies": {
77
"babel": "^5.4.7",
88
"babel-runtime": "^5.8.20",
9-
"jsdom": "^3.1.2",
109
"karma": "^0.13.9",
1110
"karma-browserify": "^4.3.0",
1211
"karma-firefox-launcher": "^0.1.6",
1312
"karma-mocha": "^0.2.0",
1413
"mocha": "^2.2.5",
15-
"mocha-jsdom": "^1.0.0",
1614
"react": "^0.13.3"
1715
},
1816
"peerDependencies": {
@@ -21,7 +19,7 @@
2119
"scripts": {
2220
"build:lib": "babel --stage 0 src --out-dir lib",
2321
"pretest": "babel --stage 0 test.es6 -o test.js && npm run build:lib",
24-
"test": "mocha test.js",
22+
"test": "karma start",
2523
"prepublish": "npm run build:lib"
2624
},
2725
"repository": {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class FileInput extends React.Component {
6464
React.findDOMNode(this.refs._reactFileReaderInput).click();
6565
}
6666
render() {
67-
const hiddenInputStyle = this.props.children ?{
67+
const hiddenInputStyle = this.props.children ? {
6868
// If user passes in children, display children and hide input.
6969
position: 'absolute',
7070
top: '-9999px'

test.es6

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import assert from 'assert';
2-
import _jsdom from 'jsdom';
3-
import mochaJsdom from 'mocha-jsdom';
2+
import React from 'react/addons';
43

54
import FileInput from './lib/index';
65

76

8-
global.document = _jsdom.jsdom('<html><body></body></html>');
9-
global.window = document.parentWindow;
10-
global.navigator = window.navigator;
11-
const jsdom = mochaJsdom.bind(this, {skipWindowCheck: true});
7+
const test = React.addons.TestUtils;
128

139

1410
describe('FileInput', () => {
15-
jsdom();
16-
const React = require('react/addons');
17-
1811
let div;
1912
beforeEach(() => {
2013
div = document.createElement('div');
@@ -24,6 +17,41 @@ describe('FileInput', () => {
2417
});
2518

2619
it('renders', () => {
27-
React.addons.TestUtils.renderIntoDocument(<FileInput/>, div);
20+
const fileInput = test.renderIntoDocument(
21+
<FileInput className="input"/>, div);
22+
23+
const input = test.findRenderedDOMComponentWithTag(fileInput, 'input');
24+
assert.ok(input);
25+
assert.ok(!input.props.children);
26+
assert.deepEqual(input.props.style, {});
27+
assert.equal(input.props.type, 'file');
28+
});
29+
30+
it('can hide input with children', () => {
31+
const fileInput = test.renderIntoDocument(<FileInput className="input">
32+
<p>Input</p>
33+
</FileInput>, div);
34+
35+
const input = test.findRenderedDOMComponentWithTag(fileInput, 'input');
36+
assert.ok(!input.props.children);
37+
assert.ok(Object.keys(input.props.style).length);
38+
assert.equal(input.props.type, 'file');
39+
40+
const p = test.findRenderedDOMComponentWithTag(fileInput, 'p');
41+
assert.ok('p');
42+
});
43+
44+
it('can hide input with children', () => {
45+
const fileInput = test.renderIntoDocument(<FileInput className="input">
46+
<p>Input</p>
47+
</FileInput>, div);
48+
49+
const input = test.findRenderedDOMComponentWithTag(fileInput, 'input');
50+
assert.ok(!input.props.children);
51+
assert.ok(input.props.style);
52+
assert.equal(input.props.type, 'file');
53+
54+
const p = test.findRenderedDOMComponentWithTag(fileInput, 'p');
55+
assert.ok('p');
2856
});
2957
});

test.js

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,72 @@ var _assert = require('assert');
66

77
var _assert2 = _interopRequireDefault(_assert);
88

9-
var _jsdom2 = require('jsdom');
9+
var _reactAddons = require('react/addons');
1010

11-
var _jsdom3 = _interopRequireDefault(_jsdom2);
12-
13-
var _mochaJsdom = require('mocha-jsdom');
14-
15-
var _mochaJsdom2 = _interopRequireDefault(_mochaJsdom);
11+
var _reactAddons2 = _interopRequireDefault(_reactAddons);
1612

1713
var _libIndex = require('./lib/index');
1814

1915
var _libIndex2 = _interopRequireDefault(_libIndex);
2016

21-
global.document = _jsdom3['default'].jsdom('<html><body></body></html>');
22-
global.window = document.parentWindow;
23-
global.navigator = window.navigator;
24-
var jsdom = _mochaJsdom2['default'].bind(undefined, { skipWindowCheck: true });
17+
var test = _reactAddons2['default'].addons.TestUtils;
2518

2619
describe('FileInput', function () {
27-
jsdom();
28-
var React = require('react/addons');
29-
3020
var div = undefined;
3121
beforeEach(function () {
3222
div = document.createElement('div');
3323
});
3424
afterEach(function () {
35-
React.unmountComponentAtNode(div);
25+
_reactAddons2['default'].unmountComponentAtNode(div);
3626
});
3727

3828
it('renders', function () {
39-
React.addons.TestUtils.renderIntoDocument(React.createElement(_libIndex2['default'], null), div);
29+
var fileInput = test.renderIntoDocument(_reactAddons2['default'].createElement(_libIndex2['default'], { className: 'input' }), div);
30+
31+
var input = test.findRenderedDOMComponentWithTag(fileInput, 'input');
32+
_assert2['default'].ok(input);
33+
_assert2['default'].ok(!input.props.children);
34+
_assert2['default'].deepEqual(input.props.style, {});
35+
_assert2['default'].equal(input.props.type, 'file');
36+
});
37+
38+
it('can hide input with children', function () {
39+
var fileInput = test.renderIntoDocument(_reactAddons2['default'].createElement(
40+
_libIndex2['default'],
41+
{ className: 'input' },
42+
_reactAddons2['default'].createElement(
43+
'p',
44+
null,
45+
'Input'
46+
)
47+
), div);
48+
49+
var input = test.findRenderedDOMComponentWithTag(fileInput, 'input');
50+
_assert2['default'].ok(!input.props.children);
51+
_assert2['default'].ok(Object.keys(input.props.style).length);
52+
_assert2['default'].equal(input.props.type, 'file');
53+
54+
var p = test.findRenderedDOMComponentWithTag(fileInput, 'p');
55+
_assert2['default'].ok('p');
56+
});
57+
58+
it('can hide input with children', function () {
59+
var fileInput = test.renderIntoDocument(_reactAddons2['default'].createElement(
60+
_libIndex2['default'],
61+
{ className: 'input' },
62+
_reactAddons2['default'].createElement(
63+
'p',
64+
null,
65+
'Input'
66+
)
67+
), div);
68+
69+
var input = test.findRenderedDOMComponentWithTag(fileInput, 'input');
70+
_assert2['default'].ok(!input.props.children);
71+
_assert2['default'].ok(input.props.style);
72+
_assert2['default'].equal(input.props.type, 'file');
73+
74+
var p = test.findRenderedDOMComponentWithTag(fileInput, 'p');
75+
_assert2['default'].ok('p');
4076
});
4177
});

0 commit comments

Comments
 (0)