This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Nav.js
112 lines (93 loc) · 3.16 KB
/
Nav.js
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
var React = require('react');
var joinClasses = require('./utils/joinClasses');
var BootstrapMixin = require('./BootstrapMixin');
var CollapsableMixin = require('./CollapsableMixin');
var classSet = require('./utils/classSet');
var domUtils = require('./utils/domUtils');
var cloneWithProps = require('./utils/cloneWithProps');
var ValidComponentChildren = require('./utils/ValidComponentChildren');
var createChainedFunction = require('./utils/createChainedFunction');
var Nav = React.createClass({displayName: "Nav",
mixins: [BootstrapMixin, CollapsableMixin],
propTypes: {
bsStyle: React.PropTypes.oneOf(['tabs','pills']),
stacked: React.PropTypes.bool,
justified: React.PropTypes.bool,
onSelect: React.PropTypes.func,
collapsable: React.PropTypes.bool,
expanded: React.PropTypes.bool,
navbar: React.PropTypes.bool,
eventKey: React.PropTypes.any,
right: 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.collapsable ? this.getCollapsableClassSet() : {};
classes['navbar-collapse'] = this.props.collapsable;
if (this.props.navbar && !this.props.collapsable) {
return (this.renderUl());
}
return (
React.createElement("nav", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}),
this.renderUl()
)
);
},
renderUl: function () {
var classes = this.getBsClassSet();
classes['nav-stacked'] = this.props.stacked;
classes['nav-justified'] = this.props.justified;
classes['navbar-nav'] = this.props.navbar;
classes['pull-right'] = this.props.pullRight;
classes['navbar-right'] = this.props.right;
return (
React.createElement("ul", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes)), ref: "ul"}),
ValidComponentChildren.map(this.props.children, this.renderNavItem)
)
);
},
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;
},
renderNavItem: function (child, index) {
return cloneWithProps(
child,
{
active: this.getChildActiveProp(child),
activeKey: this.props.activeKey,
activeHref: this.props.activeHref,
onSelect: createChainedFunction(child.props.onSelect, this.props.onSelect),
ref: child.ref,
key: child.key ? child.key : index,
navItem: true
}
);
}
});
module.exports = Nav;