UNPKG

antd

Version:

An enterprise-class UI design language and React components implementation

119 lines (118 loc) 5.11 kB
"use client"; var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import { forwardRef } from 'react'; import CloseCircleFilled from "@ant-design/icons/es/icons/CloseCircleFilled"; import classNames from 'classnames'; import RcTextArea from 'rc-textarea'; import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils'; import { ConfigContext } from '../config-provider'; import DisabledContext from '../config-provider/DisabledContext'; import useSize from '../config-provider/hooks/useSize'; import { FormItemInputContext } from '../form/context'; import { triggerFocus } from './Input'; import useStyle from './style'; import useCSSVarCls from '../config-provider/hooks/useCSSVarCls'; import useVariant from '../form/hooks/useVariants'; import { devUseWarning } from '../_util/warning'; const TextArea = /*#__PURE__*/forwardRef((props, ref) => { var _a; const { prefixCls: customizePrefixCls, bordered = true, size: customizeSize, disabled: customDisabled, status: customStatus, allowClear, classNames: classes, rootClassName, className, variant: customVariant } = props, rest = __rest(props, ["prefixCls", "bordered", "size", "disabled", "status", "allowClear", "classNames", "rootClassName", "className", "variant"]); if (process.env.NODE_ENV !== 'production') { const { deprecated } = devUseWarning('TextArea'); deprecated(!('bordered' in props), 'bordered', 'variant'); } const { getPrefixCls, direction } = React.useContext(ConfigContext); // ===================== Size ===================== const mergedSize = useSize(customizeSize); // ===================== Disabled ===================== const disabled = React.useContext(DisabledContext); const mergedDisabled = customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled; // ===================== Status ===================== const { status: contextStatus, hasFeedback, feedbackIcon } = React.useContext(FormItemInputContext); const mergedStatus = getMergedStatus(contextStatus, customStatus); // ===================== Ref ===================== const innerRef = React.useRef(null); React.useImperativeHandle(ref, () => { var _a; return { resizableTextArea: (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.resizableTextArea, focus: option => { var _a, _b; triggerFocus((_b = (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.resizableTextArea) === null || _b === void 0 ? void 0 : _b.textArea, option); }, blur: () => { var _a; return (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.blur(); } }; }); const prefixCls = getPrefixCls('input', customizePrefixCls); // Allow clear let mergedAllowClear; if (typeof allowClear === 'object' && (allowClear === null || allowClear === void 0 ? void 0 : allowClear.clearIcon)) { mergedAllowClear = allowClear; } else if (allowClear) { mergedAllowClear = { clearIcon: /*#__PURE__*/React.createElement(CloseCircleFilled, null) }; } // ===================== Style ===================== const rootCls = useCSSVarCls(prefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls); const [variant, enableVariantCls] = useVariant(customVariant, bordered); return wrapCSSVar( /*#__PURE__*/React.createElement(RcTextArea, Object.assign({}, rest, { disabled: mergedDisabled, allowClear: mergedAllowClear, className: classNames(cssVarCls, rootCls, className, rootClassName), classNames: Object.assign(Object.assign({}, classes), { textarea: classNames({ [`${prefixCls}-sm`]: mergedSize === 'small', [`${prefixCls}-lg`]: mergedSize === 'large' }, hashId, classes === null || classes === void 0 ? void 0 : classes.textarea), variant: classNames({ [`${prefixCls}-${variant}`]: enableVariantCls }, getStatusClassNames(prefixCls, mergedStatus)), affixWrapper: classNames(`${prefixCls}-textarea-affix-wrapper`, { [`${prefixCls}-affix-wrapper-rtl`]: direction === 'rtl', [`${prefixCls}-affix-wrapper-sm`]: mergedSize === 'small', [`${prefixCls}-affix-wrapper-lg`]: mergedSize === 'large', [`${prefixCls}-textarea-show-count`]: props.showCount || ((_a = props.count) === null || _a === void 0 ? void 0 : _a.show) }, hashId) }), prefixCls: prefixCls, suffix: hasFeedback && /*#__PURE__*/React.createElement("span", { className: `${prefixCls}-textarea-suffix` }, feedbackIcon), ref: innerRef }))); }); export default TextArea;