UNPKG

@alifd/meet-react

Version:

Fusion Mobile React UI System Component

44 lines 2.81 kB
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() { _extends = Object.assign ? Object.assign.bind() : 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 _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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); } import { __rest } from "tslib"; import React, { createElement, forwardRef, useContext } from "react"; import classnames from 'classnames'; import Icon from '../icon'; import List from '../list'; import MenuContext from './menu-context'; import { isInvalidValue } from '../utils'; var MenuItem = function MenuItem(props, ref) { var context = useContext(MenuContext); var className = props.className, children = props.children, disabled = props.disabled, itemKey = props.itemKey, title = props.title, others = __rest(props, ["className", "children", "disabled", "itemKey", "title"]); var prefix = context.prefix, selectMode = context.selectMode, selectedKeys = context.selectedKeys, onClickItem = context.onClickItem, onSelect = context.onSelect; var selected = !isInvalidValue(itemKey) && selectedKeys.includes(itemKey); var handleClick = function handleClick(e) { onClickItem(itemKey, props, e); if (selectMode) { onSelect(!selected, props); } }; return /*#__PURE__*/React.createElement(List.Item, _extends({}, others, { ref: ref, className: classnames("".concat(prefix, "menu-item"), className, _defineProperty({}, "".concat(prefix, "menu-item--disabled"), disabled)), title: children || title, disabled: disabled, extra: selected ? /*#__PURE__*/React.createElement(Icon, { name: "select" }) : null, onClick: handleClick })); }; export default /*#__PURE__*/forwardRef(MenuItem);