Add react links to nav bar
This commit is contained in:
27
common/app/components/Flash/Queue.jsx
Normal file
27
common/app/components/Flash/Queue.jsx
Normal file
@ -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 (
|
||||||
|
<Alert>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { messages = [] } = this.props;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{ this.renderMessages(messages) }
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
0
common/app/components/Flash/index.jsx
Normal file
0
common/app/components/Flash/index.jsx
Normal file
@ -1,4 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
|
import { LinkContainer } from 'react-router-bootstrap';
|
||||||
import {
|
import {
|
||||||
Col,
|
Col,
|
||||||
CollapsibleNav,
|
CollapsibleNav,
|
||||||
@ -11,16 +12,6 @@ import navLinks from './links.json';
|
|||||||
import FCCNavItem from './NavItem.jsx';
|
import FCCNavItem from './NavItem.jsx';
|
||||||
|
|
||||||
const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg';
|
const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg';
|
||||||
const navElements = navLinks.map((navItem, index) => {
|
|
||||||
return (
|
|
||||||
<NavItem
|
|
||||||
eventKey={ index + 1 }
|
|
||||||
href={ navItem.link }
|
|
||||||
key={ index }>
|
|
||||||
{ navItem.content }
|
|
||||||
</NavItem>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const logoElement = (
|
const logoElement = (
|
||||||
<a href='/'>
|
<a href='/'>
|
||||||
@ -39,18 +30,40 @@ const toggleButton = (
|
|||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
||||||
export default class extends React.Component {
|
export default React.createClass({
|
||||||
constructor(props) {
|
displayName: 'Nav',
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
static displayName = 'Nav'
|
propTypes: {
|
||||||
static propTypes = {
|
|
||||||
points: PropTypes.number,
|
points: PropTypes.number,
|
||||||
picture: PropTypes.string,
|
picture: PropTypes.string,
|
||||||
signedIn: PropTypes.bool,
|
signedIn: PropTypes.bool,
|
||||||
username: PropTypes.string
|
username: PropTypes.string
|
||||||
}
|
},
|
||||||
|
|
||||||
|
renderLinks() {
|
||||||
|
return navLinks.map(({ content, link, react }, index) => {
|
||||||
|
if (react) {
|
||||||
|
return (
|
||||||
|
<LinkContainer
|
||||||
|
eventKey={ index + 1 }
|
||||||
|
key={ content }
|
||||||
|
to={ link }>
|
||||||
|
<NavItem>
|
||||||
|
{ content }
|
||||||
|
</NavItem>
|
||||||
|
</LinkContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<NavItem
|
||||||
|
eventKey={ index + 1 }
|
||||||
|
href={ link }
|
||||||
|
key={ content }>
|
||||||
|
{ content }
|
||||||
|
</NavItem>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
renderPoints(username, points) {
|
renderPoints(username, points) {
|
||||||
if (!username) {
|
if (!username) {
|
||||||
@ -62,7 +75,7 @@ export default class extends React.Component {
|
|||||||
[ { points } ]
|
[ { points } ]
|
||||||
</NavItem>
|
</NavItem>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
|
||||||
renderSignin(username, picture) {
|
renderSignin(username, picture) {
|
||||||
if (username) {
|
if (username) {
|
||||||
@ -87,7 +100,7 @@ export default class extends React.Component {
|
|||||||
</FCCNavItem>
|
</FCCNavItem>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { username, points, picture } = this.props;
|
const { username, points, picture } = this.props;
|
||||||
@ -103,12 +116,12 @@ export default class extends React.Component {
|
|||||||
className='hamburger-dropdown'
|
className='hamburger-dropdown'
|
||||||
navbar={ true }
|
navbar={ true }
|
||||||
right={ true }>
|
right={ true }>
|
||||||
{ navElements }
|
{ this.renderLinks() }
|
||||||
{ this.renderPoints(username, points)}
|
{ this.renderPoints(username, points) }
|
||||||
{ this.renderSignin(username, picture) }
|
{ this.renderSignin(username, picture) }
|
||||||
</Nav>
|
</Nav>
|
||||||
</CollapsibleNav>
|
</CollapsibleNav>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
@ -4,11 +4,14 @@ import BootstrapMixin from 'react-bootstrap/lib/BootstrapMixin';
|
|||||||
|
|
||||||
export default React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'FCCNavItem',
|
displayName: 'FCCNavItem',
|
||||||
|
|
||||||
mixins: [BootstrapMixin],
|
mixins: [BootstrapMixin],
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
active: React.PropTypes.bool,
|
active: React.PropTypes.bool,
|
||||||
'aria-controls': React.PropTypes.string,
|
'aria-controls': React.PropTypes.string,
|
||||||
|
children: React.PropTypes.node,
|
||||||
|
className: React.PropTypes.string,
|
||||||
disabled: React.PropTypes.bool,
|
disabled: React.PropTypes.bool,
|
||||||
eventKey: React.PropTypes.any,
|
eventKey: React.PropTypes.any,
|
||||||
href: React.PropTypes.string,
|
href: React.PropTypes.string,
|
||||||
@ -30,7 +33,11 @@ export default React.createClass({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!this.props.disabled) {
|
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
|
...props
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
let classes = {
|
const linkClassName = classNames(className, {
|
||||||
active,
|
// 'active': active, we don't actually use the active class
|
||||||
disabled
|
// but it is used for a11y below
|
||||||
};
|
'disabled': disabled
|
||||||
|
});
|
||||||
|
|
||||||
let linkProps = {
|
let linkProps = {
|
||||||
role,
|
role,
|
||||||
@ -75,9 +83,9 @@ export default React.createClass({
|
|||||||
role='presentation'>
|
role='presentation'>
|
||||||
<a
|
<a
|
||||||
{ ...linkProps }
|
{ ...linkProps }
|
||||||
aria-selected={ active }
|
|
||||||
aria-controls={ ariaControls }
|
aria-controls={ ariaControls }
|
||||||
className={ className }>
|
aria-selected={ active }
|
||||||
|
className={ linkClassName }>
|
||||||
{ children }
|
{ children }
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -9,5 +9,6 @@
|
|||||||
"link": "/news"
|
"link": "/news"
|
||||||
},{
|
},{
|
||||||
"content": "Jobs",
|
"content": "Jobs",
|
||||||
"link": "/jobs"
|
"link": "/jobs",
|
||||||
|
"react": true
|
||||||
}]
|
}]
|
||||||
|
Reference in New Issue
Block a user