UNPKG

@elastic/eui

Version:

Elastic UI Component Library

837 lines (822 loc) 50.2 kB
var _excluded = ["data"], _excluded2 = ["label", "isGroupLabel", "checked", "disabled", "prepend", "append", "ref", "key", "searchableLabel", "data", "truncationProps", "css"], _excluded3 = ["className", "options", "searchValue", "onOptionClick", "renderOption", "height", "windowProps", "rowHeight", "activeOptionIndex", "makeOptionId", "showIcons", "singleSelection", "visibleOptions", "allowExclusions", "bordered", "paddingSize", "searchable", "onFocusBadge", "listId", "setActiveOptionIndex", "aria-label", "aria-labelledby", "aria-describedby", "role", "isPreFiltered", "isVirtualized", "textWrap", "truncationProps", "autoFocus"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import React, { Component, memo } from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import { VariableSizeList, areEqual } from 'react-window'; import { RenderWithEuiStylesMemoizer } from '../../../services'; import { EuiAutoSizer } from '../../auto_sizer'; import { EuiHighlight } from '../../highlight'; import { EuiMark } from '../../mark'; import { EuiTextTruncate } from '../../text_truncate'; import { EuiSelectableListItem } from './selectable_list_item'; import { euiSelectableListGroupLabelStyles, euiSelectableListStyles } from './selectable_list.styles'; import { getListItemSize } from './utils/get_list_item_size'; // Consumer Configurable Props via `EuiSelectable.listProps` import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiSelectableList = /*#__PURE__*/function (_Component) { function EuiSelectableList(props) { var _this; _classCallCheck(this, EuiSelectableList); _this = _callSuper(this, EuiSelectableList, [props]); _defineProperty(_this, "animationFrameId", void 0); // counter for tracking list renders and ensuring rerenders _defineProperty(_this, "listRowRerender", 0); _defineProperty(_this, "listRef", null); _defineProperty(_this, "listBoxRef", null); _defineProperty(_this, "setListRef", function (ref) { _this.listRef = ref; if (ref && _this.props.activeOptionIndex) { ref.scrollToItem(_this.props.activeOptionIndex, 'auto'); } }); _defineProperty(_this, "removeScrollableTabStop", function (ref) { // Firefox adds a tab stop for scrollable containers // We handle this inside so need to stop firefox from doing its thing if (ref) { ref.setAttribute('tabindex', '-1'); } }); _defineProperty(_this, "setListBoxRef", function (ref) { _this.listBoxRef = ref; var _this$props = _this.props, listId = _this$props.listId, searchable = _this$props.searchable, singleSelection = _this$props.singleSelection, autoFocus = _this$props.autoFocus, ariaLabel = _this$props['aria-label'], ariaLabelledby = _this$props['aria-labelledby'], ariaDescribedby = _this$props['aria-describedby']; if (ref) { ref.setAttribute('id', listId); ref.setAttribute('role', 'listbox'); if (searchable !== true) { ref.setAttribute('tabindex', '0'); if (singleSelection !== 'always' && singleSelection !== true) { ref.setAttribute('aria-multiselectable', 'true'); } } if (typeof ariaLabel === 'string') { ref.setAttribute('aria-label', ariaLabel); } else if (typeof ariaLabelledby === 'string') { ref.setAttribute('aria-labelledby', ariaLabelledby); } if (typeof ariaDescribedby === 'string') { ref.setAttribute('aria-describedby', ariaDescribedby); } if (autoFocus === true) { // manually focus listbox once available // use last stack execution to prevent potential focus order issues setTimeout(function () { return ref.focus(); }); } } }); // This utility is necessary to exclude group labels from the aria set count _defineProperty(_this, "calculateAriaSetAttrs", function (optionArray) { var ariaPosInSetMap = {}; var latestAriaPosIndex = 0; optionArray.forEach(function (option, index) { if (!option.isGroupLabel) { latestAriaPosIndex++; ariaPosInSetMap[index] = latestAriaPosIndex; } }); return { ariaPosInSetMap: ariaPosInSetMap, ariaSetSize: latestAriaPosIndex }; }); _defineProperty(_this, "getItemSize", function (index) { var _ref = _this.props, rowHeight = _ref.rowHeight; var option = _this.state.optionArray[index]; return getListItemSize(index, rowHeight, !!(option !== null && option !== void 0 && option.isGroupLabel)); }); _defineProperty(_this, "ListRow", /*#__PURE__*/memo(function (_ref2) { var _option$textWrap; var data = _ref2.data, index = _ref2.index, style = _ref2.style; var option = data[index]; var optionData = option.data, _option = _objectWithoutProperties(option, _excluded); var label = option.label, isGroupLabel = option.isGroupLabel, checked = option.checked, disabled = option.disabled, prepend = option.prepend, append = option.append, ref = option.ref, key = option.key, searchableLabel = option.searchableLabel, _data = option.data, _truncationProps = option.truncationProps, css = option.css, optionRest = _objectWithoutProperties(option, _excluded2); var _this$props2 = _this.props, activeOptionIndex = _this$props2.activeOptionIndex, allowExclusions = _this$props2.allowExclusions, onFocusBadge = _this$props2.onFocusBadge, showIcons = _this$props2.showIcons, makeOptionId = _this$props2.makeOptionId, renderOption = _this$props2.renderOption, setActiveOptionIndex = _this$props2.setActiveOptionIndex, searchable = _this$props2.searchable, searchValue = _this$props2.searchValue, isPreFiltered = _this$props2.isPreFiltered, isVirtualized = _this$props2.isVirtualized, singleSelection = _this$props2.singleSelection; if (isGroupLabel) { return ___EmotionJSX(RenderWithEuiStylesMemoizer, null, function (stylesMemoizer) { var styles = stylesMemoizer(euiSelectableListGroupLabelStyles); return ___EmotionJSX("li", _extends({ role: "presentation", css: [styles.groupLabel, css, ";label:EuiSelectableList;"], className: "euiSelectableList__groupLabel", style: style }, optionRest), prepend, label, append); }); } var id = makeOptionId(index); var isFocused = activeOptionIndex === index; // Search highlighting var hasSearch = !!searchValue; var highlightSearch = hasSearch && (_typeof(isPreFiltered) === 'object' ? isPreFiltered.highlightSearch !== false : true); // Text wrapping var canWrap = !isVirtualized; var _textWrap = (_option$textWrap = option.textWrap) !== null && _option$textWrap !== void 0 ? _option$textWrap : _this.props.textWrap; var textWrap = canWrap ? _textWrap : 'truncate'; // Truncation config (if any). If none, CSS truncation is used var truncationProps = textWrap === 'truncate' ? _this.getTruncationProps(option, highlightSearch, isFocused) : undefined; return ___EmotionJSX(EuiSelectableListItem, _extends({ key: id, id: id, style: style, onMouseDown: function onMouseDown() { setActiveOptionIndex(index); }, onClick: function onClick(event) { event.persist(); // NOTE: This is needed for React v16 backwards compatibility _this.onAddOrRemoveOption(option, event); }, isFocused: isFocused, title: !truncationProps && !option.toolTipContent ? searchableLabel || label : undefined, checked: checked, disabled: disabled, prepend: prepend, append: append, "aria-posinset": _this.state.ariaPosInSetMap[index], "aria-setsize": _this.state.ariaSetSize, onFocusBadge: onFocusBadge, allowExclusions: allowExclusions, showIcons: showIcons, searchable: searchable, textWrap: textWrap, singleSelection: singleSelection === false ? false : true // @ts-ignore complex }, optionRest), renderOption ? renderOption( // @ts-ignore complex _objectSpread(_objectSpread({}, _option), optionData), searchValue) : highlightSearch ? _this.renderSearchedText(label, truncationProps) : truncationProps ? _this.renderTruncatedText(label, truncationProps) : label); }, areEqual)); _defineProperty(_this, "renderVirtualizedList", function (listClasses) { if (!_this.props.isVirtualized) return null; var _this$state = _this.state, optionArray = _this$state.optionArray, itemData = _this$state.itemData; var _this$props3 = _this.props, windowProps = _this$props3.windowProps, forcedHeight = _this$props3.height, rowHeight = _this$props3.rowHeight; var heightIsFull = forcedHeight === 'full'; var virtualizationProps = _objectSpread({ className: listClasses, ref: _this.setListRef, outerRef: _this.removeScrollableTabStop, innerRef: _this.setListBoxRef, innerElementType: 'ul', itemCount: optionArray.length, itemData: itemData, itemSize: _this.getItemSize, // Prevents scrollbar jump before VariableSizeList populates the cached size estimatedItemSize: rowHeight, 'data-skip-axe': 'scrollable-region-focusable' }, windowProps); // Calculated height is only used if height is not full var calculatedHeight = !heightIsFull ? forcedHeight || 0 : 0; // If calculatedHeight is still falsy, then calculate it if (!heightIsFull && !calculatedHeight) { var maxVisibleOptions = 7; var numVisibleOptions = optionArray.length; var numVisibleMoreThanMax = optionArray.length > maxVisibleOptions; if (numVisibleMoreThanMax) { // Show only half of the last one to indicate there's more to scroll to calculatedHeight = (maxVisibleOptions - 0.5) * rowHeight; } else { calculatedHeight = numVisibleOptions * rowHeight; } } return heightIsFull ? ___EmotionJSX(EuiAutoSizer, { onResize: _this.calculateDefaultOptionWidth }, function (_ref3) { var width = _ref3.width, height = _ref3.height; return ___EmotionJSX(VariableSizeList, _extends({ width: width, height: height }, virtualizationProps), _this.ListRow); }) : ___EmotionJSX(EuiAutoSizer, { disableHeight: true, onResize: _this.calculateDefaultOptionWidth }, function (_ref4) { var width = _ref4.width; return ___EmotionJSX(VariableSizeList, _extends({ width: width, height: calculatedHeight }, virtualizationProps), _this.ListRow); }); }); _defineProperty(_this, "forceVirtualizedListRowRerender", function () { _this.setState({ itemData: _objectSpread({}, _this.state.optionArray) }); }); // EuiTextTruncate is expensive perf-wise - we use several utilities here to // offset its performance cost // and creates a resize observer for // each individual item. This logic tries to offset this performance hit by // guesstimating a default width for each option _defineProperty(_this, "focusBadgeOffset", 0); _defineProperty(_this, "calculateDefaultOptionWidth", function (_ref5) { var containerWidth = _ref5.width; var _this$props4 = _this.props, truncationProps = _this$props4.truncationProps, searchable = _this$props4.searchable, searchValue = _this$props4.searchValue; // If it's not likely we'll need to use EuiTextTruncate, don't set state/rerender on every panel resize var mayTruncate = searchable || truncationProps; if (!mayTruncate) return; var paddingOffset = 24; // 2 * list item padding (8px) + 2 * text padding (4px) var checkedIconOffset = _this.props.showIcons === false ? 0 : 24; // icon (16px) + gap (8px) _this.focusBadgeOffset = !_this.props.onFocusBadge ? 0 : 28; // badge (20px) + gap (8px) // Wait a tick for the listbox ref to update before proceeding _this.animationFrameId = requestAnimationFrame(function () { var scrollbarOffset = _this.listBoxRef ? containerWidth - _this.listBoxRef.offsetWidth : 0; _this.setState({ defaultOptionWidth: containerWidth - scrollbarOffset - paddingOffset - checkedIconOffset }); // Potentially force list rows to rerender on dynamic resize as well, // but try to do it as lightly as possible if (truncationProps || searchable && searchValue) { _this.forceVirtualizedListRowRerender(); } }); }); _defineProperty(_this, "getTruncationProps", function (option, highlightSearch, isFocused) { // Individual truncation settings should override component-wide settings var truncationProps = _objectSpread(_objectSpread({}, _this.props.truncationProps), option.truncationProps); // If we're not actually using EuiTextTruncate, no need to continue var hasComplexTruncation = highlightSearch || Object.keys(truncationProps).length > 0; if (!hasComplexTruncation) return undefined; // Determine whether we can use the optimized default option width var defaultOptionWidth = _this.state.defaultOptionWidth; var useDefaultWidth = !option.append && !option.prepend; var defaultWidth = useDefaultWidth && defaultOptionWidth ? isFocused ? defaultOptionWidth - _this.focusBadgeOffset : defaultOptionWidth : undefined; return _objectSpread({ width: defaultWidth }, truncationProps); }); _defineProperty(_this, "renderSearchedText", function (text, truncationProps) { var searchValue = _this.props.searchValue; // If truncationProps is undefined, we're using non-virtualized text wrapping if (!truncationProps) { return ___EmotionJSX(EuiHighlight, { search: searchValue }, text); } var searchPositionStart = text.toLowerCase().indexOf(searchValue.toLowerCase()); var searchPositionCenter = searchPositionStart + Math.floor(searchValue.length / 2); return ___EmotionJSX(EuiTextTruncate, _extends({}, truncationProps, { // When searching, don't allow overriding the truncation settings truncation: "startEnd", truncationPosition: searchPositionCenter, text: text }), function (text) { return ___EmotionJSX(React.Fragment, null, text.length >= searchValue.length ? ___EmotionJSX(EuiHighlight, { search: searchValue }, text) : // If the available truncated text is shorter than the full search string, // just highlight the entire truncated text ___EmotionJSX(EuiMark, null, text)); }); }); _defineProperty(_this, "renderTruncatedText", function (text, truncationProps) { return ( // For some bizarre reason, truncation in EuiSelectable is off on initial mount // (but not on rerender) for Safari and _some_ truncation types in Firefox :| // Waiting a tick before calculating truncation seems to smooth over the issue ___EmotionJSX(EuiTextTruncate, _extends({ calculationDelayMs: 2 }, truncationProps, { text: text }), function (text) { return text; }) ); }); _defineProperty(_this, "onAddOrRemoveOption", function (option, event) { if (option.disabled) { return; } var _this$props5 = _this.props, allowExclusions = _this$props5.allowExclusions, options = _this$props5.options, _this$props5$visibleO = _this$props5.visibleOptions, visibleOptions = _this$props5$visibleO === void 0 ? options : _this$props5$visibleO; _this.props.setActiveOptionIndex(visibleOptions.findIndex(function (_ref6) { var label = _ref6.label; return label === option.label; }), function () { if (option.checked === 'on' && allowExclusions) { _this.onExcludeOption(option, event); } else if (option.checked === 'on' || option.checked === 'off') { _this.onRemoveOption(option, event); } else { _this.onAddOption(option, event); } }); }); _defineProperty(_this, "onAddOption", function (addedOption, event) { var _this$props6 = _this.props, onOptionClick = _this$props6.onOptionClick, options = _this$props6.options, singleSelection = _this$props6.singleSelection; var changedOption = _objectSpread({}, addedOption); var updatedOptions = options.map(function (option) { // if singleSelection is enabled, uncheck any selected option(s) var updatedOption = _objectSpread({}, option); if (singleSelection) { delete updatedOption.checked; } // if this is the now-selected option, check it if (option === addedOption) { updatedOption.checked = 'on'; changedOption = updatedOption; } return updatedOption; }); onOptionClick(updatedOptions, event, changedOption); }); _defineProperty(_this, "onRemoveOption", function (removedOption, event) { var _this$props7 = _this.props, onOptionClick = _this$props7.onOptionClick, singleSelection = _this$props7.singleSelection, options = _this$props7.options; var changedOption = _objectSpread({}, removedOption); var updatedOptions = options.map(function (option) { var updatedOption = _objectSpread({}, option); if (option === removedOption && singleSelection !== 'always') { delete updatedOption.checked; changedOption = updatedOption; } return updatedOption; }); onOptionClick(updatedOptions, event, changedOption); }); _defineProperty(_this, "onExcludeOption", function (excludedOption, event) { var _this$props8 = _this.props, onOptionClick = _this$props8.onOptionClick, options = _this$props8.options; var changedOption = _objectSpread({}, excludedOption); var updatedOptions = options.map(function (option) { var updatedOption = _objectSpread({}, option); if (option === excludedOption) { updatedOption.checked = 'off'; changedOption = updatedOption; } return updatedOption; }); onOptionClick(updatedOptions, event, changedOption); }); var _optionArray = props.visibleOptions || props.options; _this.state = _objectSpread({ defaultOptionWidth: 0, optionArray: _optionArray, itemData: _objectSpread({}, _optionArray) }, _this.calculateAriaSetAttrs(_optionArray)); return _this; } _inherits(EuiSelectableList, _Component); return _createClass(EuiSelectableList, [{ key: "componentWillUnmount", value: function componentWillUnmount() { // ensure requestAnimationFrame is canceled on unmount as // it could potentially run on a next tick otherwise if (this.animationFrameId !== undefined) { cancelAnimationFrame(this.animationFrameId); this.animationFrameId = undefined; } } }, { key: "shouldComponentUpdate", value: function shouldComponentUpdate(nextProps) { var _this$props9 = this.props, allowExclusions = _this$props9.allowExclusions, showIcons = _this$props9.showIcons, paddingSize = _this$props9.paddingSize, textWrap = _this$props9.textWrap, onFocusBadge = _this$props9.onFocusBadge, searchable = _this$props9.searchable, singleSelection = _this$props9.singleSelection; // using shouldComponentUpdate to determine needed rerender before actual rerender // without needing state updates or lagging behind on updates if (nextProps.allowExclusions !== allowExclusions || nextProps.showIcons !== showIcons || nextProps.paddingSize !== paddingSize || nextProps.textWrap !== textWrap || nextProps.onFocusBadge !== onFocusBadge || nextProps.searchable !== searchable || nextProps.singleSelection !== singleSelection) { this.listRowRerender += 1; } return true; } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this$props10 = this.props, isVirtualized = _this$props10.isVirtualized, activeOptionIndex = _this$props10.activeOptionIndex, visibleOptions = _this$props10.visibleOptions, options = _this$props10.options, allowExclusions = _this$props10.allowExclusions, showIcons = _this$props10.showIcons, paddingSize = _this$props10.paddingSize, textWrap = _this$props10.textWrap, onFocusBadge = _this$props10.onFocusBadge, searchable = _this$props10.searchable, singleSelection = _this$props10.singleSelection; if (prevProps.activeOptionIndex !== activeOptionIndex) { var makeOptionId = this.props.makeOptionId; if (this.listBoxRef && this.props.searchable !== true) { this.listBoxRef.setAttribute('aria-activedescendant', makeOptionId(activeOptionIndex)); } if (typeof activeOptionIndex !== 'undefined') { if (isVirtualized) { var _this$listRef; // NOTE: Maybe we might want to consider changing scroll position to // 'center' to not have items stick to the edges of the list (_this$listRef = this.listRef) === null || _this$listRef === void 0 || _this$listRef.scrollToItem(activeOptionIndex, 'auto'); } else { var _this$listBoxRef; var activeOptionId = makeOptionId(activeOptionIndex); var activeOptionEl = (_this$listBoxRef = this.listBoxRef) === null || _this$listBoxRef === void 0 ? void 0 : _this$listBoxRef.querySelector("[id=\"".concat(activeOptionId, "\"]")); if (activeOptionEl) { var _activeOptionEl$scrol; // TODO: we can remove scrollIntoView's conditional chaining once jsdom stubs it // @see https://github.com/jsdom/jsdom/issues/1695 (_activeOptionEl$scrol = activeOptionEl.scrollIntoView) === null || _activeOptionEl$scrol === void 0 || _activeOptionEl$scrol.call(activeOptionEl, { block: 'nearest' }); } } } } var optionArray = visibleOptions || options; if (prevProps.visibleOptions !== visibleOptions || prevProps.options !== options) { this.setState(_objectSpread({ optionArray: optionArray, itemData: _objectSpread({}, optionArray) }, this.calculateAriaSetAttrs(optionArray))); } else if (isVirtualized) { // ensure that ListRow updates based on item props if (prevProps.allowExclusions !== allowExclusions || prevProps.showIcons !== showIcons || prevProps.paddingSize !== paddingSize || prevProps.textWrap !== textWrap || prevProps.onFocusBadge !== onFocusBadge || prevProps.searchable !== searchable || prevProps.singleSelection !== singleSelection) { this.setState({ itemData: _objectSpread({}, optionArray) }); } } } }, { key: "render", value: function render() { var _this2 = this; var _this$props11 = this.props, className = _this$props11.className, options = _this$props11.options, searchValue = _this$props11.searchValue, onOptionClick = _this$props11.onOptionClick, renderOption = _this$props11.renderOption, forcedHeight = _this$props11.height, windowProps = _this$props11.windowProps, rowHeight = _this$props11.rowHeight, activeOptionIndex = _this$props11.activeOptionIndex, makeOptionId = _this$props11.makeOptionId, showIcons = _this$props11.showIcons, singleSelection = _this$props11.singleSelection, visibleOptions = _this$props11.visibleOptions, allowExclusions = _this$props11.allowExclusions, bordered = _this$props11.bordered, paddingSize = _this$props11.paddingSize, searchable = _this$props11.searchable, onFocusBadge = _this$props11.onFocusBadge, listId = _this$props11.listId, setActiveOptionIndex = _this$props11.setActiveOptionIndex, ariaLabel = _this$props11['aria-label'], ariaLabelledby = _this$props11['aria-labelledby'], ariaDescribedby = _this$props11['aria-describedby'], role = _this$props11.role, isPreFiltered = _this$props11.isPreFiltered, isVirtualized = _this$props11.isVirtualized, textWrap = _this$props11.textWrap, truncationProps = _this$props11.truncationProps, autoFocus = _this$props11.autoFocus, rest = _objectWithoutProperties(_this$props11, _excluded3); var heightIsFull = forcedHeight === 'full'; var classes = classNames('euiSelectableList', className); return ___EmotionJSX(RenderWithEuiStylesMemoizer, null, function (stylesMemoizer) { var styles = stylesMemoizer(euiSelectableListStyles); var cssStyles = [styles.euiSelectableList, heightIsFull && styles.fullHeight, bordered && styles.bordered, paddingSize === 's' && styles.paddingSize.s]; var listClasses = classNames('euiSelectableList__list', styles.euiSelectableList__list); return ___EmotionJSX("div", _extends({ css: cssStyles, className: classes }, rest), isVirtualized ? _this2.renderVirtualizedList(listClasses) : ___EmotionJSX("div", { className: listClasses, style: !heightIsFull ? { blockSize: forcedHeight } : undefined, ref: _this2.removeScrollableTabStop }, ___EmotionJSX("ul", { ref: _this2.setListBoxRef }, _this2.state.optionArray.map(function (_, index) { return /*#__PURE__*/React.createElement(_this2.ListRow, { key: "".concat(index, "-").concat(_this2.listRowRerender), data: _this2.state.optionArray, index: index }, null); })))); }); } }]); }(Component); _defineProperty(EuiSelectableList, "defaultProps", { rowHeight: 32, paddingSize: 'none', searchValue: '', isVirtualized: true }); EuiSelectableList.propTypes = { className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * The index of the option to be highlighted as pseudo-focused; * Good for use when only one selection is allowed and needing to open * directly to that option */ activeOptionIndex: PropTypes.number, /** * Show the check/cross selection indicators */ showIcons: PropTypes.bool, singleSelection: PropTypes.oneOfType([PropTypes.oneOf(["always"]), PropTypes.bool.isRequired]), /** * Any props to send specifically to the react-window `FixedSizeList` */ windowProps: PropTypes.any, /** * Adds a border around the list to indicate the bounds; * Useful when the list scrolls, otherwise use your own container */ bordered: PropTypes.bool, /** * When enabled by setting to either `true` or passing custom text, * shows a hollow badge as an append (far right) when the item is focused. * The default content when `true` is `↩ to select/deselect/include/exclude` */ onFocusBadge: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.shape({ /** * Accepts any string from our icon library */ iconType: PropTypes.oneOfType([PropTypes.oneOf(["accessibility", "addDataApp", "addToDashboard", "advancedSettingsApp", "agentApp", "aggregate", "alignBottom", "alignBottomLeft", "alignBottomRight", "alignCenterHorizontal", "alignCenterVertical", "alignLeft", "alignRight", "alignTop", "alignTopLeft", "alignTopRight", "alert", "analyzeEvent", "annotation", "anomalyChart", "chartAnomaly", "anomalySwimLane", "apmApp", "apmTrace", "chartWaterfall", "appSearchApp", "apps", "arrowDown", "chevronSingleDown", "arrowLeft", "chevronSingleLeft", "arrowRight", "chevronSingleRight", "arrowUp", "chevronSingleUp", "arrowStart", "chevronLimitLeft", "arrowEnd", "chevronLimitRight", "article", "asterisk", "at", "archive", "axisX", "axisYLeft", "axisYRight", "auditbeatApp", "backgroundTask", "beaker", "bell", "bellSlash", "beta", "bolt", "boxesHorizontal", "boxesVertical", "branch", "briefcase", "branchUser", "broom", "brush", "bug", "bulb", "bullseye", "calendar", "canvasApp", "casesApp", "changePointDetection", "chartChangePoint", "chartArea", "chartAreaStack", "chartBarHorizontal", "chartBarHorizontalStack", "chartBarVertical", "chartBarVerticalStack", "chartGauge", "chartHeatmap", "chartLine", "chartPie", "chartTagCloud", "chartThreshold", "check", "checkCircle", "checkInCircleFilled", "checkCircleFill", "cheer", "popper", "classificationJob", "clickLeft", "clickRight", "clock", "clockCounter", "clockControl", "cloud", "cloudDrizzle", "cloudStormy", "cloudSunny", "cluster", "code", "codeApp", "color", "paintBucket", "commandLine", "comment", "compare", "compute", "processor", "console", "consoleApp", "container", "continuityAbove", "continuityAboveBelow", "continuityBelow", "continuityWithin", "contrast", "contrastHigh", "contrastFill", "controls", "controlsHorizontal", "controlsVertical", "copy", "copyClipboard", "crossProjectSearch", "createAdvancedJob", "createGenericJob", "createGeoJob", "createMultiMetricJob", "createPopulationJob", "createSingleMetricJob", "cross", "crossClusterReplicationApp", "crossInCircle", "crossCircle", "crosshair", "crosshairs", "currency", "money", "cut", "scissors", "dashboardApp", "dashedCircle", "dataVisualizer", "database", "desktop", "display", "devToolsApp", "diff", "discoverApp", "distributeHorizontal", "distributeVertical", "download", "drag", "dragHorizontal", "dragVertical", "discuss", "document", "documentEdit", "documentation", "documents", "dot", "dotInCircle", "doubleArrowLeft", "chevronDoubleLeft", "doubleArrowRight", "chevronDoubleRight", "ellipsis", "editorAlignCenter", "textAlignCenter", "editorAlignLeft", "textAlignLeft", "editorAlignRight", "textAlignRight", "editorBold", "textBold", "editorChecklist", "listCheck", "editorCodeBlock", "editorComment", "editorDistributeHorizontal", "editorDistributeVertical", "editorHeading", "textHeading", "editorItalic", "textItalic", "editorItemAlignBottom", "editorItemAlignCenter", "editorItemAlignLeft", "editorItemAlignMiddle", "editorItemAlignRight", "editorItemAlignTop", "editorLink", "editorOrderedList", "listNumber", "editorPositionBottomLeft", "editorPositionBottomRight", "editorPositionTopLeft", "editorPositionTopRight", "editorRedo", "redo", "editorStrike", "textStrike", "editorTable", "table", "editorUnderline", "textUnderline", "editorUndo", "undo", "editorUnorderedList", "listBullet", "email", "mail", "empty", "emsApp", "endpoint", "eql", "query", "eraser", "error", "errorFilled", "errorFill", "esqlVis", "exit", "logOut", "expand", "maximize", "expandMini", "export", "exportAction", "upload", "external", "eye", "eyeClosed", "eyeSlash", "faceHappy", "faceNeutral", "faceSad", "fieldStatistics", "tableInfo", "filebeatApp", "filter", "filterExclude", "filterIgnore", "filterInclude", "filterInCircle", "flask", "flag", "fleetApp", "fold", "folder", "folderClosed", "folderClose", "folderCheck", "folderExclamation", "folderOpen", "folderOpened", "frameNext", "framePrevious", "fullScreen", "fullScreenExit", "function", "gear", "gisApp", "glasses", "globe", "grab", "grabHorizontal", "grabOmnidirectional", "gradient", "graphApp", "grid", "grokApp", "heart", "heartbeatApp", "heatmap", "help", "home", "hourglass", "if", "info", "image", "importAction", "index", "indexClose", "indexEdit", "indexFlush", "indexManagementApp", "indexMapping", "mapping", "indexOpen", "indexPatternApp", "indexRollupApp", "indexRuntime", "indexSettings", "indexTemporary", "tableTime", "infinity", "inputOutput", "inspect", "invert", "ip", "key", "keyboard", "kqlField", "queryField", "kqlFunction", "kqlOperand", "queryOperand", "kqlSelector", "querySelector", "kqlValue", "queryValue", "kubernetesNode", "kubernetesPod", "launch", "rocket", "layers", "lensApp", "lettering", "text", "lineBreak", "lineBreakSlash", "lineDash", "lineDashed", "lineDot", "lineDotted", "lineSolid", "link", "linkSlash", "list", "listAdd", "lock", "lockOpen", "logPatternAnalysis", "pattern", "logRateAnalysis", "logoAWS", "logoAWSMono", "logoAerospike", "logoApache", "logoAppSearch", "logoAzure", "logoAzureMono", "logoBeats", "logoBusinessAnalytics", "logoCeph", "logoCloud", "logoCloudEnterprise", "logoCode", "logoCodesandbox", "logoCouchbase", "logoDocker", "logoDropwizard", "logoElastic", "logoElasticStack", "logoElasticsearch", "logoEnterpriseSearch", "logoEtcd", "logoGCP", "logoGCPMono", "logoGithub", "logoGmail", "logoGolang", "logoGoogleG", "logoHAproxy", "logoIBM", "logoIBMMono", "logoKafka", "logoKibana", "logoKubernetes", "logoLogging", "logoLogstash", "logoMaps", "logoMemcached", "logoMetrics", "logoMongodb", "logoMySQL", "logoNginx", "logoObservability", "logoOsquery", "logoPhp", "logoPostgres", "logoPrometheus", "logoRabbitmq", "logoRedis", "logoSecurity", "logoSiteSearch", "logoSketch", "logoSlack", "logoUptime", "logoVectorDB", "logoVulnerabilityManagement", "logoWebhook", "logoWindows", "logoWorkplaceSearch", "logsApp", "logstashFilter", "logstashIf", "logstashInput", "logstashOutput", "logstashQueue", "queue", "machineLearningApp", "magnet", "magnify", "magnifyExclamation", "magnifyMinus", "magnifyPlus", "magnifyWithExclamation", "magnifyWithMinus", "magnifyWithPlus", "managementApp", "map", "mapMarker", "waypoint", "megaphone", "memory", "menu", "menuDown", "menuLeft", "menuRight", "menuUp", "merge", "metricbeatApp", "metricsApp", "minimize", "minus", "minusCircle", "minusInCircle", "minusInCircleFilled", "minusInSquare", "minusSquare", "mobile", "monitoringApp", "moon", "move", "namespace", "nested", "newChat", "node", "vectorTriangle", "notebookApp", "number", "offline", "wifiSlash", "online", "wifi", "outlierDetectionJob", "package", "packetbeatApp", "pageSelect", "pagesSelect", "palette", "paperClip", "partial", "pause", "payment", "pencil", "percent", "pin", "pinFill", "pinFilled", "pipeBreaks", "pipelineApp", "pipeNoBreaks", "pivot", "play", "playFilled", "plugs", "plus", "plusCircle", "plusInCircle", "plusInCircleFilled", "plusInSquare", "plusSquare", "popout", "presentation", "productRobot", "productAgent", "productCloudInfra", "productDashboard", "productDiscover", "productML", "productStreamsClassic", "productStreamsWired", "push", "send", "question", "quote", "radar", "readOnly", "recentlyViewedApp", "refresh", "regressionJob", "reporter", "reportingApp", "return", "returnKey", "save", "savedObjectsApp", "scale", "search", "searchProfilerApp", "section", "securityAnalyticsApp", "securityApp", "securitySignal", "securitySignalDetected", "securitySignalResolved", "server", "sessionViewer", "shard", "share", "significantEvents", "singleMetricViewer", "snowflake", "sortAscending", "sortDescending", "sortDown", "sortLeft", "sortRight", "sortUp", "sortable", "spaces", "spacesApp", "sparkles", "sqlApp", "star", "starEmpty", "starEmptySpace", "starFill", "starFilled", "starFillSpace", "starFilledSpace", "starMinusEmpty", "starMinusFill", "starMinusFilled", "starPlusEmpty", "starPlusFill", "starPlusFilled", "stats", "stop", "stopFill", "stopFilled", "stopSlash", "storage", "streamsClassic", "streamsWired", "string", "submodule", "sun", "swatchInput", "symlink", "tableDensityCompact", "tableDensityHigh", "tableDensityExpanded", "tableDensityLow", "tableDensityNormal", "tableOfContents", "tag", "tear", "temperature", "thermometer", "thumbDown", "thumbUp", "timeline", "timelineWithArrow", "timelionApp", "timeRefresh", "refreshTime", "timeslider", "training", "transitionBottomIn", "transitionBottomOut", "transitionLeftIn", "transitionLeftOut", "transitionTopIn", "transitionTopOut", "trash", "unfold", "unlink", "upgradeAssistantApp", "uptimeApp", "user", "userAvatar", "users", "usersRolesApp", "unarchive", "vector", "vectorSquare", "videoPlayer", "visArea", "visAreaStacked", "visBarHorizontal", "visBarHorizontalStacked", "visBarVertical", "visBarVerticalStacked", "visGauge", "visGoal", "visLine", "visMapCoordinate", "visMapRegion", "visMetric", "chartMetric", "visPie", "visTable", "visTagCloud", "visText", "visTimelion", "visVega", "visVisualBuilder", "visualizeApp", "vulnerabilityManagementApp", "warning", "warningFilled", "warningFill", "watchesApp", "web", "wordWrap", "wordWrapDisabled", "workflowsApp", "workflow", "workplaceSearchApp", "wrench", "tokenAlias", "tokenAnnotation", "tokenArray", "tokenBinary", "tokenBoolean", "tokenClass", "tokenCompletionSuggester", "tokenConstant", "tokenDate", "tokenDimension", "tokenElement", "tokenEnum", "tokenEnumMember", "tokenEvent", "tokenException", "tokenField", "tokenFile", "tokenFlattened", "tokenFunction", "tokenGeo", "tokenHistogram", "tokenInterface", "tokenIP", "tokenJoin", "tokenKey", "tokenKeyword", "tokenMethod", "tokenMetricCounter", "tokenMetricGauge", "tokenModule", "tokenNamespace", "tokenNested", "tokenNull", "tokenNumber", "tokenObject", "tokenOperator", "tokenPackage", "tokenParameter", "tokenPercolator", "tokenProperty", "tokenRange", "tokenRankFeature", "tokenRankFeatures", "tokenRepo", "tokenSearchType", "tokenSemanticText", "tokenShape", "tokenString", "tokenStruct", "tokenSymbol", "tokenTag", "tokenText", "tokenTokenCount", "tokenVariable", "tokenVectorDense", "tokenDenseVector", "tokenVectorSparse"]).isRequired, PropTypes.string.isRequired, PropTypes.elementType.isRequired]), /** * The side of the badge the icon should sit */ iconSide: PropTypes.any, /** * Accepts either our palette colors (primary, success ..etc) or a hex value `#FFFFFF`, `#000`. */ color: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.string.isRequired]), /** * Whether the badge should use filled (more intense) colors. * It has no effect when a non-named color is passed to the `color` prop. * @default false */ fill: PropTypes.bool, /** * Will override any color passed through the `color` prop. */ isDisabled: PropTypes.bool, /** * Props passed to the close button. */ closeButtonProps: PropTypes.any, className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * Will apply an onclick to icon within the badge */ iconOnClick: PropTypes.func, /** * Aria label applied to the iconOnClick button */ iconOnClickAriaLabel: PropTypes.any, /** * Will apply an onclick to the badge itself */ onClick: PropTypes.func, /** * Aria label applied to the onClick button */ onClickAriaLabel: PropTypes.any, href: PropTypes.string, target: PropTypes.string, rel: PropTypes.string }).isRequired]), /** * Optional list container padding. * @default 'none' */ paddingSize: PropTypes.oneOf(["none", "s"]), /** * How to handle long text within the item. * Wrapping only works if virtualization is off. */ textWrap: PropTypes.oneOf(["truncate", "wrap"]), /** * If textWrap is set to `truncate`, you can pass a custom truncation configuration * that accepts any [EuiTextTruncate](/#/utilities/text-truncation) prop except for * `text` and `children`. * * Note: when searching, custom truncation props are ignored. The highlighted search * text will always take precedence. */ truncationProps: PropTypes.any, /** * Use virtualized rendering for list items with `react-window`. * Sets each row's height to the value of `rowHeight`. */ isVirtualized: PropTypes.oneOfType([PropTypes.oneOf([true]), PropTypes.oneOf([false]).isRequired]), /** * The height of each option in pixels. Defaults to `32`. * Has no effect if `isVirtualized=false`. */ rowHeight: PropTypes.number, /** * All possible options */ options: PropTypes.arrayOf(PropTypes.shape({ /** * Optional `boolean`. * Set to `true` to indicate object is just a grouping label, not a selectable item */ isGroupLabel: PropTypes.oneOfType([PropTypes.oneOf([true]).isRequired, PropTypes.oneOf([false])]), className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * Visible label of option. * Must be unique across items if `key` is not supplied */ label: PropTypes.string, /** * Optionally change the searchable term by passing a different string other than the `label`. * Best used when creating a custom `optionRender` to separate the label from metadata but allowing to search on both */ searchableLabel: PropTypes.string, /** * Must be unique across items. * Will be used to match options instead of `label` */ key: PropTypes.string, /** * Leave `undefined` to indicate not selected. Pass a string of * 'on' to indicate inclusion, 'off' to indicate exclusion, * or 'mixed' to indicate inclusion for some. */ checked: PropTypes.any, disabled: PropTypes.bool, /** * Node to add between the selection icon and the label */ prepend: PropTypes.node, /** * Node to add to the far right of the item */ append: PropTypes.node, ref: PropTypes.func, /** * Option data to pass through to the `renderOptions` element. * Bypass `EuiSelectableItem` and avoid DOM attribute warnings. */ data: PropTypes.shape({}), /** * How to handle long text within the item. * Wrapping only works if `isVirtualization` is false. * @default 'truncate' */ textWrap: PropTypes.oneOf(["truncate", "wrap"]), /** * If textWrap is set to `truncate`, you can pass a custom truncation configuration * that accepts any [EuiTextTruncate](/#/utilities/text-truncation) prop except for * `text` and `children`. * * Note: when searching, custom truncation props are ignored. The highlighted search * text will always take precedence. */ truncationProps: PropTypes.any, /** * Optional custom tooltip content for the button */ toolTipContent: PropTypes.node, /** * Optional props to pass to the underlying **[EuiToolTip](/#/display/tooltip)** */ toolTipProps: PropTypes.any }).isRequired).isRequired, /** * Filtered options list (if applicable) */ visibleOptions: PropTypes.arrayOf(PropTypes.shape({ isGroupLabel: PropTypes.oneOfType([PropTypes.oneOf([true]).isRequired, PropTypes.oneOf([false])]), className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, label: PropTypes.string, searchableLabel: PropTypes.string, key: PropTypes.string, checked: PropTypes.any, disabled: PropTypes.bool, prepend: PropTypes.node, append: PropTypes.node, ref: PropTypes.func, data: PropTypes.shape({}), textWrap: PropTypes.oneOf(["truncate", "wrap"]), truncationProps: PropTypes.any, toolTipContent: PropTypes.node, toolTipProps: PropTypes.any }).isRequired), /** * Search value to highlight on the option render */ searchValue: PropTypes.string.isRequired, /** * Returns the array of options with altered checked state, the click/keyboard event, * and the option that triggered the click/keyboard event */ onOptionClick: PropTypes.func.isRequired, /** * Custom render for the label portion of the option; * Takes (option, searchValue), returns ReactNode */ renderOption: PropTypes.func, /** * Sets the max height in pixels or pass `full` to allow * the whole group to fill the height of its container and * allows the list grow as well */ height: PropTypes.oneOfType([PropTypes.number.isRequired, PropTypes.oneOf(["full"])]), /** * Allow cycling through the on, off and undefined state of option.checked * and not just on and undefined */ allowExclusions: PropTypes.bool, searchable: PropTypes.bool, isPreFiltered: PropTypes.oneOfType([PropTy