import classNames from 'classnames' import PropTypes, { InferProps } from 'prop-types' import React from 'react' import { Textarea, View } from '@vnxjs/components' import { CommonEvent } from '@vnxjs/components/types/common' import Vnmf from '@vnxjs/vnmf' import { AtTextareaProps } from '../../../types/textarea' type ExtendEvent = { target: { value: string } } function getMaxLength( maxLength: number, textOverflowForbidden: boolean ): number { if (!textOverflowForbidden) { return maxLength + 500 } return maxLength } const ENV = Vnmf.getEnv() export default class AtTextarea extends React.Component { public static defaultProps: AtTextareaProps public static propTypes: InferProps private handleInput = (event: CommonEvent & ExtendEvent): void => { this.props.onChange(event.detail.value, event) } private handleFocus = (event: CommonEvent): void => { this.props.onFocus && this.props.onFocus(event) } private handleBlur = (event: CommonEvent): void => { this.props.onBlur && this.props.onBlur(event) } private handleConfirm = (event: CommonEvent): void => { this.props.onConfirm && this.props.onConfirm(event) } private handleLinechange = (event: CommonEvent): void => { this.props.onLinechange && this.props.onLinechange(event) } public render(): JSX.Element { const { customStyle, className, value, cursorSpacing, placeholder, placeholderStyle, placeholderClass, maxLength = 200, count, disabled, autoFocus, focus, showConfirmBar, selectionStart, selectionEnd, fixed, textOverflowForbidden = true, height } = this.props const _maxLength = parseInt(maxLength.toString()) const actualMaxLength = getMaxLength(_maxLength, textOverflowForbidden) const textareaStyle: any = {} if (height) { textareaStyle.height = parseInt(Vnmf.pxTransform(Number(height))) } const rootCls = classNames('at-textarea', `at-textarea--${ENV}`, className) const sizeError = _maxLength < value.length const placeholderCls = classNames('placeholder', placeholderClass) return (