@i-novus/ui-core
Version:
Базовые UI компоненты
27 lines (26 loc) • 1.86 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef, useCallback, useMemo } from 'react';
import RCTextarea from 'rc-textarea';
import classNames from 'classnames';
import { CloseIcon, useConfigProvider } from '../core';
import { Button } from '../general/Button';
export const TextArea = forwardRef((props, ref) => {
const { disabled, placeholder, onChange, className, error, value, style, prefix, autoSize = false, clearIcon = true, ...restProps } = props;
const { getPrefix } = useConfigProvider();
const prefixCls = getPrefix(prefix);
const onTextAreaValueChange = useCallback((event) => {
const textAreaValue = event.target.value;
onChange?.(textAreaValue, event);
}, [onChange]);
const clearValue = useCallback((event) => {
// @ts-ignore
onChange?.('', event);
}, [onChange]);
const icon = typeof clearIcon === 'object' ? clearIcon.icon : _jsx(CloseIcon, {});
const isShowClearIcon = useMemo(() => (Boolean(!disabled && clearIcon && value)), [clearIcon, disabled, value]);
return (_jsxs("div", { style: style, className: classNames(`${prefixCls}-textArea-wrapper`, {
[`${prefixCls}-textArea-wrapper_disabled`]: disabled,
[`${prefixCls}-textArea-wrapper_error`]: error,
}, className), children: [_jsx(RCTextarea, { ref: ref, prefixCls: `${prefixCls}-textArea`, disabled: disabled, placeholder: placeholder, value: value || '', defaultValue: value || '', onChange: onTextAreaValueChange, autoSize: autoSize, ...restProps }), isShowClearIcon && (_jsx(Button, { "aria-label": "\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C", disabled: disabled, onClick: clearValue, variant: "link", className: classNames('btn-xs', `${prefixCls}-textArea__clear-button`), icon: icon }))] }));
});
TextArea.displayName = 'TextArea';