import * as Nerv from 'nervjs' import classnames from 'classnames' import { calcTextareaHeight } from './utils' import { styleStr2Obj } from '../util/util' export interface TextareaProps { className?: string type?: string disabled?: boolean placeholder?: string autofocus?: boolean autosize?: boolean resize?: string name?: string value?: any } class Textarea extends Nerv.Component { private $textarea: any constructor (props) { super(props) this.inputHandler = this.inputHandler.bind(this) this.state = { height: '', value: '' } } renderTextareaClassNames (props: TextareaProps) { return classnames( 'at-textarea', [props.disabled ? 'at-textarea--disabled' : ''], props.className ) } render () { const props = this.props const { style, placeholder, autofocus, onDragLeave, onDragOver, onDrop, onMouseOver, onMouseEnter, onMouseOut, onMouseLeave, onClick, children } = props const needProps = { children, onDragLeave, onDragOver, onDrop, onMouseOver, onMouseOut, onMouseEnter, onMouseLeave, onClick } const classNames = this.renderTextareaClassNames(props) let disabled: boolean = false if (props.disabled) { disabled = true } let styleComputed: any = {} if (typeof style === 'string' || style instanceof String) { styleComputed = Object.assign(styleStr2Obj(style), { height: this.state.height }) } else { styleComputed = { ...style, height: this.state.height } } let minRows = props.minRows if (props.autosize) { minRows = 1 } else if (!props.minRows) { minRows = 2 } const className = classnames('at-textarea__original', [ ], props.className) return (