forked from react-bootstrap/react-bootstrap-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavbar.js
More file actions
141 lines (118 loc) · 4.34 KB
/
Navbar.js
File metadata and controls
141 lines (118 loc) · 4.34 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
131
132
133
134
135
136
137
138
139
140
141
define(function (require, exports, module) {var React = require('react');
var joinClasses = require('./utils/joinClasses');
var BootstrapMixin = require('./BootstrapMixin');
var classSet = require('./utils/classSet');
var cloneWithProps = require('./utils/cloneWithProps');
var ValidComponentChildren = require('./utils/ValidComponentChildren');
var createChainedFunction = require('./utils/createChainedFunction');
var Nav = require('./Nav');
var Navbar = React.createClass({displayName: 'Navbar',
mixins: [BootstrapMixin],
propTypes: {
fixedTop: React.PropTypes.bool,
fixedBottom: React.PropTypes.bool,
staticTop: React.PropTypes.bool,
inverse: React.PropTypes.bool,
fluid: React.PropTypes.bool,
role: React.PropTypes.string,
componentClass: React.PropTypes.node.isRequired,
brand: React.PropTypes.node,
toggleButton: React.PropTypes.node,
onToggle: React.PropTypes.func,
navExpanded: React.PropTypes.bool,
defaultNavExpanded: React.PropTypes.bool
},
getDefaultProps: function () {
return {
bsClass: 'navbar',
bsStyle: 'default',
role: 'navigation',
componentClass: 'Nav'
};
},
getInitialState: function () {
return {
navExpanded: this.props.defaultNavExpanded
};
},
shouldComponentUpdate: function() {
// Defer any updates to this component during the `onSelect` handler.
return !this._isChanging;
},
handleToggle: function () {
if (this.props.onToggle) {
this._isChanging = true;
this.props.onToggle();
this._isChanging = false;
}
this.setState({
navExpanded: !this.state.navExpanded
});
},
isNavExpanded: function () {
return this.props.navExpanded != null ? this.props.navExpanded : this.state.navExpanded;
},
render: function () {
var classes = this.getBsClassSet();
var ComponentClass = this.props.componentClass;
classes['navbar-fixed-top'] = this.props.fixedTop;
classes['navbar-fixed-bottom'] = this.props.fixedBottom;
classes['navbar-static-top'] = this.props.staticTop;
classes['navbar-inverse'] = this.props.inverse;
return (
React.createElement(ComponentClass, React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}),
React.createElement("div", {className: this.props.fluid ? 'container-fluid' : 'container'},
(this.props.brand || this.props.toggleButton || this.props.toggleNavKey) ? this.renderHeader() : null,
ValidComponentChildren.map(this.props.children, this.renderChild)
)
)
);
},
renderChild: function (child, index) {
return cloneWithProps(child, {
navbar: true,
collapsable: this.props.toggleNavKey != null && this.props.toggleNavKey === child.props.eventKey,
expanded: this.props.toggleNavKey != null && this.props.toggleNavKey === child.props.eventKey && this.isNavExpanded(),
key: child.key ? child.key : index,
ref: child.ref
});
},
renderHeader: function () {
var brand;
if (this.props.brand) {
brand = React.isValidElement(this.props.brand) ?
cloneWithProps(this.props.brand, {
className: 'navbar-brand'
}) : React.createElement("span", {className: "navbar-brand"}, this.props.brand);
}
return (
React.createElement("div", {className: "navbar-header"},
brand,
(this.props.toggleButton || this.props.toggleNavKey != null) ? this.renderToggleButton() : null
)
);
},
renderToggleButton: function () {
var children;
if (React.isValidElement(this.props.toggleButton)) {
return cloneWithProps(this.props.toggleButton, {
className: 'navbar-toggle',
onClick: createChainedFunction(this.handleToggle, this.props.toggleButton.props.onClick)
});
}
children = (this.props.toggleButton != null) ?
this.props.toggleButton : [
React.createElement("span", {className: "sr-only", key: 0}, "Toggle navigation"),
React.createElement("span", {className: "icon-bar", key: 1}),
React.createElement("span", {className: "icon-bar", key: 2}),
React.createElement("span", {className: "icon-bar", key: 3})
];
return (
React.createElement("button", {className: "navbar-toggle", type: "button", onClick: this.handleToggle},
children
)
);
}
});
module.exports = Navbar;
});