blob: 07d447b42f9a2e99416994ddede37669ff7703f9 (
plain)
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
|
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var React = require('react'),
autosize = require('autosize');
var TextareaAutosize = React.createClass({
displayName: 'TextareaAutosize',
propTypes: {
onResize: React.PropTypes.func
},
getDefaultProps: function getDefaultProps() {
return {
rows: 1
};
},
componentDidMount: function componentDidMount() {
autosize(this.refs.textarea.getDOMNode());
if (this.props.onResize) {
this.refs.textarea.getDOMNode().addEventListener('autosize:resized', this.props.onResize);
}
},
componentWillUnmount: function componentWillUnmount() {
if (this.props.onResize) {
this.refs.textarea.getDOMNode().removeEventListener('autosize:resized');
}
},
render: function render() {
return React.createElement(
'textarea',
_extends({}, this.props, { ref: 'textarea' }),
this.props.children
);
}
});
module.exports = TextareaAutosize;
|