forked from react-bootstrap/react-bootstrap-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubNav.js
More file actions
130 lines (108 loc) · 3.05 KB
/
SubNav.js
File metadata and controls
130 lines (108 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
define(function (require, exports, module) {var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var cloneWithProps = require('./utils/cloneWithProps');
var ValidComponentChildren = require('./utils/ValidComponentChildren');
var createChainedFunction = require('./utils/createChainedFunction');
var BootstrapMixin = require('./BootstrapMixin');
var SubNav = React.createClass({displayName: 'SubNav',
mixins: [BootstrapMixin],
propTypes: {
onSelect: React.PropTypes.func,
active: React.PropTypes.bool,
disabled: React.PropTypes.bool,
href: React.PropTypes.string,
title: React.PropTypes.string,
text: React.PropTypes.node
},
getDefaultProps: function () {
return {
bsClass: 'nav'
};
},
handleClick: function (e) {
if (this.props.onSelect) {
e.preventDefault();
if (!this.props.disabled) {
this.props.onSelect(this.props.eventKey, this.props.href);
}
}
},
isActive: function () {
return this.isChildActive(this);
},
isChildActive: function (child) {
if (child.props.active) {
return true;
}
if (this.props.activeKey != null && this.props.activeKey === child.props.eventKey) {
return true;
}
if (this.props.activeHref != null && this.props.activeHref === child.props.href) {
return true;
}
if (child.props.children) {
var isActive = false;
ValidComponentChildren.forEach(
child.props.children,
function (child) {
if (this.isChildActive(child)) {
isActive = true;
}
},
this
);
return isActive;
}
return false;
},
getChildActiveProp: function (child) {
if (child.props.active) {
return true;
}
if (this.props.activeKey != null) {
if (child.props.eventKey == this.props.activeKey) {
return true;
}
}
if (this.props.activeHref != null) {
if (child.props.href === this.props.activeHref) {
return true;
}
}
return child.props.active;
},
render: function () {
var classes = {
'active': this.isActive(),
'disabled': this.props.disabled
};
return (
React.createElement("li", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}),
React.createElement("a", {
href: this.props.href,
title: this.props.title,
onClick: this.handleClick,
ref: "anchor"},
this.props.text
),
React.createElement("ul", {className: "nav"},
ValidComponentChildren.map(this.props.children, this.renderNavItem)
)
)
);
},
renderNavItem: function (child, index) {
return cloneWithProps(
child,
{
active: this.getChildActiveProp(child),
onSelect: createChainedFunction(child.props.onSelect, this.props.onSelect),
ref: child.ref,
key: child.key ? child.key : index
}
);
}
});
module.exports = SubNav;
});