Skip to content

Commit

Permalink
Update to use react-proptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhm committed May 20, 2019
1 parent b7df4ae commit 29600fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
41 changes: 22 additions & 19 deletions lib/TextareaAutosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = undefined;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

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; };

Expand All @@ -19,6 +19,10 @@ var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactProptypes = require('react-proptypes');

var _reactProptypes2 = _interopRequireDefault(_reactProptypes);

var _calculateNodeHeight = require('./calculateNodeHeight');

var _calculateNodeHeight2 = _interopRequireDefault(_calculateNodeHeight);
Expand All @@ -41,7 +45,7 @@ var TextareaAutosize = (_temp = _class = function (_React$Component) {
function TextareaAutosize(props) {
_classCallCheck(this, TextareaAutosize);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TextareaAutosize).call(this, props));
var _this = _possibleConstructorReturn(this, (TextareaAutosize.__proto__ || Object.getPrototypeOf(TextareaAutosize)).call(this, props));

_this.state = {
height: null,
Expand All @@ -59,13 +63,12 @@ var TextareaAutosize = (_temp = _class = function (_React$Component) {
key: 'render',
value: function render() {
// Remove unsupported <textarea> props
var _props = this.props;
var valueLink = _props.valueLink;
var useCacheForDOMMeasurements = _props.useCacheForDOMMeasurements;
var minRows = _props.minRows;
var onHeightChange = _props.onHeightChange;

var props = _objectWithoutProperties(_props, ['valueLink', 'useCacheForDOMMeasurements', 'minRows', 'onHeightChange']);
var _props = this.props,
valueLink = _props.valueLink,
useCacheForDOMMeasurements = _props.useCacheForDOMMeasurements,
minRows = _props.minRows,
onHeightChange = _props.onHeightChange,
props = _objectWithoutProperties(_props, ['valueLink', 'useCacheForDOMMeasurements', 'minRows', 'onHeightChange']);

props = _extends({}, props);
if ((typeof valueLink === 'undefined' ? 'undefined' : _typeof(valueLink)) === 'object') {
Expand Down Expand Up @@ -119,9 +122,9 @@ var TextareaAutosize = (_temp = _class = function (_React$Component) {
key: '_onChange',
value: function _onChange(e) {
this._resizeComponent(this.props.value);
var _props2 = this.props;
var valueLink = _props2.valueLink;
var onChange = _props2.onChange;
var _props2 = this.props,
valueLink = _props2.valueLink,
onChange = _props2.onChange;

if (valueLink) {
valueLink.requestChange(e.target.value);
Expand Down Expand Up @@ -218,17 +221,17 @@ var TextareaAutosize = (_temp = _class = function (_React$Component) {
/**
* Current textarea value.
*/
value: _react2.default.PropTypes.string,
value: _reactProptypes2.default.string,

/**
* Callback on value change.
*/
onChange: _react2.default.PropTypes.func,
onChange: _reactProptypes2.default.func,

/**
* Callback on height changes.
*/
onHeightChange: _react2.default.PropTypes.func,
onHeightChange: _reactProptypes2.default.func,

/**
* Try to cache DOM measurements performed by component so that we don't
Expand All @@ -237,22 +240,22 @@ var TextareaAutosize = (_temp = _class = function (_React$Component) {
* This optimization doesn't work if we dynamically style <textarea />
* component.
*/
useCacheForDOMMeasurements: _react2.default.PropTypes.bool,
useCacheForDOMMeasurements: _reactProptypes2.default.bool,

/**
* Minimal numbder of rows to show.
*/
rows: _react2.default.PropTypes.number,
rows: _reactProptypes2.default.number,

/**
* Alias for `rows`.
*/
minRows: _react2.default.PropTypes.number,
minRows: _reactProptypes2.default.number,

/**
* Maximum number of rows to show.
*/
maxRows: _react2.default.PropTypes.number
maxRows: _reactProptypes2.default.number
}, _class.defaultProps = {
onChange: emptyFunction,
onHeightChange: emptyFunction,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
],
"license": "MIT",
"main": "lib/TextareaAutosize.js",
"peerDependencies": {
"react": ">=0.14.0 <16.0.0"
},
"peerDependencies": {},
"repository": {
"type": "git",
"url": "git://github.com/andreypopp/react-textarea-autosize.git"
Expand All @@ -39,5 +37,7 @@
"eslint-config-prometheusresearch": "^0.2.0",
"react": "^15.0.0"
},
"dependencies": {}
"dependencies": {
"react-proptypes": "^1.0.0"
}
}
15 changes: 8 additions & 7 deletions src/TextareaAutosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import React from 'react';
import PropTypes from 'react-proptypes';
import calculateNodeHeight from './calculateNodeHeight';

const emptyFunction = function() {};
Expand All @@ -13,17 +14,17 @@ export default class TextareaAutosize extends React.Component {
/**
* Current textarea value.
*/
value: React.PropTypes.string,
value: PropTypes.string,

/**
* Callback on value change.
*/
onChange: React.PropTypes.func,
onChange: PropTypes.func,

/**
* Callback on height changes.
*/
onHeightChange: React.PropTypes.func,
onHeightChange: PropTypes.func,

/**
* Try to cache DOM measurements performed by component so that we don't
Expand All @@ -32,22 +33,22 @@ export default class TextareaAutosize extends React.Component {
* This optimization doesn't work if we dynamically style <textarea />
* component.
*/
useCacheForDOMMeasurements: React.PropTypes.bool,
useCacheForDOMMeasurements: PropTypes.bool,

/**
* Minimal numbder of rows to show.
*/
rows: React.PropTypes.number,
rows: PropTypes.number,

/**
* Alias for `rows`.
*/
minRows: React.PropTypes.number,
minRows: PropTypes.number,

/**
* Maximum number of rows to show.
*/
maxRows: React.PropTypes.number
maxRows: PropTypes.number
}

static defaultProps = {
Expand Down

0 comments on commit 29600fa

Please sign in to comment.