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