1 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
2 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
3 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
4 | import _inherits from 'babel-runtime/helpers/inherits';
|
5 | import _extends from 'babel-runtime/helpers/extends';
|
6 | import classNames from 'classnames';
|
7 | import React from 'react';
|
8 | import PropTypes from 'prop-types';
|
9 |
|
10 | import Dropdown from './Dropdown';
|
11 | import splitComponentProps from './utils/splitComponentProps';
|
12 | import ValidComponentChildren from './utils/ValidComponentChildren';
|
13 |
|
14 | var propTypes = _extends({}, Dropdown.propTypes, {
|
15 |
|
16 |
|
17 | title: PropTypes.node.isRequired,
|
18 | noCaret: PropTypes.bool,
|
19 | active: PropTypes.bool,
|
20 | activeKey: PropTypes.any,
|
21 | activeHref: PropTypes.string,
|
22 |
|
23 |
|
24 | |
25 |
|
26 |
|
27 | children: PropTypes.node
|
28 | });
|
29 |
|
30 | var NavDropdown = function (_React$Component) {
|
31 | _inherits(NavDropdown, _React$Component);
|
32 |
|
33 | function NavDropdown() {
|
34 | _classCallCheck(this, NavDropdown);
|
35 |
|
36 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
37 | }
|
38 |
|
39 | NavDropdown.prototype.isActive = function isActive(_ref, activeKey, activeHref) {
|
40 | var props = _ref.props;
|
41 |
|
42 | var _this2 = this;
|
43 |
|
44 | if (props.active || activeKey != null && props.eventKey === activeKey || activeHref && props.href === activeHref) {
|
45 | return true;
|
46 | }
|
47 |
|
48 | if (ValidComponentChildren.some(props.children, function (child) {
|
49 | return _this2.isActive(child, activeKey, activeHref);
|
50 | })) {
|
51 | return true;
|
52 | }
|
53 |
|
54 | return props.active;
|
55 | };
|
56 |
|
57 | NavDropdown.prototype.render = function render() {
|
58 | var _this3 = this;
|
59 |
|
60 | var _props = this.props,
|
61 | title = _props.title,
|
62 | activeKey = _props.activeKey,
|
63 | activeHref = _props.activeHref,
|
64 | className = _props.className,
|
65 | style = _props.style,
|
66 | children = _props.children,
|
67 | props = _objectWithoutProperties(_props, ['title', 'activeKey', 'activeHref', 'className', 'style', 'children']);
|
68 |
|
69 | var active = this.isActive(this, activeKey, activeHref);
|
70 | delete props.active;
|
71 | delete props.eventKey;
|
72 |
|
73 | var _splitComponentProps = splitComponentProps(props, Dropdown.ControlledComponent),
|
74 | dropdownProps = _splitComponentProps[0],
|
75 | toggleProps = _splitComponentProps[1];
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | return React.createElement(
|
81 | Dropdown,
|
82 | _extends({}, dropdownProps, {
|
83 | componentClass: 'li',
|
84 | className: classNames(className, { active: active }),
|
85 | style: style
|
86 | }),
|
87 | React.createElement(
|
88 | Dropdown.Toggle,
|
89 | _extends({}, toggleProps, { useAnchor: true }),
|
90 | title
|
91 | ),
|
92 | React.createElement(
|
93 | Dropdown.Menu,
|
94 | null,
|
95 | ValidComponentChildren.map(children, function (child) {
|
96 | return React.cloneElement(child, {
|
97 | active: _this3.isActive(child, activeKey, activeHref)
|
98 | });
|
99 | })
|
100 | )
|
101 | );
|
102 | };
|
103 |
|
104 | return NavDropdown;
|
105 | }(React.Component);
|
106 |
|
107 | NavDropdown.propTypes = propTypes;
|
108 |
|
109 | export default NavDropdown; |
\ | No newline at end of file |