UNPKG

3.22 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6
7var _class, _temp;
8
9import React, { Component, cloneElement } from 'react';
10import PropTypes from 'prop-types';
11import classNames from 'classnames';
12import Menu from '../menu';
13import Icon from '../icon';
14
15/**
16 * Nav.PopupItem
17 * @description 继承自 `Menu.PopupItem` 的能力请查看 `Menu.PopupItem` 文档
18 */
19var PopupItem = (_temp = _class = function (_Component) {
20 _inherits(PopupItem, _Component);
21
22 function PopupItem() {
23 _classCallCheck(this, PopupItem);
24
25 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
26 }
27
28 PopupItem.prototype.render = function render() {
29 var _classNames;
30
31 var _context = this.context,
32 prefix = _context.prefix,
33 iconOnly = _context.iconOnly,
34 iconOnlyWidth = _context.iconOnlyWidth,
35 hasArrow = _context.hasArrow;
36
37 var _props = this.props,
38 className = _props.className,
39 icon = _props.icon,
40 label = _props.label,
41 children = _props.children,
42 others = _objectWithoutProperties(_props, ['className', 'icon', 'label', 'children']);
43
44 var cls = classNames((_classNames = {}, _classNames[prefix + 'nav-popup-item'] = true, _classNames[className] = !!className, _classNames));
45
46 var iconEl = typeof icon === 'string' ? React.createElement(Icon, { className: prefix + 'nav-icon', type: icon }) : icon;
47 if (iconOnly) {
48 if (hasArrow) {
49 iconEl = React.createElement(Icon, { className: prefix + 'nav-icon-only-arrow', type: 'arrow-right' });
50 }
51 }
52 var newLabel = [iconEl ? cloneElement(iconEl, { key: 'icon' }) : null];
53
54 var showLabel = !iconOnly || iconOnly && !iconOnlyWidth;
55
56 if (showLabel) {
57 newLabel.push(React.createElement(
58 'span',
59 { key: 'label' },
60 label
61 ));
62 }
63
64 return React.createElement(
65 Menu.PopupItem,
66 _extends({ className: cls, label: newLabel }, others),
67 children
68 );
69 };
70
71 return PopupItem;
72}(Component), _class.menuChildType = 'submenu', _class.propTypes = {
73 /**
74 * 自定义类名
75 */
76 className: PropTypes.string,
77 /**
78 * 自定义图标,可以使用 Icon 的 type, 也可以使用组件 `<Icon type="icon type" />`
79 */
80 icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
81 /**
82 * 标签内容
83 */
84 label: PropTypes.node,
85 /**
86 * 弹出内容
87 */
88 children: PropTypes.node
89}, _class.contextTypes = {
90 prefix: PropTypes.string,
91 iconOnly: PropTypes.bool,
92 iconOnlyWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
93 hasArrow: PropTypes.bool
94}, _temp);
95PopupItem.displayName = 'PopupItem';
96
97
98export default PopupItem;
\No newline at end of file