UNPKG

@brizy/ui

Version:
27 lines (26 loc) 1.67 kB
import React, { useCallback } from "react"; import { classNames } from "../classNamesFn"; import { ifElse } from "ramda"; import AntInputTextarea from "antd/lib/input/TextArea"; import { isString, isNumber, emptyStyles } from "../utils"; import { getFieldsStyleTheme } from "../utils/getFieldsTheme"; import { getCustomTextareaHeight } from "./utils"; import { WrapperForDisabled } from "./WrapperForDisabled"; export const TextArea = (props) => { const { size, strong, value = "", autoSize, placeholder, onBlur, onFocus, onPressEnter, onResize, theme, onChange, disabled, } = props; const className = classNames()("input-form", "input__textarea", { "input__textarea--strong": strong }, { [`input__textarea--${size}`]: isString(size) && size }); const customHeight = ifElse(isNumber, getCustomTextareaHeight, emptyStyles); const handleChange = useCallback((e) => { if (!disabled) onChange === null || onChange === void 0 ? void 0 : onChange(e.target.value); }, [disabled, onChange]); const handlePressEnter = (e) => { const { shiftKey } = e; if (typeof onPressEnter === "function" && !shiftKey) { e.preventDefault(); onPressEnter(); } }; return (React.createElement(WrapperForDisabled, { disabled: disabled }, React.createElement(AntInputTextarea, { style: Object.assign(Object.assign({}, getFieldsStyleTheme(theme)), customHeight(size)), className: className, value: value, autoSize: autoSize, placeholder: placeholder, onPressEnter: handlePressEnter, onResize: onResize, onBlur: onBlur, onFocus: onFocus, onChange: handleChange, disabled: disabled }))); };