UNPKG

choerodon-ui

Version:

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

160 lines (133 loc) 5.04 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; 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 isString from 'lodash/isString'; import omit from 'lodash/omit'; 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'; 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: "getOtherProps", value: function getOtherProps() { var _this$props$resize = this.props.resize, resize = _this$props$resize === void 0 ? ResizeType.none : _this$props$resize; var otherProps = omit(_get(_getPrototypeOf(TextArea.prototype), "getOtherProps", this).call(this), ['resize', 'autoSize', 'onResize']); var _otherProps$style = otherProps.style, style = _otherProps$style === void 0 ? {} : _otherProps$style; style.resize = resize; if (resize !== ResizeType.none) { style.transition = 'none'; } var autoSize = this.props.autoSize; var textAreaStyles = {}; if (autoSize) { var minRows = autoSize.minRows, maxRows = autoSize.maxRows; otherProps.rows = minRows; if (this.element) { textAreaStyles = calculateNodeHeight(this.element, true, minRows, maxRows); } } otherProps.style = _objectSpread({}, style, {}, textAreaStyles); return otherProps; } }, { key: "renderWrapper", value: function renderWrapper() { var _this$props = this.props, onResize = _this$props.onResize, _this$props$resize2 = _this$props.resize, resize = _this$props$resize2 === void 0 ? ResizeType.none : _this$props$resize2; var text = this.getTextNode(); var wrap = React.createElement("div", _extends({ key: "wrapper" }, this.getWrapperProps()), this.renderPlaceHolder(), React.createElement("label", null, React.createElement("textarea", _extends({}, this.getOtherProps(), { placeholder: this.hasFloatLabel ? undefined : this.getPlaceholders()[0], readOnly: !this.editable, value: isString(text) ? text : this.getText(this.getValue()) })), this.renderFloatLabel())); if (onResize && resize !== ResizeType.none) { return React.createElement(ReactResizeObserver, { onResize: onResize, resizeProp: getResizeProp(resize) }, wrap); } return wrap; } }, { 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; TextArea = __decorate([observer], TextArea); export default TextArea; //# sourceMappingURL=TextArea.js.map