1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 | var _class, _temp;
|
8 |
|
9 | import React, { Component, cloneElement } from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import classNames from 'classnames';
|
12 | import Menu from '../menu';
|
13 | import Icon from '../icon';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var 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 |
|
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);
|
95 | PopupItem.displayName = 'PopupItem';
|
96 |
|
97 |
|
98 | export default PopupItem; |
\ | No newline at end of file |