forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNav.jsx
106 lines (87 loc) · 2.63 KB
/
Nav.jsx
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
/** @jsx React.DOM */
import React from './react-es6';
import classSet from './react-es6/lib/cx';
import BootstrapMixin from './BootstrapMixin';
import CollapsableMixin from './CollapsableMixin';
import utils from './utils';
import domUtils from './domUtils';
var Nav = React.createClass({
mixins: [BootstrapMixin, CollapsableMixin],
propTypes: {
bsStyle: React.PropTypes.oneOf(['tabs','pills']),
stacked: React.PropTypes.bool,
justified: React.PropTypes.bool,
onSelect: React.PropTypes.func,
isCollapsable: React.PropTypes.bool,
isOpen: React.PropTypes.bool,
navbar: React.PropTypes.bool
},
getDefaultProps: function () {
return {
bsClass: 'nav'
};
},
getCollapsableDOMNode: function () {
return this.getDOMNode();
},
getCollapsableDimensionValue: function () {
var node = this.refs.ul.getDOMNode(),
height = node.offsetHeight,
computedStyles = domUtils.getComputedStyles(node);
return height + parseInt(computedStyles.marginTop, 10) + parseInt(computedStyles.marginBottom, 10);
},
render: function () {
var classes = this.props.isCollapsable ? this.getCollapsableClassSet() : {};
classes['navbar-collapse'] = this.props.isCollapsable;
if (this.props.navbar) {
return this.renderUl();
}
return this.transferPropsTo(
<nav className={classSet(classes)}>
{this.renderUl()}
</nav>
);
},
renderUl: function () {
var classes = this.getBsClassSet();
classes['nav-stacked'] = this.props.stacked;
classes['nav-justified'] = this.props.justified;
classes['navbar-nav'] = this.props.navbar;
return (
<ul className={classSet(classes)} ref="ul">
{utils.modifyChildren(this.props.children, this.renderNavItem)}
</ul>
);
},
getChildActiveProp: function (child) {
if (child.props.active) {
return true;
}
if (this.props.activeKey != null) {
if (child.props.key === this.props.activeKey) {
return true;
}
}
if (this.props.activeHref != null) {
if (child.props.href === this.props.activeHref) {
return true;
}
}
return child.props.active;
},
renderNavItem: function (child) {
return utils.cloneWithProps(
child,
{
active: this.getChildActiveProp(child),
activeKey: this.props.activeKey,
activeHref: this.props.activeHref,
onSelect: utils.createChainedFunction(child.props.onSelect, this.props.onSelect),
ref: child.props.ref,
key: child.props.key,
navItem: true
}
);
}
});
export default = Nav;