UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

226 lines (189 loc) 13.3 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireWildcard(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _Label = _interopRequireDefault(require("@zohodesk/components/lib/Label/Label")); var _Textarea = _interopRequireDefault(require("@zohodesk/components/lib/Textarea/Textarea")); var _ValidationMessage = _interopRequireDefault(require("../ValidationMessage/ValidationMessage")); var _IdProvider = require("@zohodesk/components/lib/Provider/IdProvider"); var _FieldContainer = _interopRequireDefault(require("../FieldContainer/FieldContainer")); var _FieldsModule = _interopRequireDefault(require("../Fields.module.css")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var TextareaField = /*#__PURE__*/function (_PureComponent) { _inherits(TextareaField, _PureComponent); var _super = _createSuper(TextareaField); function TextareaField(props) { var _this; _classCallCheck(this, TextareaField); _this = _super.call(this, props); _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this)); _this.handleBlur = _this.handleBlur.bind(_assertThisInitialized(_this)); _this.handleGetRef = _this.handleGetRef.bind(_assertThisInitialized(_this)); // this.handleLabelClick = this.handleLabelClick.bind(this); _this.getNextId = (0, _IdProvider.getUniqueId)(_assertThisInitialized(_this)); return _this; } _createClass(TextareaField, [{ key: "handleChange", value: function handleChange(value) { var _this$props = this.props, id = _this$props.id, onChange = _this$props.onChange; onChange && onChange(id, value); } }, { key: "handleBlur", value: function handleBlur(value) { var _this$props2 = this.props, id = _this$props2.id, onBlur = _this$props2.onBlur; onBlur && onBlur(id, value); } }, { key: "handleGetRef", value: function handleGetRef(el) { var _this$props3 = this.props, getRef = _this$props3.getRef, id = _this$props3.id; this.textarea = el; getRef && getRef(el, id); } // handleLabelClick() { // let { isFocusOnLabelClick } = this.props; // if (isFocusOnLabelClick && this.textarea && this.textarea.focus) { // this.textarea.focus(); // } // } }, { key: "render", value: function render() { var _this$props4 = this.props, labelName = _this$props4.labelName, id = _this$props4.id, isMandatory = _this$props4.isMandatory, textBoxSize = _this$props4.textBoxSize, animated = _this$props4.animated, textBoxVariant = _this$props4.textBoxVariant, isReadOnly = _this$props4.isReadOnly, validationMessage = _this$props4.validationMessage, validationPalette = _this$props4.validationPalette, maxLength = _this$props4.maxLength, value = _this$props4.value, errorType = _this$props4.errorType, isDisabled = _this$props4.isDisabled, title = _this$props4.title, placeHolder = _this$props4.placeHolder, dataId = _this$props4.dataId, dataSelectorId = _this$props4.dataSelectorId, validationRuleMessage = _this$props4.validationRuleMessage, validationRulePalette = _this$props4.validationRulePalette, onFocus = _this$props4.onFocus, infoText = _this$props4.infoText, borderColor = _this$props4.borderColor, fieldSize = _this$props4.fieldSize, labelPalette = _this$props4.labelPalette, labelCustomClass = _this$props4.labelCustomClass, htmlId = _this$props4.htmlId, lockedInfoText = _this$props4.lockedInfoText, isLocked = _this$props4.isLocked, customProps = _this$props4.customProps, renderLabelProps = _this$props4.renderLabelProps, renderRightPlaceholderNode = _this$props4.renderRightPlaceholderNode, rightPlaceholderCustomClass = _this$props4.rightPlaceholderCustomClass; var _customProps$LabelPro = customProps.LabelProps, LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro, _customProps$Textarea = customProps.TextareaProps, TextareaProps = _customProps$Textarea === void 0 ? {} : _customProps$Textarea, _customProps$Validati = customProps.ValidationMessageProps1, ValidationMessageProps1 = _customProps$Validati === void 0 ? {} : _customProps$Validati, _customProps$Validati2 = customProps.ValidationMessageProps2, ValidationMessageProps2 = _customProps$Validati2 === void 0 ? {} : _customProps$Validati2; var uniqueId = htmlId ? htmlId : this.getNextId(); var textAreaContent = /*#__PURE__*/_react["default"].createElement(_Textarea["default"], _extends({ onChange: this.handleChange, animated: animated, size: fieldSize === 'medium' ? textBoxSize : 'xmedium', variant: textBoxVariant, isReadOnly: isReadOnly, isDisabled: isDisabled, getRef: this.handleGetRef, maxLength: maxLength, text: value, placeHolder: placeHolder, dataId: "property(".concat(dataId, ")"), onFocus: onFocus, onBlur: this.handleBlur, borderColor: borderColor, needEffect: isReadOnly || isDisabled ? false : true, resize: "vertical" // onKeyDown={onKeyDown} , htmlId: uniqueId }, TextareaProps, { a11y: { ariaLabelledby: labelName } })); return /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_FieldsModule["default"].container, " ").concat(isDisabled ? _FieldsModule["default"].disabled : isReadOnly ? _FieldsModule["default"].readonly : ''), "data-title": isDisabled ? title : null, "data-selector-id": dataSelectorId }, labelName && /*#__PURE__*/_react["default"].createElement(_FieldContainer["default"], { infoText: infoText, isLocked: isLocked, lockedInfoText: lockedInfoText, renderProps: renderLabelProps }, /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({ text: labelName, id: id, size: fieldSize === 'small' ? 'small' : 'medium', palette: isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette, customClass: "".concat(_FieldsModule["default"].fieldLabel, " ").concat(labelCustomClass, " ").concat(isMandatory ? _FieldsModule["default"].labelMandatory : ''), htmlFor: uniqueId, dataId: isDisabled ? "".concat(dataId, "_label_disabled") : isMandatory ? "".concat(dataId, "_label_mandatory") : "".concat(dataId, "_label") }, LabelProps))), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_FieldsModule["default"].fieldContainer, " ").concat(labelName ? _FieldsModule["default"]["fieldMargin_".concat(fieldSize)] : '') }, !renderRightPlaceholderNode ? textAreaContent : /*#__PURE__*/_react["default"].createElement("div", { className: _FieldsModule["default"].hasChildren }, textAreaContent, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_FieldsModule["default"].rightPlaceholder, " ").concat(rightPlaceholderCustomClass) }, renderRightPlaceholderNode)), validationMessage && /*#__PURE__*/_react["default"].createElement(_ValidationMessage["default"], _extends({ text: validationMessage, palette: validationPalette, type: errorType, htmlFor: uniqueId, dataId: "".concat(dataId, "_ValidationMessage") }, ValidationMessageProps1)), validationRuleMessage && /*#__PURE__*/_react["default"].createElement(_ValidationMessage["default"], _extends({ text: validationRuleMessage, palette: validationRulePalette, type: errorType, htmlFor: uniqueId, dataId: "".concat(dataId, "_ValidationRuleMessage") }, ValidationMessageProps2)))); } }]); return TextareaField; }(_react.PureComponent); exports["default"] = TextareaField; TextareaField.propTypes = _propTypes.propTypes; TextareaField.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // TextareaField.docs = { // componentGroup: 'Form Fields', // folderName: 'General' // }; // }