import _extends from"babel-runtime/helpers/extends";import _defineProperty from"babel-runtime/helpers/defineProperty";import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import*as React from"react";import omit from"omit.js";import classNames from"classnames";import calculateNodeHeight from"./calculateNodeHeight";function onNextFrame(e){return window.requestAnimationFrame?window.requestAnimationFrame(e):window.setTimeout(e,1)}function clearNextFrameAction(e){window.cancelAnimationFrame?window.cancelAnimationFrame(e):window.clearTimeout(e)}var TextArea=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments));return e.state={textareaStyles:{}},e.resizeTextarea=function(){var t=e.props.autosize;if(t&&e.textAreaRef){var r=t?t.minRows:null,a=t?t.maxRows:null,n=calculateNodeHeight(e.textAreaRef,!1,r,a);e.setState({textareaStyles:n})}},e.handleTextareaChange=function(t){"value"in e.props||e.resizeTextarea();var r=e.props.onChange;r&&r(t)},e.handleKeyDown=function(t){var r=e.props,a=r.onPressEnter,n=r.onKeyDown;13===t.keyCode&&a&&a(t),n&&n(t)},e.saveTextAreaRef=function(t){e.textAreaRef=t},e}return _inherits(t,e),_createClass(t,[{key:"componentDidMount",value:function(){this.resizeTextarea()}},{key:"componentWillReceiveProps",value:function(e){this.props.value!==e.value&&(this.nextFrameActionId&&clearNextFrameAction(this.nextFrameActionId),this.nextFrameActionId=onNextFrame(this.resizeTextarea))}},{key:"focus",value:function(){this.textAreaRef.focus()}},{key:"blur",value:function(){this.textAreaRef.blur()}},{key:"getTextAreaClassName",value:function(){var e=this.props,t=e.prefixCls,r=e.className,a=e.disabled;return classNames(t,r,_defineProperty({},t+"-disabled",a))}},{key:"render",value:function(){var e=this.props,t=omit(e,["prefixCls","onPressEnter","autosize"]),r=_extends({},e.style,this.state.textareaStyles);return"value"in t&&(t.value=t.value||""),React.createElement("textarea",_extends({},t,{className:this.getTextAreaClassName(),style:r,onKeyDown:this.handleKeyDown,onChange:this.handleTextareaChange,ref:this.saveTextAreaRef}))}}]),t}(React.Component);export default TextArea;TextArea.defaultProps={prefixCls:"dt-input"};