Files
freeCodeCamp/common/app/components/Nav/Nav.jsx

128 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-07-24 21:54:19 -07:00
import React, { PropTypes } from 'react';
2015-10-27 15:40:04 -07:00
import { LinkContainer } from 'react-router-bootstrap';
2015-07-23 22:58:44 -07:00
import {
Col,
Nav,
NavbarBrand,
2015-07-23 22:58:44 -07:00
Navbar,
NavItem
} from 'react-bootstrap';
import navLinks from './links.json';
import FCCNavItem from './NavItem.jsx';
2015-06-04 10:53:01 -07:00
const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg';
const logoElement = (
<a href='/'>
<img
alt='learn to code javascript at Free Code Camp logo'
className='img-responsive nav-logo'
src={ fCClogo } />
</a>
);
const toggleButtonChild = (
2016-01-27 11:34:44 -08:00
<Col xs={ 12 }>
<span className='hamburger-text'>Menu</span>
</Col>
2015-07-23 22:58:44 -07:00
);
2016-01-27 11:34:44 -08:00
export default class extends React.Component {
static displayName = 'Nav';
2015-06-04 10:53:01 -07:00
2016-01-27 11:34:44 -08:00
static propTypes = {
2015-07-24 21:54:19 -07:00
points: PropTypes.number,
picture: PropTypes.string,
signedIn: PropTypes.bool,
username: PropTypes.string
2016-01-27 11:34:44 -08:00
};
2015-10-27 15:40:04 -07:00
renderLinks() {
return navLinks.map(({ content, link, react, target }, index) => {
2015-10-27 15:40:04 -07:00
if (react) {
return (
<LinkContainer
eventKey={ index + 1 }
key={ content }
to={ link }>
2015-11-13 12:54:46 -08:00
<NavItem
target={ target || null }>
2015-10-27 15:40:04 -07:00
{ content }
</NavItem>
</LinkContainer>
);
}
return (
<NavItem
eventKey={ index + 1 }
href={ link }
2015-11-13 12:54:46 -08:00
key={ content }
target={ target || null }>
2015-10-27 15:40:04 -07:00
{ content }
</NavItem>
);
});
2016-01-27 11:34:44 -08:00
}
2015-06-04 10:53:01 -07:00
2015-07-24 21:54:19 -07:00
renderPoints(username, points) {
if (!username) {
return null;
}
return (
<FCCNavItem
className='brownie-points-nav'
2015-07-24 21:54:19 -07:00
href={ '/' + username }>
[ { points } ]
</FCCNavItem>
2015-07-24 21:54:19 -07:00
);
2016-01-27 11:34:44 -08:00
}
2015-07-24 21:54:19 -07:00
renderSignin(username, picture) {
if (username) {
2015-06-04 10:53:01 -07:00
return (
<li
className='hidden-xs hidden-sm avatar'
2015-06-04 10:53:01 -07:00
eventKey={ 2 }>
2015-07-24 21:54:19 -07:00
<a href={ '/' + username }>
2015-07-28 11:18:11 -07:00
<img
className='profile-picture float-right'
src={ picture } />
2015-07-24 21:54:19 -07:00
</a>
</li>
2015-06-04 10:53:01 -07:00
);
} else {
return (
<NavItem
2015-06-04 10:53:01 -07:00
eventKey={ 2 }
2016-05-03 15:06:20 +00:00
href='/signin'>
2015-06-17 21:04:28 -07:00
Sign In
</NavItem>
2015-06-04 10:53:01 -07:00
);
}
2016-01-27 11:34:44 -08:00
}
2015-06-04 10:53:01 -07:00
2015-06-17 21:04:28 -07:00
render() {
2015-07-24 21:54:19 -07:00
const { username, points, picture } = this.props;
2015-11-19 22:45:31 -08:00
2015-06-04 10:53:01 -07:00
return (
<Navbar
2015-06-17 21:04:28 -07:00
className='nav-height'
fixedTop={ true }>
<NavbarBrand>{ logoElement }</NavbarBrand>
<Navbar.Toggle children={ toggleButtonChild } />
<Navbar.Collapse eventKey={ 0 }>
2015-07-24 21:54:19 -07:00
<Nav
className='hamburger-dropdown'
navbar={ true }
pullRight={ true }>
2015-10-27 15:40:04 -07:00
{ this.renderLinks() }
{ this.renderPoints(username, points) }
2015-07-24 21:54:19 -07:00
{ this.renderSignin(username, picture) }
</Nav>
</Navbar.Collapse>
2015-06-04 10:53:01 -07:00
</Navbar>
);
}
2016-01-27 11:34:44 -08:00
}