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 SubNav = (_temp = _class = function (_Component) {
|
20 | _inherits(SubNav, _Component);
|
21 |
|
22 | function SubNav() {
|
23 | _classCallCheck(this, SubNav);
|
24 |
|
25 | return _possibleConstructorReturn(this, _Component.apply(this, arguments));
|
26 | }
|
27 |
|
28 | SubNav.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 | noIcon = _context.noIcon,
|
37 | mode = _context.mode;
|
38 |
|
39 | var _props = this.props,
|
40 | className = _props.className,
|
41 | icon = _props.icon,
|
42 | label = _props.label,
|
43 | children = _props.children,
|
44 | level = _props.level,
|
45 | others = _objectWithoutProperties(_props, ['className', 'icon', 'label', 'children', 'level']);
|
46 |
|
47 | var cls = classNames((_classNames = {}, _classNames[prefix + 'nav-sub-nav-item'] = true, _classNames[prefix + 'nav-popup'] = mode === 'popup', _classNames[className] = !!className, _classNames));
|
48 | var iconEl = typeof icon === 'string' ? React.createElement(Icon, { className: prefix + 'nav-icon', type: icon }) : icon;
|
49 |
|
50 |
|
51 | if (iconOnly && hasArrow && (mode === 'inline' || level === 1 && mode === 'popup')) {
|
52 | iconEl = React.createElement(Icon, {
|
53 | className: prefix + 'nav-icon-only-arrow',
|
54 | type: mode === 'popup' ? 'arrow-right' : 'arrow-down'
|
55 | });
|
56 | }
|
57 |
|
58 | var newLabel = [iconEl ? cloneElement(iconEl, { key: 'icon' }) : null];
|
59 |
|
60 | var showLabel = !iconOnly || iconOnly && !iconOnlyWidth;
|
61 |
|
62 | if (showLabel) {
|
63 | newLabel.push(React.createElement(
|
64 | 'span',
|
65 | { key: 'label' },
|
66 | label
|
67 | ));
|
68 | }
|
69 |
|
70 | var title = void 0;
|
71 |
|
72 | if (typeof label === 'string') {
|
73 | title = label;
|
74 | }
|
75 |
|
76 | return React.createElement(
|
77 | Menu.SubMenu,
|
78 | _extends({ className: cls, label: newLabel, level: level, title: title, noIcon: noIcon }, others),
|
79 | children
|
80 | );
|
81 | };
|
82 |
|
83 | return SubNav;
|
84 | }(Component), _class.menuChildType = 'submenu', _class.propTypes = {
|
85 | |
86 |
|
87 |
|
88 | className: PropTypes.string,
|
89 | |
90 |
|
91 |
|
92 | icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
93 | |
94 |
|
95 |
|
96 | label: PropTypes.node,
|
97 | |
98 |
|
99 |
|
100 | selectable: PropTypes.bool,
|
101 | |
102 |
|
103 |
|
104 | children: PropTypes.node,
|
105 | |
106 |
|
107 |
|
108 | noIcon: PropTypes.bool
|
109 | }, _class.defaultProps = {
|
110 | selectable: false
|
111 | }, _class.contextTypes = {
|
112 | prefix: PropTypes.string,
|
113 | mode: PropTypes.string,
|
114 | iconOnly: PropTypes.bool,
|
115 | iconOnlyWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
116 | hasArrow: PropTypes.bool
|
117 | }, _temp);
|
118 | SubNav.displayName = 'SubNav';
|
119 |
|
120 |
|
121 | export default SubNav; |
\ | No newline at end of file |