UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

195 lines (161 loc) 6.1 kB
import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _get from "@babel/runtime/helpers/get"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import { __decorate } from "tslib"; import React from 'react'; import { observer } from 'mobx-react'; import { action, observable } from 'mobx'; import isString from 'lodash/isString'; import PropTypes from 'prop-types'; import ReactResizeObserver from '../../../es/_util/resizeObserver'; import { TextField } from '../text-field/TextField'; import { ResizeType } from './enum'; import calculateNodeHeight from './calculateNodeHeight'; import autobind from '../_util/autobind'; function getResizeProp(resize) { switch (resize) { case ResizeType.both: return 'both'; case ResizeType.vertical: return 'height'; case ResizeType.horizontal: return 'width'; default: return undefined; } } var TextArea = /*#__PURE__*/ function (_TextField) { _inherits(TextArea, _TextField); var _super = _createSuper(TextArea); function TextArea() { _classCallCheck(this, TextArea); return _super.apply(this, arguments); } _createClass(TextArea, [{ key: "getOmitPropsKeys", value: function getOmitPropsKeys() { return _get(_getPrototypeOf(TextArea.prototype), "getOmitPropsKeys", this).call(this).concat(['resize', 'autoSize', 'onResize']); } }, { key: "getOtherProps", value: function getOtherProps() { var _this$props = this.props, _this$props$resize = _this$props.resize, resize = _this$props$resize === void 0 ? ResizeType.none : _this$props$resize, autoSize = _this$props.autoSize; var otherProps = _get(_getPrototypeOf(TextArea.prototype), "getOtherProps", this).call(this); var _otherProps$style = otherProps.style, style = _otherProps$style === void 0 ? {} : _otherProps$style; style.resize = resize; if (resize !== ResizeType.none) { style.transition = 'none'; } if (autoSize) { var minRows = autoSize.minRows, maxRows = autoSize.maxRows; otherProps.rows = minRows; var element = this.element; if (element) { _extends(style, calculateNodeHeight(element, true, minRows, maxRows)); } } otherProps.style = style; return otherProps; } }, { key: "handleResize", value: function handleResize(width, height, target) { var onResize = this.props.onResize; if (!this.resized) { var element = this.element; if (element && element.style.width) { this.resized = true; } } if (onResize) { onResize(width, height, target); } } }, { key: "renderWrapper", value: function renderWrapper() { var _this$props$resize2 = this.props.resize, resize = _this$props$resize2 === void 0 ? ResizeType.none : _this$props$resize2; var text = this.getTextNode(); var resizable = resize !== ResizeType.none; var wrapperProps = this.getWrapperProps() || {}; var elementProps = this.getOtherProps() || {}; var lengthElement = this.renderLengthInfo(); if (this.resized) { var wrapperStyle = wrapperProps.style; wrapperProps.style = _objectSpread({}, wrapperStyle, { width: 'auto' }); } var element = React.createElement("textarea", _extends({}, elementProps, { placeholder: this.hasFloatLabel ? undefined : this.getPlaceholders()[0], readOnly: !this.editable, value: isString(text) ? text : this.processValue(this.getValue()) })); return React.createElement("div", _extends({ key: "wrapper" }, wrapperProps), this.renderPlaceHolder(), React.createElement("label", null, resizable ? React.createElement(ReactResizeObserver, { onResize: this.handleResize, resizeProp: getResizeProp(resize) }, element, lengthElement) : React.createElement(React.Fragment, null, element, lengthElement), this.renderFloatLabel())); } }, { key: "handleEnterDown", value: function handleEnterDown() {} }]); return TextArea; }(TextField); TextArea.displayName = 'TextArea'; TextArea.propTypes = _objectSpread({ cols: PropTypes.number, rows: PropTypes.number, resize: PropTypes.oneOf([ResizeType.vertical, ResizeType.horizontal, ResizeType.none, ResizeType.both]), autoSize: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]) }, TextField.propTypes); TextArea.defaultProps = _objectSpread({}, TextField.defaultProps, { suffixCls: 'textarea', rows: 4, autoSize: false }); // eslint-disable-next-line camelcase TextArea.__PRO_TEXTAREA = true; __decorate([observable], TextArea.prototype, "resized", void 0); __decorate([autobind, action], TextArea.prototype, "handleResize", null); TextArea = __decorate([observer], TextArea); export default TextArea; //# sourceMappingURL=TextArea.js.map