UNPKG

3.35 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 } from 'react';
10import PropTypes from 'prop-types';
11import classNames from 'classnames';
12import Menu from '../menu';
13import Icon from '../icon';
14import Balloon from '../balloon';
15
16var Tooltip = Balloon.Tooltip;
17
18/**
19 * Nav.Item
20 * @description 继承自 `Menu.Item` 的能力请查看 `Menu.Item` 文档
21 */
22
23var 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 * 自定义图标,可以使用 Icon 的 type,也可以使用组件 `<Icon type="icon type" />`
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);
101Item.displayName = 'Item';
102
103
104export default Item;
\No newline at end of file