-
- {displayHeader ? this.renderHeader() : null}
- {ValidComponentChildren.map(this.props.children, this.renderChildren)}
-
+
+
+ {showHeader ? this.renderBrandHeader() : null}
+ {ValidComponentChildren.map(children, this.renderChild)}
+
);
},
- renderNavBrand(child, index) {
- let navbrandEl = cloneElement(child, {
- navbar: true,
- toggleNavKey: this.props.toggleNavKey,
- toggleButton: this.props.toggleButton,
- handleToggle: this.handleToggle,
- key: child.key ? child.key : index
- });
-
- return this.renderHeader(navbrandEl);
- },
-
- renderChild(child, index) {
- return cloneElement(child, {
- navbar: true,
- collapsible: 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
- });
- },
+ renderBrandHeader() {
+ let {brand} = this.props;
+ if (brand) {
+ brand = {brand};
+ }
- renderChildren(child, index) {
- return (child.props.navbrand) ? this.renderNavBrand(child, index) : this.renderChild(child, index);
+ return this.renderHeader(brand);
},
- renderHeader(navbrandEl) {
- let brand = navbrandEl || '';
-
- if (!brand && this.props.brand) {
- if (React.isValidElement(this.props.brand)) {
- brand = cloneElement(this.props.brand, {
- className: classNames(this.props.brand.props.className, 'navbar-brand')
- });
- } else {
- brand = {this.props.brand};
- }
- }
+ renderHeader(brand) {
+ const hasToggle =
+ this.props.toggleButton || this.props.toggleNavKey != null;
return (
{brand}
- {(this.props.toggleButton || this.props.toggleNavKey != null) ? this.renderToggleButton() : null}
+ {hasToggle ? this.renderToggleButton() : null}
);
},
- renderToggleButton() {
- let children;
+ renderChild(child, index) {
+ const key = child.key != null ? child.key : index;
+
+ if (child.props.bsRole === 'brand') {
+ return React.cloneElement(this.renderHeader(child), {key});
+ }
+
+ const {toggleNavKey} = this.props;
+ const collapsible =
+ toggleNavKey != null && toggleNavKey === child.props.eventKey;
- if (React.isValidElement(this.props.toggleButton)) {
- return cloneElement(this.props.toggleButton, {
- className: classNames(this.props.toggleButton.props.className, 'navbar-toggle'),
- onClick: createChainedFunction(this.handleToggle, this.props.toggleButton.props.onClick)
+ return React.cloneElement(child, {
+ navbar: true,
+ collapsible,
+ expanded: collapsible && this.isNavExpanded(),
+ key
+ });
+ },
+
+ renderToggleButton() {
+ const {toggleButton} = this.props;
+
+ if (React.isValidElement(toggleButton)) {
+ return React.cloneElement(toggleButton, {
+ className: classNames(toggleButton.props.className, 'navbar-toggle'),
+ onClick: createChainedFunction(
+ this.handleToggle, toggleButton.props.onClick
+ )
});
}
- children = (this.props.toggleButton != null) ?
- this.props.toggleButton : [
+ let children;
+ if (toggleButton != null) {
+ children = toggleButton;
+ } else {
+ children = [
Toggle navigation,
,
,
];
+ }
return (
-