summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFrancesco <firefelix@gmail.com>2015-06-09 16:53:04 +0200
committerFrancesco <firefelix@gmail.com>2015-06-09 16:53:04 +0200
commita54e39b4db5f845841f1258b7398f24d0b1b8117 (patch)
treea44b31c9e9aa728afa777e142b2e20fb966e480a /lib
parent472048d2afd6ede93715cd20fe20156ba6e679f0 (diff)
downloadreact-autosize-textarea-a54e39b4db5f845841f1258b7398f24d0b1b8117.zip
react-autosize-textarea-a54e39b4db5f845841f1258b7398f24d0b1b8117.tar.gz
react-autosize-textarea-a54e39b4db5f845841f1258b7398f24d0b1b8117.tar.bz2
Initial Commitv0.1.0
Diffstat (limited to 'lib')
-rw-r--r--lib/TextareaAutosize.js35
-rw-r--r--lib/__tests__/Rating-test.js30
-rw-r--r--lib/index.js3
3 files changed, 68 insertions, 0 deletions
diff --git a/lib/TextareaAutosize.js b/lib/TextareaAutosize.js
new file mode 100644
index 0000000..c7a68df
--- /dev/null
+++ b/lib/TextareaAutosize.js
@@ -0,0 +1,35 @@
+'use strict';
+
+const React = require('react'),
+ autosize = require('autosize');
+
+const TextareaAutosize = React.createClass({
+
+ propTypes: {
+ onResize: React.PropTypes.func
+ },
+
+ getDefaultProps() {
+ return {
+ rows: 1
+ };
+ },
+
+ componentDidMount() {
+ autosize(this.refs.textarea.getDOMNode());
+ if (this.props.onResize) {
+ this.refs.textarea.getDOMNode().addEventListener('autosize:resized', this.props.onResize);
+ }
+ },
+
+ render() {
+ return (
+ <textarea {...this.props} ref='textarea'>
+ {this.props.children}
+ </textarea>
+ );
+ }
+
+});
+
+module.exports = TextareaAutosize; \ No newline at end of file
diff --git a/lib/__tests__/Rating-test.js b/lib/__tests__/Rating-test.js
new file mode 100644
index 0000000..75734cc
--- /dev/null
+++ b/lib/__tests__/Rating-test.js
@@ -0,0 +1,30 @@
+var React = require('react/addons');
+var TestUtils = React.addons.TestUtils;
+var expect = require('expect');
+var {Rating, RatingIcon} = require('../');
+
+describe('Rating', function() {
+
+ it('should render 5 RatingIcons as default', function() {
+ var ratingWrapper = TestUtils.renderIntoDocument(
+ <div>
+ <Rating onRate={() => {}} />
+ </div>
+ );
+
+ var ratingIcons = TestUtils.scryRenderedComponentsWithType(ratingWrapper, RatingIcon);
+ expect(ratingIcons.length).toBe(5, 'Rating is not rendering 5 icons as default');
+ });
+
+ it('should render 3 RatingIcons', function() {
+ var ratingWrapper = TestUtils.renderIntoDocument(
+ <div>
+ <Rating onRate={() => {}} maxRating={3} />
+ </div>
+ );
+
+ var ratingIcons = TestUtils.scryRenderedComponentsWithType(ratingWrapper, RatingIcon);
+ expect(ratingIcons.length).toBe(3, 'Rating is not renderin 3 icons');
+ });
+
+});
diff --git a/lib/index.js b/lib/index.js
new file mode 100644
index 0000000..8051157
--- /dev/null
+++ b/lib/index.js
@@ -0,0 +1,3 @@
+import TextareaAutosize from './TextareaAutosize.js';
+
+export { TextareaAutosize }; \ No newline at end of file