@tarojsx/ui
Version:
We reinvents the UI for Taro3+
31 lines • 1.92 kB
JavaScript
import { __rest } from "tslib";
import React, { useMemo } from 'react';
import Taro from '@tarojs/taro';
import classNames from 'classnames';
import { View } from '@tarojs/components';
import { TextareaEnhance } from './TextareaEnhance';
import '../style/Textarea.scss';
const ENV = Taro.getEnv();
export const Textarea = (props) => {
var _a, _b;
const { className, style = {}, textareaRef, value = '', cursorSpacing = 100, placeholderClass, count = true, autoFocus, textOverflowForbidden = true, height, onChange } = props, rest = __rest(props, ["className", "style", "textareaRef", "value", "cursorSpacing", "placeholderClass", "count", "autoFocus", "textOverflowForbidden", "height", "onChange"]);
const maxlength = (_b = (_a = props.maxlength) !== null && _a !== void 0 ? _a : props.maxLength) !== null && _b !== void 0 ? _b : 200;
const actualMaxLength = useMemo(() => (textOverflowForbidden ? maxlength : maxlength + 500), [
maxlength,
textOverflowForbidden,
]);
const textareaStyle = height ? { height: Taro.pxTransform(Number(height)) } : {};
const rootCls = classNames('at-textarea', `at-textarea--${ENV}`, {
'at-textarea--error': maxlength < value.length,
}, className);
const placeholderCls = classNames('placeholder', placeholderClass);
return (React.createElement(View, { className: rootCls, style: style },
React.createElement(TextareaEnhance, Object.assign({ ref: textareaRef, className: "at-textarea__textarea", style: textareaStyle, placeholderClass: placeholderCls, cursorSpacing: cursorSpacing, value: value,
/* 兼容之前的版本 */
maxlength: actualMaxLength, focus: autoFocus, onInput: onChange }, rest)),
count && (React.createElement(View, { className: "at-textarea__counter" },
value.length,
"/",
maxlength))));
};
//# sourceMappingURL=Textarea.js.map