UNPKG

@zohodesk/components

Version:

In this Package, we Provide Some Basic Components to Build Web App

901 lines (794 loc) • 40.8 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"] = exports.GroupSelectComponent = void 0; var _react = _interopRequireWildcard(require("react")); var _defaultProps = require("./props/defaultProps"); var _propTypes = require("./props/propTypes"); var _Popup = _interopRequireDefault(require("../Popup/Popup")); var _TextBoxIcon = _interopRequireDefault(require("../TextBoxIcon/TextBoxIcon")); var _TextBox = _interopRequireDefault(require("../TextBox/TextBox")); var _Card = _interopRequireWildcard(require("../Card/Card")); var _Suggestions = _interopRequireDefault(require("../MultiSelect/Suggestions")); var _EmptyState = _interopRequireDefault(require("../MultiSelect/EmptyState")); var _icons = require("@zohodesk/icons"); var _Loader = _interopRequireDefault(require("@zohodesk/svg/lib/Loader/Loader")); var _DropDownHeading = _interopRequireDefault(require("../DropDown/DropDownHeading")); var _Layout = require("../Layout"); var _IdProvider = require("../Provider/IdProvider"); var _ResponsiveDropBox = _interopRequireDefault(require("../ResponsiveDropBox/ResponsiveDropBox")); var _CustomResponsive = require("../Responsive/CustomResponsive"); var _SelectModule = _interopRequireDefault(require("./Select.module.css")); var _dropDownUtils = require("../utils/dropDownUtils"); var _Common = require("../utils/Common"); 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } 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); } /* eslint-disable react/no-unused-prop-types */ /* eslint-disable react/sort-prop-types */ /* eslint-disable react/forbid-component-props */ var GroupSelectComponent = /*#__PURE__*/function (_PureComponent) { _inherits(GroupSelectComponent, _PureComponent); var _super = _createSuper(GroupSelectComponent); function GroupSelectComponent(props) { var _this; _classCallCheck(this, GroupSelectComponent); _this = _super.call(this, props); _this.getNextAriaId = (0, _IdProvider.getUniqueId)(_assertThisInitialized(_this)); var _props$autoSelectDebo = props.autoSelectDebouneTime, autoSelectDebouneTime = _props$autoSelectDebo === void 0 ? 350 : _props$autoSelectDebo, _props$searchDebounce = props.searchDebounceTime, searchDebounceTime = _props$searchDebounce === void 0 ? 500 : _props$searchDebounce; _this.getGroupSelectOptions = (0, _dropDownUtils.makeGetGroupSelectOptions)(); _this.getFilterSuggestions = (0, _dropDownUtils.makeGetGroupSelectFilterSuggestions)(); _this.handleGetGroupSelectOptions = _this.handleGetGroupSelectOptions.bind(_assertThisInitialized(_this)); _this.handleGetSelectedId = _this.handleGetSelectedId.bind(_assertThisInitialized(_this)); _this.handleFilterSuggestions = _this.handleFilterSuggestions.bind(_assertThisInitialized(_this)); _this.handleSearch = _this.handleSearch.bind(_assertThisInitialized(_this)); _this.handleKeyDown = _this.handleKeyDown.bind(_assertThisInitialized(_this)); _this.handleMouseEnter = _this.handleMouseEnter.bind(_assertThisInitialized(_this)); _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this)); _this.togglePopup = _this.togglePopup.bind(_assertThisInitialized(_this)); _this.handlePopupClose = _this.handlePopupClose.bind(_assertThisInitialized(_this)); _this.suggestionContainerRef = _this.suggestionContainerRef.bind(_assertThisInitialized(_this)); _this.suggestionItemRef = _this.suggestionItemRef.bind(_assertThisInitialized(_this)); _this.searchInputRef = _this.searchInputRef.bind(_assertThisInitialized(_this)); _this.valueInputRef = _this.valueInputRef.bind(_assertThisInitialized(_this)); _this.handleSelectFocus = _this.handleSelectFocus.bind(_assertThisInitialized(_this)); _this.handleClearSearch = _this.handleClearSearch.bind(_assertThisInitialized(_this)); _this.handleValueInputChange = _this.handleValueInputChange.bind(_assertThisInitialized(_this)); _this.handleChangeOnType = (0, _Common.debounce)(_this.handleChangeOnType.bind(_assertThisInitialized(_this)), autoSelectDebouneTime); _this.handleFetchOptions = _this.handleFetchOptions.bind(_assertThisInitialized(_this)); _this.handleGetNextOptions = _this.handleGetNextOptions.bind(_assertThisInitialized(_this)); _this.handleScroll = _this.handleScroll.bind(_assertThisInitialized(_this)); _this.handleSearchOptions = (0, _Common.debounce)(_this.handleSearchOptions.bind(_assertThisInitialized(_this)), searchDebounceTime); _this.valueInputTypeString = ''; _this.valueInputSearchString = ''; _this.autoSelectSuggestions = []; _this.autoSelectIndex = 0; var _this$handleGetGroupS = _this.handleGetGroupSelectOptions(props), revampedGroups = _this$handleGetGroupS.revampedGroups, normalizedAllOptions = _this$handleGetGroupS.normalizedAllOptions, normalizedFormatOptions = _this$handleGetGroupS.normalizedFormatOptions, allOptionIds = _this$handleGetGroupS.allOptionIds; var _this$handleGetSelect = _this.handleGetSelectedId(props, allOptionIds), selectedId = _this$handleGetSelect.selectedId, hoverIndex = _this$handleGetSelect.hoverIndex; _this.normalizedAllOptions = normalizedAllOptions; _this.normalizedFormatOptions = normalizedFormatOptions; _this.state = { revampedGroups: revampedGroups, allOptionIds: allOptionIds, selectedId: selectedId, hoverIndex: hoverIndex, searchStr: '', isFetchingOptions: false }; _this._isMounted = false; return _this; } _createClass(GroupSelectComponent, [{ key: "componentDidMount", value: function componentDidMount() { this._isMounted = true; } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this2 = this; var _this$props = this.props, groupedOptions = _this$props.groupedOptions, selectedOption = _this$props.selectedOption, isPopupOpen = _this$props.isPopupOpen, needSearch = _this$props.needSearch, isSearchClearOnClose = _this$props.isSearchClearOnClose; var _this$state = this.state, allOptionIds = _this$state.allOptionIds, hoverIndex = _this$state.hoverIndex, selectedId = _this$state.selectedId, searchStr = _this$state.searchStr; var suggestionContainer = this.suggestionContainer; var newOptionIds = allOptionIds; var newSelectedId = selectedId; if (groupedOptions !== prevProps.groupedOptions) { var _this$handleGetGroupS2 = this.handleGetGroupSelectOptions(this.props), revampedGroups = _this$handleGetGroupS2.revampedGroups, normalizedAllOptions = _this$handleGetGroupS2.normalizedAllOptions, _allOptionIds = _this$handleGetGroupS2.allOptionIds, normalizedFormatOptions = _this$handleGetGroupS2.normalizedFormatOptions; this.normalizedAllOptions = normalizedAllOptions; this.normalizedFormatOptions = normalizedFormatOptions; newOptionIds = _allOptionIds; this.setState({ revampedGroups: revampedGroups, allOptionIds: _allOptionIds }); } if (selectedOption !== prevProps.selectedOption) { var _this$handleGetSelect2 = this.handleGetSelectedId(this.props, newOptionIds), _selectedId = _this$handleGetSelect2.selectedId, _hoverIndex = _this$handleGetSelect2.hoverIndex; newSelectedId = _selectedId; this.setState({ selectedId: _selectedId, hoverIndex: _hoverIndex }); } var _this$handleFilterSug = this.handleFilterSuggestions(), suggestionOptionIds = _this$handleFilterSug.suggestionOptionIds; var hoverId = (0, _Common.getIsEmptyValue)(suggestionOptionIds[hoverIndex]) ? '' : suggestionOptionIds[hoverIndex]; var selSuggestion = this["suggestion_".concat(hoverId)]; isPopupOpen && (0, _Common.scrollTo)(suggestionContainer, selSuggestion); if (isPopupOpen !== prevProps.isPopupOpen) { if (isPopupOpen) { setTimeout(function () { _this2.searchInput && _this2.searchInput.focus({ preventScroll: true }); }, 10); } else { // needSearch && this.valueInput && this.valueInput.focus({preventScroll:true}); isSearchClearOnClose && searchStr && this.handleSearch(''); var _hoverIndex2 = newOptionIds.indexOf(newSelectedId); _hoverIndex2 = _hoverIndex2 >= 0 ? _hoverIndex2 : 0; this.setState({ hoverIndex: _hoverIndex2 }); } } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this._isMounted = false; } }, { key: "handleGetGroupSelectOptions", value: function handleGetGroupSelectOptions(props) { var groupedOptions = props.groupedOptions, allowValueFallback = props.allowValueFallback; return this.getGroupSelectOptions({ groupedOptions: groupedOptions, allowValueFallback: allowValueFallback }); } }, { key: "handleGetSelectedId", value: function handleGetSelectedId(props, allOptionIds) { var selectedOption = props.selectedOption, isDefaultSelectValue = props.isDefaultSelectValue; var selected = selectedOption.selected, groupId = selectedOption.groupId; var selectedId = (0, _dropDownUtils.optionIdGrouping)(selected, groupId); var selectedIdIndex = allOptionIds.indexOf(selectedId); if (selectedIdIndex === -1) { selectedIdIndex = 0; if (isDefaultSelectValue) { var _allOptionIds2 = _slicedToArray(allOptionIds, 1); selectedId = _allOptionIds2[0]; } else { selectedId = ''; } } return { selectedId: selectedId, hoverIndex: selectedIdIndex }; } }, { key: "handleFilterSuggestions", value: function handleFilterSuggestions() { var _this$props2 = this.props, needSearch = _this$props2.needSearch, needLocalSearch = _this$props2.needLocalSearch; var _this$state2 = this.state, revampedGroups = _this$state2.revampedGroups, _this$state2$searchSt = _this$state2.searchStr, searchStr = _this$state2$searchSt === void 0 ? '' : _this$state2$searchSt, allOptionIds = _this$state2.allOptionIds; if (needSearch && searchStr && searchStr.trim().length) { searchStr = (0, _Common.getSearchString)(searchStr); var _this$getFilterSugges = this.getFilterSuggestions({ revampedGroups: revampedGroups, searchStr: searchStr, needSearch: needLocalSearch }), suggestionGroups = _this$getFilterSugges.suggestionGroups, suggestionOptionIds = _this$getFilterSugges.suggestionOptionIds; return { suggestionGroups: suggestionGroups, suggestionOptionIds: suggestionOptionIds }; } return { suggestionGroups: revampedGroups, suggestionOptionIds: allOptionIds }; } }, { key: "handleSearchOptions", value: function handleSearchOptions() { var onSearch = this.props.onSearch; var searchStr = this.state.searchStr; searchStr && this.handleFetchOptions(onSearch, searchStr); } }, { key: "handleSearch", value: function handleSearch(value) { var _this3 = this; // let { value = '' } = e.target; var _this$state$searchStr = this.state.searchStr, searchStr = _this$state$searchStr === void 0 ? '' : _this$state$searchStr; var onSearch = this.props.onSearch; var searchStrRegex = (0, _Common.getSearchString)(searchStr); var valueStrRegex = (0, _Common.getSearchString)(value); var isSearch = searchStrRegex !== valueStrRegex ? true : false; this.setState({ searchStr: value, hoverIndex: 0 }, function () { if (!value) { onSearch && _this3.handleFetchOptions(onSearch, ''); } else if (isSearch && onSearch) { _this3.handleSearchOptions(); } }); } }, { key: "handleKeyDown", value: function handleKeyDown(e) { var _this$props3 = this.props, isPopupOpen = _this$props3.isPopupOpen, isPopupOpenOnEnter = _this$props3.isPopupOpenOnEnter, onKeyDown = _this$props3.onKeyDown; var hoverIndex = this.state.hoverIndex; var _this$handleFilterSug2 = this.handleFilterSuggestions(), suggestionOptionIds = _this$handleFilterSug2.suggestionOptionIds; var keyCode = e.keyCode; if (!isPopupOpen && !isPopupOpenOnEnter) { onKeyDown && onKeyDown(e); } if (isPopupOpen && (keyCode === 38 || keyCode === 40) && e.preventDefault) { e.preventDefault(); //prevent body scroll } else if (!isPopupOpen && keyCode === 40) { e.preventDefault(); //prevent body scroll this.togglePopup(e); } if (keyCode === 38 && isPopupOpen && suggestionOptionIds.length) { if (hoverIndex === 0) {// hoverIndex = options.length - 1; } else { hoverIndex -= 1; } this.setState({ hoverIndex: hoverIndex }); } else if (keyCode === 40 && isPopupOpen && suggestionOptionIds.length) { if (hoverIndex === suggestionOptionIds.length - 1) {// hoverIndex = 0; } else { if (hoverIndex === suggestionOptionIds.length - 3) { this.handleGetNextOptions(); } hoverIndex += 1; } this.setState({ hoverIndex: hoverIndex }); } else if (keyCode === 13) { var id = suggestionOptionIds[hoverIndex]; isPopupOpen && this.handleChange(id, null, null, e); !isPopupOpen && isPopupOpenOnEnter && this.togglePopup(e); } else if (keyCode === 27) { this.valueInput && this.valueInput.focus({ preventScroll: true }); // this.handlePopupClose(e); } } }, { key: "handleMouseEnter", value: function handleMouseEnter(id) { var hoverIndex = this.state.hoverIndex; var _this$handleFilterSug3 = this.handleFilterSuggestions(), suggestionOptionIds = _this$handleFilterSug3.suggestionOptionIds; var newHoverIndex = suggestionOptionIds.indexOf(id); hoverIndex !== newHoverIndex && this.setState({ hoverIndex: newHoverIndex }); } }, { key: "handleChange", value: function handleChange(id, value, index, e) { e && e.preventDefault && e.preventDefault(); var _this$props4 = this.props, onChange = _this$props4.onChange, isReadOnly = _this$props4.isReadOnly; var normalizedAllOptions = this.normalizedAllOptions; var _ref = (0, _dropDownUtils.extractOptionId)(id) || (0, _dropDownUtils.extractOptionIdFromJson)(id, normalizedAllOptions), selected = _ref.id, groupId = _ref.groupId; if (!(0, _Common.getIsEmptyValue)(id) && !isReadOnly) { onChange && onChange({ groupId: groupId, selected: selected }, normalizedAllOptions[id]); this.handlePopupClose(); // this.valueInput && this.valueInput.focus({preventScroll:true}); } } }, { key: "togglePopup", value: function togglePopup(e) { var _this$props5 = this.props, togglePopup = _this$props5.togglePopup, isReadOnly = _this$props5.isReadOnly, defaultDropBoxPosition = _this$props5.defaultDropBoxPosition; !isReadOnly && togglePopup(e, defaultDropBoxPosition ? "".concat(defaultDropBoxPosition, "Center") : null); } }, { key: "handlePopupClose", value: function handlePopupClose(e) { var _this$props6 = this.props, closePopupOnly = _this$props6.closePopupOnly, isPopupOpen = _this$props6.isPopupOpen; this.valueInput && this.valueInput.focus({ preventScroll: true }); isPopupOpen && closePopupOnly(e); } }, { key: "suggestionContainerRef", value: function suggestionContainerRef(el) { this.suggestionContainer = el; } }, { key: "suggestionItemRef", value: function suggestionItemRef(el, index, id) { this["suggestion_".concat(id)] = el; } }, { key: "searchInputRef", value: function searchInputRef(el) { this.searchInput = el; } }, { key: "valueInputRef", value: function valueInputRef(el) { var getRef = this.props.getRef; this.valueInput = el; getRef && getRef(el); } }, { key: "handleSelectFocus", value: function handleSelectFocus(e) { var _ref2 = e || {}, target = _ref2.target; target && target.setSelectionRange(target, 0); } }, { key: "handleClearSearch", value: function handleClearSearch() { var _this4 = this; this.handleSearch(''); setTimeout(function () { _this4.searchInput && _this4.searchInput.focus({ preventScroll: true }); }, 1); } }, { key: "handleValueInputChange", value: function handleValueInputChange(e) { var typeString = (0, _Common.getKeyValue)(e); var _this$props7 = this.props, isPopupOpen = _this$props7.isPopupOpen, autoSelectOnType = _this$props7.autoSelectOnType; if (!isPopupOpen && autoSelectOnType) { this.valueInputTypeString += (typeString || '').trim(); this.handleChangeOnType(); } } }, { key: "handleChangeOnType", value: function handleChangeOnType() { var _this5 = this; var revampedGroups = this.state.revampedGroups; var typeString = this.valueInputTypeString; this.valueInputTypeString = ''; var changeValue = function changeValue() { var id = _this5.autoSelectSuggestions[_this5.autoSelectIndex]; var _this5$handleFilterSu = _this5.handleFilterSuggestions(), suggestionOptionIds = _this5$handleFilterSu.suggestionOptionIds; if (!(0, _Common.getIsEmptyValue)(id)) { _this5.handleChange(id); var hoverIndex = suggestionOptionIds.indexOf(id); _this5.setState({ hoverIndex: hoverIndex }); } }; if (typeString && typeString === this.valueInputSearchString) { if (this.autoSelectIndex < this.autoSelectSuggestions.length - 1) { this.autoSelectIndex += 1; } else { this.autoSelectIndex = 0; } changeValue(); } else if (typeString) { this.valueInputSearchString = typeString; var _this$getFilterSugges2 = this.getFilterSuggestions({ revampedGroups: revampedGroups, searchStr: typeString, needSearch: true, isStartsWithSearch: true }), suggestionOptionIds = _this$getFilterSugges2.suggestionOptionIds; this.autoSelectIndex = 0; this.autoSelectSuggestions = suggestionOptionIds; changeValue(); } } }, { key: "handleScroll", value: function handleScroll(e) { var ele = e.target; var isScrollReachedBottom = (0, _Common.findScrollEnd)(ele); isScrollReachedBottom && this.handleGetNextOptions(); } }, { key: "handleFetchOptions", value: function handleFetchOptions(APICall) { var _this6 = this; var searchStr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; // let funcArgs = args.slice(1, args.length); var _this$state$isFetchin = this.state.isFetchingOptions, isFetchingOptions = _this$state$isFetchin === void 0 ? false : _this$state$isFetchin; var _isMounted = this._isMounted; if (!isFetchingOptions && APICall) { this.setState({ isFetchingOptions: true }); try { return APICall(searchStr).then(function () { _isMounted && _this6.setState({ isFetchingOptions: false }); }, function () { _isMounted && _this6.setState({ isFetchingOptions: false }); }); } catch (e) { _isMounted && this.setState({ isFetchingOptions: false }); } } } }, { key: "handleGetNextOptions", value: function handleGetNextOptions() { var _this$props8 = this.props, isNextOptions = _this$props8.isNextOptions, getNextOptions = _this$props8.getNextOptions; var searchStr = this.state.searchStr; isNextOptions && getNextOptions && this.handleFetchOptions(getNextOptions, searchStr); } }, { key: "responsiveFunc", value: function responsiveFunc(_ref3) { var mediaQueryOR = _ref3.mediaQueryOR; return { tabletMode: mediaQueryOR([{ maxWidth: 700 }]) }; } }, { key: "render", value: function render() { var _this7 = this; var _this$props9 = this.props, isDisabled = _this$props9.isDisabled, isReadOnly = _this$props9.isReadOnly, needSearch = _this$props9.needSearch, emptyMessage = _this$props9.emptyMessage, needSelectDownIcon = _this$props9.needSelectDownIcon, maxLength = _this$props9.maxLength, needBorder = _this$props9.needBorder, placeHolder = _this$props9.placeHolder, defaultDropBoxPosition = _this$props9.defaultDropBoxPosition, searchBoxPlaceHolder = _this$props9.searchBoxPlaceHolder, searchEmptyMessage = _this$props9.searchEmptyMessage, dataId = _this$props9.dataId, dataIdSlctComp = _this$props9.dataIdSlctComp, dataIdDownIcon = _this$props9.dataIdDownIcon, dataIdSrchEmptyMsg = _this$props9.dataIdSrchEmptyMsg, needResponsive = _this$props9.needResponsive, className = _this$props9.className, size = _this$props9.size, title = _this$props9.title, textBoxSize = _this$props9.textBoxSize, textBoxVariant = _this$props9.textBoxVariant, animationStyle = _this$props9.animationStyle, dropBoxSize = _this$props9.dropBoxSize, searchBoxSize = _this$props9.searchBoxSize, getTargetRef = _this$props9.getTargetRef, isPopupOpen = _this$props9.isPopupOpen, position = _this$props9.position, getContainerRef = _this$props9.getContainerRef, isPopupReady = _this$props9.isPopupReady, removeClose = _this$props9.removeClose, isAbsolutePositioningNeeded = _this$props9.isAbsolutePositioningNeeded, positionsOffset = _this$props9.positionsOffset, targetOffset = _this$props9.targetOffset, isRestrictScroll = _this$props9.isRestrictScroll, borderColor = _this$props9.borderColor, needTick = _this$props9.needTick, children = _this$props9.children, getFooter = _this$props9.getFooter, i18nKeys = _this$props9.i18nKeys, htmlId = _this$props9.htmlId, iconOnHover = _this$props9.iconOnHover, isLoading = _this$props9.isLoading, dataSelectorId = _this$props9.dataSelectorId, customProps = _this$props9.customProps; i18nKeys = Object.assign({}, i18nKeys, { emptyText: i18nKeys.emptyText || emptyMessage, searchEmptyText: i18nKeys.searchEmptyText || searchEmptyMessage }); var _i18nKeys = i18nKeys, TextBoxIcon_i18n = _i18nKeys.TextBoxIcon_i18n, _i18nKeys$TextBox_all = _i18nKeys.TextBox_ally_label, TextBox_ally_label = _i18nKeys$TextBox_all === void 0 ? 'Click to select options' : _i18nKeys$TextBox_all; var _this$state3 = this.state, selectedId = _this$state3.selectedId, hoverIndex = _this$state3.hoverIndex, searchStr = _this$state3.searchStr, revampedGroups = _this$state3.revampedGroups, isFetchingOptions = _this$state3.isFetchingOptions; var normalizedFormatOptions = this.normalizedFormatOptions; var _this$handleFilterSug4 = this.handleFilterSuggestions(), suggestionGroups = _this$handleFilterSug4.suggestionGroups, suggestionOptionIds = _this$handleFilterSug4.suggestionOptionIds; var _ref4 = normalizedFormatOptions[selectedId] || {}, _ref4$value = _ref4.value, selected = _ref4$value === void 0 ? '' : _ref4$value; var setAriaId = this.getNextAriaId(); var ariaErrorId = this.getNextAriaId(); var _customProps$TextBoxI = customProps.TextBoxIconProps, TextBoxIconProps = _customProps$TextBoxI === void 0 ? {} : _customProps$TextBoxI, _customProps$TextBoxP = customProps.TextBoxProps, TextBoxProps = _customProps$TextBoxP === void 0 ? {} : _customProps$TextBoxP; return /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_SelectModule["default"].container, " ").concat(_SelectModule["default"]["box_".concat(size)], " ").concat(isReadOnly ? _SelectModule["default"].readonly : '', " ").concat(borderColor === 'transparent' ? _SelectModule["default"].transparentContainer : '', " ").concat(iconOnHover && (isReadOnly || isDisabled) ? _SelectModule["default"].iconOnHoverReadonly : iconOnHover && !(isReadOnly || isDisabled) ? _SelectModule["default"].iconOnHoverStyle : ''), "data-id": dataIdSlctComp, "data-test-id": dataIdSlctComp, "data-title": isDisabled ? title : null, "data-selector-id": dataSelectorId }, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(className ? className : ''), onClick: isDisabled || isReadOnly ? null : this.togglePopup, ref: getTargetRef, "data-id": "".concat(isDisabled ? "".concat(dataId, "_disabled") : isReadOnly ? "".concat(dataId, "_readOnly") : dataId), "data-test-id": "".concat(isDisabled ? "".concat(dataId, "_disabled") : isReadOnly ? "".concat(dataId, "_readOnly") : dataId) }, children ? children : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, needSelectDownIcon ? /*#__PURE__*/_react["default"].createElement(_TextBoxIcon["default"], _extends({ isDisabled: isDisabled, iconRotated: isPopupOpen, inputRef: this.valueInputRef, maxLength: maxLength, needBorder: needBorder, onFocus: this.handleSelectFocus, onKeyDown: this.handleKeyDown, placeHolder: placeHolder, isReadOnly: true, size: textBoxSize, value: selected, variant: textBoxVariant, needReadOnlyStyle: isReadOnly ? true : false, dataId: "".concat(dataId, "_textBox"), onKeyPress: this.handleValueInputChange, needEffect: isReadOnly || isDisabled ? false : true, borderColor: borderColor, htmlId: htmlId, a11y: { role: 'combobox', ariaControls: setAriaId, ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false, ariaHaspopup: true, ariaReadonly: true, ariaActivedescendant: selectedId, ariaOwns: setAriaId }, i18nKeys: TextBoxIcon_i18n, isFocus: isPopupReady, autoComplete: false }, TextBoxIconProps), /*#__PURE__*/_react["default"].createElement(_Layout.Container, { align: "both", dataId: dataIdDownIcon }, /*#__PURE__*/_react["default"].createElement(_icons.Icon, { name: "ZD-down", size: "7", iconClass: _SelectModule["default"].arrowIcon }))) : /*#__PURE__*/_react["default"].createElement(_TextBox["default"], _extends({ isDisabled: isDisabled, inputRef: this.valueInputRef, maxLength: maxLength, needBorder: needBorder, onFocus: this.handleSelectFocus, onKeyDown: this.handleKeyDown, placeHolder: placeHolder, isReadOnly: true, needEffect: isReadOnly || isDisabled ? false : true, size: textBoxSize, value: selected, variant: textBoxVariant, needReadOnlyStyle: isReadOnly ? true : false, dataId: "".concat(dataId, "_textBox"), onKeyPress: this.handleValueInputChange, borderColor: borderColor, htmlId: htmlId, a11y: { role: 'combobox', ariaLabel: TextBox_ally_label, ariaControls: setAriaId, ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false, ariaHaspopup: true, ariaReadonly: true, ariaActivedescendant: selectedId, ariaOwns: setAriaId }, autoComplete: false, isFocus: isPopupReady }, TextBoxProps)))), !isReadOnly && !isDisabled && isPopupOpen ? /*#__PURE__*/_react["default"].createElement(_CustomResponsive.ResponsiveReceiver, { query: this.responsiveFunc, responsiveId: "Helmet" }, function (_ref5) { var tabletMode = _ref5.tabletMode; return /*#__PURE__*/_react["default"].createElement(_ResponsiveDropBox["default"], { animationStyle: animationStyle, boxPosition: position || "".concat(defaultDropBoxPosition, "Center"), getRef: getContainerRef, isActive: isPopupReady, isAnimate: true, isArrow: false, onClick: removeClose, needResponsive: needResponsive, isPadding: false, isAbsolutePositioningNeeded: isAbsolutePositioningNeeded, positionsOffset: positionsOffset, targetOffset: targetOffset, isRestrictScroll: isRestrictScroll, isResponsivePadding: getFooter ? false : true, alignBox: "row", dataId: "".concat(dataId, "_suggestionBox") }, isLoading ? /*#__PURE__*/_react["default"].createElement(_Layout.Container, { align: "both", className: _SelectModule["default"].loader }, /*#__PURE__*/_react["default"].createElement(_Loader["default"], null)) : /*#__PURE__*/_react["default"].createElement(_Layout.Box, { flexible: true }, /*#__PURE__*/_react["default"].createElement(_Card["default"], { customClass: _SelectModule["default"].box, onScroll: _this7.handleScroll }, needSearch ? /*#__PURE__*/_react["default"].createElement(_Card.CardHeader, null, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(_SelectModule["default"].search, " ").concat(_SelectModule["default"][size]) }, /*#__PURE__*/_react["default"].createElement(_TextBoxIcon["default"], { inputRef: _this7.searchInputRef, maxLength: maxLength, onChange: _this7.handleSearch, onKeyDown: _this7.handleKeyDown, placeHolder: searchBoxPlaceHolder, size: searchBoxSize, value: searchStr, onClear: _this7.handleClearSearch, a11y: { ariaControls: setAriaId, ariaAutocomplete: 'list', ariaDescribedby: ariaErrorId }, autoComplete: false, dataId: "".concat(dataId, "_search") }))) : null, /*#__PURE__*/_react["default"].createElement(_Card.CardContent, { shrink: true, customClass: !tabletMode && dropBoxSize ? _SelectModule["default"][dropBoxSize] : '', eleRef: _this7.suggestionContainerRef }, suggestionGroups.length ? suggestionGroups.map(function (group) { var groupId = group.id, groupName = group.name, options = group.options; var hoverId = suggestionOptionIds[hoverIndex]; return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, { key: groupId }, groupName && /*#__PURE__*/_react["default"].createElement("div", { className: _SelectModule["default"].groupTitle }, /*#__PURE__*/_react["default"].createElement(_DropDownHeading["default"], { text: groupName, a11y: { role: 'heading' } })), /*#__PURE__*/_react["default"].createElement(_Suggestions["default"], { activeId: selectedId, suggestions: options, getRef: _this7.suggestionItemRef, hoverId: hoverId, onClick: _this7.handleChange, onMouseEnter: _this7.handleMouseEnter, selectedOptions: [selectedId], needTick: needTick, needBorder: false, htmlId: setAriaId, a11y: { ariaParentRole: 'listbox', role: 'option' }, dataId: "".concat(dataId, "_Options") })); }) : /*#__PURE__*/_react["default"].createElement(_EmptyState["default"], { options: revampedGroups, searchString: searchStr, suggestions: suggestionGroups, dataId: dataIdSrchEmptyMsg, isLoading: isFetchingOptions, i18nKeys: i18nKeys, htmlId: ariaErrorId }), isFetchingOptions && /*#__PURE__*/_react["default"].createElement(_Layout.Container, { isCover: false, align: "both" }, /*#__PURE__*/_react["default"].createElement(_Loader["default"], null))), getFooter ? /*#__PURE__*/_react["default"].createElement(_Card.CardFooter, null, getFooter()) : null))); }) : null); } }]); return GroupSelectComponent; }(_react.PureComponent); exports.GroupSelectComponent = GroupSelectComponent; GroupSelectComponent.propTypes = _propTypes.GroupSelect_propTypes; GroupSelectComponent.defaultProps = _defaultProps.GroupSelect_defaultProps; GroupSelectComponent.displayName = 'GroupSelect'; var GroupSelect = (0, _Popup["default"])(GroupSelectComponent); GroupSelect.defaultProps = GroupSelectComponent.defaultProps; GroupSelect.propTypes = GroupSelectComponent.propTypes; var _default = GroupSelect; // if (__DOCS__) { // GroupSelect.docs = { // componentGroup: 'Form Elements', // folderName: 'Style Guide' // }; // // eslint-disable-next-line react/forbid-foreign-prop-types // GroupSelect.propTypes = GroupSelectComponent.propTypes; // } exports["default"] = _default;