UNPKG

@zohodesk/dot

Version:

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

268 lines (233 loc) 14.6 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 _MultiSelect = _interopRequireDefault(require("@zohodesk/components/lib/MultiSelect/MultiSelect")); 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 MultiSelectField = /*#__PURE__*/function (_PureComponent) { _inherits(MultiSelectField, _PureComponent); var _super = _createSuper(MultiSelectField); function MultiSelectField(props) { var _this; _classCallCheck(this, MultiSelectField); _this = _super.call(this, props); _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this)); _this.handleGetRef = _this.handleGetRef.bind(_assertThisInitialized(_this)); _this.onDropBoxOpen = _this.onDropBoxOpen.bind(_assertThisInitialized(_this)); // this.handleLabelClick = this.handleLabelClick.bind(this); _this.onSearch = _this.onSearch.bind(_assertThisInitialized(_this)); _this.getNextOptions = _this.getNextOptions.bind(_assertThisInitialized(_this)); _this.getNextId = (0, _IdProvider.getUniqueId)(_assertThisInitialized(_this)); return _this; } _createClass(MultiSelectField, [{ key: "handleChange", value: function handleChange(selectedValueIds, selectedValues) { var _this$props = this.props, id = _this$props.id, onChange = _this$props.onChange; onChange && onChange(id, selectedValueIds, selectedValues); } }, { key: "onDropBoxOpen", value: function onDropBoxOpen() { var _this$props2 = this.props, onDropBoxOpen = _this$props2.onDropBoxOpen, id = _this$props2.id; return onDropBoxOpen && onDropBoxOpen(id); } }, { key: "onSearch", value: function onSearch(searchStr) { var _this$props3 = this.props, onSearch = _this$props3.onSearch, id = _this$props3.id; return onSearch && onSearch(searchStr, { id: id }); } }, { key: "getNextOptions", value: function getNextOptions(searchStr) { var _this$props4 = this.props, getNextOptions = _this$props4.getNextOptions, id = _this$props4.id; return getNextOptions && getNextOptions(searchStr, { id: id }); } }, { key: "handleGetRef", value: function handleGetRef(el) { var _this$props5 = this.props, getRef = _this$props5.getRef, id = _this$props5.id; this.multiSelectBox = el; getRef && getRef(el, id); } // handleLabelClick() { // let { isFocusOnLabelClick } = this.props; // if ( // isFocusOnLabelClick && // this.multiSelectBox && // this.multiSelectBox.focus // ) { // this.multiSelectBox.focus(); // } // } }, { key: "render", value: function render() { var _this$props6 = this.props, labelName = _this$props6.labelName, id = _this$props6.id, isMandatory = _this$props6.isMandatory, options = _this$props6.options, selectedOptions = _this$props6.selectedOptions, needSelectAll = _this$props6.needSelectAll, selectAllText = _this$props6.selectAllText, isAnimate = _this$props6.isAnimate, emptyMessage = _this$props6.emptyMessage, size = _this$props6.size, variant = _this$props6.variant, textBoxSize = _this$props6.textBoxSize, animationStyle = _this$props6.animationStyle, validationMessage = _this$props6.validationMessage, validationPalette = _this$props6.validationPalette, isReadOnly = _this$props6.isReadOnly, errorType = _this$props6.errorType, isDisabled = _this$props6.isDisabled, title = _this$props6.title, dataId = _this$props6.dataId, dataSelectorId = _this$props6.dataSelectorId, validationRuleMessage = _this$props6.validationRuleMessage, validationRulePalette = _this$props6.validationRulePalette, onKeyDown = _this$props6.onKeyDown, infoText = _this$props6.infoText, borderColor = _this$props6.borderColor, placeHolder = _this$props6.placeHolder, fieldSize = _this$props6.fieldSize, valueField = _this$props6.valueField, textField = _this$props6.textField, isNextOptions = _this$props6.isNextOptions, isSearching = _this$props6.isSearching, popupGroup = _this$props6.popupGroup, labelPalette = _this$props6.labelPalette, palette = _this$props6.palette, lockedInfoText = _this$props6.lockedInfoText, isLocked = _this$props6.isLocked, htmlId = _this$props6.htmlId, children = _this$props6.children, customChildrenClass = _this$props6.customChildrenClass, onFocus = _this$props6.onFocus, customProps = _this$props6.customProps, i18nKeys = _this$props6.i18nKeys, renderLabelProps = _this$props6.renderLabelProps; var _customProps$LabelPro = customProps.LabelProps, LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro, _customProps$MultiSel = customProps.MultiSelectProps, MultiSelectProps = _customProps$MultiSel === void 0 ? {} : _customProps$MultiSel, _customProps$Validati = customProps.ValidationMessageProps1, ValidationMessageProps1 = _customProps$Validati === void 0 ? {} : _customProps$Validati, _customProps$Validati2 = customProps.ValidationMessageProps2, ValidationMessageProps2 = _customProps$Validati2 === void 0 ? {} : _customProps$Validati2; var isDarkPalette = palette === 'dark'; 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, id: id, size: fieldSize === 'small' ? 'small' : 'medium', palette: isDarkPalette ? 'dark' : isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette // onClick={this.handleLabelClick} , customClass: "".concat(_FieldsModule["default"].fieldLabel, " ").concat(isMandatory ? _FieldsModule["default"].labelMandatory : ''), dataId: isDisabled ? "".concat(dataId, "_label_disabled") : isMandatory ? "".concat(dataId, "_label_mandatory") : "".concat(dataId, "_label"), htmlFor: uniqueId }, LabelProps))), /*#__PURE__*/_react["default"].createElement(_MultiSelect["default"], _extends({ options: options, onChange: this.handleChange, selectedOptions: selectedOptions, getRef: this.handleGetRef, isReadOnly: isReadOnly, needSelectAll: needSelectAll, selectAllText: selectAllText, isAnimate: isAnimate, emptyMessage: emptyMessage, textBoxSize: textBoxSize, variant: variant, size: size, animationStyle: animationStyle, dataId: dataId, onKeyDown: onKeyDown, borderColor: borderColor, placeHolder: placeHolder, isDisabled: isDisabled, textField: textField, valueField: valueField, getNextOptions: this.getNextOptions, onSearch: this.onSearch, onDropBoxOpen: this.onDropBoxOpen, popupGroup: popupGroup, isNextOptions: isNextOptions, isSearching: isSearching, palette: palette, i18nKeys: i18nKeys, htmlId: uniqueId, customChildrenClass: customChildrenClass, onFocus: onFocus }, MultiSelectProps, { ariaLabelledby: uniqueId }), children ? children : null), validationMessage && /*#__PURE__*/_react["default"].createElement(_ValidationMessage["default"], _extends({ text: validationMessage, palette: validationPalette, type: errorType, dataId: "".concat(dataId, "_ValidationMessage"), htmlFor: uniqueId }, ValidationMessageProps1)), validationRuleMessage && /*#__PURE__*/_react["default"].createElement(_ValidationMessage["default"], _extends({ text: validationRuleMessage, palette: validationRulePalette, type: errorType, dataId: "".concat(dataId, "_ValidationRuleMessage"), htmlFor: uniqueId }, ValidationMessageProps2))); } }]); return MultiSelectField; }(_react.PureComponent); exports["default"] = MultiSelectField; MultiSelectField.propTypes = _propTypes.propTypes; MultiSelectField.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) { // MultiSelectField.docs = { // componentGroup: 'Form Fields', // folderName: 'General' // }; // }