UNPKG

2.67 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2import _createClass from "@babel/runtime/helpers/esm/createClass";
3import _inherits from "@babel/runtime/helpers/esm/inherits";
4import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5import Menu, { MenuItem } from 'rc-menu';
6import * as React from 'react';
7import { MentionsContextConsumer } from './MentionsContext';
8/**
9 * We only use Menu to display the candidate.
10 * The focus is controlled by textarea to make accessibility easy.
11 */
12
13var DropdownMenu = /*#__PURE__*/function (_React$Component) {
14 _inherits(DropdownMenu, _React$Component);
15
16 var _super = _createSuper(DropdownMenu);
17
18 function DropdownMenu() {
19 var _this;
20
21 _classCallCheck(this, DropdownMenu);
22
23 _this = _super.apply(this, arguments);
24
25 _this.renderDropdown = function (_ref) {
26 var notFoundContent = _ref.notFoundContent,
27 activeIndex = _ref.activeIndex,
28 setActiveIndex = _ref.setActiveIndex,
29 selectOption = _ref.selectOption,
30 onFocus = _ref.onFocus,
31 onBlur = _ref.onBlur;
32 var _this$props = _this.props,
33 prefixCls = _this$props.prefixCls,
34 options = _this$props.options;
35 var activeOption = options[activeIndex] || {};
36 return /*#__PURE__*/React.createElement(Menu, {
37 prefixCls: "".concat(prefixCls, "-menu"),
38 activeKey: activeOption.key,
39 onSelect: function onSelect(_ref2) {
40 var key = _ref2.key;
41 var option = options.find(function (_ref3) {
42 var optionKey = _ref3.key;
43 return optionKey === key;
44 });
45 selectOption(option);
46 },
47 onFocus: onFocus,
48 onBlur: onBlur
49 }, options.map(function (option, index) {
50 var key = option.key,
51 disabled = option.disabled,
52 children = option.children,
53 className = option.className,
54 style = option.style;
55 return /*#__PURE__*/React.createElement(MenuItem, {
56 key: key,
57 disabled: disabled,
58 className: className,
59 style: style,
60 onMouseEnter: function onMouseEnter() {
61 setActiveIndex(index);
62 }
63 }, children);
64 }), !options.length && /*#__PURE__*/React.createElement(MenuItem, {
65 disabled: true
66 }, notFoundContent));
67 };
68
69 return _this;
70 }
71
72 _createClass(DropdownMenu, [{
73 key: "render",
74 value: function render() {
75 return /*#__PURE__*/React.createElement(MentionsContextConsumer, null, this.renderDropdown);
76 }
77 }]);
78
79 return DropdownMenu;
80}(React.Component);
81
82export default DropdownMenu;
\No newline at end of file