From 7ac7a4ccfcc8c35d91f7e8b441c6b93fc0112b40 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 27 Oct 2015 15:40:04 -0700 Subject: [PATCH] Add react links to nav bar --- common/app/components/Flash/Queue.jsx | 27 +++++++++++++ common/app/components/Flash/index.jsx | 0 common/app/components/Nav/Nav.jsx | 57 ++++++++++++++++----------- common/app/components/Nav/NavItem.jsx | 22 +++++++---- common/app/components/Nav/links.json | 3 +- 5 files changed, 79 insertions(+), 30 deletions(-) create mode 100644 common/app/components/Flash/Queue.jsx create mode 100644 common/app/components/Flash/index.jsx diff --git a/common/app/components/Flash/Queue.jsx b/common/app/components/Flash/Queue.jsx new file mode 100644 index 0000000000..718733a923 --- /dev/null +++ b/common/app/components/Flash/Queue.jsx @@ -0,0 +1,27 @@ +import React, { createClass, PropTypes } from 'react'; +import { Alert } from 'react-bootstrap'; + +export default createClass({ + displayName: 'FlashQueue', + + propTypes: { + messages: PropTypes.array + }, + + renderMessages(messages) { + return messages.map(message => { + return ( + + ); + }); + }, + + render() { + const { messages = [] } = this.props; + return ( +
+ { this.renderMessages(messages) } +
+ ); + } +}); diff --git a/common/app/components/Flash/index.jsx b/common/app/components/Flash/index.jsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/common/app/components/Nav/Nav.jsx b/common/app/components/Nav/Nav.jsx index ad7f81f7b8..a199d0a539 100644 --- a/common/app/components/Nav/Nav.jsx +++ b/common/app/components/Nav/Nav.jsx @@ -1,4 +1,5 @@ import React, { PropTypes } from 'react'; +import { LinkContainer } from 'react-router-bootstrap'; import { Col, CollapsibleNav, @@ -11,16 +12,6 @@ import navLinks from './links.json'; import FCCNavItem from './NavItem.jsx'; const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg'; -const navElements = navLinks.map((navItem, index) => { - return ( - - { navItem.content } - - ); -}); const logoElement = ( @@ -39,18 +30,40 @@ const toggleButton = ( ); -export default class extends React.Component { - constructor(props) { - super(props); - } +export default React.createClass({ + displayName: 'Nav', - static displayName = 'Nav' - static propTypes = { + propTypes: { points: PropTypes.number, picture: PropTypes.string, signedIn: PropTypes.bool, username: PropTypes.string - } + }, + + renderLinks() { + return navLinks.map(({ content, link, react }, index) => { + if (react) { + return ( + + + { content } + + + ); + } + return ( + + { content } + + ); + }); + }, renderPoints(username, points) { if (!username) { @@ -62,7 +75,7 @@ export default class extends React.Component { [ { points } ] ); - } + }, renderSignin(username, picture) { if (username) { @@ -87,7 +100,7 @@ export default class extends React.Component { ); } - } + }, render() { const { username, points, picture } = this.props; @@ -103,12 +116,12 @@ export default class extends React.Component { className='hamburger-dropdown' navbar={ true } right={ true }> - { navElements } - { this.renderPoints(username, points)} + { this.renderLinks() } + { this.renderPoints(username, points) } { this.renderSignin(username, picture) } ); } -} +}); diff --git a/common/app/components/Nav/NavItem.jsx b/common/app/components/Nav/NavItem.jsx index eec245e7d8..383a7a646e 100644 --- a/common/app/components/Nav/NavItem.jsx +++ b/common/app/components/Nav/NavItem.jsx @@ -4,11 +4,14 @@ import BootstrapMixin from 'react-bootstrap/lib/BootstrapMixin'; export default React.createClass({ displayName: 'FCCNavItem', + mixins: [BootstrapMixin], propTypes: { active: React.PropTypes.bool, 'aria-controls': React.PropTypes.string, + children: React.PropTypes.node, + className: React.PropTypes.string, disabled: React.PropTypes.bool, eventKey: React.PropTypes.any, href: React.PropTypes.string, @@ -30,7 +33,11 @@ export default React.createClass({ e.preventDefault(); if (!this.props.disabled) { - this.props.onSelect(this.props.eventKey, this.props.href, this.props.target); + this.props.onSelect( + this.props.eventKey, + this.props.href, + this.props.target + ); } } }, @@ -50,10 +57,11 @@ export default React.createClass({ ...props } = this.props; - let classes = { - active, - disabled - }; + const linkClassName = classNames(className, { + // 'active': active, we don't actually use the active class + // but it is used for a11y below + 'disabled': disabled + }); let linkProps = { role, @@ -75,9 +83,9 @@ export default React.createClass({ role='presentation'> + aria-selected={ active } + className={ linkClassName }> { children } diff --git a/common/app/components/Nav/links.json b/common/app/components/Nav/links.json index 4baea28e78..175e5170cf 100644 --- a/common/app/components/Nav/links.json +++ b/common/app/components/Nav/links.json @@ -9,5 +9,6 @@ "link": "/news" },{ "content": "Jobs", - "link": "/jobs" + "link": "/jobs", + "react": true }]