UNPKG

@zohodesk/dot

Version:

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

237 lines (202 loc) 13.9 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 _Select = _interopRequireDefault(require("@zohodesk/components/lib/Select/Select")); 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 SelectField = /*#__PURE__*/function (_PureComponent) { _inherits(SelectField, _PureComponent); var _super = _createSuper(SelectField); function SelectField(props) { var _this; _classCallCheck(this, SelectField); _this = _super.call(this, props); _this.handleChange = _this.handleChange.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(SelectField, [{ key: "handleChange", value: function handleChange(selctedId, selectedValue) { var _this$props = this.props, fieldId = _this$props.id, onChange = _this$props.onChange, propValue = _this$props.selectedValue; onChange && propValue !== selctedId && onChange(fieldId, selctedId, selectedValue); } }, { key: "handleGetRef", value: function handleGetRef(el) { var _this$props2 = this.props, getRef = _this$props2.getRef, id = _this$props2.id; this.selectBox = el; getRef && getRef(el, id); } // handleLabelClick() { // let { isFocusOnLabelClick } = this.props; // if (isFocusOnLabelClick && this.selectBox && this.selectBox.focus) { // this.selectBox.focus(); // } // } }, { key: "render", value: function render() { var _this$props3 = this.props, labelName = _this$props3.labelName, id = _this$props3.id, isMandatory = _this$props3.isMandatory, options = _this$props3.options, selectedValue = _this$props3.selectedValue, needSearch = _this$props3.needSearch, emptyMessage = _this$props3.emptyMessage, animationStyle = _this$props3.animationStyle, textBoxSize = _this$props3.textBoxSize, textBoxVariant = _this$props3.textBoxVariant, searchBoxSize = _this$props3.searchBoxSize, searchBoxPlaceHolder = _this$props3.searchBoxPlaceHolder, validationMessage = _this$props3.validationMessage, validationPalette = _this$props3.validationPalette, isReadOnly = _this$props3.isReadOnly, valueField = _this$props3.valueField, textField = _this$props3.textField, excludeOptions = _this$props3.excludeOptions, errorType = _this$props3.errorType, isDisabled = _this$props3.isDisabled, title = _this$props3.title, dataId = _this$props3.dataId, dataSelectorId = _this$props3.dataSelectorId, fieldClass = _this$props3.fieldClass, validationRuleMessage = _this$props3.validationRuleMessage, validationRulePalette = _this$props3.validationRulePalette, onKeyDown = _this$props3.onKeyDown, infoText = _this$props3.infoText, isLocked = _this$props3.isLocked, lockedInfoText = _this$props3.lockedInfoText, borderColor = _this$props3.borderColor, fieldSize = _this$props3.fieldSize, isNextOptions = _this$props3.isNextOptions, getNextOptions = _this$props3.getNextOptions, popupGroup = _this$props3.popupGroup, onSearch = _this$props3.onSearch, labelPalette = _this$props3.labelPalette, labelCustomClass = _this$props3.labelCustomClass, htmlId = _this$props3.htmlId, needLocalSearch = _this$props3.needLocalSearch, isDefaultSelectValue = _this$props3.isDefaultSelectValue, placeHolder = _this$props3.placeHolder, children = _this$props3.children, onFocus = _this$props3.onFocus, iconOnHover = _this$props3.iconOnHover, customProps = _this$props3.customProps, renderLabelProps = _this$props3.renderLabelProps; var _customProps$LabelPro = customProps.LabelProps, LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro, _customProps$SelectPr = customProps.SelectProps, SelectProps = _customProps$SelectPr === void 0 ? {} : _customProps$SelectPr, _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(); 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, 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, { id: uniqueId }))), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_FieldsModule["default"].fieldContainer, " ").concat(labelName ? _FieldsModule["default"]["fieldMargin_".concat(fieldSize)] : '', " ").concat(fieldClass ? fieldClass : '') }, /*#__PURE__*/_react["default"].createElement(_Select["default"], _extends({ options: options, selectedValue: selectedValue, onChange: this.handleChange, onFocus: onFocus, getRef: this.handleGetRef, needSearch: needSearch, emptyMessage: emptyMessage, animationStyle: animationStyle, textBoxSize: fieldSize === 'medium' ? textBoxSize : 'xsmall', textBoxVariant: textBoxVariant, searchBoxSize: searchBoxSize, searchBoxPlaceHolder: searchBoxPlaceHolder, valueField: valueField, textField: textField, excludeOptions: excludeOptions, dataId: dataId, onKeyDown: onKeyDown, borderColor: borderColor, isDisabled: isDisabled, isReadOnly: isReadOnly, isNextOptions: isNextOptions, getNextOptions: getNextOptions, popupGroup: popupGroup, onSearch: onSearch, htmlId: uniqueId, needLocalSearch: needLocalSearch, isDefaultSelectValue: isDefaultSelectValue, placeHolder: placeHolder, iconOnHover: iconOnHover, title: title }, SelectProps, { ariaLabelledby: uniqueId }), children ? children : null)), 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 SelectField; }(_react.PureComponent); exports["default"] = SelectField; SelectField.propTypes = _propTypes.propTypes; SelectField.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // SelectField.docs = { // componentGroup: 'Form Fields', // folderName: 'General' // }; // }