import React from 'react'; import ButtonDropdown from 'simple-react-bootstrap-button-dropdown'; const spreadClassNames = (userClassName, baseCssClasses) => `${baseCssClasses || ''} ${userClassName || ''}`; const NavBarForm = props => { let { className, style, ...rest } = props; return (
evt.preventDefault()} className={spreadClassNames(className, 'navbar-form')}> {props.children}
); }; const NavBarBrand = props => React.cloneElement(props.children, { className: 'navbar-brand', key: 'nav-bar-brand' }); const NavBarToggle = props => ; const NavBarHeader = props =>
{ React.Children.map(props.children, child => child.type === NavBarToggle ? React.cloneElement(child, {onClick: props.onClick, key: 'nav-bar-toggle'}) : child) }
; const NavBarItem = props => { let { disabled, className, href, children, ...rest } = props; return (
  • {children}
  • ); }; const NavBarDropdown = props => { let { toggleClassName, style, disabled, text, children, ...rest } = props; return ( {text} ); }; const Nav = props => ; class NavBar extends React.Component{ constructor(){ super(); this.state = { collapsed: true, heightExpanded: false, collapseHeight: null }; } toggleMobileCollapse(evt){ if (this._pendingAnimationClear){ clearTimeout(this._pendingAnimationClear); this._pendingAnimationClear = null; } if (this.state.expanded || this.state.expanding){ this.setState({ collapsing: true, collapseHeight: null, expanding: false, expanded: false }); this._pendingAnimationClear = setTimeout(() => { this.setState({ collapsing: false, collapseHeight: null }); this._cachedHeight = null; }, 300); } else { if (!this._cachedHeight) { let currentNode = evt.target, collapseContentToToggle; while (currentNode = currentNode.parentNode){ if (currentNode.tagName === 'DIV'){ collapseContentToToggle = currentNode.nextSibling; break; } } collapseContentToToggle.style.visibility = 'hidden'; collapseContentToToggle.classList.add('in'); let offsetHeight = collapseContentToToggle.offsetHeight; collapseContentToToggle.style.visibility = ''; collapseContentToToggle.classList.remove('in'); this._cachedHeight = offsetHeight; } this.setState({ collapsing: true, expanding: true }); setTimeout(() => this.setState({ collapseHeight: this._cachedHeight }), 2); this._pendingAnimationClear = setTimeout(() => this.setState({ collapsing: false, expanded: true, expanding: false }), 300); } } componentWillUnmount(){ clearTimeout(this._pendingAnimationClear); } render(){ let header = this.props.children.find(c => c.type === NavBarHeader), navSubItems = this.props.children.filter(filterValidNavSubItems); if (header) { header = React.cloneElement(header, {onClick: this.toggleMobileCollapse.bind(this)}); } return ( ); } } NavBar.Nav = Nav; NavBar.Item = NavBarItem; NavBar.Header = NavBarHeader; NavBar.Brand = NavBarBrand; NavBar.Toggle = NavBarToggle; NavBar.Dropdown = NavBarDropdown; NavBar.Form = NavBarForm; function filterValidNavSubItems(item){ return item.type !== NavBarHeader; } export default NavBar;