import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _createSuper from "@babel/runtime/helpers/esm/createSuper"; import * as React from 'react'; import KeyCode from "rc-util/es/KeyCode"; import classNames from 'classnames'; import omit from 'omit.js'; import { connect } from 'mini-store'; import { noop, menuAllProps } from './util'; export var MenuItem = /*#__PURE__*/function (_React$Component) { _inherits(MenuItem, _React$Component); var _super = _createSuper(MenuItem); function MenuItem() { var _this; _classCallCheck(this, MenuItem); _this = _super.apply(this, arguments); _this.onKeyDown = function (e) { var keyCode = e.keyCode; if (keyCode === KeyCode.ENTER) { _this.onClick(e); return true; } return undefined; }; _this.onMouseLeave = function (e) { var _this$props = _this.props, eventKey = _this$props.eventKey, onItemHover = _this$props.onItemHover, onMouseLeave = _this$props.onMouseLeave; onItemHover({ key: eventKey, hover: false }); onMouseLeave({ key: eventKey, domEvent: e }); }; _this.onMouseEnter = function (e) { var _this$props2 = _this.props, eventKey = _this$props2.eventKey, onItemHover = _this$props2.onItemHover, onMouseEnter = _this$props2.onMouseEnter; onItemHover({ key: eventKey, hover: true }); onMouseEnter({ key: eventKey, domEvent: e }); }; _this.onClick = function (e) { var _this$props3 = _this.props, eventKey = _this$props3.eventKey, multiple = _this$props3.multiple, onClick = _this$props3.onClick, onSelect = _this$props3.onSelect, onDeselect = _this$props3.onDeselect, isSelected = _this$props3.isSelected; var info = { key: eventKey, keyPath: [eventKey], item: _assertThisInitialized(_this), domEvent: e }; onClick(info); if (multiple) { if (isSelected) { onDeselect(info); } else { onSelect(info); } } else if (!isSelected) { onSelect(info); } }; _this.saveNode = function (node) { _this.node = node; }; return _this; } _createClass(MenuItem, [{ key: "componentDidMount", value: function componentDidMount() { // invoke customized ref to expose component to mixin this.callRef(); } }, { key: "componentDidUpdate", value: function componentDidUpdate() { this.callRef(); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { var props = this.props; if (props.onDestroy) { props.onDestroy(props.eventKey); } } }, { key: "getPrefixCls", value: function getPrefixCls() { return "".concat(this.props.rootPrefixCls, "-item"); } }, { key: "getActiveClassName", value: function getActiveClassName() { return "".concat(this.getPrefixCls(), "-active"); } }, { key: "getSelectedClassName", value: function getSelectedClassName() { return "".concat(this.getPrefixCls(), "-selected"); } }, { key: "getDisabledClassName", value: function getDisabledClassName() { return "".concat(this.getPrefixCls(), "-disabled"); } }, { key: "callRef", value: function callRef() { if (this.props.manualRef) { this.props.manualRef(this); } } }, { key: "render", value: function render() { var _classNames; var props = _objectSpread({}, this.props); var className = classNames(this.getPrefixCls(), props.className, (_classNames = {}, _defineProperty(_classNames, this.getActiveClassName(), !props.disabled && props.active), _defineProperty(_classNames, this.getSelectedClassName(), props.isSelected), _defineProperty(_classNames, this.getDisabledClassName(), props.disabled), _classNames)); var attrs = _objectSpread(_objectSpread({}, props.attribute), {}, { title: typeof props.title === 'string' ? props.title : undefined, className: className, // set to menuitem by default role: props.role || 'menuitem', 'aria-disabled': props.disabled }); if (props.role === 'option') { // overwrite to option attrs = _objectSpread(_objectSpread({}, attrs), {}, { role: 'option', 'aria-selected': props.isSelected }); } else if (props.role === null || props.role === 'none') { // sometimes we want to specify role inside
element //