UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

628 lines (522 loc) 31.1 kB
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } import _find from "lodash/find"; import _filter from "lodash/filter"; import _isNil from "lodash/isNil"; import _assign from "lodash/assign"; import _keys from "lodash/keys"; import _first from "lodash/first"; import _some from "lodash/some"; import _every from "lodash/every"; import _isFunction from "lodash/isFunction"; import _isString from "lodash/isString"; import _omit from "lodash/omit"; import _escapeRegExp from "lodash/escapeRegExp"; import _findIndex from "lodash/findIndex"; import _get from "lodash/get"; import _map from "lodash/map"; import _isEmpty from "lodash/isEmpty"; import _includes from "lodash/includes"; import _partition from "lodash/partition"; import _reject from "lodash/reject"; import _noop from "lodash/noop"; function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _extends() { _extends = Object.assign || 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) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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); 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || 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; } 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 { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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; } import React from 'react'; import PropTypes from 'react-peek/prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { buildModernHybridComponent } from '../../util/state-management'; import { partitionText, propsSearch } from '../../util/text-manipulation'; import { omitProps, getFirst, findTypes, rejectTypes } from '../../util/component-types'; import { SearchFieldDumb as SearchField } from '../SearchField/SearchField'; import { DropMenuDumb as DropMenu } from '../DropMenu/DropMenu'; import LoadingIcon from '../Icon/LoadingIcon/LoadingIcon'; import CheckboxLabeled from '../CheckboxLabeled/CheckboxLabeled'; import Selection from '../Selection/Selection'; import { Validation } from '../Validation/Validation'; import * as reducers from './SearchableMultiSelect.reducers'; var any = PropTypes.any, arrayOf = PropTypes.arrayOf, bool = PropTypes.bool, func = PropTypes.func, number = PropTypes.number, oneOfType = PropTypes.oneOfType, shape = PropTypes.shape, string = PropTypes.string, oneOf = PropTypes.oneOf, node = PropTypes.node; var cx = lucidClassNames.bind('&-SearchableMultiSelect'); var SelectionOption = function SelectionOption(_props) { return null; }; SelectionOption.displayName = 'SearchableMultiSelect.Option.Selection'; SelectionOption.propTypes = Selection.propTypes; SelectionOption.propName = 'Selection'; SelectionOption.peek = { description: "\n\t\tCustomizes the rendering of the Option when it is selected\n\t\tand is displayed instead of the Placeholder.\n\t" }; var Selected = function Selected(_props) { return null; }; Selected.displayName = 'SearchableMultiSelect.Option.Selected'; Selected.peek = { description: "\n\t\tCustomizes the rendering of the Option when it is selected\n\t\tand is displayed instead of the Placeholder.\n\t" }; Selected.propName = 'Selected'; Selected.propTypes = {}; var OptionGroup = function OptionGroup(_props) { return null; }; OptionGroup.displayName = 'SearchableMultiSelect.OptionGroup'; OptionGroup.peek = { description: "\n\t\tA special kind of `Option` that is always rendered at the top of\n\t\tthe menu and has an `optionIndex` of `null`. Useful for\n\t\tunselect.\n\t" }; OptionGroup.propName = 'OptionGroup'; OptionGroup.propTypes = DropMenu.OptionGroup.propTypes; OptionGroup.defaultProps = DropMenu.OptionGroup.defaultProps; OptionGroup.Selected = Selected; var SearchFieldComponent = function SearchFieldComponent(_props) { return null; }; SearchFieldComponent.displayName = 'SearchableMultiSelect.SearchField'; SearchFieldComponent.peek = { description: "\n\t\tPasses props through to the `Search Field`.\n\t" }; SearchFieldComponent.propName = 'SearchField'; SearchFieldComponent.propTypes = SearchField.propTypes; SearchFieldComponent.defaultProps = SearchField.defaultProps; var Option = function Option(_props) { return null; }; Option.displayName = 'SearchableMultiSelect.Option'; Option.peek = { description: "\n\t\tA selectable option in the list.\n\t" }; Option.Selection = SelectionOption; Option.Selected = Selected; Option.propName = 'Option'; Option.propTypes = _objectSpread({ Selected: any, Selection: any, value: string, filterText: string }, DropMenu.Option.propTypes); Option.defaultProps = DropMenu.Option.defaultProps; var defaultProps = { isDisabled: false, isLoading: false, hasRemoveAll: true, hasSelections: true, hasSelectAll: false, selectAllText: 'Select All', searchText: '', responsiveMode: 'large', selectedIndices: [], DropMenu: DropMenu.defaultProps, Error: null, optionFilter: propsSearch, onSearch: _noop, onRemoveAll: _noop, onSelect: _noop }; var SearchableMultiSelect = /*#__PURE__*/function (_React$Component) { _inherits(SearchableMultiSelect, _React$Component); var _super = _createSuper(SearchableMultiSelect); function SearchableMultiSelect() { var _this; _classCallCheck(this, SearchableMultiSelect); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "handleDropMenuSelect", function (optionIndex, _ref) { var event = _ref.event, props = _ref.props; var onSelect = _this.props.onSelect; event.preventDefault(); if (optionIndex === 0) { return _this.handleSelectAll({ event: event, props: props }); } // this index is decremented to account for the "Select All" Option if (optionIndex) { return onSelect(optionIndex - 1, { event: event, props: props }); } }); _defineProperty(_assertThisInitialized(_this), "handleSelectAll", function (_ref2) { var event = _ref2.event, props = _ref2.props; // This is needed otherwise clicking the checkbox will double fire this // event _and_ the `handleDropMenuSelect` handler var _assertThisInitialize = _assertThisInitialized(_this), _assertThisInitialize2 = _assertThisInitialize.props, selectedIndices = _assertThisInitialize2.selectedIndices, onSelect = _assertThisInitialize2.onSelect, flattenedOptionsData = _assertThisInitialize.state.flattenedOptionsData; event.preventDefault(); var visibleOptions = _reject(flattenedOptionsData, 'optionProps.isHidden'); var _partition2 = _partition(visibleOptions, function (_ref3) { var optionIndex = _ref3.optionIndex; return _includes(selectedIndices, optionIndex); }), _partition3 = _slicedToArray(_partition2, 2), selected = _partition3[0], unselected = _partition3[1]; var indices = _isEmpty(unselected) ? _map(selected, 'optionIndex') : _map(unselected, 'optionIndex'); return onSelect(indices, { props: props, event: event }); }); _defineProperty(_assertThisInitialized(_this), "handleSelectionRemove", function (_ref4) { var event = _ref4.event, props = _ref4.props, optionIndex = _ref4.props.callbackId; // We don't want to send the consumer the selection's props so we have to // lookup the option they clicked and send its props along var selectedOptionProps = _get(findTypes(_this.props, SearchableMultiSelect.Option), "[".concat(optionIndex, "].props")); return _this.props.onSelect(optionIndex, { event: event, props: selectedOptionProps }); }); _defineProperty(_assertThisInitialized(_this), "handleRemoveAll", function (_ref5) { var event = _ref5.event, props = _ref5.props; _this.props.onRemoveAll({ event: event, props: props }); }); _defineProperty(_assertThisInitialized(_this), "handleSearch", function (searchText, _ref6) { var event = _ref6.event; var _assertThisInitialize3 = _assertThisInitialized(_this), props = _assertThisInitialize3.props, _assertThisInitialize4 = _assertThisInitialize3.props, onSearch = _assertThisInitialize4.onSearch, optionFilter = _assertThisInitialize4.optionFilter, onExpand = _assertThisInitialize4.DropMenu.onExpand; var options = _map(findTypes(props, SearchableMultiSelect.Option), 'props'); var firstVisibleIndex = _findIndex(options, function (option) { return optionFilter(searchText, option); }); var firstVisibleProps = options[firstVisibleIndex]; var dropMenuProps = _this.props.DropMenu; // Just an extra call to make sure the search results show up when a user // is typing onExpand && onExpand({ event: event, props: dropMenuProps }); return onSearch(searchText, firstVisibleIndex, { event: event, props: firstVisibleProps }); }); _defineProperty(_assertThisInitialized(_this), "renderUnderlinedChildren", function (childText, searchText) { var _partitionText = partitionText(childText, new RegExp(_escapeRegExp(searchText), 'i'), searchText.length), _partitionText2 = _slicedToArray(_partitionText, 3), pre = _partitionText2[0], match = _partitionText2[1], post = _partitionText2[2]; return [pre && /*#__PURE__*/React.createElement("span", { key: "pre", className: cx('&-Option-underline-pre') }, pre), match && /*#__PURE__*/React.createElement("span", { key: "match", className: cx('&-Option-underline-match') }, match), post && /*#__PURE__*/React.createElement("span", { key: "post", className: cx('&-Option-underline-post') }, post)]; }); _defineProperty(_assertThisInitialized(_this), "renderOption", function (_ref7) { var optionProps = _ref7.optionProps, optionIndex = _ref7.optionIndex; var _this$props = _this.props, searchText = _this$props.searchText, selectedIndices = _this$props.selectedIndices, isLoading = _this$props.isLoading, optionFilter = _this$props.optionFilter; return /*#__PURE__*/React.createElement(DropMenu.Option, _extends({ key: 'SearchableMultiSelectOption' + optionIndex }, _omit(optionProps, ['children', 'Selected', 'filterText']), { isHidden: !optionFilter(searchText, optionProps), isDisabled: optionProps.isDisabled || isLoading }), /*#__PURE__*/React.createElement(CheckboxLabeled, { className: cx('&-CheckboxLabeled'), callbackId: optionIndex.toString(), isSelected: _includes(selectedIndices, optionIndex) }, /*#__PURE__*/React.createElement(CheckboxLabeled.Label, null, _isString(optionProps.children) ? _this.renderUnderlinedChildren(optionProps.children, searchText) : _isFunction(optionProps.children) ? /*#__PURE__*/React.createElement(optionProps.children, { searchText: searchText }) : optionProps.children))); }); _defineProperty(_assertThisInitialized(_this), "renderOptions", function () { var _this$props2 = _this.props, searchText = _this$props2.searchText, isLoading = _this$props2.isLoading, hasSelectAll = _this$props2.hasSelectAll, selectedIndices = _this$props2.selectedIndices, selectAllText = _this$props2.selectAllText; var _this$state = _this.state, optionGroups = _this$state.optionGroups, optionGroupDataLookup = _this$state.optionGroupDataLookup, ungroupedOptionData = _this$state.ungroupedOptionData, flattenedOptionsData = _this$state.flattenedOptionsData; var visibleOptions = _reject(flattenedOptionsData, 'optionProps.isHidden'); var isAllOptionsHidden = _isEmpty(visibleOptions); var isEveryVisibleOptionSelected = _every(visibleOptions, function (_ref8) { var optionIndex = _ref8.optionIndex; return _includes(selectedIndices, optionIndex); }); var isAnyVisibleOptionSelected = _some(visibleOptions, function (_ref9) { var optionIndex = _ref9.optionIndex; return _includes(selectedIndices, optionIndex); }); // for each option group passed in, render a DropMenu.OptionGroup, any label will be included in it's children, render each option inside the group var dropMenuOptions = [/*#__PURE__*/React.createElement(DropMenu.FixedOption, { className: cx('&-Option-select-all'), key: 'SearchableMultiSelectOption-select-all', isHidden: !hasSelectAll, isDisabled: isLoading }, /*#__PURE__*/React.createElement(CheckboxLabeled, { className: cx('&-CheckboxLabeled'), isSelected: isEveryVisibleOptionSelected, isIndeterminate: !isEveryVisibleOptionSelected && isAnyVisibleOptionSelected }, /*#__PURE__*/React.createElement(CheckboxLabeled.Label, null, selectAllText)))].concat(_map(optionGroups, function (optionGroupProps, optionGroupIndex) { return /*#__PURE__*/React.createElement(DropMenu.OptionGroup, _extends({ key: 'SearchableMultiSelectOptionGroup' + optionGroupIndex }, _omit(optionGroupProps, 'children', 'Selected')), optionGroupProps.children, _map(optionGroupDataLookup[optionGroupIndex], function (option) { return _this.renderOption(option); })); }).concat( // then render all the ungrouped options at the end _map(ungroupedOptionData, function (option) { return _this.renderOption(option); }))); if (!isAllOptionsHidden || _isEmpty(searchText)) { return dropMenuOptions; } if (!isLoading) { return /*#__PURE__*/React.createElement(DropMenu.Option, { isDisabled: true }, /*#__PURE__*/React.createElement("span", { className: cx('&-noresults') }, "No results match \"", searchText, "\"")); } return null; }); _defineProperty(_assertThisInitialized(_this), "render", function () { var _assertThisInitialize5 = _assertThisInitialized(_this), props = _assertThisInitialize5.props, _assertThisInitialize6 = _assertThisInitialize5.props, className = _assertThisInitialize6.className, isLoading = _assertThisInitialize6.isLoading, isDisabled = _assertThisInitialize6.isDisabled, maxMenuHeight = _assertThisInitialize6.maxMenuHeight, selectedIndices = _assertThisInitialize6.selectedIndices, dropMenuProps = _assertThisInitialize6.DropMenu, optionContainerStyle = _assertThisInitialize6.DropMenu.optionContainerStyle, responsiveMode = _assertThisInitialize6.responsiveMode, searchText = _assertThisInitialize6.searchText, hasRemoveAll = _assertThisInitialize6.hasRemoveAll, hasSelections = _assertThisInitialize6.hasSelections, passThroughs = _objectWithoutProperties(_assertThisInitialize6, ["className", "isLoading", "isDisabled", "maxMenuHeight", "selectedIndices", "DropMenu", "DropMenu", "responsiveMode", "searchText", "hasRemoveAll", "hasSelections"]); var _this$state2 = _this.state, optionGroupDataLookup = _this$state2.optionGroupDataLookup, optionGroups = _this$state2.optionGroups, ungroupedOptionData = _this$state2.ungroupedOptionData; var searchFieldProps = _get(getFirst(props, SearchableMultiSelect.SearchField), 'props', {}); var errorChildProps = _first(_map(findTypes(props, Validation.Error), 'props')); var selectionLabel = _get(getFirst(props, SearchableMultiSelect.SelectionLabel), 'props', {}) || /*#__PURE__*/React.createElement(SearchableMultiSelect.SelectionLabel, null, "Selected"); var isSmall = responsiveMode === 'small'; return /*#__PURE__*/React.createElement("div", _extends({}, omitProps(passThroughs, undefined, _keys(SearchableMultiSelect.propTypes)), { className: cx('&', className) }), /*#__PURE__*/React.createElement(DropMenu, _extends({}, dropMenuProps, { selectedIndices: null, className: cx('&-DropMenu', { '&-DropMenu-is-small': isSmall }, dropMenuProps.className), optionContainerStyle: _assign({}, optionContainerStyle, !_isNil(maxMenuHeight) ? { maxHeight: maxMenuHeight } : null), isDisabled: isDisabled, onSelect: _this.handleDropMenuSelect, ContextMenu: { alignmentOffset: -13, directonOffset: -1, minWidthOffset: -28 } }), /*#__PURE__*/React.createElement(DropMenu.Control, null, /*#__PURE__*/React.createElement(SearchField, _extends({}, searchFieldProps, { autoComplete: searchFieldProps.autoComplete || 'off', isDisabled: isDisabled, className: cx('&-search', { '&-search-is-small': isSmall, '&-search-is-error': errorChildProps && errorChildProps.children }, searchFieldProps.className), value: searchText, onChange: _this.handleSearch }))), isLoading ? /*#__PURE__*/React.createElement(DropMenu.Option, { key: "SearchableMultiSelectLoading", className: cx('&-loading'), isDisabled: true }, /*#__PURE__*/React.createElement(LoadingIcon, null)) : null, _this.renderOptions()), hasSelections && !_isEmpty(selectedIndices) ? /*#__PURE__*/React.createElement("div", { className: cx('&-Selection-padding') }, /*#__PURE__*/React.createElement(Selection, { className: cx('&-Selection-section'), isBold: true, hasBackground: true, kind: "container", onRemove: _this.handleRemoveAll, responsiveMode: responsiveMode, isRemovable: hasRemoveAll }, /*#__PURE__*/React.createElement(Selection.Label, null, selectionLabel.children ? selectionLabel.children : 'Selected'), _map(optionGroupDataLookup, function (groupedOptionsData, optionGroupIndex) { var selectedGroupedOptions = _filter(groupedOptionsData, function (_ref10) { var optionIndex = _ref10.optionIndex; return _includes(selectedIndices, optionIndex); }); if (!_isEmpty(selectedGroupedOptions)) { var selectedOptionGroupChildren = _get(getFirst(optionGroups[optionGroupIndex], SearchableMultiSelect.OptionGroup.Selected), 'props.children'); return /*#__PURE__*/React.createElement(Selection, { className: cx('&-Selection-group'), key: 'optionGroup-' + optionGroupIndex, responsiveMode: responsiveMode, isRemovable: false, isBold: true, kind: "container" }, /*#__PURE__*/React.createElement(Selection.Label, null, !_isNil(selectedOptionGroupChildren) ? selectedOptionGroupChildren : _first(rejectTypes(optionGroups[optionGroupIndex].children, SearchableMultiSelect.Option))), _map(selectedGroupedOptions, function (_ref11) { var optionIndex = _ref11.optionIndex, optionProps = _ref11.optionProps; var selectionProps = _get(getFirst(optionProps, SearchableMultiSelect.Option.Selection), 'props'); return /*#__PURE__*/React.createElement(Selection, _extends({ key: optionIndex }, selectionProps, { callbackId: optionIndex, responsiveMode: responsiveMode, onRemove: _this.handleSelectionRemove }), /*#__PURE__*/React.createElement(Selection.Label, null, _get(getFirst(optionProps, SearchableMultiSelect.Option.Selected), 'props.children') || (_isFunction(optionProps.children) ? /*#__PURE__*/React.createElement(optionProps.children) : optionProps.children))); })); } return null; }), _map(selectedIndices, function (selectedIndex) { var selectedUngroupedOptionData = _find(ungroupedOptionData, { optionIndex: selectedIndex }); if (selectedUngroupedOptionData) { var optionProps = selectedUngroupedOptionData.optionProps; var selectionProps = _get(getFirst(optionProps, SearchableMultiSelect.Option.Selection), 'props'); return /*#__PURE__*/React.createElement(Selection, _extends({ key: selectedIndex }, selectionProps, { callbackId: selectedIndex, responsiveMode: responsiveMode, onRemove: _this.handleSelectionRemove }), /*#__PURE__*/React.createElement(Selection.Label, null, _get(getFirst(optionProps, SearchableMultiSelect.Option.Selected), 'props.children') || (_isFunction(optionProps.children) ? /*#__PURE__*/React.createElement(optionProps.children) : optionProps.children))); } return null; }))) : null, errorChildProps && errorChildProps.children && errorChildProps.children !== true ? /*#__PURE__*/React.createElement("div", _extends({}, omitProps(errorChildProps, undefined), { className: cx('&-error-content') }), errorChildProps.children) : null); }); return _this; } _createClass(SearchableMultiSelect, [{ key: "UNSAFE_componentWillMount", value: function UNSAFE_componentWillMount() { // preprocess the options data before rendering var _DropMenu$preprocessO = DropMenu.preprocessOptionData(this.props, SearchableMultiSelect), optionGroups = _DropMenu$preprocessO.optionGroups, flattenedOptionsData = _DropMenu$preprocessO.flattenedOptionsData, ungroupedOptionData = _DropMenu$preprocessO.ungroupedOptionData, optionGroupDataLookup = _DropMenu$preprocessO.optionGroupDataLookup; this.setState({ optionGroups: optionGroups, flattenedOptionsData: flattenedOptionsData, ungroupedOptionData: ungroupedOptionData, optionGroupDataLookup: optionGroupDataLookup }); } }, { key: "UNSAFE_componentWillReceiveProps", value: function UNSAFE_componentWillReceiveProps(nextProps) { // only preprocess options data when it changes (via new props) - better performance than doing this each render var _DropMenu$preprocessO2 = DropMenu.preprocessOptionData(nextProps, SearchableMultiSelect), optionGroups = _DropMenu$preprocessO2.optionGroups, flattenedOptionsData = _DropMenu$preprocessO2.flattenedOptionsData, ungroupedOptionData = _DropMenu$preprocessO2.ungroupedOptionData, optionGroupDataLookup = _DropMenu$preprocessO2.optionGroupDataLookup; this.setState({ optionGroups: optionGroups, flattenedOptionsData: flattenedOptionsData, ungroupedOptionData: ungroupedOptionData, optionGroupDataLookup: optionGroupDataLookup }); } }]); return SearchableMultiSelect; }(React.Component); _defineProperty(SearchableMultiSelect, "displayName", 'SearchableMultiSelect'); _defineProperty(SearchableMultiSelect, "peek", { description: "\n A control used to select multiple options from a dropdown list using a\n SearchField.\n ", categories: ['controls', 'selectors'], madeFrom: ['Checkbox', 'SearchField', 'DropMenu', 'LoadingIcon', 'Selection'] }); _defineProperty(SearchableMultiSelect, "defaultProps", defaultProps); _defineProperty(SearchableMultiSelect, "reducers", reducers); _defineProperty(SearchableMultiSelect, "Option", Option); _defineProperty(SearchableMultiSelect, "OptionGroup", OptionGroup); _defineProperty(SearchableMultiSelect, "SearchField", SearchFieldComponent); _defineProperty(SearchableMultiSelect, "NullOption", DropMenu.NullOption); _defineProperty(SearchableMultiSelect, "FixedOption", DropMenu.FixedOption); _defineProperty(SearchableMultiSelect, "DropMenu", DropMenu); _defineProperty(SearchableMultiSelect, "SelectionLabel", Selection.Label); _defineProperty(SearchableMultiSelect, "propTypes", { children: node, className: string, isDisabled: bool, isLoading: bool, maxMenuHeight: oneOfType([number, string]), onSearch: func, onSelect: func, onRemoveAll: func, optionFilter: func, searchText: string, selectedIndices: arrayOf(number), DropMenu: shape(DropMenu.propTypes), Option: any, responsiveMode: oneOf(['small', 'medium', 'large']), hasRemoveAll: bool, hasSelections: bool, hasSelectAll: bool, selectAllText: string, Error: any, FixedOption: any, NullOption: any, OptionGroup: any, SearchField: any, Label: any }); export default buildModernHybridComponent(SearchableMultiSelect, { reducers: reducers }); export { SearchableMultiSelect as SearchableMultiSelectDumb };