choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
90 lines (76 loc) • 2.74 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Component } from 'react';
import Menu from '../../../es/menu';
import { MentionsContextConsumer } from './MentionsContext';
var Item = Menu.Item;
/**
* We only use Menu to display the candidate.
* The focus is controlled by textarea to make accessibility easy.
*/
var DropdownMenu = /*#__PURE__*/function (_Component) {
_inherits(DropdownMenu, _Component);
var _super = _createSuper(DropdownMenu);
function DropdownMenu() {
var _this;
_classCallCheck(this, DropdownMenu);
_this = _super.apply(this, arguments);
_this.renderDropdown = function (_ref) {
var notFoundContent = _ref.notFoundContent,
activeIndex = _ref.activeIndex,
setActiveIndex = _ref.setActiveIndex,
selectOption = _ref.selectOption,
onFocus = _ref.onFocus,
onBlur = _ref.onBlur;
var options = _this.props.options;
var activeOption = options[activeIndex] || {};
var handleClick = function handleClick(_ref2) {
var key = _ref2.key;
var option = options.find(function (_ref3) {
var optionKey = _ref3.key;
return optionKey === key;
});
if (option) {
selectOption(option);
}
};
var selectedKeys = activeOption && activeOption.key ? [activeOption.key] : [];
return /*#__PURE__*/React.createElement(Menu, {
selectedKeys: selectedKeys,
onClick: handleClick,
onFocus: onFocus,
onBlur: onBlur,
focusable: true
}, options.map(function (option, index) {
var key = option.key,
disabled = option.disabled,
children = option.children,
className = option.className,
style = option.style;
return /*#__PURE__*/React.createElement(Item, {
key: key,
disabled: disabled,
className: className,
style: style,
onMouseEnter: function onMouseEnter() {
setActiveIndex(index);
}
}, children);
}), !options.length && /*#__PURE__*/React.createElement(Item, {
disabled: true
}, notFoundContent));
};
return _this;
}
_createClass(DropdownMenu, [{
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(MentionsContextConsumer, null, this.renderDropdown);
}
}]);
return DropdownMenu;
}(Component);
export default DropdownMenu;
//# sourceMappingURL=DropdownMenu.js.map