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 } from 'react';
|
10 | import PropTypes from 'prop-types';
|
11 | import classNames from 'classnames';
|
12 | import Menu from '../menu';
|
13 | import Icon from '../icon';
|
14 | import Balloon from '../balloon';
|
15 |
|
16 | var Tooltip = Balloon.Tooltip;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var Item = (_temp = _class = function (_Component) {
|
24 | _inherits(Item, _Component);
|
25 |
|
26 | function Item() {
|
27 | _classCallCheck(this, Item);
|
28 |
|
29 | return _possibleConstructorReturn(this, _Component.apply(this, arguments));
|
30 | }
|
31 |
|
32 | Item.prototype.render = function render() {
|
33 | var _classNames;
|
34 |
|
35 | var _context = this.context,
|
36 | prefix = _context.prefix,
|
37 | iconOnly = _context.iconOnly,
|
38 | iconOnlyWidth = _context.iconOnlyWidth,
|
39 | hasTooltip = _context.hasTooltip,
|
40 | iconTextOnly = _context.iconTextOnly;
|
41 |
|
42 | var _props = this.props,
|
43 | icon = _props.icon,
|
44 | children = _props.children,
|
45 | className = _props.className,
|
46 | others = _objectWithoutProperties(_props, ['icon', 'children', 'className']);
|
47 |
|
48 | var iconEl = typeof icon === 'string' ? React.createElement(Icon, { className: prefix + 'nav-icon', type: icon }) : icon;
|
49 |
|
50 | var title = void 0;
|
51 |
|
52 | if (typeof children === 'string') {
|
53 | title = children;
|
54 | }
|
55 |
|
56 | var showChildren = !iconOnly || iconOnly && !iconOnlyWidth || iconTextOnly;
|
57 | var cls = classNames((_classNames = {}, _classNames[prefix + 'nav-with-title'] = iconOnly && iconTextOnly, _classNames[className] = !!className, _classNames));
|
58 |
|
59 | var newChildren = showChildren ? iconTextOnly ? React.createElement(
|
60 | 'span',
|
61 | { className: prefix + 'nav-text' },
|
62 | children
|
63 | ) : children : null;
|
64 |
|
65 | var item = React.createElement(
|
66 | Menu.Item,
|
67 | _extends({ title: title, className: cls }, others),
|
68 | iconEl,
|
69 | newChildren
|
70 | );
|
71 |
|
72 | if (iconOnly && hasTooltip && others.parentMode !== 'popup') {
|
73 | return React.createElement(
|
74 | Tooltip,
|
75 | { align: 'r', trigger: item },
|
76 | children
|
77 | );
|
78 | }
|
79 |
|
80 | return item;
|
81 | };
|
82 |
|
83 | return Item;
|
84 | }(Component), _class.menuChildType = 'item', _class.propTypes = {
|
85 | |
86 |
|
87 |
|
88 | icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
89 | |
90 |
|
91 |
|
92 | children: PropTypes.node,
|
93 | parentMode: PropTypes.oneOf(['inline', 'popup'])
|
94 | }, _class.contextTypes = {
|
95 | prefix: PropTypes.string,
|
96 | iconOnly: PropTypes.bool,
|
97 | iconOnlyWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
98 | iconTextOnly: PropTypes.bool,
|
99 | hasTooltip: PropTypes.bool
|
100 | }, _temp);
|
101 | Item.displayName = 'Item';
|
102 |
|
103 |
|
104 | export default Item; |
\ | No newline at end of file |