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 ConfigProvider from '../config-provider';
|
13 | import Menu from '../menu';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var Nav = (_temp = _class = function (_Component) {
|
20 | _inherits(Nav, _Component);
|
21 |
|
22 | function Nav(props) {
|
23 | _classCallCheck(this, Nav);
|
24 |
|
25 | var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
26 |
|
27 | _this.getMenuRef = _this.getMenuRef.bind(_this);
|
28 | return _this;
|
29 | }
|
30 |
|
31 | Nav.prototype.getChildContext = function getChildContext() {
|
32 | var _props = this.props,
|
33 | prefix = _props.prefix,
|
34 | direction = _props.direction,
|
35 | mode = _props.mode,
|
36 | iconOnly = _props.iconOnly,
|
37 | iconOnlyWidth = _props.iconOnlyWidth,
|
38 | iconTextOnly = _props.iconTextOnly,
|
39 | hasTooltip = _props.hasTooltip,
|
40 | hasArrow = _props.hasArrow;
|
41 | var isCollapse = this.context.isCollapse;
|
42 |
|
43 |
|
44 | return {
|
45 | prefix: prefix,
|
46 | mode: direction === 'hoz' ? 'popup' : mode,
|
47 | iconOnly: 'iconOnly' in this.props ? iconOnly : isCollapse,
|
48 | iconOnlyWidth: 'iconOnlyWidth' in this.props ? iconOnlyWidth : undefined,
|
49 | iconTextOnly: iconTextOnly,
|
50 | hasTooltip: hasTooltip,
|
51 | hasArrow: hasArrow
|
52 | };
|
53 | };
|
54 |
|
55 | Nav.prototype.getMenuRef = function getMenuRef(ref) {
|
56 | this.menu = ref;
|
57 | };
|
58 |
|
59 | Nav.prototype.render = function render() {
|
60 | var _classNames, _classNames2;
|
61 |
|
62 |
|
63 | var _props2 = this.props,
|
64 | prefix = _props2.prefix,
|
65 | className = _props2.className,
|
66 | style = _props2.style,
|
67 | children = _props2.children,
|
68 | type = _props2.type,
|
69 | direction = _props2.direction,
|
70 | activeDirection = _props2.activeDirection,
|
71 | mode = _props2.mode,
|
72 | triggerType = _props2.triggerType,
|
73 | inlineIndent = _props2.inlineIndent,
|
74 | openMode = _props2.openMode,
|
75 | popupAlign = _props2.popupAlign,
|
76 | popupClassName = _props2.popupClassName,
|
77 | iconOnly = _props2.iconOnly,
|
78 | iconOnlyWidth = _props2.iconOnlyWidth,
|
79 | iconTextOnly = _props2.iconTextOnly,
|
80 | hasArrow = _props2.hasArrow,
|
81 | hasTooltip = _props2.hasTooltip,
|
82 | embeddable = _props2.embeddable,
|
83 | _popupProps = _props2.popupProps,
|
84 | rtl = _props2.rtl,
|
85 | others = _objectWithoutProperties(_props2, ['prefix', 'className', 'style', 'children', 'type', 'direction', 'activeDirection', 'mode', 'triggerType', 'inlineIndent', 'openMode', 'popupAlign', 'popupClassName', 'iconOnly', 'iconOnlyWidth', 'iconTextOnly', 'hasArrow', 'hasTooltip', 'embeddable', 'popupProps', 'rtl']);
|
86 |
|
87 | var isCollapse = this.context.isCollapse;
|
88 |
|
89 |
|
90 | var newIconOnly = 'iconOnly' in this.props ? iconOnly : isCollapse;
|
91 |
|
92 | var realActiveDirection = activeDirection;
|
93 | if (realActiveDirection && (direction === 'hoz' && (realActiveDirection === 'left' || realActiveDirection === 'right') || direction === 'ver' && (realActiveDirection === 'top' || realActiveDirection === 'bottom'))) {
|
94 | realActiveDirection = null;
|
95 | }
|
96 |
|
97 | if (!newIconOnly && realActiveDirection === undefined) {
|
98 | realActiveDirection = direction === 'hoz' ? 'bottom' : type === 'line' ? 'right' : 'left';
|
99 | }
|
100 |
|
101 | var cls = classNames((_classNames = {}, _classNames[prefix + 'nav'] = true, _classNames['' + prefix + type] = type, _classNames[prefix + 'active'] = realActiveDirection, _classNames['' + prefix + realActiveDirection] = realActiveDirection, _classNames[prefix + 'icon-only'] = newIconOnly, _classNames[prefix + 'icon-only-text'] = newIconOnly && iconTextOnly, _classNames[prefix + 'custom-icon-only-width'] = newIconOnly && 'iconOnlyWidth' in this.props, _classNames[prefix + 'no-arrow'] = !hasArrow, _classNames[prefix + 'nav-embeddable'] = embeddable, _classNames[className] = !!className, _classNames));
|
102 | var newStyle = newIconOnly ? _extends({}, style, { width: iconOnlyWidth || 58 }) : style;
|
103 |
|
104 | var props = {
|
105 | prefix: prefix,
|
106 | direction: direction,
|
107 | openMode: openMode,
|
108 | triggerType: triggerType,
|
109 | mode: direction === 'hoz' ? 'popup' : mode,
|
110 | popupAlign: direction === 'hoz' ? 'follow' : popupAlign,
|
111 | inlineIndent: newIconOnly ? 0 : inlineIndent,
|
112 | hasSelectedIcon: false,
|
113 | popupAutoWidth: true,
|
114 | selectMode: 'single',
|
115 | itemClassName: prefix + 'nav-item',
|
116 | popupClassName: classNames((_classNames2 = {}, _classNames2[cls.replace(prefix + 'icon-only', '').replace(prefix + 'nav-embeddable', '')] = mode === 'popup', _classNames2[prefix + 'icon-only'] = newIconOnly && mode === 'inline', _classNames2[popupClassName] = !!popupClassName, _classNames2)),
|
117 | popupProps: function popupProps() {
|
118 | return _extends({}, _popupProps);
|
119 | }
|
120 | };
|
121 |
|
122 | return React.createElement(
|
123 | Menu,
|
124 | _extends({ className: cls, style: newStyle }, props, others, { ref: this.getMenuRef }),
|
125 | children
|
126 | );
|
127 | };
|
128 |
|
129 | return Nav;
|
130 | }(Component), _class.propTypes = {
|
131 | prefix: PropTypes.string,
|
132 | pure: PropTypes.bool,
|
133 | rtl: PropTypes.bool,
|
134 | className: PropTypes.string,
|
135 | style: PropTypes.object,
|
136 | |
137 |
|
138 |
|
139 | children: PropTypes.node,
|
140 | |
141 |
|
142 |
|
143 |
|
144 | type: PropTypes.oneOf(['normal', 'primary', 'secondary', 'line']),
|
145 | |
146 |
|
147 |
|
148 |
|
149 | direction: PropTypes.oneOf(['hoz', 'ver']),
|
150 | |
151 |
|
152 |
|
153 | hozAlign: PropTypes.oneOf(['left', 'right']),
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 | activeDirection: PropTypes.oneOf([null, 'top', 'bottom', 'left', 'right']),
|
160 | |
161 |
|
162 |
|
163 |
|
164 | mode: PropTypes.oneOf(['inline', 'popup']),
|
165 | |
166 |
|
167 |
|
168 | triggerType: PropTypes.oneOf(['click', 'hover']),
|
169 | |
170 |
|
171 |
|
172 | inlineIndent: PropTypes.number,
|
173 | |
174 |
|
175 |
|
176 | defaultOpenAll: PropTypes.bool,
|
177 | |
178 |
|
179 |
|
180 |
|
181 | openMode: PropTypes.oneOf(['single', 'multiple']),
|
182 | |
183 |
|
184 |
|
185 | selectedKeys: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
186 | |
187 |
|
188 |
|
189 | defaultSelectedKeys: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
190 | |
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | onSelect: PropTypes.func,
|
201 | |
202 |
|
203 |
|
204 |
|
205 | popupAlign: PropTypes.oneOf(['follow', 'outside']),
|
206 | |
207 |
|
208 |
|
209 | popupClassName: PropTypes.string,
|
210 | |
211 |
|
212 |
|
213 | iconOnly: PropTypes.bool,
|
214 | |
215 |
|
216 |
|
217 | iconOnlyWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
218 | |
219 |
|
220 |
|
221 | iconTextOnly: PropTypes.bool,
|
222 | |
223 |
|
224 |
|
225 | hasArrow: PropTypes.bool,
|
226 | |
227 |
|
228 |
|
229 | hasTooltip: PropTypes.bool,
|
230 | |
231 |
|
232 |
|
233 | header: PropTypes.node,
|
234 | |
235 |
|
236 |
|
237 | footer: PropTypes.node,
|
238 | |
239 |
|
240 |
|
241 |
|
242 | embeddable: PropTypes.bool,
|
243 | popupProps: PropTypes.object
|
244 | }, _class.defaultProps = {
|
245 | prefix: 'next-',
|
246 | pure: false,
|
247 | type: 'normal',
|
248 | direction: 'ver',
|
249 | hozAlign: 'left',
|
250 | mode: 'inline',
|
251 | triggerType: 'click',
|
252 | inlineIndent: 20,
|
253 | defaultOpenAll: false,
|
254 | openMode: 'multiple',
|
255 | defaultSelectedKeys: [],
|
256 | popupAlign: 'follow',
|
257 | hasTooltip: false,
|
258 | embeddable: false,
|
259 | hasArrow: true,
|
260 | popupProps: {}
|
261 | }, _class.childContextTypes = {
|
262 | prefix: PropTypes.string,
|
263 | mode: PropTypes.string,
|
264 | iconOnly: PropTypes.bool,
|
265 | iconOnlyWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
266 | iconTextOnly: PropTypes.bool,
|
267 | hasTooltip: PropTypes.bool,
|
268 | hasArrow: PropTypes.bool
|
269 | }, _class.contextTypes = {
|
270 | isCollapse: PropTypes.bool
|
271 | }, _temp);
|
272 | Nav.displayName = 'Nav';
|
273 |
|
274 |
|
275 | export default ConfigProvider.config(Nav); |
\ | No newline at end of file |