require('./nav.less'); const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); const Nav = { base : createClass({ displayName : 'Nav.base', render : function(){ return ; } }), logo : function(){ return NaturalCrit ; }, section : createClass({ displayName : 'Nav.section', render : function(){ return
{this.props.children}
; } }), item : createClass({ displayName : 'Nav.item', getDefaultProps : function() { return { icon : null, href : null, newTab : false, onClick : function(){}, color : null }; }, handleClick : function(){ this.props.onClick(); }, render : function(){ const classes = cx('navItem', this.props.color, this.props.className); let icon; if(this.props.icon) icon = ; const props = _.omit(this.props, ['newTab']); if(this.props.href){ return {this.props.children} {icon} ; } else { return
{this.props.children} {icon}
; } } }), dropdown : createClass({ displayName : 'Nav.dropdown', getInitialState : function() { return { showDropdown : false }; }, handleDropdown : function(show){ this.setState({ showDropdown : show }); }, renderDropdown : function(dropdownChildren){ if(!this.state.showDropdown) return null; return (
{dropdownChildren}
); }, render : function () { const dropdownChildren = React.Children.map(this.props.children, (child, i)=>{ // Ignore the first child if(i < 1) return; return child; }); return (
this.handleDropdown(true)} onMouseLeave={()=>this.handleDropdown(false)}> {this.props.children[0]} {this.renderDropdown(dropdownChildren)}
); } }) }; module.exports = Nav;