UNPKG

@zohodesk/components

Version:

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

1,025 lines (925 loc) • 46.4 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.SelectComponent = 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 _Layout = require("../Layout"); 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 _IdProvider = require("../../Provider/IdProvider"); var _icons = require("@zohodesk/icons"); var _ResponsiveDropBox = _interopRequireDefault(require("../ResponsiveDropBox/ResponsiveDropBox")); var _CustomResponsive = require("../../Responsive/CustomResponsive"); var _Loader = _interopRequireDefault(require("@zohodesk/svg/lib/Loader/Loader")); var _dropDownUtils = require("../../utils/dropDownUtils"); var _Common = require("../../utils/Common.js"); var _SelectModule = _interopRequireDefault(require("../../Select/Select.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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 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-deprecated */ /* eslint-disable react/no-unused-prop-types */ var dummyArray = []; var SelectComponent = /*#__PURE__*/function (_Component) { _inherits(SelectComponent, _Component); var _super = _createSuper(SelectComponent); function SelectComponent(props) { var _this; _classCallCheck(this, SelectComponent); _this = _super.call(this, props); _this.getNextAriaId = (0, _IdProvider.getUniqueId)(_assertThisInitialized(_this)); _this.getFilterSuggestions = (0, _dropDownUtils.makeGetMultiSelectFilterSuggestions)(); _this.formatOptions = (0, _dropDownUtils.makeFormatOptions)(); _this.getSelectedValue = (0, _dropDownUtils.makeGetSelectedValueText)(); _this.selectedFormatOptions = {}; var selectedValue = props.selectedValue, _props$searchDebounce = props.searchDebounceTime, searchDebounceTime = _props$searchDebounce === void 0 ? 500 : _props$searchDebounce, isDefaultSelectValue = props.isDefaultSelectValue, _props$autoSelectDebo = props.autoSelectDebouneTime, autoSelectDebouneTime = _props$autoSelectDebo === void 0 ? 350 : _props$autoSelectDebo, valueField = props.valueField, textField = props.textField; var _this$handleFormatOpt = _this.handleFormatOptions(_this.props), allOptions = _this$handleFormatOpt.allOptions, normalizedAllOptions = _this$handleFormatOpt.normalizedAllOptions, optionsOrder = _this$handleFormatOpt.optionsOrder, normalizedFormatOptions = _this$handleFormatOpt.normalizedFormatOptions; var _this$getSelectedValu = _this.getSelectedValue({ optionsOrder: optionsOrder, selectedValue: selectedValue, normalizedFormatOptions: normalizedFormatOptions, selectedFormatOptions: _this.selectedFormatOptions, isDefaultSelectValue: isDefaultSelectValue, valueField: valueField, textField: textField }), selected = _this$getSelectedValu.selected, hoverIndex = _this$getSelectedValu.hoverIndex, selectedValueDetails = _this$getSelectedValu.selectedValueDetails, selectedId = _this$getSelectedValu.selectedId, isSelfValueChanged = _this$getSelectedValu.isSelfValueChanged; // eslint-disable-next-line if (isSelfValueChanged) {// onChange && onChange(selectedId, normalizedAllOptions[selectedId]); } _this.state = { selected: selected, options: allOptions, optionsNormalize: normalizedAllOptions, hoverIndex: hoverIndex, searchStr: '', isFetchingOptions: false, selectedId: selectedId, selectedValueIndex: hoverIndex }; _this.optionsOrder = optionsOrder; _this._isMounted = false; _this.normalizedFormatOptions = normalizedFormatOptions; _this.allSelectedOptions = selectedValueDetails; _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this)); _this.handleKeyDown = _this.handleKeyDown.bind(_assertThisInitialized(_this)); _this.handleSearch = _this.handleSearch.bind(_assertThisInitialized(_this)); _this.handleFilterSuggestions = _this.handleFilterSuggestions.bind(_assertThisInitialized(_this)); _this.handleMouseEnter = _this.handleMouseEnter.bind(_assertThisInitialized(_this)); _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.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.togglePopup = _this.togglePopup.bind(_assertThisInitialized(_this)); _this.handleSelectFocus = _this.handleSelectFocus.bind(_assertThisInitialized(_this)); _this.handleFormatOptions = _this.handleFormatOptions.bind(_assertThisInitialized(_this)); _this.handlePopupClose = _this.handlePopupClose.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.handleAddNewOption = _this.handleAddNewOption.bind(_assertThisInitialized(_this)); _this.handleExposePopupHandlers = _this.handleExposePopupHandlers.bind(_assertThisInitialized(_this)); _this.handleGetAddNewOptionText = _this.handleGetAddNewOptionText.bind(_assertThisInitialized(_this)); _this.valueInputTypeString = ''; _this.valueInputSearchString = ''; _this.autoSelectSuggestions = []; _this.autoSelectIndex = 0; return _this; } _createClass(SelectComponent, [{ key: "componentDidMount", value: function componentDidMount() { this._isMounted = true; this.handleExposePopupHandlers(); // let { suggestionContainer } = this; // suggestionContainer && // suggestionContainer.addEventListener('scroll', this.handleScroll); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { var selectedValue = nextProps.selectedValue, isDefaultSelectValue = nextProps.isDefaultSelectValue, valueField = nextProps.valueField, textField = nextProps.textField; var oldHoverIndex = this.state.hoverIndex; var _this$handleFormatOpt2 = this.handleFormatOptions(nextProps), allOptions = _this$handleFormatOpt2.allOptions, normalizedAllOptions = _this$handleFormatOpt2.normalizedAllOptions, optionsOrder = _this$handleFormatOpt2.optionsOrder, normalizedFormatOptions = _this$handleFormatOpt2.normalizedFormatOptions; var oldSelectedFormatOptions = this.selectedFormatOptions; var _this$getSelectedValu2 = this.getSelectedValue({ optionsOrder: optionsOrder, selectedValue: selectedValue, normalizedFormatOptions: normalizedFormatOptions, selectedFormatOptions: oldSelectedFormatOptions, isDefaultSelectValue: isDefaultSelectValue, valueField: valueField, textField: textField }), selected = _this$getSelectedValu2.selected, hoverIndex = _this$getSelectedValu2.hoverIndex, selectedValueDetails = _this$getSelectedValu2.selectedValueDetails, selectedId = _this$getSelectedValu2.selectedId, isSelfValueChanged = _this$getSelectedValu2.isSelfValueChanged; var oldSelectedValue = this.props.selectedValue; // eslint-disable-next-line if (isSelfValueChanged && oldSelectedValue !== selectedValue) {// onChange && onChange(selectedId, normalizedAllOptions[selectedId]); } this.selectedFormatOptions = Object.assign(oldSelectedFormatOptions, selectedValueDetails); this.normalizedFormatOptions = normalizedFormatOptions; this.optionsOrder = optionsOrder; this.setState({ options: allOptions, optionsNormalize: normalizedAllOptions, selected: selected, hoverIndex: oldHoverIndex ? oldHoverIndex : hoverIndex, selectedId: selectedId, selectedValueIndex: hoverIndex }); } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this2 = this; var suggestionContainer = this.suggestionContainer, optionsOrder = this.optionsOrder; var _this$state = this.state, hoverIndex = _this$state.hoverIndex, searchStr = _this$state.searchStr, selectedValueIndex = _this$state.selectedValueIndex; var _this$props = this.props, needLocalSearch = _this$props.needLocalSearch, onDropBoxClose = _this$props.onDropBoxClose, onDropBoxOpen = _this$props.onDropBoxOpen, needSearch = _this$props.needSearch, onSearch = _this$props.onSearch, isPopupOpen = _this$props.isPopupOpen, isSearchClearOnClose = _this$props.isSearchClearOnClose; var hoverId = (0, _Common.getIsEmptyValue)(optionsOrder[hoverIndex]) ? '' : optionsOrder[hoverIndex]; var selSuggestion = this["suggestion_".concat(hoverId)]; isPopupOpen && (0, _Common.scrollTo)(suggestionContainer, selSuggestion); if (prevProps.isPopupOpen !== isPopupOpen) { if (isPopupOpen) { onDropBoxOpen && this.handleFetchOptions(onDropBoxOpen, searchStr); setTimeout(function () { _this2.searchInput && _this2.searchInput.focus({ preventScroll: true }); }, 10); } else { // needSearch && this.valueInput && this.valueInput.focus({preventScroll:true}); onDropBoxClose && onDropBoxClose(); isSearchClearOnClose && searchStr && onSearch && onSearch(''); this.setState({ searchStr: isSearchClearOnClose ? '' : searchStr, hoverIndex: selectedValueIndex }); } } //When suggestions length less than 5, getNextOptions function call var _this$props2 = this.props, isNextOptions = _this$props2.isNextOptions, getNextOptions = _this$props2.getNextOptions; // let { searchStr } = this.state; var suggestions = isPopupOpen ? this.handleFilterSuggestions() : []; var suggestionsLen = suggestions.length; if (isPopupOpen && suggestionsLen <= 5 && isNextOptions && getNextOptions && !needLocalSearch) { this.handleFetchOptions(getNextOptions, searchStr); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this._isMounted = false; var getPopupHandlers = this.props.getPopupHandlers; var methods = { removeClose: null, openPopup: null, closePopup: null, togglePopup: null }; getPopupHandlers && getPopupHandlers(methods); // let { suggestionContainer } = this; // suggestionContainer && // suggestionContainer.removeEventListener('scroll', this.handleScroll); } }, { key: "handleFormatOptions", value: function handleFormatOptions(props) { var options = props.options, valueField = props.valueField, textField = props.textField, _props$customProps = props.customProps, customProps = _props$customProps === void 0 ? {} : _props$customProps; var _customProps$listItem = customProps.listItemProps, listItemProps = _customProps$listItem === void 0 ? {} : _customProps$listItem; return this.formatOptions({ options: options, valueField: valueField, textField: textField, listItemProps: listItemProps }); } }, { key: "handleChange", value: function handleChange(id, value, index, e) { e && e.preventDefault && e.preventDefault(); var _this$props3 = this.props, onChange = _this$props3.onChange, isReadOnly = _this$props3.isReadOnly, needCloseOnSelect = _this$props3.needCloseOnSelect; var optionsNormalize = this.state.optionsNormalize; !isReadOnly && onChange && onChange(id, optionsNormalize[id]); // this.valueInput && this.valueInput.focus({preventScroll:true}); needCloseOnSelect && this.handlePopupClose(e); } }, { key: "responsiveFunc", value: function responsiveFunc(_ref) { var mediaQueryOR = _ref.mediaQueryOR; return { tabletMode: mediaQueryOR([{ maxWidth: 700 }]) }; } }, { key: "handleKeyDown", value: function handleKeyDown(e) { var _this$props4 = this.props, onChange = _this$props4.onChange, isPopupOpen = _this$props4.isPopupOpen, onKeyDown = _this$props4.onKeyDown, isPopupOpenOnEnter = _this$props4.isPopupOpenOnEnter, needCloseOnSelect = _this$props4.needCloseOnSelect, isPopupReady = _this$props4.isPopupReady; var _this$state2 = this.state, hoverIndex = _this$state2.hoverIndex, optionsNormalize = _this$state2.optionsNormalize; var options = this.handleFilterSuggestions(); var keyCode = e.keyCode; if (!isPopupOpen && !isPopupOpenOnEnter) { onKeyDown && onKeyDown(e); } if (isPopupOpen && (keyCode === 38 || keyCode === 40 || keyCode === 13) && e.preventDefault) { e.preventDefault(); //prevent body scroll and enter key prevent } else if (!isPopupOpen && keyCode === 40) { e.preventDefault(); //prevent body scroll this.togglePopup(e); } if (keyCode === 38 && isPopupOpen && options.length) { // eslint-disable-next-line if (hoverIndex === 0) {// hoverIndex = options.length - 1; } else { hoverIndex -= 1; } this.setState({ hoverIndex: hoverIndex }); } else if (keyCode === 40 && isPopupOpen && options.length) { // eslint-disable-next-line if (hoverIndex === options.length - 1) {// hoverIndex = 0; } else { if (hoverIndex === options.length - 3) { this.handleGetNextOptions(); } hoverIndex += 1; } this.setState({ hoverIndex: hoverIndex }); } else if (keyCode === 13) { var option = options[hoverIndex]; var _ref2 = option || {}, id = _ref2.id; if (isPopupReady && !(0, _Common.getIsEmptyValue)(id) && onChange) { onChange(id, optionsNormalize[id]); needCloseOnSelect && this.handlePopupClose(e); } if (!isPopupReady && isPopupOpenOnEnter) { this.togglePopup(e); } } else if (keyCode === 27) { this.valueInput && this.valueInput.focus({ preventScroll: true }); //this.handlePopupClose(e); } else if (keyCode === 9) { var _option = options[hoverIndex]; var _ref3 = _option || {}, _id = _ref3.id; if (isPopupOpen && !(0, _Common.getIsEmptyValue)(_id)) { onChange && onChange(_id, optionsNormalize[_id]); needCloseOnSelect && this.handlePopupClose(e); } if (!isPopupOpen && isPopupOpenOnEnter) { this.togglePopup(e); } } } }, { 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: "handleMouseEnter", value: function handleMouseEnter(id /*val, index*/ ) { var hoverIndex = this.state.hoverIndex; var optionsOrder = this.optionsOrder; var newHoverIndex = optionsOrder.indexOf(id); hoverIndex !== newHoverIndex && this.setState({ hoverIndex: newHoverIndex }); } }, { key: "handleFilterSuggestions", value: function handleFilterSuggestions() { var _this$props5 = this.props, needLocalSearch = _this$props5.needLocalSearch, _this$props5$excludeO = _this$props5.excludeOptions, excludeOptions = _this$props5$excludeO === void 0 ? dummyArray : _this$props5$excludeO; var _this$state3 = this.state, _this$state3$options = _this$state3.options, options = _this$state3$options === void 0 ? dummyArray : _this$state3$options, _this$state3$searchSt = _this$state3.searchStr, searchStr = _this$state3$searchSt === void 0 ? '' : _this$state3$searchSt; // if ( // (needSearch && searchStr && searchStr.trim().length) || // (excludeOptions && excludeOptions.length) // ) { searchStr = (0, _Common.getSearchString)(searchStr); var _this$getFilterSugges = this.getFilterSuggestions({ options: options, selectedOptions: excludeOptions, searchStr: searchStr, needSearch: needLocalSearch }), suggestions = _this$getFilterSugges.suggestions, suggestionIds = _this$getFilterSugges.suggestionIds; this.optionsOrder = suggestionIds; return suggestions; // } // return options; } }, { 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 _this4 = 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 && _this4.setState({ isFetchingOptions: false }); }, function () { _isMounted && _this4.setState({ isFetchingOptions: false }); }); } catch (e) { _isMounted && this.setState({ isFetchingOptions: false }); } } } }, { key: "handleGetNextOptions", value: function handleGetNextOptions() { var _this$props6 = this.props, isNextOptions = _this$props6.isNextOptions, getNextOptions = _this$props6.getNextOptions; var searchStr = this.state.searchStr; isNextOptions && getNextOptions && this.handleFetchOptions(getNextOptions, searchStr); } }, { key: "togglePopup", value: function togglePopup(e) { var _this$props7 = this.props, togglePopup = _this$props7.togglePopup, isReadOnly = _this$props7.isReadOnly, defaultDropBoxPosition = _this$props7.defaultDropBoxPosition, onFocus = _this$props7.onFocus, isPopupOpen = _this$props7.isPopupOpen; !isReadOnly && togglePopup(e, defaultDropBoxPosition ? "".concat(defaultDropBoxPosition) : null); !isPopupOpen && typeof onFocus === 'function' && onFocus(e); } }, { key: "handlePopupClose", value: function handlePopupClose(e) { var closePopupOnly = this.props.closePopupOnly; this.valueInput && this.valueInput.focus({ preventScroll: true }); 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() { var valueInput = this.valueInput; valueInput && valueInput.setSelectionRange(valueInput, 0); } }, { key: "handleClearSearch", value: function handleClearSearch() { var _this5 = this; this.handleSearch(''); setTimeout(function () { _this5.searchInput && _this5.searchInput.focus({ preventScroll: true }); }, 1); } }, { key: "handleValueInputChange", value: function handleValueInputChange(e) { var typeString = (0, _Common.getKeyValue)(e); var _this$props8 = this.props, isPopupOpen = _this$props8.isPopupOpen, autoSelectOnType = _this$props8.autoSelectOnType; if (!isPopupOpen && autoSelectOnType) { this.valueInputTypeString += (typeString || '').trim(); this.handleChangeOnType(); } } }, { key: "handleChangeOnType", value: function handleChangeOnType() { var _this6 = this; var _this$props$excludeOp = this.props.excludeOptions, excludeOptions = _this$props$excludeOp === void 0 ? dummyArray : _this$props$excludeOp; var _this$state$options = this.state.options, options = _this$state$options === void 0 ? dummyArray : _this$state$options; var optionsOrder = this.optionsOrder; var typeString = this.valueInputTypeString; this.valueInputTypeString = ''; var changeValue = function changeValue() { var optionDetails = _this6.autoSelectSuggestions[_this6.autoSelectIndex]; var _ref4 = optionDetails || {}, id = _ref4.id; if (!(0, _Common.getIsEmptyValue)(id)) { _this6.handleChange(id); var hoverIndex = optionsOrder.indexOf(id); _this6.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({ options: options, selectedOptions: excludeOptions, searchStr: typeString, needSearch: true, isStartsWithSearch: true }), _this$getFilterSugges3 = _this$getFilterSugges2.suggestions, suggestions = _this$getFilterSugges3 === void 0 ? [] : _this$getFilterSugges3; this.autoSelectIndex = 0; this.autoSelectSuggestions = suggestions; changeValue(); } } }, { key: "handleAddNewOption", value: function handleAddNewOption() { var searchStr = this.state.searchStr; var _this$props9 = this.props, onAddNewOption = _this$props9.onAddNewOption, getCustomEmptyState = _this$props9.getCustomEmptyState; if (getCustomEmptyState) { this.setState({ searchStr: '' }); this.handleFetchOptions(onAddNewOption, searchStr); } } }, { key: "handleExposePopupHandlers", value: function handleExposePopupHandlers() { var _this$props10 = this.props, removeClose = _this$props10.removeClose, openPopupOnly = _this$props10.openPopupOnly, closePopupOnly = _this$props10.closePopupOnly, togglePopup = _this$props10.togglePopup, getPopupHandlers = _this$props10.getPopupHandlers; var methods = { removeClose: removeClose, openPopup: openPopupOnly, closePopup: closePopupOnly, togglePopup: togglePopup }; getPopupHandlers && getPopupHandlers(methods); } }, { key: "handleGetAddNewOptionText", value: function handleGetAddNewOptionText() { var searchStr = this.state.searchStr; var getCustomEmptyState = this.props.getCustomEmptyState; return getCustomEmptyState({ searchString: searchStr, onAddNewOption: this.handleAddNewOption }); } }, { key: "render", value: function render() { var _this7 = this; var _this$props11 = this.props, needSearch = _this$props11.needSearch, dropBoxSize = _this$props11.dropBoxSize, emptyMessage = _this$props11.emptyMessage, searchEmptyMessage = _this$props11.searchEmptyMessage, needBorder = _this$props11.needBorder, needSelectDownIcon = _this$props11.needSelectDownIcon, position = _this$props11.position, defaultDropBoxPosition = _this$props11.defaultDropBoxPosition, getTargetRef = _this$props11.getTargetRef, getContainerRef = _this$props11.getContainerRef, removeClose = _this$props11.removeClose, isPopupOpen = _this$props11.isPopupOpen, isPopupReady = _this$props11.isPopupReady, animationStyle = _this$props11.animationStyle, textBoxSize = _this$props11.textBoxSize, textBoxVariant = _this$props11.textBoxVariant, searchBoxSize = _this$props11.searchBoxSize, searchBoxPlaceHolder = _this$props11.searchBoxPlaceHolder, maxLength = _this$props11.maxLength, isDisabled = _this$props11.isDisabled, title = _this$props11.title, size = _this$props11.size, placeHolder = _this$props11.placeHolder, className = _this$props11.className, isReadOnly = _this$props11.isReadOnly, dataId = _this$props11.dataId, needResponsive = _this$props11.needResponsive, borderColor = _this$props11.borderColor, needTick = _this$props11.needTick, listItemSize = _this$props11.listItemSize, boxSize = _this$props11.boxSize, needListBorder = _this$props11.needListBorder, getFooter = _this$props11.getFooter, getChildren = _this$props11.getChildren, getCustomEmptyState = _this$props11.getCustomEmptyState, isParentBased = _this$props11.isParentBased, i18nKeys = _this$props11.i18nKeys, htmlId = _this$props11.htmlId, children = _this$props11.children, iconOnHover = _this$props11.iconOnHover, customProps = _this$props11.customProps, autoComplete = _this$props11.autoComplete, ariaLabelledby = _this$props11.ariaLabelledby, isLoading = _this$props11.isLoading, dataSelectorId = _this$props11.dataSelectorId, isAbsolutePositioningNeeded = _this$props11.isAbsolutePositioningNeeded, positionsOffset = _this$props11.positionsOffset, targetOffset = _this$props11.targetOffset, isRestrictScroll = _this$props11.isRestrictScroll, dropBoxPortalId = _this$props11.dropBoxPortalId; 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; i18nKeys = Object.assign({}, i18nKeys, { emptyText: i18nKeys.emptyText || emptyMessage, searchEmptyText: i18nKeys.searchEmptyText || searchEmptyMessage }); var _this$state4 = this.state, hoverIndex = _this$state4.hoverIndex, selected = _this$state4.selected, searchStr = _this$state4.searchStr, isFetchingOptions = _this$state4.isFetchingOptions, selectedId = _this$state4.selectedId, options = _this$state4.options; var suggestions = this.handleFilterSuggestions(); var setAriaId = this.getNextAriaId(); var ariaErrorId = this.getNextAriaId(); var _customProps$TextBoxP = customProps.TextBoxProps, TextBoxProps = _customProps$TextBoxP === void 0 ? {} : _customProps$TextBoxP, _customProps$TextBoxI = customProps.TextBoxIconProps, TextBoxIconProps = _customProps$TextBoxI === void 0 ? {} : _customProps$TextBoxI, _customProps$Dropdown = customProps.DropdownSearchTextBoxProps, DropdownSearchTextBoxProps = _customProps$Dropdown === void 0 ? {} : _customProps$Dropdown, _customProps$Suggesti = customProps.SuggestionsProps, SuggestionsProps = _customProps$Suggesti === void 0 ? {} : _customProps$Suggesti; return /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(isParentBased || isReadOnly || isDisabled ? _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-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) }, needSelectDownIcon ? /*#__PURE__*/_react["default"].createElement(_TextBoxIcon["default"], _extends({ a11y: { role: 'Menuitem', ariaLabel: TextBox_ally_label, ariaControls: setAriaId, ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false, ariaHaspopup: true, ariaReadonly: true, ariaActivedescendant: selectedId, ariaOwns: setAriaId, ariaLabelledby: ariaLabelledby }, 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"), isClickable: isReadOnly || isDisabled ? false : true, customClass: { customTBoxWrap: isReadOnly || isDisabled ? '' : _SelectModule["default"].input }, needEffect: isReadOnly || isDisabled ? false : true, onKeyPress: this.handleValueInputChange, borderColor: borderColor, htmlId: htmlId, isFocus: isPopupReady, autoComplete: autoComplete, isScrollPrevent: true, customProps: { TextBoxProps: _objectSpread({ 'data-title': title || selected }, TextBoxProps) } }, TextBoxIconProps), /*#__PURE__*/_react["default"].createElement(_Layout.Container, { alignBox: "row", align: "both" }, children ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, { className: isPopupOpen ? _SelectModule["default"].rotate : '', dataId: "".concat(dataId, "_children") }, children) : null, /*#__PURE__*/_react["default"].createElement(_Layout.Container, { align: "both", dataId: "".concat(dataId, "_downIcon"), "aria-hidden": true, className: _SelectModule["default"].arrowIcon }, /*#__PURE__*/_react["default"].createElement(_icons.Icon, { name: "ZD-down", size: "7" })))) : /*#__PURE__*/_react["default"].createElement(_TextBox["default"], { a11y: { role: 'Menuitem', ariaLabel: TextBox_ally_label, ariaControls: setAriaId, ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false, ariaHaspopup: true, ariaReadonly: true, ariaActivedescendant: selectedId, ariaOwns: setAriaId, ariaLabelledby: ariaLabelledby }, isDisabled: isDisabled, inputRef: this.valueInputRef, maxLength: maxLength, needBorder: needBorder, onFocus: this.handleSelectFocus, onKeyDown: getChildren && 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"), isClickable: isReadOnly || isDisabled ? false : true, onKeyPress: this.handleValueInputChange, borderColor: borderColor, htmlId: htmlId, autoComplete: autoComplete, isFocus: isPopupReady, isScrollPrevent: true, customProps: _objectSpread({ 'data-title': title || selected }, 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), getRef: getContainerRef, isActive: isPopupReady, isAnimate: true, isArrow: false, onClick: removeClose, needResponsive: needResponsive, dataId: "".concat(dataId, "_suggestions"), size: boxSize, isPadding: false, isResponsivePadding: getFooter ? false : true, alignBox: "row", isAbsolutePositioningNeeded: isAbsolutePositioningNeeded, positionsOffset: positionsOffset, targetOffset: targetOffset, isRestrictScroll: isRestrictScroll, portalId: dropBoxPortalId }, isLoading ? /*#__PURE__*/_react["default"].createElement(_Layout.Container, { align: "both", className: _SelectModule["default"].loader }, /*#__PURE__*/_react["default"].createElement(_Loader["default"], null)) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !getChildren ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, { flexible: true }, /*#__PURE__*/_react["default"].createElement(_Card["default"], { 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"], { a11y: { ariaControls: setAriaId, ariaAutocomplete: 'list', ariaDescribedby: ariaErrorId }, inputRef: _this7.searchInputRef, maxLength: maxLength, onChange: _this7.handleSearch, onKeyDown: _this7.handleKeyDown, placeHolder: searchBoxPlaceHolder, size: searchBoxSize, value: searchStr, onClear: _this7.handleClearSearch, dataId: "".concat(dataId, "_search"), i18nKeys: TextBoxIcon_i18n, autoComplete: autoComplete, customProps: { TextBoxProps: DropdownSearchTextBoxProps } }))) : null, /*#__PURE__*/_react["default"].createElement(_Card.CardContent, { shrink: true, customClass: !tabletMode && dropBoxSize ? _SelectModule["default"][dropBoxSize] : '', eleRef: _this7.suggestionContainerRef }, suggestions.length ? /*#__PURE__*/_react["default"].createElement(_Suggestions["default"], _extends({ activeId: selectedId, suggestions: suggestions, getRef: _this7.suggestionItemRef, hoverOption: hoverIndex, onClick: _this7.handleChange, onMouseEnter: _this7.handleMouseEnter, dataId: "".concat(dataId, "_Options"), needTick: needTick, needBorder: needListBorder, selectedOptions: [selectedId], className: "".concat(tabletMode ? _SelectModule["default"].responsivelistItemContainer : _SelectModule["default"].listItemContainer), listItemSize: listItemSize, htmlId: setAriaId, a11y: { ariaParentRole: 'listbox', role: 'option' } }, SuggestionsProps)) : /*#__PURE__*/_react["default"].createElement(_EmptyState["default"], { isLoading: isFetchingOptions, options: options, searchString: searchStr, suggestions: suggestions, dataId: dataId, getCustomEmptyState: getCustomEmptyState ? _this7.handleGetAddNewOptionText : null, 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)) : /*#__PURE__*/_react["default"].createElement(_Layout.Box, { flexible: true }, getChildren()))); }) : null); } }]); return SelectComponent; }(_react.Component); exports.SelectComponent = SelectComponent; SelectComponent.propTypes = _propTypes.Select_propTypes; SelectComponent.defaultProps = _defaultProps.Select_defaultProps; SelectComponent.displayName = 'Select'; var Select = (0, _Popup["default"])(SelectComponent); Select.defaultProps = SelectComponent.defaultProps; Select.propTypes = _propTypes.Select_propTypes; Select.displayName = 'Select'; var _default = Select; // if (__DOCS__) { // Select.docs = { // componentGroup: 'Form Elements', // folderName: 'Style Guide', // external: true, // description: ' ' // }; // // eslint-disable-next-line react/forbid-foreign-prop-types // Select.propTypes = SelectComponent.propTypes; // } exports["default"] = _default;